I wrote this little thing at work - putting it up here in case it's useful to anyone else