<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>gluedtomyseat - Home</title>
  <id>tag:www.gluedtomyseat.com,2008:mephisto/</id>
  <generator version="0.7.3" uri="http://mephistoblog.com">Mephisto Noh-Varr</generator>
  <link href="http://www.gluedtomyseat.com/feed/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://www.gluedtomyseat.com/" rel="alternate" type="text/html"/>
  <updated>2008-08-19T13:23:17Z</updated>
  <entry xml:base="http://www.gluedtomyseat.com/">
    <author>
      <name>collin</name>
    </author>
    <id>tag:www.gluedtomyseat.com,2008-08-19:115</id>
    <published>2008-08-19T13:20:00Z</published>
    <updated>2008-08-19T13:23:17Z</updated>
    <category term="Ruby"/>
    <link href="http://www.gluedtomyseat.com/2008/8/19/a-companion-to-enumerable-inject-enumerable-build" rel="alternate" type="text/html"/>
    <title>A companion to Enumerable#inject : Enumerable#build</title>
<content type="html">
            &lt;p&gt;This was a patch idea I had for Rails.  Enumerable#inject is great, but there is a little extra bit of code cruft that I see popping up everywhere with regards to using #inject to create a new array or hash.  Since the return value of the block passed into #inject becomes the next value of the accumulator, you often see this:&lt;/p&gt;


&lt;pre class=&quot;ruby&quot;&gt;
result = (1..10).inject([]) do |array, element|
  array &amp;lt;&amp;lt; element if element % 2 == 0
  array
end

puts result.inspect # =&amp;gt; [2, 4, 6, 8, 10]
&lt;/pre&gt;

	&lt;p&gt;I&#8217;d like to see another method added to Enumerable, something like:&lt;/p&gt;


&lt;pre class=&quot;ruby&quot;&gt;
module Enumerable

  def build(accumulator)
    each do |item|
      if result = yield(accumulator, item)
        accumulator = result
      end
    end
    accumulator
  end

end
&lt;/pre&gt;

	&lt;p&gt;The #build method would essentially reassign the accumulator only if the return value of #yield was non-false.  This would shorten the above example into:&lt;/p&gt;


&lt;pre class=&quot;ruby&quot;&gt;
result = (1..10).build([]) do |array, element|
  array &amp;lt;&amp;lt; element if element % 2 == 0
end

puts result.inspect # =&amp;gt; [2, 4, 6, 8, 10]
&lt;/pre&gt;

	&lt;p&gt;So yes, one line of savings, but I feel the meaning here is much more clear than the first case using #inject.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.gluedtomyseat.com/">
    <author>
      <name>collin</name>
    </author>
    <id>tag:www.gluedtomyseat.com,2008-07-29:105</id>
    <published>2008-07-29T15:39:00Z</published>
    <updated>2008-07-29T15:39:05Z</updated>
    <category term="Ruby"/>
    <link href="http://www.gluedtomyseat.com/2008/7/29/configure-os-x-speech-voice-in-growl-glue-1-0-3" rel="alternate" type="text/html"/>
    <title>Configure OS X speech voice in growl-glue 1.0.3</title>
<content type="html">
            &lt;p&gt;Little small update for my small, but loyal &lt;a href=&quot;http://growl-glue.rubyforge.org/&quot;&gt;growl-glue&lt;/a&gt; user base.  1.0.3 released today, giving you the ability to use a different &lt;span class=&quot;caps&quot;&gt;OS X&lt;/span&gt; voice for each status.&lt;/p&gt;


&lt;pre class=&quot;ruby&quot;&gt;
GrowlGlue::Autotest.initialize do |config|
  config.notification :use_network_notifications =&amp;gt; true

  config.sound :success =&amp;gt; &quot;Glass.aiff&quot; 
  config.sound :pending =&amp;gt; &quot;Glass.aiff&quot; 

  config.say   :failure =&amp;gt; &quot;PANIC PANIC PANIC&quot; 
  config.voice :failure =&amp;gt; &quot;Hysterical&quot; 
  config.sound :failure =&amp;gt; &quot;Basso.aiff&quot; 
end
&lt;/pre&gt;

	&lt;p&gt;And of course, to update:&lt;/p&gt;


&lt;pre&gt;% sudo gem install growl-glue&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.gluedtomyseat.com/">
    <author>
      <name>collin</name>
    </author>
    <id>tag:www.gluedtomyseat.com,2008-07-29:104</id>
    <published>2008-07-29T12:27:00Z</published>
    <updated>2008-07-29T13:08:32Z</updated>
    <category term="Ruby"/>
    <link href="http://www.gluedtomyseat.com/2008/7/29/implied-types-in-ruby-s-rescue-clause" rel="alternate" type="text/html"/>
    <title>Implied types in Ruby's rescue clause</title>
<content type="html">
            &lt;p&gt;There are two different ways in which you&#8217;ll see people using &lt;strong&gt;rescue&lt;/strong&gt; in Ruby:&lt;/p&gt;


