A few more tweetable commandlines have emerged since I posted the last round-up.
From pupitetris, this little work of art:
a=1;for i in {1..34};do printf %$[40-${#a}]s"$(eval $(echo $a*$a|bc|sed 's/$/0/;s/\([0-9]\)/tput setab \1; echo -n \\ ;/g'))"\\n;a=1$a;done
This Linux-desktop specific commandline from Justin:
s=.o0O0o.o0O0o.o0O0o.o0O0o.o0O0o.o0O0o.o0;n(){ for x in `seq $1 $2 $3`;do notify-send ${s:0:x}; done };while :;do n 1 2 39;n 39 -2 1;done
And I wrote these two:
clear;for x in {0..150}; do y=`echo "12+6*s($x/6)"|bc -l|cut -d. -f 1`;echo -en \\e[$y\;"$(($x/2))"HX; sleep .1;done
s=`seq 9|shuf`;while :;do for((i=0;i<15;i+=2));do echo $s;a=${s:i:1};b=${s:i+2:1};[ $a -gt $b ]&&s=${s:0:i}$b\ $a${s:i+3};sleep .2;done;done
That last one is a bubble-sort implementation in 140 characters. Unfortunately, 140 characters is one character too many for a twitter post. Can you figure out how to shave off a character or two? (You’ll need a recent version of coreutils for shuf).
Thanks to some helpful hints in the comments (abock, knipknap, Mitch) we’re down to 137 chars:
s=`shuf -i1-9`;while i=;do for((;i<15;i+=2));do echo $s;a=${s:i:1};b=${s:i+2:1};[ $a \> $b ]&&s=${s:0:i}$b\ $a${s:i+3};sleep .2;done;done
I’ll be posting more on twitter as people send them in.
Posted on 27 April 2008
- Leave a comment
- Subscribe with Google Reader
- Follow me on Twitter
Did you like this article?
-
Don’t you have redundant brackets surrounding the for look in the bubble sort implementation? If you remove one set of brackets it should fit, no?
-
Here’s one byte saved — change the “while :” to “while i=0″ (which will also evaluate to true) and then you can remove the “i=0″ from the for(()) loop. As a bonus, it makes the script even less understandable since people will parse it as “while i==0″
-
Oh, and here’s another byte you can save: replace the “i=0″ with just “i=” An empty string will be taken as zero in bash arithmetic
-
one more byte for you: “s:0:i” can be replaced with “s::i”
-
Hello. You could replace the “;do …;done” with “;{…;}”, as this is supported on “modern” shells like bash and zsh… “for ((;i
-
I can’t believe no one has posted something like this yet:
eval `echo eGRnLW9wZW4gaHR0cDovL3Rpbnl1cmwuY29tLzJnOW1xaA== | openssl enc -d -a`
-
Absolutely amazing Tweeter scripts here. Sorry to say that I don’t have many but I promise I’ll surely share one here if I find some script that’s interesting enough. Thanks a lot for sharing these scripts. And yeah, HATS OFF to danw from me too.
Happy tweeting everyone
-
Please accept my apologies for the typing mistake in my comment above. I typed “many” instead of “any” in the second sentence for my comment above, which is:
“Sorry to say that I don’t have many but I promise I’ll surely share one here if I find some script that’s interesting enough.”Hope everyone here’s generous enough to forgive this little typing error. Thanks in advance for understanding.

15 comments