Category Archives: Uncategorized

New Jabber/XMPP account

I’ve been meaning to do it for ages, but Google’s (admittedly brief) downtime yesterday pushed me enough to actually do it – I’ve set up my own Jabber server, so my new Jabber ID is davidp@preshweb.co.uk – feel free to add me. I won’t be monitoring my old Google Talk account as much.

Now I just need a decent, capable Jabber/XMPP client for my Blackberry!

Ryanair “standing room only” plans?

Ryanair passengers could soon fly for free – if they want to stand for their journey

Ryanair boss Michael O’Leary told Sky News the low-cost airline was considering ripping out the back few rows of seats on some flights.

Um, what? I’m pretty sure that won’t fly.

The FAA regulations definately require suitable seats with safety belts:

Sec. 121.311 – Seats, safety belts, and shoulder harnesses.

(a) No person may operate an airplane unless there are available during the takeoff, en route flight, and landing —

(1) An approved seat or berth for each person on board the airplane who has reached his second birthday; and

(2) An approved safety belt for separate use by each person on board the airplane who has reached his second birthday, except that two persons occupying a berth may share one approved safety belt and two persons occupying a multiple lounge or divan seat may share one approved safety belt during en route flight only.

(b) Except as provided in this paragraph, each person on board an airplane operated under this part shall occupy an approved seat or berth with a separate safety belt properly secured about him or her during movement on the surface, takeoff, and landing. A safety belt provided for the occupant of a seat may not be used by more than one person who has reached his or her second birthday.

Pretty sure the CAA/JAA will have similar rules.

My first instinct was to check whether this story was published April 1st, but clearly not.

Now, does someone think this will really work, or is it just a PR stunt to get people talking about Ryanair again (much like previous suggestions on charging to use toilets etc)?

Looking for phishing scripts, and other strange searches

A glance at my web stats reveals that I’m getting fairly regular hits from scumbags searching for phishing scripts, with queries like “where to find phishing scripts”, “php mailer by Mr.Brain”, “phishing script” etc.

I assume it’s all because, ages back, I wrote about the Mr-Brain.php phishing script.

I also get some other quite strange search hits – some of the stranger including:

  • "is ainsley harriot an arsehole"
  • "girls peeing in the sink"
  • "essex girl"
  • "pissed my pants in front of my girlfriend"
  • "i peed in my panties today blog"

There’s some strange people out there. I can only assume the piss-related hits are due to either If you’re having a bad day or Never piss off a JCB driver.

Oh, and the guy searching for “smoke from breather pipe motorcycle”? I’d say you need to get your engine looked at :)

Subversion – show commit details when editing commit message

Something I’ve wanted to do for a while is get the list of changed files and a diff into the commit message in my editor when I make a commit with Subversion.

With Git, you can pass the -v (verbose) option when committing, and the commit message you edit will include diffs as well as the list of modified files.

Subversion provides no such option, so I put together a little wrapper shell script to do this for me.

The script provides a function named svncommit (which I alias to just ‘ci’ for supreme shortness :) ).

When used, after the “–This line, and those below, will be ignored–” marker line, the list of files and then diffs will be inserted, as shown in the screenshot below (click for full size):

Subversion commit message being edited

The script itself is relatively simple (it was knocked up quickly; I’ll probably improve on it sometime):

# Do an svn commit, with diffs included in the commit message
svncommit() {

    # Start preparing the commit message which we'll then edit
    COMMITMSG=/tmp/$USER-commitmsg
    echo > $COMMITMSG
    echo "--This line, and those below, will be ignored--" >> $COMMITMSG
    svn status "$@" >> $COMMITMSG
    echo >> $COMMITMSG

    # Now do a diff; work out stats on lines added/removed by looking at
    # the diff, add that info, then the diff itself
    svn diff "$@"   > /tmp/$USER-svndiff
    LINESADDED=$(  grep '^+[^+]' /tmp/$USER-svndiff | wc -l)
    LINESREMOVED=$(grep '^-[^-]' /tmp/$USER-svndiff | wc -l)
    echo "Added $LINESADDED lines, removed $LINESREMOVED lines" >> $COMMITMSG
    echo >> $COMMITMSG
    cat /tmp/$USER-svndiff >> $COMMITMSG
    echo >> $COMMITMSG

    ORIGMD5=$(md5sum $COMMITMSG)
    $VISUAL $COMMITMSG

    if [[ "$(md5sum $COMMITMSG)" == "$ORIGMD5" ]]; then
        echo "Commit message unchanged, commit aborted";
    else
        svn commit "$@" -F $COMMITMSG
    fi

    rm $COMMITMSG
    rm /tmp/$USER-svndiff
}