&lt;pre class=&quot;ruby&quot;&gt;
begin
  # do something terrible
rescue
  # handle error in $!
end
&lt;/pre&gt;

	&lt;p&gt;And the more explicit way:&lt;/p&gt;


&lt;pre class=&quot;ruby&quot;&gt;
begin
  # do something terrible
rescue StandardError =&amp;gt; e
  # handle error using e
end
&lt;/pre&gt;

	&lt;p&gt;These two are actually equivalent, as the former, shorter version &lt;strong&gt;implies&lt;/strong&gt; 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 &lt;strong&gt;Exception&lt;/strong&gt;:&lt;/p&gt;


&lt;pre&gt;
% 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
&lt;/pre&gt;

	&lt;p&gt;The more aggressive way to rescue from error conditions is, then, to:&lt;/p&gt;


&lt;pre class=&quot;ruby&quot;&gt;
begin
  # the most terrible code
rescue Exception =&amp;gt; e
  # whew
end
&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.gluedtomyseat.com/">
    <author>
      <name>collin</name>
    </author>
    <id>tag:www.gluedtomyseat.com,2008-07-27:103</id>
    <published>2008-07-27T18:16:00Z</published>
    <updated>2008-07-29T13:08:57Z</updated>
    <category term="Ruby"/>
    <link href="http://www.gluedtomyseat.com/2008/7/27/growl-glue-update-now-supports-the-rspec-pending-status" rel="alternate" type="text/html"/>
    <title>Growl-glue update now supports the RSpec "pending" status</title>
<content type="html">
            &lt;p&gt;&lt;a href=&quot;http://growl-glue.rubyforge.org/&quot;&gt;Growl-glue 1.0.2&lt;/a&gt; was released today.  The update adds support for a &#8220;pending&#8221; 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.&lt;/p&gt;


	&lt;p&gt;&lt;img src=&quot;http://www.gluedtomyseat.com/assets/2008/7/27/pending.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;


	&lt;p&gt;The &#8220;pending&#8221; status is configured similarly to the &#8220;failure&#8221; and &#8220;success&#8221; statuses:&lt;/p&gt;


&lt;pre class=&quot;ruby&quot;&gt;
GrowlGlue::Autotest.initialize do |config|

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

end
&lt;/pre&gt;

	&lt;p&gt;To update, simply:&lt;/p&gt;


&lt;pre&gt;
% sudo gem install growl-glue
&lt;/pre&gt;

	&lt;p&gt;If you&#8217;re wondering what growl-glue is, read the &lt;a href=&quot;http://www.gluedtomyseat.com/2008/7/9/growl-glue-tying-together-autotest-and-growl&quot;&gt;introductory post&lt;/a&gt; or the &lt;a href=&quot;http://growl-glue.rubyforge.org/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;README&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.gluedtomyseat.com/">
    <author>
      <name>collin</name>
    </author>
    <id>tag:www.gluedtomyseat.com,2008-07-24:101</id>
    <published>2008-07-24T13:59:00Z</published>
    <updated>2008-07-24T14:05:16Z</updated>
    <category term="Ruby"/>
    <link href="http://www.gluedtomyseat.com/2008/7/24/some-specs-not-being-run-by-rspec-rails-fix-it-here" rel="alternate" type="text/html"/>
    <title>Some specs not being run by rspec-rails? Fix it here.</title>
<content type="html">
            &lt;p&gt;Rspec and the Rspec-Rails plugin are awesome.  Made even more awesome by using Autotest.  Which is made even more awesome by using &lt;a href=&quot;http://www.gluedtomyseat.com/2008/7/9/growl-glue-tying-together-autotest-and-growl&quot;&gt;growl-glue&lt;/a&gt; :)&lt;/p&gt;


	&lt;p&gt;We&#8217;ve noticed on a couple of our projects that Autotest will not run all of our specs that would normally be run by &#8221;% rake spec&#8221;.  Looking into it further, I saw that the rspec-rails plugin sets up a number of Autotest &#8220;mappings&#8221;, 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.&lt;/p&gt;


	&lt;p&gt;The default mappings can be found in:&lt;/p&gt;


	&lt;p&gt;&lt;span class=&quot;caps&quot;&gt;RAILS&lt;/span&gt;_ROOT/vendor/plugins/rspec-rails/lib/autotest&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Autotest#add_mapping&lt;/strong&gt; 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 &lt;strong&gt;Autotest#files_matching&lt;/strong&gt;, which takes a regular expression that will return a set of specs that match.&lt;/p&gt;


	&lt;p&gt;In my case, there are some files in &#8220;app/filters&#8221; that I want to link up to some specs in &#8220;spec/filters&#8221;.  So, in my .autotest file inside of the project root, I include the following:&lt;/p&gt;


