Peter Blair

gvim colours that are nice on the eyes

I spend most of my time editing software in vim or gvim — I’m most comfortable in vim, since I like to drop into a shell and run snippets etc, which isn’t amenable in gvim. But, gvim can be quite nice on the eyes.

I use the following in my .gvimrc file:

syntax on
colorscheme darkslategray
set gfn=Inconsolata\ Medium\ 10


Managing mailing lists – The right tool for the job

I find that using mutt as an email client can really help when managing the different mailing lists that I subscribe to. One of the features that it supports is a send-hook which will change a couple of headers depending upon the address recipient of the email.

Meaning, if I’m emailing the mailing list address, I want my reply-to to be the mailing list address, and I may want to change my from address to match the address that I’ve subscribed with.

Not a lot of people take the time to follow proper mailing list etiquette, but they should.

I’m becoming a grumpy grey beard. I know.


Perl closures — the visitor pattern

For some reason, Perl closures have been eluding me for the past couple of months, and I just realized that they’re simply a visitor pattern. I made a rough example using C++0×11 and Perl:

Note, I understand that strictly speaking, a closure is “is a function or reference to a function together with a referencing environment”, but it made a lot more sense when I thought of it as a visitor.


Creating debian packages from Perl modules

I just wrote a little blog post at my other blog that outlines how to create debian packages from the latest Perl module tarball.

I use these scripts as I don’t like maintaining Debian package info, and just publish my distribution tarballs to a public dir — then I can use my script to pull the latest version from that dir (via HTTP) and create a .deb file that reflects it.

Take a look — enjoy.


OpenBSD and copper.net dialup information

I’ve just completed the setup for my OpenBSD 5.2 dialup server — My network currently looks like:

Laptop [ Linux ] <---> Wifi Router [ Linux Tomato ] <---> Ethernet <---> OpenBSD 5.2 <---> modem

My configuration files can be found in this gist

My modem is attached to Com0 ( /dev/cua00 ) and is a courier 56k external modem from my teenage past. The ethernet device is named bge0, and pf is configured to nat out all traffic from bge0 to tun0 which is configured via the ppp service.


Ensuring a Perl script is run as a given user

Sometimes a script requires that it be run as a given user to satisfy certain OS level constraints. The Perl code required to do this is quite simple, but it’s easier to stash that away into a package and simply call that package instead. Below is an example:


Writing a simple caching attribute in Perl

Sometimes it’s handy to be able to force a function’s results to be cached for later use. Perl allows this by making use of Attributes. My naiive example simply dumps the variable into a file, which gets evaluated until the cache time expires.

Note: This was inspired by my friend Jacob’s post:


Finding the bloated directory with Perl

Sometimes you see an alert that a given partition is growing dangerously large. There are two simple ways to troubleshoot what’s growing if you’re not intimately associated with that particular system.

1) “ls -lart”

This command will show which directory was most recently updated. You can drill through your filesystem, skipping over directories that aren’t touched often in hopes of finding the directory that’s filling up

2) du + perl

In my example, I’ll assume that our root partition is filling up, so I’ll use “du” to get the size of each directory:


$ du -x / | tee /tmp/diskspace

And walk it with perl:


$ perl -lane 'print if /\s+(\/[^\/]+){1}$/' /tmp/diskspace | sort -n

Now, you’ll notice that it uses a simple little regex which looks for the beginining of the directory name, followed by anything but another slash. Then there’s a little “{1}” which indicates that it should loop 1 time over this pattern. This gives us the top level of our search. Once we pick a directory to walk, we can change that to:


$ perl -lane 'print if /\s+(\/[^\/]+){1,2}$/' /tmp/diskspace | sort -n | grep SOMETHING

Now, the “{1}” is a “{1,2}” which will search 1 or 2 times over that pattern. Continue with “{1,3}” .. “{1,4}” etc until you’ve gone deep enough to find your trouble maker, and clean up your stale files!


Easy testing with Perl

I always place a “t” directory right under my Perl lib dir, which is a great place to run all of my regression tests.

I’ve found the easiest way to get the harness up and running is to use a Makefile, and a Perl 1 liner:


$ cat Makefile
.PHONY:test all

all: test

test:
perl -MTest::Harness -e 'runtests sort @ARGV' *.t

So, when you call “make” or “make test”, it will test against every .t file. No fuss.


Perl decorators

One of the great things that I enjoy about Python, are the decorators. I try to use them whenever possible in my Python projects, and sorely miss them at times in my Perl projects.

Last week I was thinking of profiling my Perl applications remotely and was pining for decorators. With Perl 5.10 lacking decorators, I created a Perl filter package to create “decorator like” syntax-sugar to support the emission of certain metrics like:

– Label assigned to function
– Time elapsed
– Return val

This triplet is then sent via UDP to some listener that can do with it as it may. Aggregate it, store it in a noSQL store, whatever.


Get Adobe Flash player