Neat Programming Tricks

Computer Alchemy
Ken Thompson wrote an article called 'Reflections on Trusting Trust' in 1995 about the occult science of self-reproducing programs, and using them to hide trojan horses in source code that does not exist. This article made me remember my original fascination of computer science as a weird science that creates magic from secret spells and incantations. Read at your own discretion, the text is dangerous and may cause nightmares, hallucinations, or worse.

Meta-programming
Ruby quine: b='puts "b=!#{b}!";puts b.gsub(33.chr,39.chr)' puts "b='#{b}'";puts b.gsub(33.chr,39.chr) Save to 'test.rb' and test with: diff -s <(ruby test.rb) test.rb

ASCII Art



 * See how to create beautiful ASCII Art with Ruby, Python or C++.
 * Or perhaps use Python from the Vim editor to draw directly in your source code?

Music
This example shows how to play a tune on a Windows box using the winsound module for Python.

Obfuscation
This C program: main  {char x[13] ;int n=0;       x[5] =32; for(n<4   ;n++               ){x[      n*3+1+(n               >2)]            =n+65 ;x[          (n*2              +8)% 12]=         n+72              ;x[n *3+3       ]=(n   <3?(       n*4+ 2)%10+77:0)      ;}puts(x);}
 * 1) include 

Outputs:

JAKOB SCHMID

Here's the old and ugly version:

main {char _[13] ;int   n=0; _[ 5] =0x20;for (n<4;n ++){_[n*3+1+(n>2) ]=n+65;_[ (n*2+8)% 12]=n+72;_[n*3+3] =(n<3?(n*4+2)%10+ 77:0);}puts (_);}
 * 1) include 