Nat Friedman

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.

27 April 2008
Show comments
  1. 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?

    Reply

  2. You mean the parentheses in “for((i=0;i<15;i+=2))” ? In bash you do need two there.

    Reply

  3. 139 characters:

    s=`seq 9|shuf`;while :;do for((i=0;i

    Reply

  4. Word Press FTL! It at the < in my sweet shortenization!

    Reply

  5. [ $a -gt $b ]

    may be replaced by

    [ $a \> $b ]

    Reply

  6. 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″

    Reply

  7. 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

    Reply

  8. one more byte for you: “s:0:i” can be replaced with “s::i”

    Reply

  9. Hello. You could replace the “;do …;done” with “;{…;}”, as this is supported on “modern” shells like bash and zsh… “for ((;i

    Reply

  10. I can’t believe no one has posted something like this yet:

    eval `echo eGRnLW9wZW4gaHR0cDovL3Rpbnl1cmwuY29tLzJnOW1xaA== | openssl enc -d -a`

    Reply

  11. danw gets a gold medal from me. I suspected what it would do…and yet I just had to do it.

    Reply

  12. @danw – Glorious!

    Reply

  13. 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 :)

    Reply

  14. 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.

    Reply


Copyright © 1998 - 2011 Nat Friedman