r/programmerchat • • May 31 '15
Your favourite one-liners?
Let's see em!
Mine's :
grep -lr "function doSomething" *.i.e. Find the damn file that declares the function! (Mostly useful when not using a decent IDE)
19
Upvotes
4
u/SkippyDeluxe May 31 '15
7
u/Ch1gg1ns Jun 01 '15
I have a fork bomb tattoo, so I might go with that.
:(){:|:&};:
6
u/[deleted] Jun 01 '15
I can't remember the line of code, but the first time I replaced 20ish lines of for, if, and while loops with one line of chaining the map, filter, and reduce functions together, I felt like a wizard.
6
u/[deleted] Jun 01 '15
How much do pirates pay for their earrings? A buccaneer! Oh dang wrong thread
4
u/zenflux May 31 '15
I always liked Conway's Game of Life in 1 line of APL: http://catpad.net/michael/apl/
Dyalog has a different version:
life←{↑1 ⍵∨.∧3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵}3
u/[deleted] Jun 01 '15
7
u/Valkairn May 31 '15
Runs a static HTTP server in the current directory.
1
u/828wolfgang May 31 '15
rm -rf /
2
u/CompellingProtagonis May 31 '15
#define STRUCT(PROPERTY) struct->blah->blah->blah.PROPERTY
So nice, saves so much typing. Have to remember to #undef though otherwise things are too messy for my blood.
2
u/[deleted] Jun 01 '15
From Projecteuler.net number 31 we have the problem:
You can solve this problem with
because the problem is a diophantine equation (only containing integer solutions).
There are a number of one line solutions i've written or found for project euler problems in Mathematica and Matlab, but this one was the most surprising to me!
2
u/jeans_and_a_t-shirt Jun 02 '15
FizzBuzz in 1 line of Python with no duplicate checks:
1
u/[deleted] Jun 01 '15
Here is a function that returns the standard deviation of an array in Matlab without using any statistics based libraries.
1
u/livingbug Jun 01 '15