RobL =

xterm-256color: unknown terminal type

Mon, 22 Apr 2013 11:09:04 +0000

Trying to run `top` on an Ubuntu server from OSX Mountain Lion results in the following.

root@server:~# top
'xterm-256color': unknown terminal type.

Thanks to Corentin Leclerc for the solution

Add the following to ~/.profile or ~/.bash_profile

export TERM="xterm"

Restart your terminal, or open a new tab. Magic.

root@server:~# top

top - 10:52:46 up 31 days, 16:34,  1 user,  load average: 0.04, 0.02, 0.00
Tasks:  57 total,   1 running,  56 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:    786652k total,   772360k used,    14292k free,   181920k buffers
Swap:        0k total,        0k used,        0k free,    46000k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                                                                                                              
26479 rails     20   0 89604  57m 2428 S  0.3  7.5   0:04.08 ruby1.8                                                                                                                                                                                               
    1 root      20   0  1952  508   72 S  0.0  0.1   0:13.04 init                                                                                                                                                                                                  
    2 root      15  -5     0    0    0 S  0.0  0.0   0:00.12 kthreadd

Recover committed (deleted) file in Git

Mon, 22 Apr 2013 08:33:31 +0000

What if, just suppose, you deleted a file in error, made the commit to Git, then several commits later you realise you needed the file all along. How do you get it back?

Well, you find the last commit for that file and then checkout the file with the revision number. In just a few lines then…

Robs-iMac:repo rl$ file='app/views/previously_deleted.html.haml'
Robs-iMac:repo rl$ echo $file
Robs-iMac:repo rl$ git checkout $(git rev-list -n 1 HEAD -- "$file")^ -- "$file"

Raspberry Pi - part 1

Wed, 02 Jan 2013 21:44:44 +0000

This year my main festive gift from the mighty Kat was a long awaited Raspberry Pi. Just never seemed to have the funds to nab one myself and I am pretty chuffed. If you’ve not heard of one then you’ve been living under a rock for the last year. The Raspberry Pi is basically just a very small, barebones computer. In fact its so minimal that it doesn’t even come with a case.

Raspberry Pi

You can see on the board that the mounted interfaces are a dual USB port, micro-USB power supply, HDMI output to monitor, audio out, video out, GPIO pins.

You might have enough bits and bobs lurking in your cupboard full of cables and old hardware to get going but alas I do not. So in order to get started I need some way of hooking this up to a monitor, keyboard and powering the thing.

USB Keyboard

No PS2 ports so its all USB, so a USB Keyboard is needed. Relatively cheap, I’ve spotted a great wireless one with a touch pad for £25 but for now this one will do.


While the Raspberry Pi can be easily used with a modern television I can’t see myself sitting in the front room while I’m playing with it for the time being. You can use any monitor or television with an HDMI or DVI connection. So you’ll need a cable

My spare monitor is a VGA which won’t work without an adapter to convert the signal. £30 for an adapter is a bit much really. I’ve secured a DVI monitor from a friend for £10, so I’ve opted for the HDMI to DVI while I’m playing.

SD Card / Operating System

You’ll need an SD Card to install the operating system on. Fortunately we have an old 4Gb card from a Camera. So cost £0. Yay. average cost on Amazon about £6 so not bad.

Install it yourself

You can follow the tutorial on the Raspberry Pi Downloads page to copy an OS onto a card.


You can get an 8Gb (and upwards) SD Card from ThePiHut with one of two distributions from £8.99.

  • Raspbian – pre-installed Raspian is an optimised version of Debian, containing LXDE, Midori, development tools and example source code for multimedia functions.
  • OpenElec / XBMC – pre-installed Open Embedded Linux Entertainment Center, or OpenELEC for short, is a small Linux distribution built from scratch as a platform to turn your computer into a complete XBMC media center.

That’s a start I’ve ordered what I need so now I have to sit and wait. I’ve got a few ideas about what I’d like to build.

  • MAME centre
  • Media centre
  • Spotify streaming straight into the HiFi

So I’ll do a bit of research and buy a book or two.


There’s plenty of resources out there as well as some physical publications to get started with.

More useful links…

Installing 'therubyracer' grrrr

Tue, 13 Nov 2012 18:15:32 +0000

