views:

2117

answers:

34

As an example I offer this, which was used to clear the screen in COBOL.

DISPLAY SPACES UPON CRT
+18  A: 

while (true) System.out.println("SO isn't really meant for open-ended questions like this.");

This little one-liner kills the discussion.

(Sorry for the snarkiness, I think it's time for me to go home.)

jacobko
+1  A: 

From the Python FAQ

print map(lambda x,f=lambda x,f:(x<=1) or (f(x-1,f)+f(x-2,f)): f(x,f),range(10))
mreggen
As much as I love Python, this is nothing more than a not-so-elegant piece of functional programming.
Yuval A
+12  A: 
<td align="right" style="text-align: left">

It's a tug of war!

Erick B
It would be interesting to find out if different browsers put more priority of one verses the other.
Brad Gilbert
Priority is determined by the rules of the "cascade" in Cascading Style Sheets. I believe inline style attributes on the tag have the highest priority.
Quinn Taylor
A: 

This question reminds me of the site The Daily WTF. Check it out if you've never heard of it before.

Patrik
Worse Than Failure rules. Been on my RSS list for ages now.
schonarth
I don't think it's called "Worse Than Failure" any more. It was briefly called that but changed back to its original name of "The Daily WTF".
Simon Howard
A: 
toilet.flush if toilet.full?
Brian Warshaw
+2  A: 

My favorite bash script thingy. Originally written by http://twitter.com/jf

curl -Is slashdot.org | egrep '^X-(F|B|L)' | cut -d \- -f 2
icco
Unfortunately that misses the rare quotes from other characters. X-Leela: This is by a wide margin the least likely thing that has ever happened.
Jeremy Banks
I never noticed those. This should be easy enough to modify though to grab those as well. Support for Leila, Zoidberg, the Professor. etc.
icco
Ok so I went through it, they've only add Leila recently (i can see with the blank lines in my logs :p) I've updated my one liner to include Leila. There are no other characters, yet.
icco
+3  A: 

...to steal some ThinkGeek swag:

rm -rf /bin/laden

Dillie-O
A: 

This is not super complex but I've always been charmed by this method of unbuffering IO on a file handle in perl without changing the currently selected file handle (er, technically it does change it, but it changes it back and you don't have to know what the currently selected file handle is)

select((select(SOMEFILEHANDLE), $| = 1)[0]);
jj33
+11  A: 

For me, it must be the Jaromil bash forkbomb, looks like a poem :)

:(){ :|:& };:

This is an explanation of the Jaromil program

Also, the more concise Windows shell forkbomb is a sure winner in any golf match:

%0|%0
PabloG
+23  A: 

It's not really strange, but one bit of code that I've always found particularly amusing decrementing a value and checking it as it approaches zero, e.g.

while(foo-->0)
{
    //...
}
CodeninjaTim
I particularly like the imagery there - it looks like an arrow, which could mean "as foo approaches zero" - precisely what it is doing.
JTeagle
I use that in my code, actually. =]
strager
This is...what...this is extraordinary.
Justin L.
+16  A: 
//&>/dev/null;x="${0%.*}";[ ! "$x" -ot "$0" ]||(rm -f "$x";cc -o "$x" "$0")&&"$x" $*;exit

I'd call this the most useful. I put this at the top of any simple single-file C scripts, so that I can execute them directly. It compiles if necessary and calls the executable, passing on any parameters.

Jeremy Banks
That's a joke, right? I mean, this is too amazing to be not a joke.
Bobby
I haven't tested it outside of Bash, but it works there, yeah. It's just a short shell script doing what's needed. I've explained it a little here: http://gist.github.com/448040
Jeremy Banks
How do you use this? Please provide a simple example.
Hamish Grubijan
I'm uploaded a quick video demonstration here: http://youtu.be/xLenYHg7Bek
Jeremy Banks
+1  A: 

This is on all my forum signitures:

$me->selfDestruct('NOW');

or the ocassional

if($work.status == 'done'){ takeBreak(TRUE); }

however it always evaluates to false.

Unkwntech
+1  A: 

I don't know why but it has always tickled me when I run across this.

my @lines = map ( /:\s+(\S*)\s*$/, grep ( /Name/, <> ));");
krujos
+7  A: 

My personal favorite I met in Schneier's "Applied Cryptography", to swap two integers:

x ^= y; y^= x; x^=y;

that's a classic
Hugo
+11  A: 
/* no comment */
Mo
// no comment here, move along
Myrrdyn
+5  A: 

I always thought

while ((*dst++ = *src++) != '\0');

was an interesting use of pointers to copy a string.

dlannoye
+5  A: 

A perl-regexp to check if a number is prime:

 print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/

