More Tweetable Scripts
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.
Gaute Lindkvist on 27 April 2008 at 9:00 am
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?
nat on 27 April 2008 at 1:19 pm
You mean the parentheses in “for((i=0;i<15;i+=2))” ? In bash you do need two there.
Aaron Bockover on 27 April 2008 at 3:12 pm
139 characters:
s=`seq 9|shuf`;while :;do for((i=0;i
Aaron Bockover on 27 April 2008 at 3:13 pm
Word Press FTL! It at the < in my sweet shortenization!
knipknap on 27 April 2008 at 3:31 pm
[ $a -gt $b ]
may be replaced by
[ $a \> $b ]
Mitch on 27 April 2008 at 3:52 pm
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″
Mitch on 27 April 2008 at 4:00 pm
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
Mitch on 27 April 2008 at 5:36 pm
one more byte for you: “s:0:i” can be replaced with “s::i”
Felipe Kellermann on 27 April 2008 at 5:45 pm
Hello. You could replace the “;do …;done” with “;{…;}”, as this is supported on “modern” shells like bash and zsh… “for ((;i
danw on 28 April 2008 at 9:11 am
I can’t believe no one has posted something like this yet:
eval `echo eGRnLW9wZW4gaHR0cDovL3Rpbnl1cmwuY29tLzJnOW1xaA== | openssl enc -d -a`
TheMatt on 28 April 2008 at 11:18 am
danw gets a gold medal from me. I suspected what it would do…and yet I just had to do it.
nat on 28 April 2008 at 11:20 pm
@danw – Glorious!
TOM POTTER on 6 April 2009 at 12:42 am
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
TOM POTTER on 6 April 2009 at 12:49 am
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.
Pingback from more comments on Apple, and other stuff « whileloop on 4 August 2009 at 7:42 am