Robs-iMac:testapp rl$ gem install therubyracer
Building native extensions. This could take a while…
ERROR: Error installing therubyracer:
ERROR: Failed to build gem native extension.

/Users/rl/.rvm/rubies/ruby-1.8.7-p370/bin/ruby extconf.rb
  • extconf.rb failed *
    Could not create Makefile due to some reason, probably lack of
    necessary libraries and/or headers. Check the mkmf.log file for more
    details. You may need configuration options.

Provided configuration options:
extconf.rb:13: uninitialized constant Gem (NameError)
Checking for Python…

Gem files will remain installed in /Users/rl/.rvm/gems/ruby-1.8.7-p370@thebevy/gems/libv8- for inspection.
Results logged to /Users/rl/.rvm/gems/ruby-1.8.7-p370@thebevy/gems/libv8-

It seems that libv8 requires Gem to exist, however rubygems is not available by default in Ruby 1.8.7. Ruby 1.9.x it is.

Thanks to Olly Smith for the solution

Robs-iMac:thebevy rl$ RUBYOPT=-rrubygems gem install therubyracer
Building native extensions.  This could take a while...
Fetching: therubyracer-0.10.2.gem (100%)
Building native extensions.  This could take a while...
Successfully installed libv8-
Successfully installed therubyracer-0.10.2
2 gems installed
Installing ri documentation for libv8-
Installing ri documentation for therubyracer-0.10.2...
Installing RDoc documentation for libv8-
Installing RDoc documentation for therubyracer-0.10.2...

Apache Rewrite because I can never remember how to do it

Fri, 26 Oct 2012 10:21:24 +0000

I seem to use Apache less and less these days, so every year or so I have to try and remember the syntax for VirtualHost configs, redirects and the like.

<VirtualHost *:80>
  DocumentRoot /home/duncan/
  RackEnv production
  RewriteEngine on
  RewriteCond %{HTTP_HOST} !^duncanwilkinson\.com
  RewriteRule ^/(.*)$$1 [R=permanent,L]
  CustomLog /var/log/apache2/loathsome-access.log combined
  ErrorLog  /var/log/apache2/loathsome-error.log
<VirtualHost *:80>
  RewriteEngine on
  RedirectMatch (.*)
<VirtualHost *:80>
  DocumentRoot /home/duncan/

iptables reminder

Wed, 27 Jun 2012 13:33:01 +0000

Forgot all about iptables….

rails # iptables -A INPUT -s <naughty ip> -j DROP
 rails # iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
DROP       all  --  anywhere            

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination 

Resize multiple images in one bash script

Sat, 09 Jun 2012 21:49:56 +0000


for i in *.JPG; do echo $i; base=`basename "$i" .JPG`; convert "$i" -resize 50% "thumbs/$base.jpg"; done

Delete files created more than 14 days ago

Wed, 21 Mar 2012 09:53:56 +0000

When you’ve got lots of temporary files on a unix server and you never clean them out this might help. Remove files that were created more than 14 days ago like so…

find . -type f -mtime +14 -exec rm {} \;

doing away with www.

Wed, 08 Feb 2012 08:42:56 +0000

“www.” for the most part is a pointless idea. We all know what a web page is. The “www.” prefix is outdated although necessary evil. I guess the same could be said of http:// and https:// for web requests …we all know what it means.

Here’s a quick snippet of my apache config to push all traffic from to

<VirtualHost *>
  DocumentRoot /var/www/loathsome/current/public/
  RackEnv production
  RewriteEngine on
  RewriteCond %{HTTP_HOST} ^www\.loathso\.me
  RewriteRule ^/(.*)$$1 [R=permanent,L]
  CustomLog /var/log/apache2/loathsome-access.log common
  ErrorLog  /var/log/apache2/loathsome-error.log

Rails Serializers and INET_NTOA

Sun, 29 Jan 2012 02:37:58 +0000

MySQL doesn’t have a built in type for an IP Address, PostgreSQL does though. You’ll find that ip addresses are often stored as an integer. You can translate between an integer and ip address and vice versa with a built in MySQL functions. In a recent piece of work we had to detect a user’s country code based on their incoming IP via against a range of IPs (stored as integers).

mysql> SELECT INET_ATON('');
| INET_ATON('') |
|               3232235521 |
1 row in set (0.00 sec)

mysql> SELECT INET_NTOA('3232235521');
| INET_NTOA('3232235521') |
|             |
1 row in set (0.00 sec)

