Ryan Williams.org

The random babblings of a software developer

Fork-me

Exception Notification in Rails 3

One thing I liked about Django was the email notification it sends when an exception occurs on the server. Ruby on Rails has a plugin called Exception Notification which does the same thing.

The installation instructions in the README file aren’t really complete. So here’s how to get it up and running in Rails 3.

Edit your Gemfile and add the following line

gem "exception_notification",
        :git => "git://github.com/rails/exception_notification.git",
        :require => "exception_notifier"

Then run bundle to install it.

Once that’s done you need to create a file named config/initializers/exception_notification.rb and populate it with:

YourAppName::Application.config.middleware.use ExceptionNotifier,
  :email_prefix => "[ERROR] ",
  :sender_address => '"Notifier" <notifier@yourdomain.com>',
  :exception_recipients => ['exceptions@yourdomain.com']

From then on you will receive an email to exceptions@yourdomain.com that contains a tonne of information to help you diagnose what caused the error.


Rails 3 and PostgreSQL 9.0 on Mac OS X Snow Leopard

Getting Rails 3 to work with PostgreSQL 9.0 on Snow Leopard is pretty straight forward once you know what needs doing.

Installing PostgreSQL 9.0

I recommend using the 1 click installer of PostgreSQL available from EnterpriseDB. It makes installation very simple and will even let you automatically install addons such as PostGIS.

When that’s done you should have a PostgreSQL folder inside your Applications folder. Go ahead and launch pgAdmin from there and create a login role for your development database.

Installing the PostgreSQL Gem

You will need to install the pg gem to use PostgreSQL. So open up your Gemfile and add the line:

gem 'pg'

Unfortunately if you run bundle you will get an error when it tries to install “pg”. You will instead need to install it manually using the following command.

 sudo env ARCHFLAGS="-arch x86_64" \
  gem install pg -- \
  --with-pg-include=/Library/PostgreSQL/9.0/include/ \
  --with-pg-lib=/Library/PostgreSQL/9.0/lib/

Now run bundle to update your Gemfile.lock.

Once that’s all done you can edit your config/database.yml file and add the login role you setup previously.


GNU/Screen with 256 colours in Mac OS X

Updating GNU/Screen

I use gnu/screen a lot on various Linux machines and like to have 256 colours when running Vim. Unfortunately the build that comes with OS X doesn’t support this so I had to go ahead and build it myself. It’s pretty straight forward.

First thing you’ll need is a terminal client that can actually handle 256 colours. The standard Apple Terminal.app doesn’t. I recommend giving iTerm a try. It also has xterm mouse support.

The next thing to do is compile and install the latest version of gnu/screen. I’ll assume you already have Git installed.

git clone git://git.savannah.gnu.org/screen.git
cd screen/src
./autogen.sh
./configure --enable-colors256 --with-sys-screenrc=/etc/screenrc
make   # I got a lot of warnings here, but they don't seem to matter
sudo make install
sudo cp etc/etcscreenrc /etc/screenrc

If everything went to plan you can run screen and should see “+color-256” in the welcome message. To properly test things you can download 256colors2.pl and run that in the terminal. It will draw all 256 colours to the terminal.

Supporting Vim

If you run vim it will complain about the lack of a 256 colour terminal. This is just because the $TERM environment variable is “screen” instead of “screen-256color”. You can set this manually or you can make screen do it for you. To get screen to do it for you simply edit your ~/.screenrc file and add:

term "screen-256color"

You may also want to enable xterm title support. This means your current vim document name will appear in the iTerm tab. For this add the following to your ~/.screenrc:

termcapinfo xterm*|rxvt*|kterm*|Eterm* 'hs:ts=\E]0;:fs=\007:ds=\E]0;\007'

If you find that the xterm titling still doesn’t work in Vim, then you may need to add this to your ~/.vimrc. Note the special characters ^[ and ^G need to be entered using CTRL+v, ESC for ^[ and CTRL+v, CTRL+g for ^G. Don’t enter them literally.

set t_ts=^[]0;
set t_fs=^G
set title

The final test to make sure everything works is to run screen then run vim. The title in your iTerm tab should say “[No Name] – VIM”.


Search Light jQuery Plugin

I needed a nice looking javascript search result script for a site I’m working on and after looking around for a while I couldn’t find anything that really did what I wanted. So, I took it upon myself to write a nifty jQuery plugin that does exactly what I want.

The plugin is named Search Light. You can view a demo of it and download it using the links at the end of this post. Please let me know what you think of it.

Screen shot of Search Light


Google Maps with Cappuccino – MapKit

As I have been playing around with the awesome Cappuccino framework, I decided to add my own little extension to the framework in order to support Google Maps and abstract away the API into a more Objective-J/Cappuccino fashion. I’ve dubbed it MapKit. It’s very early days but you can add map views to your project quite easily and it’s straight forward to fall back to the usual Google Maps API to do anything that’s currently unsupported in MapKit.

You can get MapKit from github. Also available is a simple “Hello, World” example to explain how it’s used.