&lt;pre&gt;
Autotest.add_hook :initialize do |autotest|

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

end 
&lt;/pre&gt;

	&lt;p&gt;Here I&#8217;m pretty aggressive &#8211; 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 &#8211; make sure to check out the default autotest configuration inside of the rspec-rails plugin to get an idea for what&#8217;s possible.&lt;/p&gt;


	&lt;p&gt;If you&#8217;re unsure about which specs are not getting run, try running autotest as:&lt;/p&gt;


&lt;pre&gt;
% autotest -v
&lt;/pre&gt;

	&lt;p&gt;Autotest will say &#8220;Dunno!&#8221; for each file for which it doesn&#8217;t have a mapping.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.gluedtomyseat.com/">
    <author>
      <name>collin</name>
    </author>
    <id>tag:www.gluedtomyseat.com,2008-07-22:100</id>
    <published>2008-07-22T22:49:00Z</published>
    <updated>2008-07-24T14:05:26Z</updated>
    <category term="Ruby"/>
    <link href="http://www.gluedtomyseat.com/2008/7/22/did-my-team-win-today" rel="alternate" type="text/html"/>
    <title>Did my team win today?</title>
<content type="html">
            &lt;p&gt;&lt;a href=&quot;http://www.didmyteamwintoday.com&quot;&gt;Did my team win today?&lt;/a&gt; is a little rails app that I wrote that will show you if your &lt;span class=&quot;caps&quot;&gt;MLB&lt;/span&gt; team won today or not.   Well, actually, it&#8217;ll just show you the last known score for your team.&lt;/p&gt;


	&lt;p&gt;&lt;a href=&quot;http://www.didmyteamwintoday.com&quot;&gt;&lt;img src=&quot;http://www.gluedtomyseat.com/assets/2008/7/22/didmyteamwintoday.png&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;Hope you like it.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.gluedtomyseat.com/">
    <author>
      <name>collin</name>
    </author>
    <id>tag:www.gluedtomyseat.com,2008-07-20:97</id>
    <published>2008-07-20T22:39:00Z</published>
    <updated>2008-07-20T22:40:18Z</updated>
    <link href="http://www.gluedtomyseat.com/2008/7/20/terrible-lizards" rel="alternate" type="text/html"/>
    <title>Terrible Lizards</title>
<content type="html">
            &lt;p&gt;Incredible to think that these once roamed the earth.&lt;/p&gt;


&lt;div class=&quot;thickbox&quot;&gt;
&lt;a href=&quot;http://gluedtomyseat.com/assets/2008/7/20/dino3.jpg&quot; class=&quot;thickbox&quot; title=&quot;&quot;&gt;&lt;img src=&quot;http://gluedtomyseat.com/assets/2008/7/20/dino3_thumb.jpg&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;http://gluedtomyseat.com/assets/2008/7/20/dino2.jpg&quot; class=&quot;thickbox&quot; title=&quot;&quot;&gt;&lt;img src=&quot;http://gluedtomyseat.com/assets/2008/7/20/dino2_thumb.jpg&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;http://gluedtomyseat.com/assets/2008/7/20/dino1.jpg&quot; class=&quot;thickbox&quot; title=&quot;&quot;&gt;&lt;img src=&quot;http://gluedtomyseat.com/assets/2008/7/20/dino1_thumb.jpg&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;
          </content>  </entry>
  <entry xml:base="http://www.gluedtomyseat.com/">
    <author>
      <name>collin</name>
    </author>
    <id>tag:www.gluedtomyseat.com,2008-07-13:95</id>
    <published>2008-07-13T15:12:00Z</published>
    <updated>2008-07-24T14:07:10Z</updated>
    <category term="Ruby"/>
    <link href="http://www.gluedtomyseat.com/2008/7/13/restart-passenger-phusion-using-a-textmate-bundle" rel="alternate" type="text/html"/>
    <title>Restart Passenger Phusion using a TextMate bundle</title>
<content type="html">
            &lt;p&gt;So I&#8217;ve recently started running my development instances using Passenger. It&#8217;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 &lt;span class=&quot;caps&quot;&gt;OS X&lt;/span&gt; preference pane, but I prefer to do the extra steps.&lt;/p&gt;


	&lt;p&gt;One extra step I don&#8217;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&#8217;t have to load up Terminal every time I wanted to restart my application.&lt;/p&gt;


	&lt;p&gt;&lt;img src=&quot;http://gluedtomyseat.com/assets/2008/7/13/passenger_tm_bundle.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;


	&lt;p&gt;You can simply hit the hotkey to restart the app.  It&#8217;s project relative, so it should work for whatever rails project you happen to have loaded in TextMate.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.gluedtomyseat.com/">
    <author>
      <name>collin</name>
    </author>
    <id>tag:www.gluedtomyseat.com,2008-07-09:71</id>
    <published>2008-07-09T11:48:00Z</published>
    <updated>2008-07-09T20:03:03Z</updated>
    <category term="Ruby"/>
    <link href="http://www.gluedtomyseat.com/2008/7/9/growl-glue-tying-together-autotest-and-growl" rel="alternate" type="text/html"/>
    <title>GrowlGlue : tying together Autotest and Growl</title>