Wouldn’t it be nice to get a Rails model to accept an ip address and store it as an integer. Well its basically serializing the ip address and using Rails 3.1’s new serialization api we can do the following.

class IpEncoder
  # Converts IP to number
  # inet_aton
  def load(n)
    return unless n
    [n].pack("N").unpack("C*").join "."

  # Converts number to IP
  # inet_ntoa
  def dump(n)


Basicially a class with two methods IpEncoder#load encodes its input, and IpEncoder#dump decodes it. Then you simply add the following to your model.

require 'ip_encoder'
class Log < ActiveRecord::Base
  serialize :ip_address,

And there you have it.

Rob-Laceys-MacBook-Pro:loathsome roblacey$ ./script/rails c
Loading development environment (Rails 3.1.2)
>> Log.create(:ip_address => '')
  SQL (0.5ms)  INSERT INTO "logs" ("ip_address") VALUES (?)  [["ip_address", 3232235521]]
=> #<Log id: 1, ip_address: "">

JRuby Swing

Sun, 22 Jan 2012 22:39:02 +0000

I was mulling at the end of last year that while I’ve been programming for far too many years now its been for the most part web development and databases. But I don’t know how to build a GUI, and least of all one that would be cross platform. Time to learn.

I’ve just picked myself up a copy of O’Reilly Java Swing 2nd Edition which, while its old, should help me get to grips with building my first GUIs.

As an interesting learning process I’ve decided that while of course this is all about Java that I am going to read the book in Java, I shall translate it all into JRuby since I use Ruby as my programming language of choice. So I’ll learn three skills in one;

  • GUI Development
  • Java
  • JRuby

I think the best way to pick it up is to go through every last example until it becomes second nature so all the Java AWT and Swing examples I come across in the book I shall be adding in a new jruby-swing github repository are here as JRuby.

In fact here’s the first example

Desktop app here I come.

Disable startup items in Debian / Ubuntu

Wed, 18 Jan 2012 23:18:48 +0000

Needed to get rid of PostegreSQL on start up. That’s freeing up 8Mb of memory….its better than nothing.

rails@cool-server-name-001:~$ sudo update-rc.d -f postgresql-8.3 remove
 Removing any system startup links for /etc/init.d/postgresql-8.3 ...

New Relic - Get a FREE 'data nerd' t-shirt

Wed, 18 Jan 2012 23:06:32 +0000

Just signed up to a new New Relic account today for a client and got a free t-shirt to book. Now its not that I’m without clothes but I do like grey and I’m not afraid to admit I am a nerd. So why the hell not. All you need to do is sign up and deploy your first app which isn’t that much of a bother really and I was going to do it anyway.

Sign up for New Relic and get your free t-shirt and that also gives you 10% off your first bill which is nothing if you use the free version and $50 off my own bill that I am not paying anyway because I’m using the free version :)

Its all about the FREE.

Facebook Open Graph (Complex Types)

Tue, 11 Oct 2011 09:07:37 +0000

Complex Types

Music API

JRuby Resources

Sun, 09 Oct 2011 11:38:50 +0000

Just a few resources for the almighty JRuby Desktop app I will one day build, maybe.

MIDI Keyboard


Netbeans Tutorial

Soft Token


Darkness Clone

Downgrading Rubygems

Fri, 23 Sep 2011 15:33:03 +0000

Installed latest Rubygems which broken my dev environment.

