Category Archives: reviews

OpenDNS vs Google – speed comparison

I read a Twitter post earlier mentioning Google’s public DNS service, and suggesting that it could displace the popular OpenDNS

I thought it would be interesting to do a performance comparison between Google and OpenDNS, to see how they compare. I also decided to include the nameservers of my ISP, Virgin Media, to illustrate whether there are performance gains to be had by changing to OpenDNS (which I primarily use, along with others) or Google, or whether staying with defaults works. Continue reading OpenDNS vs Google – speed comparison

SSH and rsync on Lacie Ethernet Disk Mini v2

Lacie Ethernet Disk Mini v2

A couple of months back, I acquired a Lacie Ethernet Disk Mini v2 for backups – I’m planning to give it to a friend to plug in, so I’ll have a little self-contained box to back up to.

The drive is a pretty stylish-looking and very solid-feeling device.

However, it comes with rather limited software – a rather poor and ugly web interface (even worse when you see the code behind it), and it supports Samba (SMB/CIFS) shares, FTP, some kind of Apple file sharing protocol, and uPnP media streaming.

Ignoring all that though, what I want is the ability to back up to it by rsync – something it doesn’t support, out of the box. However, it’s an ARM-powered unit running Linux underneath, so with a little trickery, you can make it much more functional.

There are several guides on uncrippling it to get SSH access to make proper use of it – I followed this one.

Basically, the process consists of opening up the device, and temporarily hooking up the hard drive directly to your computer in order to add a telnet binary and a backdoor to the web interface. I used a little USB to SATA/IDE adaptor I bought from eBuyer, meaning I could hook it up happily to my laptop, and didn’t have to remove the drive from the Lacie unit, simply removing the outer case and unplugging the cables from the drive and plugging in the ones from the USB unit.

See the guide linked to above for the full process, but you basically drop in a shell script which you can call via its web interface once it’s back up to execute whatever you want. The webserver on it runs at root (ugh) so it can start whatever you want it to. Typically, you’ll start utelnetd so that you can then telnet to it, download some ARM packages to install OpenSSH, rsync and other bits, get SSH working, then disable telnet, the horrible web interface, and anything else you don’t plan to use (I disabled proftpd, Samba, and the uPnP media sharing software).

Once it’s all done, you have a small but usable Linux system you can SSH to:

lacienas1

Naturally it’s not super-fast, but it does the job well enough!

A few tech specs, for anyone interested:

davidp@EDmini davidp $ cat /proc/cpuinfo 
Processor	: ARM926EJ-Sid(wb) rev 0 (v5l)
BogoMIPS	: 266.24
Features	: swp half thumb fastmult 
CPU implementer	: 0x41
CPU architecture: 5TEJ
CPU variant	: 0x0
CPU part	: 0x926
CPU revision	: 0
Cache type	: write-back
Cache clean	: cp15 c7 ops
Cache lockdown	: format C
Cache format	: Harvard
I size		: 32768
I assoc		: 1
I line length	: 32
I sets		: 1024
D size		: 32768
D assoc		: 1
D line length	: 32
D sets		: 1024

Hardware	: MV-88fxx81
Revision	: 0000
Serial		: 0000000000000000
davidp@EDmini davidp $ cat /proc/meminfo 
MemTotal:        61632 kB
MemFree:          1380 kB
Buffers:           188 kB
Cached:          28924 kB
SwapCached:          0 kB
Active:          17336 kB
Inactive:        23328 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:        61632 kB
LowFree:          1380 kB
SwapTotal:      128448 kB
SwapFree:       128448 kB
Dirty:            3472 kB
Writeback:           0 kB
Mapped:          14548 kB
Slab:            16688 kB
CommitLimit:    159264 kB
Committed_AS:    56104 kB
PageTables:        508 kB
VmallocTotal:   450560 kB
VmallocUsed:       716 kB
VmallocChunk:   449844 kB

Re-review: Williams Ale & Wine House

Yesterday I was Googling to try to find the menu for the Williams Ale & Wine House online to pass to a new colleague, and I found my own review of it, written back in 2007.

Williams Wine and Ale House

That review was done after probably our first visit, and criticised them for bringing the food out slowly; we’ve since been there many, many times, and they’ve been very good, so I think it’s time to re-review them – it’s only fair :)

The Williams Ale & Wine House is at 22/24 Artillery lane London E1 7LS (Google map). Artillery Row is a small back street not far from Bishopsgate & Liverpool Street station.

The food is consistently good there; their burgers are very large & tasty, many people have praised their beef & yorkshire pudding wraps, their Lasagne is top-class, and I’ve never seen anyone really disappointed with their food (except Esben, when they accidentally brought him a vegeterian lasagne (this, to the guy who won’t touch anything plant-related :) ). You can see their food menu online (or as a PDF), and their wine list is also available.

The staff are always friendly and helpful, and despite the pub’s popularity, we rarely have to wait more than a couple of minutes to get served, and the food arrives quickly.