(I would like to give credit for this one, but I can't remember who actually dicovered it - not me)

Mo
+12  A: 

Best I ever saw was someone's sig on usenet that was a couple of lines of ob-C that generated the mandlebrot set. it was freaking cool:

~~~~~~~~~~~~~}}}}}}}}}}}}}}}}}}}}||||||||{{{zyvrwuW{|||||}}}}}}~~~~~~~~~~~~
~~~~~~~~~~}}}}}}}}}}}}}}}}}}}}|||||||||{{{zyxwoaqwxz{{{|||||}}}}}}~~~~~~~~~
~~~~~~~~}}}}}}}}}}}}}}}}}}}|||||||||{{zzzyxvn    Knwyz{{{{||||}}}}}}~~~~~~~
~~~~~~}}}}}}}}}}}}}}}}}}||||||||{{zyxuxxxwvuq     svwwyzzzyr{||}}}}}}}~~~~~
~~~~}}}}}}}}}}}}}}}}}|||||{{{{{zzzxt>  qf             pttfqeqz{|}}}}}}}}~~~
~~~}}}}}}}}}}}}}}|||{{{{{{{{{zzzywotn                     atyz{||}}}}}}}}~~
~~}}}}}}}}}||||{{zwvyyyyyyyyyyyxvsP                        swvz{||}}}}}}}}~
~}}}}|||||||{{{{zyxvpN[ur]spvwwvi                           qxz{|||}}}}}}}}
~}||||||||{{{{{zyytun         qq                            avz{|||}}}}}}}}
~||||||{zzzzyyxtroqb           a                            xz{{|||}}}}}}}}
[email protected]::# 6# (                                              pvxyz{{||||}}}}}}}
~||||||{zzzzyyxtroqb           a                            xz{{|||}}}}}}}}
~}||||||||{{{{{zyytun         qq                            avz{|||}}}}}}}}
~}}}}|||||||{{{{zyxvpN[ur]spvwwvi                           qxz{|||}}}}}}}}
~~}}}}}}}}}||||{{zwvyyyyyyyyyyyxvsP                        swvz{||}}}}}}}}~
~~~}}}}}}}}}}}}}}|||{{{{{{{{{zzzywotn                     atyz{||}}}}}}}}~~
~~~~}}}}}}}}}}}}}}}}}|||||{{{{{zzzxt>  qf             pttfqeqz{|}}}}}}}}~~~
~~~~~~}}}}}}}}}}}}}}}}}}||||||||{{zyxuxxxwvuq     svwwyzzzyr{||}}}}}}}~~~~~
~~~~~~~~}}}}}}}}}}}}}}}}}}}|||||||||{{zzzyxvn    Knwyz{{{{||||}}}}}}~~~~~~~
~~~~~~~~~~}}}}}}}}}}}}}}}}}}}}|||||||||{{{zyxwoaqwxz{{{|||||}}}}}}~~~~~~~~~
~~~~~~~~~~~~~}}}}}}}}}}}}}}}}}}}}||||||||{{{zyvrwuW{|||||}}}}}}~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~}}}}}}}}}}}}}}}}}}}}}|||||{zmt{{{||||}}}}}~~~~~~~~~~~~~~~~

Source that does it:

main(){float A,B,P,Q,X,Y,d;int i,D=80,n=3120;for(X=-2.,Y=-1.5,d=6./D;B=2*A
*B+Y,A=P-Q+X,n;((P=A*A)+(Q=B*B)>4||++i>D)&&putchar(*((n--%D?X+=d/2,i<D?i%11
:11:(X=-2.0,Y+=d,12))+"Mandelbrot! \n"))&&(A=B=P=Q=i=0));}
MikeJ
does that really count as a one-liner?
Viktor Sehr
this is too cool.
Justin L.
+4  A: 
cd /pub
more beer
Yaba
+1  A: 
//For each inventory that is a sofa and has a comfortclass, test sleeping in it, and if you like it save it to the wishList.
wishList = inventories.match({type: "Sofa", comfortClass: required}).forEach(testSleepInObjectFunction);

Elegant, eigh? Soon it's gonna be possible in C# too!!!

Hugo
A: 

$Completed = AskUserWhatTheyWantAndTakeCareOfIt();

Eli
A: 
Console.WriteLine("Hello World!");

It ensures that your system is set up properly and ready for any programming action!

Adrian Godong
Except that won't compile. You need more code to actually make it compile and run.
jasonh
Hmm... strange. I'm quite sure I wasn't answering this question but a different duplicate.
Adrian Godong
+5  A: 

Truncate Table

One line of SQL can do so much damage to data that would take many programs hundreds of lines of code.

Kevin
+1  A: 
mvn clean compile sonar:sonar
Mercer Traieste
+1  A: 
return 0;

It doesn't get better than that

jtbradle
A: 
rm -rf *.*
PSU_Kardi
I just use "rm -rf *". That way, I blow away all the files that don't have periods in the name also. It's even better when it starts with "cd /".
David Thornley
or, `rm -rf /`
nik
A: 
chdir %windir%
Chalkey
+2  A: 
make

Short and to the point.

balpha
A: 
Arrays.sort(somearray)
kd304
A: 

When I used ASP classic a lot, I was always frustrated that there was no floor/ceiling functions available. int works for floor, but there was no built-in ceiling, until I somehow, somewhere, I figured this out:

ceilOfX = -int -x

I always thought that was an elegant one-liner.

mgroves
A: 
if (this == null) return;

I tend to see some kind of poetry in that line. (I've actually ran across it)

Viktor Sehr
+1  A: 

From the unix C shell...

$ ar x God

ar: God does not exist
Mike Howard
A: 

C++ Interview question.

  1. What does the following line do. C++;
martsbradley
A: 

I've always found interesting how IBM i RPG declares its files:

 FSOMEFILE  UF A E           K Disk    UsrOpn Commit

Declares the externally described disk file SOMEFILE for Input/Update/Write with keyed access, user-controlled open and commitment control.

ASalazar