Is Ruby Slow? Try Every Icon

Can a machine produce every possible image? 

While Every Icon is resolved conceptually, it is unresolvable in practice. 

It posits a representational system where computational promise is intricately linked to extraordinary duration and momentary sensation.

In 1996, John F. Simon, Jr. created "Every Icon", a program/art piece to display every possible 32x32 icon.

The quotes above are from his statement about the project: http://numeral.com/articles/paraicon/paraicon.html

Every Icon is an awesome conceptual art piece, and a fun programming problem.

Here's my ruby version: https://github.com/teeparham/every_icon

Send Devise Emails with Resque

Sending devise emails using resque does not work out of the box with devise and resque_mailer. There are a few purported solutions online that don't work.

Below are 2 ways to make it work. Either way, I'll assume you already have devise and resque working with this in your Gemfile: 

Tell Devise you are going to use a different mailer in config/initializers/devise.rb: 

Now create the DeviseResqueMailer class. Here are 2 alternate ways to make it happen:

1. Copy/Paste FTW

Add lib/devise_resque_mailer.rb: 

2. Use a new module in resque_mailer:

Use this fork of resque_mailer: http://github.com/teeparham/resque_mailer/tree/model-mailer . Specify that fork in your Gemfile:

gem 'resque_mailer', :git => 'git://github.com/teeparham/resque_mailer'

You'll now have an additional model available called Resque::ModelMailer. Include that in a new mailer (again, lib/devise_resque_mailer.rb): 

For either #1 or #2, If you use a mailer class called DeviseResqueMailer, the view files for the mailer need to be in the expected place. Move your devise views from app/views/devise/mailer/ to app/views/devise_resque_mailer/.

You should now be able to send emails directly in development, or using resque in production. 

Why is this necessary?

The devise mailer takes a resource (typically a user) as the argument to all its mailer actions. ResqueMailer repurposes the Mailer class as a Resque Job class. Enqueuing a job with an argument of an object (a user) is not advised since the marshaling and unmarshaling of that object may not be well-defined since it must be stored in redis as a primitive type. Essentially what we're doing is queuing a resque job of the DeviseResqueMailer class with the class name and id ("User", 123 for example) instead of the object itself. Then when the job is performed, we call User.find(123) and pass that to the mail action. 

 

Update Your Rails App to Ruby 1.9.3

Ruby 1.9.3 is offically released. Updating from 1.9.2 is easy with rvm.

Note that 1.9.3 will install rake 0.9.2.2, so you should remove any gem spec for rake from your Gemfile if you have specified a rake version there.

Also, you should update your .rvmrc file in your project(s) to "rvm 1.9.3".

Test rails app with ruby 1.9.3-preview

Update: Ruby 1.9.3 is officially released! This is old news now.

See this post instead.

Let's test our Rails 3 app with the new ruby 1.9.3 preview release, using RVM and bundler.

Step 1 - Install ruby 1.9.3 preview and run our tests. That should do it!

But we get this:

/Users/tee/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/1.9.1/test/unit.rb:167:in `block in non_options': file not found: test/unit/**/*_test.rb (ArgumentError)

Let's update rake to fix this. First, let's create a new branch to isolate any hacks we need to make.

Then put this in your Gemfile:

Now install your bundle and test again:

 

Finished tests in 1.825648s, 651.5643 tests/s, 1483.5197 assertions/s.

1289 tests, 2885 assertions, 0 failures, 0 errors, 0 skips

 

Victory! (OK you got me - the numbers are fibbed).

More info on the rake error here:

https://github.com/jimweirich/rake/issues/51

http://www.ruby-forum.com/topic/2335362 

 

Amazon's Simple Email Service on rails using aws-ses and devise

Dan Croak at ThoughtBot recently wrote a nice summary of Amazon's Simple Email Service and the ruby aws-ses gem.

After signing up for SES, here's the gist of using aws-ses, with an extra tip for setting the display from address:

If you're using Devise, follow the aws-ses instructions to configure ActionMailer. The Devise::Mailer is a subclass of ActionMailer, so the standard ActionMailer configuration works. See the "For Rails 3.x" section at http://github.com/drewblas/aws-ses

It's also easy to change the from email address and the corresponding display name in the Devise initializer: 

 

Monkey Business Sorting Nulls in Sqlite

Sqlite sorts null values first. They admit it quite plainly on http://www.sqlite.org/datatype3.html
Sqlite-smoking-gun
However, most other databases sort null values last. This is a head-slapper when you have a development database in Sqlite and a production database in Postgres, for example.

If you want to sort on a column that has null values in Sqlite, you should either exclude rows with null values from your list, or set a default value in the table definition for  that column.

Here's the gist:

Ubuntu 10.10 EC2 Setup Tips

The Amazon EC2 interface for selecting an AMI is totally unmanageable. Everything else in the GUI is reasonable, though, so I prefer it to doing it all via the command line tools. This is nuts:
Ec2-ami-selection-unmanageable
First, decide what Ubuntu version you want to run and find the EC2 AMI for it. 

I chose the latest and greatest, Maverick Meerkat, here: http://uec-images.ubuntu.com/releases/10.10/release/

Now when you start your image in AWS, filter by the AMI ID & the selection becomes much easier:
Ec2-ami-selection-much-better
This guide is great: https://help.ubuntu.com/community/EC2StartersGuide . If you started your instance in the AWS GUI, it's easy to see the command line steps that correspond to what you did in the GUI.

Note that with the Canonical Ubuntu images, you'll need to ssh as the "ubuntu" user:
ssh -i /path/to/ec2-keypair.pem ubuntu@<external-host-name>