<content type="html">
            &lt;p&gt;A while ago I blogged about modifying one&#8217;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&#8217;s unreasonable to assume that anyone would actually &lt;strong&gt;want&lt;/strong&gt; to do all of that, I made my first gem: &lt;a href=&quot;http://growl-glue.rubyforge.org/&quot;&gt;growl-glue&lt;/a&gt;.&lt;/p&gt;


&lt;pre&gt;
% sudo gem install growl-glue
&lt;/pre&gt;

	&lt;p&gt;And then inside of your ~/.autotest file, something simple like:&lt;/p&gt;


&lt;pre&gt;
require 'rubygems'
require 'growl_glue'

GrowlGlue::Autotest.initialize do |config|
  config.notification :use_network_notifications =&amp;gt; true
  config.title :success =&amp;gt; &quot;Everything is Great&quot; 
  config.title :failure =&amp;gt; &quot;Hate&quot; 
  config.say :failure =&amp;gt; &quot;ON NO!!!&quot; 
end
&lt;/pre&gt;

	&lt;p&gt;And that&#8217;s it! It even comes embedded with sample success and failure images that you can override with your own if you wish (but don&#8217;t have to).  Make sure to &lt;a href=&quot;http://growl-glue.rubyforge.org/&quot;&gt;look over the &lt;span class=&quot;caps&quot;&gt;README&lt;/span&gt;&lt;/a&gt; to get started.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.gluedtomyseat.com/">
    <author>
      <name>collin</name>
    </author>
    <id>tag:www.gluedtomyseat.com,2008-05-26:24</id>
    <published>2008-05-26T12:40:00Z</published>
    <updated>2008-07-09T20:03:17Z</updated>
    <category term="Ruby"/>
    <link href="http://www.gluedtomyseat.com/2008/5/26/plugin-migrator-migrations-for-your-rails-plugins" rel="alternate" type="text/html"/>
    <title>Plugin Migrator: migrations for your Rails plugins</title>
<content type="html">
            &lt;h2&gt;Overview&lt;/h2&gt;


	&lt;p&gt;My current work involves writing a handful of Rails plugins.  These plugins provide additional functionality that includes ActiveRecord models that need to be persisted to the database.  I originally created a migration class for one of the plugins that re-used much of the ActiveRecord logic (in fact, just overrides schema management).  This worked fine, but as we started creating new plugins that needed the same functionality, we decided to pull the migration logic into a separate Rails plugin.&lt;/p&gt;


	&lt;p&gt;And hence, the PluginMigrator was born!&lt;/p&gt;


	&lt;p&gt;In order to use the PluginMigrator, your plugin must simply extend the PluginMigrator::Migrator class:&lt;/p&gt;


&lt;pre class=&quot;ruby&quot;&gt;
module MyPlugin
  class Migrator &amp;lt; PluginMigrator::Migrator

    set_schema_table_override &quot;my_plugin_schema_info&quot; 
    set_migration_directory(File.dirname(__FILE__) + &quot;/../../db/migrate&quot;) 

  end
end
&lt;/pre&gt;

	&lt;p&gt;The &lt;strong&gt;set_schema_table_override&lt;/strong&gt; method tells the plugin where the version info for your plugin should be stored.  For rails apps, this schema information lives in a table named &#8220;schema_info&#8221;.  You&#8217;ll need to specify a different table name for your plugin, so that your plugin migrations can be managed separately from the Rails app.  Don&#8217;t worry if it doesn&#8217;t exist yet &#8211; the migration system will automatically create it.&lt;/p&gt;


	&lt;p&gt;The &lt;strong&gt;set_migration_directory&lt;/strong&gt; method tells the plugin where to find the migrations.  The migrations for your plugin should probably be stored in the same way as the main rails app. In your plugin root, it&#8217;s easy to just have a db/migrate structure:&lt;/p&gt;


	&lt;p&gt;&lt;img src=&quot;http://gluedtomyseat.com/assets/2008/5/26/plugin_structure.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;


	&lt;p&gt;To actually migrate, simply create a Rake task in your tasks directory inside of your plugin or in the main Rakefile for your plugin, depending on from where you want to run the migrate task:&lt;/p&gt;


&lt;pre class=&quot;ruby&quot;&gt;
namespace :myplugin do
  desc &quot;Run the migrations for my plugin&quot; 
  task :migrate =&amp;gt; :environment do
    MyPlugin::Migrator.migrate(ENV['VERSION'],false)
  end
end
&lt;/pre&gt;

	&lt;p&gt;And then:&lt;/p&gt;


