Interesting Code Snippets: No‑Code Project, Shuffle Algorithm, Sleep Sort, Simple AI Loop, Fast Inverse Square Root and More
This article showcases a collection of intriguing code examples—including a no‑code GitHub project, a two‑line shuffle algorithm, the sleep‑sort technique, a minimal AI loop, a fast inverse‑square‑root constant, and a basic hello‑world snippet—while also containing promotional messages.
1. No code
Project address: https://github.com/kelseyhightower/nocode . This GitHub repository, currently with 34k stars, claims to provide a fully automatic, cross‑platform tool that requires no source code to deploy, compile, package, install, and run.
2. Shuffle algorithm
The following two‑line code generates a uniformly random permutation of n elements, ensuring each element has equal probability of appearing in any position.
for(int i = n - 1; i >= 0; i--)
// rand(0, i) generates a random integer in [0, i]
swap(arr[i], arr[rand(0, i)])3. Sleep sort
This method creates n threads, each associated with one of the numbers to be sorted; each thread sleeps for a duration proportional to its number and then prints the number, resulting in an ordered output.
public class SleepSort {
public static void main(String[] args) {
int[] ints = {1,4,7,3,8,9,2,6,5};
SortThread[] sortThreads = new SortThread[ints.length];
for(int i = 0; i < sortThreads.length; i++) {
sortThreads[i] = new SortThread(ints[i]);
}
for(int i = 0; i < sortThreads.length; i++) {
sortThreads[i].start();
}
}
}
class SortThread extends Thread {
int ms = 0;
public SortThread(int ms) { this.ms = ms; }
public void run() {
try { sleep(ms*10+10); } catch(InterruptedException e) { e.printStackTrace(); }
System.out.println(ms);
}
}4. AI core code
A minimal interactive loop that reads input, removes Chinese question particles, and prints the transformed string; presented as a “billion‑yuan AI core” example.
while True:
print(input('').replace('吗','').replace('?','!'))5. Get next‑day time
Simple Java snippet that pauses the current thread for one day.
// talent talent
thread.sleep(86400*1000L);6. 0x5f375a86
The article discusses the famous fast inverse‑square‑root constant used in graphics engines (originally 0x5f3759df) and mentions alternative values such as 0x5f37642f and 0x5f375a86, referencing the underlying algorithm and its mysterious origin.
7. Hello world
Every programmer eventually writes a “Hello World” program, regardless of language.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.