Facebook vs Twitter is a flawed comparison

Marshall Fitzpatrick writes on ReadWriteWeb that "despite new openness, Facebook remains fundamentally closed".

What are people saying on Facebook about the swine flu? Facebook knows, but they won’t tell you. The company made a major move today to open up some of the data on the site in some interesting ways – but the conversation on Facebook remains fundamentally closed due to extensive privacy limitations and the company’s disinterest in overcoming those limitations in an appropriate way.

Ask Twitter what people are saying on that site about the swine flu and you can get the full story to parse until you’re blue in the face.

Um, I can’t help thinking he’s comparing apples with polar bears here.

Twitter and Facebook are two very different beasts. On Twitter, it’s expected that whatever you say is public, and can be seen both by your followers and the general public on the public timeline (unless of course you’ve protected your updates, but I don’t think many Twitter users do that (I’d be interested to know the percentage that do, actually)).

On the other hand, you have different fingers Facebook is built from the ground up to facilitate sharing information with your friends, and only your friends – there isn’t much public access to the data.

The fact that you can’t readily find out what people are talking about via Facebook APIs in the way that you can with Twitter is not a surprise to me.

Easy CLI option parsing with Getopt::Lucid

I often write Perl scripts which need to read options given on the command line. Normally I turn to the venerable old Getopt::Long which does the job.

However, I was writing a script which needed to be able to accept only certain parameters, which were mostly optional, and also take a list of filenames. I wanted this to be possible in any order, e.g.:

myscript --foo=foo --bar=bar file1 file2
myscript file1 file --foo foo

Getopt::Lucid makes this all pretty easy, and also makes the code pretty self-documenting, too. Straight from the documentation, showing the various types of parameters it can parse:

@specs = (
    Switch("version|V"),
    Counter("verbose|v"),
    Param("config|C"),
    List("lib|l|I"),
    Keypair("define"),
    Switch("help|h"),
);

$opt = Getopt::Lucid->getopt( \@specs );

$verbosity = $opt->get_verbose;
@libs = $opt->get_lib;
%defs = $opt->get_define;

A real-world example,from one of my scripts which handles ID3-tagging:

# The options we can take - these correspond to the name of the tag that
# they'll set:
my @options = qw(track title artist album comment);

my @option_specs = (
    Getopt::Lucid::Switch('verbose|v'),
    map { Getopt::Lucid::Param($_) } @options,
);
my $opt = Getopt::Lucid->getopt(\@option_specs);

my @tags_to_set = grep { $opt->{seen}{$_} } @options;
my @files = @{ $opt->{target} };

if (!@tags_to_set) {
    say "Nothing to do.  Use one or more of the options:\n" .
        join ', ', map {'--'.$_} @options;
    exit;
}

(The script then goes on to loop over all files, and use Music::Tag to set the ID3 tags requested).

Favourite new Perl features

I’ve been starting to make use of the new features introduced in perl 5.10 recently (after being constrained by my main dev environments still running perl 5.8.8, and not having the time to upgrade).

My favourite features so far are:

The smart match operator

The new smart-match operator, ~~, is a great example of DWIM.

A few examples:

if (@a ~~ 'foo')  # list contains at least one item equalling 'foo'
if (@a ~~ /foo/) # list contains at least one item matching /fo+/
if (@a ~~ @b)   # lists contain same values

That’s just a brief overview; there’s plenty more documentation

say

Not a big change, but the new say keyword acts just like print, but adds an implicit newline to the end – so say 'Hello'; is just the same as print "Hello\n";

It’s more useful in cases where you would have had to add parenthesis to get correct precedence – something like: print join(';', @foo) . "\n"; can now be written more concisely as just say join ';', @foo;.

Switch (given) statement

given ($foo) {
    when (/^abc/) { abc(); }
    when (/^def/) { def(); }
    when (/^xyz/) { xyz(); }
    default { die "Unrecognised foo"; }
}

Defined-or

// is now the defined-or operator.

It’s pretty common to use conditional assignments like: $a ||= $b to assign to $a unless $a already has a value. Now you can use $a //= $b to test for definedness rather than truthiness.

Likewise, if ($hash{foo} // $hash{bar}) will be true if either of them is defined (even if they’re defined but have a false value).

Named regex captures

Parenthesised sub-expressions in regular expressions can now be given a name, and accessed via the special %+ hash:

if ($foo =~ m{ (? \d{4} ) - (? \d{2}) - (? \d{2}) }xms) {
    say "Year: $+{year}";
}

The features above are my own personal favourites, in no particular order. The full (large) set of changes can be found in the perldelta for 5.10.0.