A warning about lingering Rails 2.3 ActiveRecord::Observers

I just had a Rails 2.3 ActiveRecord::Observer that wasn't configured to be used "spontaneously" get pulled into my running app and get activated.  

This observer was old and should have been deleted from the source code.  But I kept it around.  

Anyway, it got pulled into the namespace after my app had been running for a week and crashed a lot of functionality.

So get rid of ActiveRecord::Observers that are not being used!!!!

Spotlight can't find Applications

So spotlight decided that it didn't know where any of my Applications
were. This really puts a damper in my work flow so here is the
solution.

In Snow Leopard open Terminal and type:

 
arch -i386 mdimport /Applications 

If you aren't using Snow Leopard just skip the 'arch -i386' and it should work.

This will reindex your Applications directory which will enable
Spotlight to find your Applications again.

The elegant way to make square images in Ruby (avatar style)

The problem: we have an image and you want to make a smaller square
version of it. We want the smaller version to cropped so that the
image fills the square.

For example you have this:

And you want to square it and crop off the sides:

And then end up with a resulting square image:

This is a problem that I have solved over and over again. But this is
my favorite solution:

Using mini_magick (http://github.com/probablycorey/mini_magick)

Dont' miss the '^' in the resize geometry. That resizes to the
closest dimension while maintaining the aspect ratio.

Note that this works when you want to "magically" crop rectangular
images as well.

Getting started with AMQP and Ruby

OK so I want to see the most simple basic example of using a message
queue from Ruby.

Install the rabbitmq server and the amqp ruby bindings.

 
brew install rabbitmq 
sudo gem install amqp 
sudo gem install carrot 

(I use homebrew http://github.com/mxcl/homebrew for package management on OSX.)

Now start the server.

 
rabbitmq-server 

Create a server.rb that handles the messages.

This server is pretty basic it handles the messages and prints them
out as it gets them.

Now lets create a client.rb that sends messages to the queue.

Note that I used the 'carrot' library. Carrot makes it easy for me to
publish to asynchronous queues from synchronous processes like Sinatra
or Rails.

Now run the server in one terminal.

 
ruby server.rb 

And run the client in another window.

 
ruby client.rb 

You should see this show up in the terminal where you ran server.rb :

 
Message number 0 
Message number 1 
Message number 2 
Message number 3 
Message number 4 
Message number 5 
Message number 6 
Message number 7 
Message number 8 
Message number 9 

There you have it. A very simple example.

Now if you want to send structured data, you may want to try using the
JSON library to serialize the data you want to send.