&lt;pre&gt;
% rake myplugin:migrate
&lt;/pre&gt;

	&lt;p&gt;Typical &lt;span class=&quot;caps&quot;&gt;VERSION&lt;/span&gt; behavior is also supported:&lt;/p&gt;


&lt;pre&gt;
% rake myplugin:migrate VERSION=1
&lt;/pre&gt;

	&lt;h2&gt;Installation&lt;/h2&gt;


	&lt;p&gt;The PluginMigrator project &lt;a href=&quot;http://github.com/oculardisaster/plugin_migrator/tree/master&quot;&gt;is hosted at GitHub&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;From the Terminal:&lt;/p&gt;


&lt;pre&gt;
~/testapp $ cd vendor/plugins
~/testapp/vendor/plugins $ git clone git://github.com/oculardisaster/plugin_migrator.git
&lt;/pre&gt;

	&lt;p&gt;If you don&#8217;t have Git on your system, you can simply &lt;a href=&quot;http://github.com/oculardisaster/plugin_migrator/tree/master&quot;&gt;go to the main project page&lt;/a&gt; and click the download button.&lt;/p&gt;


	&lt;h2&gt;Known Issues and Planned Features&lt;/h2&gt;


	&lt;ul&gt;
	&lt;li&gt;Would like to be able to optionally exclude having the main rails app include plugin tables when writing out the schema.rb file during a Rails app migration.&lt;/li&gt;
		&lt;li&gt;Would like to have the plugin migrator automatically create rake tasks to migrate the plugin&lt;/li&gt;
	&lt;/ul&gt;
          </content>  </entry>
  <entry xml:base="http://www.gluedtomyseat.com/">
    <author>
      <name>collin</name>
    </author>
    <id>tag:www.gluedtomyseat.com,2008-05-20:18</id>
    <published>2008-05-20T20:04:00Z</published>
    <updated>2008-05-20T20:04:30Z</updated>
    <link href="http://www.gluedtomyseat.com/2008/5/20/a-six-hundred-series" rel="alternate" type="text/html"/>
    <title>A six hundred+ series</title>
<content type="html">
            &lt;p&gt;After much research into getting rid of lane oil and finally restoring my ball coverstock back to its near original condition I ruled the lanes today.  My first 600+ series.  This should help my street cred at league night tomorrow.&lt;/p&gt;


	&lt;p&gt;:D&lt;/p&gt;


&lt;div class=&quot;thickbox&quot;&gt;
&lt;a href=&quot;http://gluedtomyseat.com/assets/2008/5/20/639_series.png&quot; class=&quot;thickbox&quot; title=&quot;&quot;&gt;&lt;img src=&quot;http://gluedtomyseat.com/assets/2008/5/20/639_series_thumb.png&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;
          </content>  </entry>
  <entry xml:base="http://www.gluedtomyseat.com/">
    <author>
      <name>collin</name>
    </author>
    <id>tag:www.gluedtomyseat.com,2008-05-12:16</id>
    <published>2008-05-12T02:04:00Z</published>
    <updated>2008-07-14T11:23:13Z</updated>
    <category term="Ruby"/>
    <link href="http://www.gluedtomyseat.com/2008/5/12/configuring-autotest-and-growl-in-osx-leopard" rel="alternate" type="text/html"/>
    <title>Configuring Autotest and Growl in OS X 10.5.x</title>
<content type="html">
            &lt;h2&gt;&lt;i&gt;&lt;span class=&quot;caps&quot;&gt;UPDATE&lt;/span&gt; &#8211; Use &lt;a href=&quot;http://gluedtomyseat.com/2008/7/9/growl-glue-tying-together-autotest-and-growl&quot;&gt;GrowlGlue&lt;/a&gt; Instead&lt;/i&gt;&lt;/h2&gt;


	&lt;p&gt;Autotest Just got a &lt;strong&gt;lot&lt;/strong&gt; simpler.. For an easier time of configuring Autotest and Growl please read &lt;a href=&quot;http://gluedtomyseat.com/2008/7/9/growl-glue-tying-together-autotest-and-growl&quot;&gt;Configuring Autotest and Growl in &lt;span class=&quot;caps&quot;&gt;OS X 10&lt;/span&gt;.5.x&lt;/a&gt; instead.&lt;/p&gt;


&lt;hr /&gt;
&lt;br /&gt;

	&lt;p&gt;First off, if you are not running &lt;a href=&quot;http://nubyonrails.com/articles/autotest-rails&quot;&gt;autotest&lt;/a&gt; then you need to start.  It&#8217;s awesome and a pretty integral part of my &lt;span class=&quot;caps&quot;&gt;TDD&lt;/span&gt; workflow.  A popular combination these days is to run a combination of autotest along &lt;a href=&quot;http://growl.info/&quot;&gt;Growl&lt;/a&gt;.  There are already quite a few guides out there on how to set up a development environment with autotest and Growl&#8212;why am I writing this one?  It is because many of the guides out there do not work exactly right under &lt;span class=&quot;caps&quot;&gt;OS X 10&lt;/span&gt;.5.2, making it frustrating to set up these tools.  After trying a number of them, and taking what worked right and what didn&#8217;t, here is what works for me.&lt;/p&gt;


	&lt;h2&gt;Setting up Autotest&lt;/h2&gt;


	&lt;p&gt;Autotest is part of the ZenTest suite, which should be installed as a gem:&lt;/p&gt;