There’s also apparently free wi-fi (although I’ve never tried it; we go there to get away from work, not to work :) ), and you can book a table online (or just call 020 7247 5163).

So, hopefully that will set the record straight :)

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

Easy file finding with File::Find::Rule

Recently I found File::Find::Rule on the CPAN, and I’m impressed how easy it makes it to get a list of files to work on.

A fairly common way to do this in Perl would be something like:

my $dirh = new DirHandle($somedir);
while (my $entry = $dirh->read) {
    # Skip hidden files and directories:
    next if ($entry =~ /^\./ || !-f $entry);

    # Skip if it doesn't match the name we want:
    next if ($entry !~ /\.txt$/);

    print "Found: $somedir/$entry\n";
}

File::Find::Rule makes things rather easier:

my @files = File::Find::Rule->file()->name('*.txt')->in($somedir);

Various conditions can be chained together to find exactly what you want.

Another example, showing combining rules with ->any() to find files matching any of those conditions:

# find avis, movs, things over 200M and empty files
my @files = File::Find::Rule->any(
    File::Find::Rule->name( '*.avi', '*.mov' ),
    File::Find::Rule->size( '>200M' ),
    File::Find::Rule->file->empty,
)->in('/home');

There’s plenty of other ways to do this, but I think File::Find::Rule gives a way to clearly and concisely state what you want and get the job done.

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.

Pastebin Firefox extension

My friend James Ronan has just released a Pastebin Firefox extension, making it even easier to paste code etc to pastebin.com.

As the code by Paul Dixon which powers pastebin.com is Open Source and can be installed on your own server, the extension allows you to provide the URL of your own private pastebin install if you have one – this is ideal for me, as we have a private pastebin setup at work which is often used.

Using the extension is as simple as right clicking and chosing “pastebin my clipboard”, which submits the contents of your clipboard (or highlight buffer) to pastebin, and copies the resulting URL to the clipboard, ready for you to paste on IRC / IM / whatever.
Continue reading Pastebin Firefox extension

KDE 4.1 – very nice

KDE 4.1 was released today, and is already in Arch Linux‘s repos, so I decided to update and give it a try.

First impressions – pretty slick indeed, especially after turning on proper compositing support for various funky effects including see-thru windows, “wobbly windows” etc – lots of which is fairly pointless but very nice at the same time :)

So far it seems very polished, it looks like the KDE team have put in a whole lot of work here!

Screenshots/videos may follow, if I get a chance (although I’m sure there’s enough out there already).

Even with the extra eye-candy enabled, the system feels at least as responsive as it did under KDE 3.5, and I think even more responsive actually.

Book Review: “Catalyst (Accelerating Perl Web Application Development)” by Johnathan Rockway

Catalyst is a web framework for Perl, which claims to "make web development something you had never expected it to be: Fun, rewarding and quick&quot.

I’m a professional Perl developer, but hadn’t tried Catalyst – it was one of the things I really wanted to try out but didn’t get round to it. Recently I obtained a copy of Johnathan Rockway’s book, Catalyst (Accelerating Perl Web Application Development) from PACKT publishing, so here’s a review of the book.

Johnathan is a member of the core Catalyst development team and certainly knows his stuff, so that lends credence to this book.

My first impression was that the book is somewhat thin at 187 pages for its £24.99 ($39.99 USD) cover price.

However, reading through the book, it covers Catalyst and some of the modules commonly used with Catalyst in just the right amount of detail – if you have some experience with Perl already, this book will give you just what you need to get using Catalyst with the minimum of fuss. The also covers various related tasks you’ll want to do when developing web apps with Catalyst, including:

  • using Template::Toolkit to generate output
  • object-relational mapping with DBIx::Class
  • generating forms automatically with FormBuilder
  • authentication and authorisation
  • session management
  • adding REST APIs, AJAX interactivity and RSS feeds

So, overall, I’d say it’s a quite good book, a perfect introduction to developing maintainable web applications using Catalyst, and using current best practices including MVC designs and ORM database access. However, one thing I felt wasn’t covered very well was Perl’s attributes which are used in many code examples – that’s one area of Perl that I haven’t really made any use of up until now. (The perldoc page does warn that "attribute declarations for variables are still evoving. The semantics and interfaces of such declarations could change in future versions. They are present for purposes of experimentation with what the semantics ought to be. Do not rely on the current implementation of this feature."). The book fails to really describe attributes at all (which I suspect is something a fair number of Perl developers won’t be familiar with). It also doesn’t explain the principles behind MVC design; I guess it’s a reasonable assumption that anyone planning to use Catalyst will probably already be fairly familiar with MVC principles, but a better introduction (perhaps with pointers to external reading for those needing to learn more first) wouldn’t have hurt.

Also, unfortunately the book is marred by several typos – it exudes a feel of perhaps being rushed out a little, without enough time being spent on editing. I don’t feel it detracts badly from the book, but is a little shoddy.

Despite the flaws, I still feel it’s a useful book to help get to grips with Catalyst.

Grab yourself a copy from Amazon (price at time of writing: £23.74), or buy it direct from Packt for £22.49.