Configure OS X speech voice in growl-glue 1.0.3

Posted by collin
on Tuesday, July 29

Little small update for my small, but loyal growl-glue user base. 1.0.3 released today, giving you the ability to use a different OS X voice for each status.

GrowlGlue::Autotest.initialize do |config|
  config.notification :use_network_notifications => true

  config.sound :success => "Glass.aiff" 
  config.sound :pending => "Glass.aiff" 

  config.say   :failure => "PANIC PANIC PANIC" 
  config.voice :failure => "Hysterical" 
  config.sound :failure => "Basso.aiff" 
end

And of course, to update:

% sudo gem install growl-glue

Implied types in Ruby's rescue clause

Posted by collin
on Tuesday, July 29

There are two different ways in which you’ll see people using rescue in Ruby:

begin
  # do something terrible
rescue
  # handle error in $!
end

And the more explicit way:

begin
  # do something terrible
rescue StandardError => e
  # handle error using e
end

These two are actually equivalent, as the former, shorter version implies that you are catching any error that is or is a subclass of StandardError. The problem is that while StandardError does encompass a large number of different exception types, it still lives under the broader umbrella of Exception:

% cheat exceptions
exceptions:
  Exception
   NoMemoryError
   ScriptError
     LoadError
     NotImplementedError
     SyntaxError
   SignalException
     Interrupt
   StandardError
     ArgumentError
     IOError
       EOFError
     IndexError
     LocalJumpError
     NameError
       NoMethodError
     RangeError
       FloatDomainError
     RegexpError
     RuntimeError
     SecurityError
     SystemCallError
     SystemStackError
     ThreadError
     TypeError
     ZeroDivisionError
   SystemExit
   fatal

The more aggressive way to rescue from error conditions is, then, to:

begin
  # the most terrible code
rescue Exception => e
  # whew
end

Growl-glue update now supports the RSpec "pending" status

Posted by collin
on Sunday, July 27

Growl-glue 1.0.2 was released today. The update adds support for a “pending” status. Without any extra configuration, the gem will use a yellow graphic to match the text in the terminal and will also output a unique title for the growl notification.

The “pending” status is configured similarly to the “failure” and “success” statuses:

GrowlGlue::Autotest.initialize do |config|

    config.notification :use_network_notifications => true
    config.title :success => "Love", :failure => "Hate", :pending => "Keep Going!" 
    config.say :failure => "Something is horribly wrong!" 
    config.say :pending => "I know you can do it!" 

end

To update, simply:

% sudo gem install growl-glue

If you’re wondering what growl-glue is, read the introductory post or the README.

Some specs not being run by rspec-rails? Fix it here.

Posted by collin
on Thursday, July 24

Rspec and the Rspec-Rails plugin are awesome. Made even more awesome by using Autotest. Which is made even more awesome by using growl-glue :)

We’ve noticed on a couple of our projects that Autotest will not run all of our specs that would normally be run by ”% rake spec”. Looking into it further, I saw that the rspec-rails plugin sets up a number of Autotest “mappings”, which are ways of telling the Autotest loop of not only the files that should be tested, but also which specs to run when a source file is modified.

The default mappings can be found in:

RAILS_ROOT/vendor/plugins/rspec-rails/lib/autotest

Autotest#add_mapping takes a regular expression that, if it matches a source file path, can either then return a path or a list of paths that point to the specs that correspond to the source file. If you wanted to return a glob of files, you can use Autotest#files_matching, which takes a regular expression that will return a set of specs that match.

In my case, there are some files in “app/filters” that I want to link up to some specs in “spec/filters”. So, in my .autotest file inside of the project root, I include the following:

Autotest.add_hook :initialize do |autotest|

  autotest.add_mapping(%r%^app/filters/(.*)\.rb$%) { |_, m|
    autotest.files_matching %r%^spec/filters/.*_spec.rb$%
  }

end 

Here I’m pretty aggressive – I simply run all of the filter specs in spec/filters when any file in app/filters is modified. You can get pretty specific though – make sure to check out the default autotest configuration inside of the rspec-rails plugin to get an idea for what’s possible.

If you’re unsure about which specs are not getting run, try running autotest as:

% autotest -v

Autotest will say “Dunno!” for each file for which it doesn’t have a mapping.

Did my team win today?

Posted by collin
on Tuesday, July 22

Did my team win today? is a little rails app that I wrote that will show you if your MLB team won today or not. Well, actually, it’ll just show you the last known score for your team.

Hope you like it.

Terrible Lizards

Posted by collin
on Sunday, July 20

Incredible to think that these once roamed the earth.

Restart Passenger Phusion using a TextMate bundle

Posted by collin
on Sunday, July 13

So I’ve recently started running my development instances using Passenger. It’s been a really nice transition, even with the extra steps of setting up a hostfile and adding an entry into an Apache config file. I know about the OS X preference pane, but I prefer to do the extra steps.

One extra step I don’t like doing is having to touch the [project_home]/tmp/restart.txt file in order to restart the application. Since I do most of my work in TextMate, I decided to write a little bundle so that I wouldn’t have to load up Terminal every time I wanted to restart my application.

You can simply hit the hotkey to restart the app. It’s project relative, so it should work for whatever rails project you happen to have loaded in TextMate.

GrowlGlue : tying together Autotest and Growl

Posted by collin
on Wednesday, July 09

A while ago I blogged about modifying one’s ~/.autotest file and adding all sort of regular expression pattern matching to parse autotest output and then display notifications with images through Growl. Because it’s unreasonable to assume that anyone would actually want to do all of that, I made my first gem: growl-glue.

% sudo gem install growl-glue

And then inside of your ~/.autotest file, something simple like:

require 'rubygems'
require 'growl_glue'

GrowlGlue::Autotest.initialize do |config|
  config.notification :use_network_notifications => true
  config.title :success => "Everything is Great" 
  config.title :failure => "Hate" 
  config.say :failure => "ON NO!!!" 
end

And that’s it! It even comes embedded with sample success and failure images that you can override with your own if you wish (but don’t have to). Make sure to look over the README to get started.