&lt;pre&gt;
sudo gem install ZenTest
&lt;/pre&gt;

	&lt;p&gt;After you install the ZenTest gem, you should then have autotest at /usr/bin/autotest.&lt;/p&gt;


	&lt;h2&gt;Setting up Growl&lt;/h2&gt;


	&lt;p&gt;You can download Growl from the &lt;a href=&quot;http://growl.info/&quot;&gt;Growl website&lt;/a&gt; of course.  You will want to install the Growl application normally, but then after that is complete, &lt;strong&gt;you will also want to install the growlnotify extra&lt;/strong&gt; that comes with Growl.&lt;/p&gt;


	&lt;p&gt;&lt;img src=&quot;http://www.gluedtomyseat.com/assets/2008/5/12/growl_dmg.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;


	&lt;p&gt;Once you&#8217;ve installed Growl and while the &lt;span class=&quot;caps&quot;&gt;DMG&lt;/span&gt; is still open, open up a Terminal.app window and execute the following:&lt;/p&gt;


&lt;pre&gt;
cd /Volumes/Growl\ 1.1.2/Extras/growlnotify/
./install.sh 
&lt;/pre&gt;

	&lt;p&gt;Now you should be able to test this out by typing the following into the Terminal.ap window:&lt;/p&gt;


&lt;pre&gt;
echo &quot;Hello World&quot; | growlnotify
&lt;/pre&gt;

	&lt;p&gt;If you receive a &#8220;growlnotify: command not found&#8221;, then you need to add /usr/local/bin into your &lt;span class=&quot;caps&quot;&gt;PATH&lt;/span&gt; environment variable.&lt;/p&gt;


	&lt;p&gt;If this fails silently, that is because of an incompatibility between Growl and &lt;span class=&quot;caps&quot;&gt;OS X 10&lt;/span&gt;.5.x that will cause dropped messages about 50% of the time. So even if you got the Growl notification, you should install the following fix for Growl.&lt;/p&gt;


	&lt;h2&gt;Fixing Growl&lt;/h2&gt;


	&lt;p&gt;Simply put, on &lt;span class=&quot;caps&quot;&gt;OS X 10&lt;/span&gt;.5.x, growlnotify works about 50% of the time for me.  To address this, first open up your Growl preferences (under System Preferences), click the network tab, and then make sure that the &#8220;Listen for incoming notifications&#8221; checkbox is checked. Like this:&lt;/p&gt;


	&lt;p&gt;&lt;img src=&quot;http://www.gluedtomyseat.com/assets/2008/5/12/growl_listen_notifications.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;


	&lt;p&gt;After you set that, click back to the General tab, and then Stop Growl, and Start Growl again.&lt;/p&gt;


	&lt;p&gt;Now, the bug in Growl that I mentioned does not affect incoming network Growl notifications. So we&#8217;re going to make a wrapper for growlnotify that will forward received growl notifications to the network port that Growl listens on.  Create ~/safegrowlnotify with the contents:&lt;/p&gt;


&lt;pre&gt;
#!/bin/bash

# growlnotify leopard bug workaround
list_args()
{
    for p in &quot;$@&quot; 
    do
        if [ &quot;${p:0:1}&quot; == &quot;-&quot; ];then
            echo -n &quot;$p &quot; 
        else
            echo -n &quot;\&quot;$p\&quot; &quot; 
        fi
    done
}
argstr=$(list_args &quot;${@:$?}&quot;)
echo &quot;-H localhost $argstr&quot; | xargs /usr/local/bin/growlnotify
&lt;/pre&gt;

	&lt;p&gt;And of course you will want to chmod 755 that file. To test that you have it configured, run thusly:&lt;/p&gt;


&lt;pre&gt;
safegrowlnotify 'Hello World!'
&lt;/pre&gt;

	&lt;p&gt;You should have growl notifications coming up now:&lt;/p&gt;


	&lt;p&gt;&lt;img src=&quot;http://www.gluedtomyseat.com/assets/2008/5/12/growl_success.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;


	&lt;h2&gt;Configuring Autotest for Growl&lt;/h2&gt;


	&lt;p&gt;Now that we have everything installed, it&#8217;s time to configure Autotest.  When Autotest loads up and starts the test loop, it will configure itself from ./.autotest and also ~/.autotest.  It is in the latter that we&#8217;ll make our Growl modifications.  This way the behavior will be shared amongst all projects that use Autotest.&lt;/p&gt;


	&lt;p&gt;Insert the the following into ~/.autotest (create if it does not already exist):&lt;/p&gt;


	&lt;h4&gt;.autotest&lt;/h4&gt;


