2009

Thanks to the enthusiasm I’ve returned from EuroPython with (and the fact I couldn’t make it to OpenTech because of washing machine issues) I decided to spend a little bit of time porting Nagios Webchecks to python. As a use case it covers a lot of the functionality I need in my day to day system scripts. The ability to specify command line arguments, read a config file and interpolate a template file for output. Read on →

DNS is one of those ‘small config change here, errors a long way over there later’ technologies that always leaves me a little worried about the knock on effect of my changes. As a simple, coarse, safeguard at work we use Nagios to check that a canary record in each zone can be resolved from each DNS server. It’s far from a perfect solution but it does catch some of the bigger errors and typos. Read on →

I recently watched the first in the series of the Pragmatic Programmers Erlang in Practice Screencasts (by Kevin Smith - no, not that Kevin Smith). As I’ve not seen them discussed that much else where I thought I’d jot down my thoughts. First up a disclaimer/warning - I’m not an Erlang person and despite the title of ‘Episode 1’ this series of screencasts is not aimed at people with no experience in the language. Read on →

2008

- file_move_safe(move_from_path, move_to_path) + move_file(move_from_path, move_to_path) Is move_file not as safe as file_move_safe? Is it safer? Dare I read the other diffs to find out? Am I better off not knowing?

I’ve been spending a fair amount of time recently trying to choose my Language of the year for 2009. I’ve always been a dynamic language fan (yes, I know this means I should be looking further afield for the next one) and I was surprised at how different even such a common task as joining all the elements of an array together, using a given separator, looks between them. First let’s look at the big three, including perl, my current favourite. Read on →

While I’ve always been a bit of a perl guy I don’t want this post to be “perl has x and python doesn’t” in tone. Which is lucky really as Python has exceptions and threading as first class features where as perl has… ahem. So after spending a chunk of today reading a python book and spending some time writing code here’s my initial short list of gripes - except IOError print adding newlines Significance of whitespace in blocks. Read on →

While paging through reddit programming recently (seems only fair since they linked to me ;)) I stumbled on to the very nifty Randexp gem, a library that uses regular expression patterns to generate data that would satisfy the pattern. Or in less tech terms - a really good test data generator. # install randexp $ irb require "rubygems" require "randexp" # simple fake phone number - /020(7|8) \d{3} \d{4}/.gen # build a reusable class. Read on →

There is nothing like other peoples code to highlight all those little gaps in your knowledge of a programming language. I know what the first one does: $ mkdir -p {projectone_,projecttwo_,projectthree_}log $ ls -1 projectone_log projectthree_log projecttwo_log And I was a confident (and a little bit happy) about knowing what the second one does: $ mkdir -p {project_one,}log $ ls -1 log project_onelog But I had no clue about this one. Read on →

2007

I’m on-call tonight so I invested some time in facter, “A cross-platform Ruby library for retrieving facts from operating systems.” While facter is an interesting command line program (its extension mechanism is quite nice) its main claim to fame is that it’s used by puppet (which I’m slowly evaluating as a CFEngine replacement) to determine facts about a machine. While the docs are a little light on the ground the tgz contains a couple of examples and after some playing around I think I’ve got a basic Linux Bonding fact ready. Read on →

Both Jim Weirich and Ben Summers were kind enough to email me about my Daemon Logging Percentages and Playing with Ruby Idioms post. They sent me an explanation on how to do the hash assignment in a way I find much nicer, so with no more delays I present - Option 4: tally = Hash.new(0) tally[daemon] += 1 It really is that simple - and I still missed it by a mile. Read on →

2006

Hell is other peoples code. – Not quite Sartre. I don’t mind using other peoples code. I’ll even submit patches if I find a problem, but discovering the same mistakes in almost half-a-dozen projects is enough to drive me insane. Here are three common red flags involving the find command and how to get around them: If you want to be portable, don't use GNU/Linuxisms. Compare these two commands - `find -name "*.log"` # not portable `find . Read on →

2005

A tag cloud is a visual depiction of content tags used on a website. Often, more frequently used tags are depicted in a larger font or otherwise emphasized. Selecting a single tag within a tag cloud will generally lead to a collection of items that are associated with that tag. From the Wikipedia Tag cloud entry. Ever wanted a tag cloud of your Blosxom posts? With just this blosxom-tagcloud.pl script (and three Perl modules from CPAN) you can have one that integrates itself with your Blosxom footer and even allows easy merging of the tag cloud and any static text/HTML you’ve used in the past. Read on →

There are a list of things you don’t want to see in your Unix machines start up scripts but one of the leaders has to be a snippet like this: [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live. For now." Before we look at what the chunk of code is supposed to actually do it’s worth mentioning that $RANDOM is a built-in shell variable. Read on →

2004

Leafing through the live source-code should be a pleasant, calming experience, instead it often becomes a game of cringe and seek. While digging through some custom bandwidth monitoring scripts i came across this gem. cat /proc/net/dev | grep eth0 | sed -e 's/:/ /g; s/ / /g; s/ / /g; s/ / /g; s/ / /g; s/ / /g; s/ / /g; s/ / /g; s/ / /g; s/ / /g; s/ / /g; s/ / /g;' Working left to right we have the useless use of cat. Read on →