Entries from May 2008

Deploying Rails on Dreamhost with Phusion Passenger

Deploying Ruby on Rails has always been a pain, even with tools like Mongrel and Capistrano. On shared hosting, it’s nearly impossible. A little while ago, I noticed a project called Phusion Passenger (aka mod_rails), which sought to make deploying as easy as uploading your application to your webhost. A few days ago, Dreamhost (my host) announced on their blog that Phusion Passenger was available on their servers. Naturally, I took some time to play around with it, and so far I’ve been extremely impressed. I threw together a quick app using Viddler.rb and deployed it to Dreamhost (you can see it here). Here’s a quick guide on how to deploy to Dreamhost yourself using mod_rails.

Getting set up

The first thing to do is to set up your domain or subdomain to use Passenger. Just go to the Manage Domains page on the DH web panel, and either create a new domain or edit an existing one. Check the “Ruby on Rails Passenger (mod_rails)?” checkbox and set the web directory to where the public directory of your app will be. Below is a screenshot of my settings for viddler.fidgeting.net.

mod_rails settings

Next, you need to create your database, so just go into the Manage MySQL section of the panel. Create your database, which should be named as a production database. In my case, it was viddler_production. Then, make sure to change your database.yml to reflect the database you just created.

Uploading and running your application

Before uploading, make sure the first line of your public/dispatch.fcgi has the correct path to ruby on Dreamhost (which is /usr/bin/ruby). Then all you need to do is upload the files to Dreamhost and go to the domain. That’s it—your app is now completely functional. Amazing, huh?

If you need to first run migrations, you can do that from SSH with this command:

RAILS_ENV=production rake db:migrate

If you need to restart your application (anytime you change any files), just run the following command via SSH:

touch tmp/restart.txt

Getting Gems to work on Dreamhost

Since Dreamhost is a shared host, you can’t directly install gems on the server. Dreamhost’s wiki has a lot of information on different ways to get gems working, but they are all fairly involved, and I couldn’t get any of them to work. The way I did it was by unpacking the gems into vendor/gems by using the “gem unpack” command:

gem unpack <GEM NAME>

I’m sure there are better ways to do it, but this method worked perfectly for me.

Overall Impressions

Like I said at the beginning, I’m very impressed with Passenger, and so far I haven’t noticed any issues. The total time for me to deploy was about 20 minutes: way faster than with Mongrel or FastCGI. It’s definitely awesome to see a host as large as Dreamhost using this, and hopefully soon more will follow suit.

Posted on May 17, 2008 31 Comments
Tagged with: , , , , , ,

Releasing Java Vector Class

This semester, I took a class called “Computational Physics,” where we simulated various physical properties. For my final project, I wrote a simulation of the Solar System, and in the process, I wrote a “Vector” class for Java. It allows you to do 3 dimensional vector math operations pretty easily, like in the examples below:

// Create vector <1,2,3>
Vector v1 = new Vector(1,2,3);

// Unit Vector <0.27, 0.53, 0.80>
Vector unit = v1.getUnitVector();

// Magnitude (3.74)
double mag = v1.getMagnitude();

// Get each value
double x = v1.getX(); // 1
double y = v1.getY(); // 2
double z = v1.getZ(); // 3

// Multiply v1 by scalar (<5,10,15>)
Vector scalarM = v1.scalarMult(5);

// Create vector <-4,-5,-6>
Vector v2 = new Vector(-4,-5,6);

// Add v1 and v2 (<-3,-3,-3>)
Vector add = v1.add(v2);

// Subtract v2 from v1 (<5, 7, 9>)
Vector sub = v1.minus(v2);

// Dot v1 and v2 (-32)
Double dot = v1.dot(v2);

// Cross v1 and v2 (<3,-6,3>)
Vector cross = v1.cross(v2);

I’ve never really used Java before, so my code might not be the best, but it gets the job done. If you want to download the Vector class, here’s the link. If this comes in handy to anyone, I’d really appreciate it if you left a comment!

Posted on May 4, 2008 Leave a Comment
Tagged with: , ,

Tacos in Vegas

An ad for What Happens In Vegas came on TV this evening, and I noticed something bizarre. Take a look at the font they’re using:

Now, take a look at the font Taco Bell’s been using for years:

Someone in advertising definitely dropped the ball on this one.

Posted on May 1, 2008 2 Comments
Tagged with: , , , , ,