&lt;pre class=&quot;ruby&quot;&gt;
module Autotest::Growl
  GROWLNOTIFY = &quot;/Users/collin/safegrowlnotify&quot; 

  def self.notify title, msg, img, pri=1, sticky=&quot;&quot; 
    commands = [&quot;#{GROWLNOTIFY}  --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{sticky}&quot;]
    commands.each { |c| system(c) }
  end

  Autotest.add_hook :ran_command do |at|
    results = [at.results].flatten.join(&quot;\n&quot;)
    # rpsec
    output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+pending)?/)
    if output
      if $~[2].to_i &amp;gt; 0
        notify &quot;Test Results&quot;, &quot;#{output}&quot;, &quot;~/Library/autotest/rails_fail.png&quot;, 2
      else
        notify &quot;Test Results&quot;, &quot;#{output}&quot;, &quot;~/Library/autotest/rails_ok.png&quot; 
      end
    end
    # test::unit
    output = results.slice(/(\d+)\s+tests?,\s*(\d+)\s+assertions?,\s*(\d+)\s+failures?,\s*(\d+)\s+errors?/)
    if output
      if (($~[3].to_i &amp;gt; 0) or ($~[4].to_i &amp;gt; 0))
        notify &quot;Test Results&quot;, &quot;#{output}&quot;, &quot;~/Library/autotest/rails_fail.png&quot;, 2
      else
        notify &quot;Test Results&quot;, &quot;#{output}&quot;, &quot;~/Library/autotest/rails_ok.png&quot; 
      end
    end
  end

end
&lt;/pre&gt;

	&lt;p&gt;&lt;em&gt;&lt;strong&gt;(thanks to samsm for the Test::Unit modifications)&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;


	&lt;p&gt;It is very important to change the value of &lt;span class=&quot;caps&quot;&gt;GROWLNOTIFY&lt;/span&gt; to whereever you installed it previously.  Also, you will want to put the following into ~/Library/autotest (create if it does not already exist). You can use whatever images you&#8217;d like, but I used these that some other kind soul before me shared in a similar blog post:&lt;/p&gt;


	&lt;p&gt;&lt;img src=&quot;http://www.gluedtomyseat.com/assets/2008/5/12/rails_ok.png&quot; alt=&quot;&quot; /&gt; &lt;img src=&quot;http://www.gluedtomyseat.com/assets/2008/5/12/rails_fail.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;


	&lt;p&gt;At this point, you should be all set up and ready to go. Simply running autotest should run the tests and then display the Growl messages along with an icon to boot that signifies success or failure:&lt;/p&gt;


	&lt;p&gt;&lt;img src=&quot;http://www.gluedtomyseat.com/assets/2008/5/12/test_success.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;


	&lt;p&gt;Happy Autotesting!&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.gluedtomyseat.com/">
    <author>
      <name>collin</name>
    </author>
    <id>tag:www.gluedtomyseat.com,2008-05-08:14</id>
    <published>2008-05-08T14:05:00Z</published>
    <updated>2008-05-08T14:05:26Z</updated>
    <link href="http://www.gluedtomyseat.com/2008/5/8/braves-vs-padres-5-wins-in-a-row" rel="alternate" type="text/html"/>
    <title>Braves vs Padres - 5 wins in a row</title>
<content type="html">
            &lt;p&gt;Thanks to Brett for the nice tickets to the Braves game yesterday.  The seats were on the lower level, quite a bit closer than the nosebleeds I usually purchase.  If we win today&#8217;s game at 1pm, we will have swept the Padres.  Go Braves!&lt;/p&gt;


&lt;div class=&quot;thickbox&quot;&gt;
&lt;a href=&quot;http://gluedtomyseat.com/assets/2008/5/8/IMG_0062.JPG&quot; class=&quot;thickbox&quot; title=&quot;&quot;&gt;&lt;img src=&quot;http://gluedtomyseat.com/assets/2008/5/8/IMG_0062_thumb.JPG&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;http://gluedtomyseat.com/assets/2008/5/8/IMG_0061.JPG&quot; class=&quot;thickbox&quot; title=&quot;&quot;&gt;&lt;img src=&quot;http://gluedtomyseat.com/assets/2008/5/8/IMG_0061_thumb.JPG&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;
          </content>  </entry>
  <entry xml:base="http://www.gluedtomyseat.com/">
    <author>
      <name>collin</name>
    </author>
    <id>tag:www.gluedtomyseat.com,2008-04-20:11</id>
    <published>2008-04-20T14:09:00Z</published>
    <updated>2008-07-13T13:16:48Z</updated>
    <category term="Ruby"/>
    <link href="http://www.gluedtomyseat.com/2008/4/20/textmate-macro-title-comment-bundle" rel="alternate" type="text/html"/>
    <title>TextMate Macro - Title Comment Bundle</title>
