Reading through Maximum PC’s list of 50 skills every real geek should have I noticed ‘Downloading flash video’ from sites like YouTube was on the list. So, cunningly avoiding the many easy ways to do it, I decided to put together a quick shell script, after all it can’t be that hard, you just need to look at the HTTP headers…
Well it turns out YouTube don’t make it that easy, but after a bit of prodding I ended up with something that will at least save a YouTube video to an flv file:
This will probably only work till the YouTube site changes, so if it’s broken blame them and not my shoddy coding
I’ve been hunting around for a shell script to download the XKCD archives, but pretty much everything I’ve found has either done loads of redundant downloads, required too much interaction, broken on the missing comic #404 or some other issue.
In the end I decided it would be quicker to write something myself. I normally post my shell stuff on http://www.shell-fu.org/, but this is a bit long to go there really, so incase it’s useful to anyone else, I’m posting it here:
To use the script, just change the directory at the top and run. You can re-run the script later on and it will fetch any new comics you’ve not already got (for example it can be run as a weekly cron job).
Any bugs, please let me know in the comments.
Quite a few of the tips that get submitted on shell-fu.org aren’t that useful if you need to remember them, but are just the thing to put in your bashrc as aliases or functions. With that in mind I decided to put together a full .bashrc using the best submissions:
Feel free to use this however you like, though I’d recommend reading through it to get some idea of what each alias/function does before you use it.
I’ve tested this on my Debian system and all worked well but if you have issues on another platform, please let me know.
Only 6 months after everyone else, I noticed Nat Friedman’s Tweetable Script Challenge, and inspired by his bubble-sort I thought I’d try for a bash quicksort in under 140 characters.
So now I present, probably the most pointless code I’ve ever written (okay, that’s definitely not true, but still ):
s=`shuf -i1-9`;q(){ l=;g=;[ $# -lt 2 ]&&echo $@||(for n in ${@:2};do [ $n -gt $1 ]&&g=”$g$n “||l=”$l$n “;done;echo `q $l` $1 `q $g`;)};q $s
(You’ll need to remove line breaks for it to (hopefully) work)
As someone kindly pointed out, “It prints out the numbers 1 to 9, er, wow!”.