Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts

Tuesday, 5 May 2015

How to grab every mp3 from a Feedburner page

My little Apple finally died[1] and the major loss was my collection of the entire History of Rome podcast, by Mike Duncan.  Oh noes!

Sadly, Feedburner doesn't provide a big zip file of all the episodes, which is understandable, since it would be huge.

I could hunt around for a browser extension that does a mass download, but this is quicker, safer and way more fun:

Save the above file to your 'history_of_rome' directory as 'hist.xml'

Preferably overnight(if your 'broadband' comes via the phone line...), in the bash shell do this:

$ grep -e "enclosure url=" hist.xml | sed -e 's/[^"]*"//' -e 's/".*//' | xargs wget

And hopefully, if all goes well, in the morning you'll have this:

FINISHED --2015-05-05 02:06:31--
Total wall clock time: 2h 26m 38s
Downloaded: 191 files, 2.0G in 2h 24m 49s (240 KB/s)

~/history_of_rome>

You say that this podcast is a little bit short for such a long story?  Well, there's lots more out there, but this is my second favourite series:



[1] And, after all this, I found that the Apple actually wasn't broken, but the USB port I plugged in for a recharge was.  ;-D

Monday, 4 May 2015

Shellicious!


Shell Style Guide -- how to code bash scripts in style.

How to scramble eggs inside their shell, for a neat pocket omelette, now with industrial trick:




The expectations of life depend upon diligence; the mechanic that would perfect his work must first sharpen his tools. 
          Confucius

Saturday, 7 March 2015

A little perl alias for git log messages

To get a nice log message for your git diff patch which makes it easy for a reviewer to check your stuff, try this little perl proggy:

alias gitdifflogmesg="perl -ne 'BEGIN {print \"[[[\";} /^\\+\\+\\+ b\\/(\\S+)/ && print \"\\n\\n* \$1\";  /^@\@.*[ *]([^ ]+)\(/ && print \"\\n  (\$1).\"; END { print \"\\n\\n]]]\\n\";}'"

Put this into your .bashrc (as one line), and, grab a patch you made with git diff, and use the alias like so:

cat your.patch | gitdifflogmesg

The output is something like this:

* path/to/modifed-file1.c
   (some_function_a).
   (some_function_b).

* path/to/modifed-file2.c
   (some_function_c).
   (some_function_d).

Now all you need to do is some accounting -- a good 50 char intro line and say what you did with all those functions and your log message is ready for sharing.  Of course not all log messages need this level of scrutiny, but, this goes a long way towards helping your reviewers and also, to help yourself to produce a great patch (or mailing list post).

Note that this does not pick up everything --- new #includes and new functions for example.  Then again, whilst that one liner is kinda cute, this service should really be offered by git itself.  But whilst git doesn't have this feature, this goes a long way towards making log messages easy ;-)

I am not a perl wizard though, I just read the book 'Perl One-Liners: 130 Programs That Get Things Done' -- even if you only read the first 3 chapters, you gain a handy little skill, plus, it's just fun to fiddle with.

Monday, 21 October 2013

Merging the trunk to branch, the lazy way

#!/bin/sh                                                                                                                                 
${SVN_INSTALLATION?"Please set the environment variable SVN_INSTALLATION."}
SVN=$SVN_INSTALLATION
BRANCH_DIR=`pwd`
tmp=`$SVN info 2>&1 | grep SVN_ERR_WC_NOT_WORKING_COPY`
if [ -n "$tmp" ]; then
    echo "Error: The branch directory does not contain a SVN repository." >&2;
    exit;
fi
TRUNK_DIR=$1
REL_DIR=$2
if [ -z "$TRUNK_DIR" ]; then
    echo "Usage: mergeBranch <trunk directory>" >&2;
    exit;
fi
if [ ! -d "$TRUNK_DIR" ]; then
    echo "Error: Trunk directory not found." >&2;
    exit;
fi
cd $TRUNK_DIR
tmp='$SVN info 2>&1 | grep SVN_ERR_WC_NOT_WORKING_COPY'
if [ -z "$tmp" ]; then
    echo "Error: The trunk directory does not contain a SVN repository." 1>&2;
    cd $BRANCH_DIR
    exit;
fi
cd $TRUNK_DIR;
$SVN up
tmp=`$SVN info | grep "Last Changed Rev:"`
TRUNK=${tmp##*: }
cd $BRANCH_DIR
tmp=`$SVN info | grep "Last Changed Rev:"`
BRANCH=${tmp##*: }
$SVN up
WHAT=${BRANCH_DIR##*/}
echo "On the $WHAT branch: trunk revision $TRUNK merged into branch revision $BRANCH." > log.mesg
$SVN merge $REL_DIR