<content type="html">
            &lt;p&gt;I like to segment my code with comments.  I don&#8217;t go nuts with it, but it helps me to have a visual delineation of what certain blocks of code do.  Usually it will look something like this:&lt;/p&gt;


&lt;pre class=&quot;ruby&quot;&gt;
class Boat &amp;lt; ActiveRecord::Base

  # validations ------------------------------------

  validates_presence_of :name
  validates_presence_of :pony
  validates_presence_of :me

  # callbacks --------------------------------------

  def before_save
    #...
  end

  # business ---------------------------------------

end
&lt;/pre&gt;

	&lt;p&gt;One problem I run into frequently is trying to keep a consistent right hand side margin with those comments.  As the source code grows in length, it becomes increasingly hard to make sure that the right hand side lines up.  Even if you&#8217;re not &lt;span class=&quot;caps&quot;&gt;OCD&lt;/span&gt;, it becomes a bit ugly to have jagged right hand side edges for these comments. So I thought, this is the perfect time to create my first TextMate bundle.&lt;/p&gt;


	&lt;p&gt;I&#8217;ll spare you the details of my failures trying to figure out how to do this.  The final macro ended up being Ruby code and made use of the environment variables that TextMate provides to these scripts.  It also uses the &lt;strong&gt;TextMate::UI&lt;/strong&gt; class to query the user for the text of the comment title.  If text is already selected before the bundle command is invoked, that will be the default for the title.&lt;/p&gt;


&lt;pre class=&quot;ruby&quot;&gt;
#!/usr/bin/env ruby

require &quot;#{ENV[&quot;TM_SUPPORT_PATH&quot;]}/lib/exit_codes&quot; 
require &quot;#{ENV[&quot;TM_SUPPORT_PATH&quot;]}/lib/ui&quot; 

MAX_LENGTH = 80

if text = TextMate::UI.request_string(:title =&amp;gt; &quot;Title&quot;, 
    :prompt =&amp;gt; &quot;Comment Title:&quot;, 
    :default =&amp;gt; ENV[&quot;TM_SELECTED_TEXT&quot;]) 

  result  = &quot;# &quot; 
  result += text
  result += &quot; &quot; 
  result += &quot;-&quot; * (MAX_LENGTH - result.length - ENV['TM_LINE_INDEX'].to_i)
  print result

end
&lt;/pre&gt;

	&lt;p&gt;The use of the &lt;strong&gt;TM_LINE_INDEX&lt;/strong&gt; environment variable gives us the column position of the caret on the current line.  Using this allows us to ensure that the right hand side always lines up, no matter what indentation one starts on when creating the comment.&lt;/p&gt;


	&lt;p&gt;I bind the command to ctrl-opt-cmd-c.&lt;/p&gt;


	&lt;p&gt;&lt;img src=&quot;http://gluedtomyseat.com/assets/2008/4/20/title_comment_before.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;


	&lt;p&gt;&lt;img src=&quot;http://gluedtomyseat.com/assets/2008/4/20/title_comment.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;


	&lt;p&gt;&lt;img src=&quot;http://gluedtomyseat.com/assets/2008/4/20/title_comment_after.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;


	&lt;p&gt;If you use this, you probably will want to use the following settings for your macro in the bundle editor:&lt;/p&gt;


	&lt;p&gt;&lt;img src=&quot;http://gluedtomyseat.com/assets/2008/4/20/title_comment_bundle_editor.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;


	&lt;p&gt;You can also &lt;a href=&quot;http://gluedtomyseat.com/assets/2008/4/20/nimble-techique-tmbundle.zip&quot;&gt;download the bundle directly&lt;/a&gt; if you&#8217;d like.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.gluedtomyseat.com/">
    <author>
      <name>collin</name>
    </author>
    <id>tag:www.gluedtomyseat.com,2008-04-18:9</id>
    <published>2008-04-18T14:48:00Z</published>
    <updated>2008-04-18T14:48:41Z</updated>
    <link href="http://www.gluedtomyseat.com/2008/4/18/three-strikes-and-you-re-out" rel="alternate" type="text/html"/>
    <title>Three strikes and you're out</title>
<content type="html">
            &lt;p&gt;But what about eight strikes and a couple of spares to boot?&lt;/p&gt;


&lt;div class=&quot;thickbox&quot;&gt;
&lt;a href=&quot;http://gluedtomyseat.com/assets/2008/4/18/bowling_a_245.jpg&quot; class=&quot;thickbox&quot; title=&quot;&quot;&gt;&lt;img src=&quot;http://gluedtomyseat.com/assets/2008/4/18/bowling_a_245_thumb.jpg&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;

	&lt;p&gt;It was a pretty amazing game.&lt;/p&gt;
          </content>  </entry>
</feed>
