Setting Up Ubuntu

11/09/2008

Although my preferred platform is OS X for personal stuff, I use Ubuntu Linux for work. I do all my work in Ubuntu via VMware Fusion.

Great thing about Ubuntu is apt. It makes setting up the machine for development really easy. OS X has Mac Ports, but imo apt is better. Plus, working in a VM allows you to have multiple OS installs, allows you to backup your setup easily, you can take snapshots, and work on the same OS that you deploy your software to.

Read on to read my notes on how to setup Ubuntu for work.

Read the rest of this entry »

Enterprise Rails

11/09/2008

I recently picked up the book Enterprise Rails by Dan Chak.

it’s an excellent book, and was sorely needed by me. The biggest thing for me was that it explains how to use a good (i.e. PostgreSQL) database effectively and shows how to use materialized views, triggers, and so forth in a Rails application.

It also delves into how to organize a large Rails application, separating your models into modules and then into standalone services. Afaik, no other book shows how to do this sort of stuff.

We’re looking to apply it to this site. (note: not all the tests are counted, since “rake stats” only shows the specs, not the “historical” tests in the tests directory)

+----------------------+-------+-------+---------+---------+-----+-------+
| Name                 | Lines |   LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Libraries            |  1301 |  1003 |      24 |     168 |   7 |     3 |
| Models               |  6112 |  4927 |     110 |     757 |   6 |     4 |
| Helpers              |  1836 |  1575 |       0 |     176 |   0 |     6 |
| Controllers          |  4342 |  3696 |      90 |     478 |   5 |     5 |
| Model specs          |  2915 |  2417 |       2 |       9 |   4 |   266 |
| View specs           |   370 |   301 |       0 |       1 |   0 |   299 |
| Controller specs     |  1307 |  1043 |       0 |       4 |   0 |   258 |
| Helper specs         |   432 |   286 |       0 |       0 |   0 |     0 |
+----------------------+-------+-------+---------+---------+-----+-------+
| Total                | 18615 | 15248 |     226 |    1593 |   7 |     7 |
+----------------------+-------+-------+---------+---------+-----+-------+
  Code LOC: 11201     Test LOC: 4047     Code to Test Ratio: 1:0.4

How To Dynamically Create ActiveRecord Classes

08/23/2008

A question came up on IRC on someone commenting on how it was a pain to have a file for each ActiveRecord class if they were all really simple and basically the same. I cooked up the following code for him.

So, in your environment file (or some other appropriate place), you can create these classes with just one line of code per class. Of course, the method that creates the class can get more complicated - you could pass in options if the classes needed to differ from each other. This is a really simple example of the power of metaprogramming - writing code that writes code.

Quite helpful if you don’t want to repeat yourself all the time.

Advertising for useful things

07/31/2008

Software that we as a small web consulting company can not live without:

  • For keeping track of our tasks, we use Pivotal Tracker. The estimation and prioritizing features are what makes it work well for us. And it’s free for now!
  • To make and share documents and spreadsheets, Google Docs does the trick.<!-more->
  • For email, good old Google Apps.
  • Tickspot lets us keep track of time spent on each client.
  • Highrise keeps track of people that we know and what’s new with them.
  • Engine Yard keeps our websites and software running. I love how they handle so much of the system administration work that I would otherwise have to do.
  • For remote communication, Adium rocks. It’s a perfect instant messaging client. Well, not quite perfect. It needs to do video.
  • For editing/programming, Jordan uses TextMate, Joe uses vim.

Starling and Facebook

07/30/2008

It’s really important to make sure that your Rails controllers complete their actions quickly. If you have some code in their that takes a while to execute (say, a remote network call), you need to have that stuff done in a different process or thread.

For Daily Caption, we use Starling to queue up messages that need to get sent to Facebook. Another program, creatively called “facebook_daemon” watches the Starling queue.

Read the rest of this entry »