Category Archives: Geeky

Technical stuff about Perl, Linux and computing & technology in general.

DancerJukebox – music queuing Perl webapp powered by Dancer

I spent some of Friday night hacking on rewriting my music queuing webapp from Catalyst (which I wrote it in ages ago, before I discovered Dancer).

It only took a couple of hours of easy and actually fairly enjoyable coding to get it all ported over, and in the process I released two Dancer plugins – Dancer::Plugin::MPD to handle easily getting a working MPD connection, and Dancer::Plugin::DebugDump to easily dump objects and data structures to the debug log to simplify development.

This time round, the code is up on GitHub – DancerJukebox on GitHub. I never released the previous code, it was developed in a private Subversion repository, and I was never happy enough with it to release it.

The basic idea is that you fill the playlist with decent music and leave MPD playing on random. If people want to hear specific songs, they can use the web app to search for whatever they want and add them to a queue.

Continue reading DancerJukebox – music queuing Perl webapp powered by Dancer

pQuery – jQuery-like fun in Perl

I discovered pQuery the other day, and had been meaning to try it out.

I got the chance to use it today, and I have to say, I’m impressed. I am, however, rather wary that the last release was nearly two years ago; I’m not sure I’d want to use it in production code unless it’s being actively maintained – I might use it for non-important things before making that call.

Anyway, a brief example:

Let’s say you want to capture the content of a paragraph/div with the class “bar” from a page somewhere.. it can be as simple as:

pQuery('http://www.example.com/foo.html')->find('.bar')->html;

Let’s say you want to extract all H1 headings instead:

pQuery($url)
    ->find('h1')
    ->each(
        sub { say "Heading: " . pQuery($_)->text; }
    );

I’d love to see this continue in active development – there’s several features it could really use, but what’s already there is handy stuff!

Dancer::Plugin::Database – easy DB connections for Dancer apps

Last night I finished and released the first version of Dancer::Plugin::Database, a plugin for the Dancer web framework to provide easy database connections using the venerable DBI.

It takes the database connection details from the app config file, and provides a database keyword which will return you a connected database handle (taking care of ensuring that the DB connection is still alive, etc).

So, usage can be as simple as:

my $books = database->selectall_arrayref(
    'select * from books where author = ?', 
    { Slice => {}}, $author
);

(Calling database() simply returns a DBI database handle, so you can obviously do anything you can do with DBI).

Also, at the moment, if a database connection could not be established for any reason, database() will just return undef, so you will need to handle errors appropriately. After considering whether it’s wise, I may tweak it to die, so that Dancer will handle the failure with a pretty 500 error for you (in which case, I’ll make it possible to disable that via the config).

Resizing ext2/3 filesystem in loop file

Quick post, mostly for my own future reference, as I couldn’t quite remember how to resize an ext3 filesystem contained in a file.

dd if=/dev/zero of=disk.img bs=1M count=1024 oflag=append conv=notrunc
e2fsck -f disk.img
resize2fs disk.img

The above will append 1GB to the end of the file, then resize the ext2/3 filesystem to take up that newly-added space.

Several Perl scripts released to Github

I’ve been playing with Github lately, and rather liking it.

I did briefly try it about a year ago, and was impressed, but wasn’t driven enough to consider moving away from Subversion.

I tried it out more when I started contributing to the Dancer Perl framework, and got to like it; since then, I’ve moved several of my modules over to Github already.

I finally got round to moving some miscellanous Perl scripts too, ones which I’ve been meaning to release as open-source in case they’re of use to anyone, but didn’t get round to doing.

They’re now online at: http://github.com/bigpresh/misc-scripts.

Github made sharing my code easy – Github++;

Now, that’s enough geekery for one evening.

Dancer 1.150 released – a flexible, lightweight web framework for Perl

Version 1.150 of the Dancer web framework has just been released, so this seemed like a good time to write up this post.

Recently, I’ve been wanting to find a Perl web framework that I really got on with. I’ve used Catalyst, which is very powerful and popular, but it’s quite heavy (a lot of dependencies, and reasonably high memory usage and startup time), and I felt as though it forced me to code “the Catalyst way”, rather than staying out of my way and getting on with writing my code.

I took a look around at the current Perl web frameworks (e.g. CGI-Application, Jifty, Catalyst, Mojo…) – all good in their own ways, but for various reasons, none of them really struck me as something I’d be particularly happy to work with.

I did briefly consider trying to write my own, but that’s a wheel I do not want to re-invent – there’s enough odd-shaped wheels out there already.

When I found Dancer (a port of Ruby’s Sinatra framework), I immediately liked the fact it looked simple and stays out of the way as much as possible, so I gave it a try – and, I must say, I’m impressed.
Continue reading Dancer 1.150 released – a flexible, lightweight web framework for Perl

Custom Bash completions for lazy bastards

At $work, we have a log server, where the current day’s logs from a given machine are stored in, e.g. /logs/machinename/year/month/day/. In a moment of yak shaving, I added a function to my .profile, named cdmachinelogs to allow me to type e.g. cdmachinelogs somemachine, and end up in the appropriate directory.

Now, Bash will automatically tab-complete e.g. “cdm” into cdmachinelogs, but I wanted to be extra-lazy and tab-complete the machine name, too.

Enter the following snippet:


complete -W "$(find /log/path -maxdepth 1 -mindepth 1 -type d -printf '%f ')" cdmachinelogs

So, it sets up tab-completion for the cdmachinelogs command, using a list of words obtained by finding each directory name under the path to the logs.

Posted mostly for my own later reference, but also for anyone who might find it useful.

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