Rob-Laceys-MacBook-Pro:app roblacey$ ./script/rails s
/Library/Ruby/Site/1.8/rubygems/specification.rb:990:in `date=': invalid date format in specification: "2011-9-23" (Gem::InvalidSpecificationException)
    from /Users/roblacey/repos/app/ruby/1.8/bundler/gems/compass-cb709350942f/compass.gemspec:7
    from /Library/Ruby/Site/1.8/rubygems/specification.rb:1346:in `initialize'
    from /Users/roblacey/repos/app/ruby/1.8/bundler/gems/compass-cb709350942f/compass.gemspec:4:in `new'
    from /Users/roblacey/repos/app/ruby/1.8/bundler/gems/compass-cb709350942f/compass.gemspec:4

One to remember next time something screwy happens, and I am to lazy to use rvm

sudo gem uninstall rubygem-update -v 1.8.10
sudo gem install rubygems-update -v 1.5.2
sudo update_rubygems _1.5.2_

Extracting Blizzard Interface Code and Art

Tue, 24 May 2011 08:13:45 +0000

In order to start moving with building Warcraft AddOns you might want to extract the Blizzard UI Code and Art bundles. A little bit fiddly but…

/Applications/World\ of\ Warcraft/World\ of\\ of\ Warcraft -console

On the login screen hit /~ to open the console and type

> exportInterfaceFiles code
> exportInterfaceFiles art

You should now have two new directories in your World Of Warcraft (/Applications/World of Warcraft/) BlizzardInterfaceArt and BlizzardInterfaceCode directory.

Rob-Laceys-MacBook-Pro:World of Warcraft roblacey$ ls -la
total 3944
drwxrwxrwx  21 roblacey  admin      714 24 May 08:59 .
drwxrwxr-x+ 71 root      admin     2414 22 May 11:45 ..
-rw-r--r--@  1 rl  admin    12292 24 May 08:59 .DS_Store
drwxrwxrwx   3 rl  admin      102  3 May 18:35 Background
drwxrwxrwx   3 rl admin      102  3 May 18:35 Blizzard
drwxrwxrwx   3 rl  admin      102 24 May 08:59 BlizzardInterfaceArt
drwxrwxrwx   3 rl  admin      102 24 May 08:59 BlizzardInterfaceCode
drwxrwxrwx   4 rl  admin      136 21 Apr 23:50 Cache
drwxrwxrwx  30 rl  admin     1020 24 May 08:59 Data
drwxrwxrwx   2 rl  admin       68 18 Apr 22:19 Errors
drwxrwxrwx   3 rl  admin      102 22 Apr 00:03 Interface
drwxrwxrwx  11 rl  admin      374 22 May 11:45 Logs
drwxrwxrwx   2 rl  admin       68  3 May 21:02 Movies
-rwxrwxrwx   1 rl  admin    67140 22 May 11:45 Patch.html
drwxrwxrwx  11 rl  admin      374 22 May 11:50 Updates
drwxrwxrwx   5 rl  admin      170 22 May 11:56 WTF
-rwxrwxrwx   1 rl  admin      177 24 May 08:59 WoW.mfil
-rwxrwxrwx   1 rl  admin  1927052 22 May 11:45 WoW.tfil
drwxrwxrwx   3 rl  admin      102  3 May 18:35 World of Warcraft
drwxrwxrwx   3 rl  admin      102  3 May 18:35 World of Warcraft
drwxrwxrwx   3 rl  admin      102 22 May 11:45 World of

World Of Warcraft AddOn - pt 1. Hello World

Mon, 23 May 2011 23:09:15 +0000

My first World Of Warcraft AddOn, ok so I found a nice tutorial on WowWiki – .

- HelloWorld.toc

## Interface: 40000
## Title: Hello World!
## Notes: My first AddOn

- HelloWorld.lua

function HelloWorld()
  print("Hello World!");

- HelloWorld.xml

<Ui xmlns="" 
  <Script File="HelloWorld.lua"/>
  <Frame name="HelloWorldFrame">

And there if you look in the chat console ‘Hello World!’. Kungla is so impressed he needs to have a proper long sit down.

Code what you mean, not what looks right.

Thu, 23 Dec 2010 17:06:48 +0000


redirects = []
redirects << params[:redirect_to] || request.referrer

…does not mean this…

redirects = []
redirects << (params[:redirect_to] || request.referrer)

…it means this.

redirects = []
(redirects << params[:redirect_to]) || request.referrer

I18n Translations with a database backend

Sun, 19 Dec 2010 01:04:21 +0000

Having used Rails I18n translations in yaml for some time, we’ve recently started thinking about how users might want to customise content on the fly, without editing flat files and reloading our application. In my mind it should read from the database.

I found the Il8n Backend Database plugin, however it appears its not Rails 3 compliant yet and we can cope with and probably should build the interface for updating our own translations

It seems there was support for ActiveRecord in the i18n gem, but it has since been moved out into the i18n-active_record gem.


gem 'i18n-active_record', 
  :git => 'git://',
  :require => 'i18n/active_record'


I18n.backend = I18n::Backend::ActiveRecord
Translation  = I18n::Backend::ActiveRecord::Translation


class CreateTranslations < ActiveRecord::Migration

  def self.up
    create_table :translations do |t|
      t.string   :locale
      t.string   :key
      t.text     :value
      t.text     :interpolations
      t.boolean  :is_proc, :default => false

  def self.down
    drop_table :translations



irb(main):001:0> I18n.t('loathsome')
=> "loathsome"
irb(main):002:0> Translation.create(:locale => :en, :key => 'loathsome', :value => 'dave')
=> #<I18n::Backend::ActiveRecord::Translation id: 1, locale: :en, key: "loathsome", value: "dave", interpolations: nil, is_proc: false>
irb(main):003:0> I18n.t('loathsome')
=> "dave"

So fairly simple start, it shouldn’t be too difficult to build an interface to handle this.

You can even keep the existing flat files as a fallback if the translations don’t exist in the database.


I18n.backend =, I18n.backend)
Translation = I18n::Backend::ActiveRecord::Translation

Fan Funded and Exciting Times

Fri, 07 May 2010 11:24:59 +0000

This week has been an interesting one, and its all come at once.

Abominable Iron Sloth

For a start, The Abominable Iron Sloth album has finally seen its release on the 27th April after 4 fours of development hell. The band asked for funding from its fans after the debut release and tour. And it seems to have been one tragedy after another for them, what keeps you down only makes you stronger, eh? And here it is, arrived today with a thanks from Justin.

Stabbing Eden

Pledge Music also got their first Grindcore band on board, Stabbing Eden and I am mightily impressed what what I’ve heard so far so I one of the first to pledge. Their project to fund the recording of their 2nd album “A Second Reason To Hate Us” was launch on the 27th April.

Funeral For A Friend

Firstly, we had Madina Lake, then Tab The Band, but now the biggest metal band so far Funeral For A Friend who went live on Monday, and made their target within 36 hours which is a first for us. Well done those men, but its not over yet.

Thomas Truax

Last but not least, a man we stumbled across lately for a random zombie event in Eastbourne. The very quirky, very eccentric Thomas Truax. If only I could afford one of his famous Sister Spinster contraptions.

installing Redcar editor on Windows in 5 minutes

Sun, 02 May 2010 10:56:18 +0000



[Start Command Prompt with Ruby]

gem install redcar --pre 
redcar install

how to create a singleton with Io

Sun, 02 May 2010 10:52:33 +0000
rl@bloodandguts:~/github/io$ io
Io 20090105
Io> Highlander := Object clone
==>  Highlander_0x1957db0:
  type             = "Highlander"

Io> Highlander clone := Highlander
==>  Highlander_0x1957db0:
  clone            = Highlander_0x1957db0
  type             = "Highlander"

Io> h := Highlander clone
==>  Highlander_0x1957db0:
  clone            = Highlander_0x1957db0
  type             = "Highlander"

Io> h type
==> Highlander
Io> h
==>  Highlander_0x1957db0:
  clone            = Highlander_0x1957db0
  type             = "Highlander"


New Facebook Tools

Thu, 22 Apr 2010 17:51:21 +0000

Just playing with the new Facebook widgets to see if we can get anything useful out of them.

Pledge Music on Facebook

autotest on ubuntu

Tue, 23 Feb 2010 16:54:46 +0000

Finally got around to sorting out autotest on this ubuntu box, I remembered reading on Mr JohnC’s blog about it. Also found a rather nice article on Autotest notifications on Ubuntu using lib-notify

vi ~/.autotest

module Autotest::GnomeNotify
  # Time notification will be displayed before disappearing automatically
  ERROR_STOCK_ICON = "gtk-dialog-error"
  SUCCESS_STOCK_ICON = "gtk-dialog-info"
  # Convenience method to send an error notification message
  # [stock_icon]   Stock icon name of icon to display
  # [title]        Notification message title
  # [message]      Core message for the notification
  def self.notify stock_icon, title, message
    options = "-t #{EXPIRATION_IN_SECONDS * 1000} -i #{stock_icon}"
    system "notify-send #{options} '#{title}' '#{message}'"
  Autotest.add_hook :red do |at|
    notify ERROR_STOCK_ICON, "Tests failed", "#{at.files_to_test.size} tests failed"
  Autotest.add_hook :green do |at|
    notify SUCCESS_STOCK_ICON, "All tests passed, good job!", ""