Finding :last

Rails makes it easy to find the first row of a query:


But what if you want the last one? It’d be great to be able to go:


… especially if you could pass in conditions, etc.

Well, this isn’t general purpose, but it tends to get you the last one that was created. Can be useful in testing circumstances:

last_order = Order.find(:first, :conditions => 'id = (select max(id) from orders)')

Two Great Radio Stations

Back in 1983, a friend of mine happened to ask, “Have you listened to the new KFOG?” Previously, KFOG had been a full-contact muzak station, but had recently changed its format to rock ‘n’ roll.

I explicitly remember driving home one evening in my then-new VW GTI in San Rafael, CA.  I was passing the high school and tuned to 104.5.  The DJ said, “You know that Genesis album Three Sides Live?  Well, in Europe, all four sides are live, so we’re going to play the live fourth side for you now.”

I was hooked.  Although KFOG’s tastes may have diverged a little from mine over the ensuing years, I would still rate it as an excellent radio station and one that played a giant role in my daily life for literally decades.  I remember trying desperately to find some place while I was at school in San Luis Obispo that could miraculously pull KFOG in from the clouds 200+ miles away.  Good thing I move back to the Bay Area when I graduated Cal Poly.

Fast forward to my recent visit to Washington DC.  Without anything compelling available in the morning on the hotel television, I turned to the radio and started scanning.  I landed on 94.7 The Globe where Roger Daltrey was belting out “Out of my BRAI-AIN on the train.”

So I start off my KFOG listening career with the Fourth Side Live of Genesis, and The Globe brings me into their fold with The Who 5.15.  Perfection.


I was doing some work in Visual Studio this morning in Vista running under Parallels on my MacBook Pro.

At one point, Vista crashed and displayed the BSOD, and I had to chuckle that I was seeing one on my Mac.  Of course, OS X didn’t care….

MacBook Pro would circle-slash on boot after Leopard update

I install Leopard on my MacBook Pro on Friday evening, messed around with it a little, and then put the computer to sleep until Saturday.  On Saturday, I had reason to restart, and that’s when I saw it:  upon restart, I would get the gray Apple logo, then a spinner beneath that logo, then eventually (3 minutes?) a circle-with-a-slash-through-it where the Apple logo was.


I tried several things to no avail, including verifying the disk and repairing disk permissions.  I even reinstalled Leopard which actually brought the computer up again but still didn’t solve the problem upon restart.

I just now got off the phone with Apple — 47 minutes from dialing to finished with about a 10-15 minute wait before I spoke to a human.  Following his instructions, I booted the computer into “safe mode” (by holding down the Shift key after restart).  Then I deleted all my login items (via System Preferences –> Accounts).  However, the clincher (I believe) was deleting all the folders in /Library/StartupItems which included, among other things, an old Nortel Contivity VPN client.

All better now!

created_at and updated_at in fixtures

I’ve been working on some code that gets a list of “old” orders based on the created_at value for an order. Of course, I wrote a test using a fixture that gets the list of old orders and makes assertions about it. I was not as rigorous as I should have been and simply checked to make sure the correct count of orders was returned and went along my merry way.

Today the test broke when I made some other changes. During my investigation, I printed out the contents of the orders and discovered the created_at and updated_at values were being set to all zeros. OK, that would explain why they’re considered “old” if they’re from “the beginning of time.” But I still wanted to be able to put values in for created_at that would cause an order to be too new to be included in the query. So, I figured I’d do something like this:

created_at: <%= %>

No workie; still zeros. Well, thanks to this blog entry, I was able to get it right:

created_at: <%= %>

Rails REST testing using XML

One of the things that has been bugging me about my REST interfaces is that, although they are thoroughly tested in functional tests with all the GETs and POSTs and PUTs (and occasionally DELETEs), it just isn’t quite the same as literally POSTing the XML.

So, this morning I took the time to figure out a way to do this. It turns out that with an integration test, it’s quite easy. It’s also probably the Right Place™ to do this.


class RestXmlTest < ActionController::IntegrationTest
  fixtures :model_fixture

  # Test creating a new resource by actually POSTing the XML.
  def test_create_resource
    post "/path_to_resource.xml",
      "<resource><attribute_1>attribute value</attribute_1>...</resource>",
      {:content_type => "application/xml"}

    assert_response 201

Verifying a Verisign Certificate Using nginx and an Intermediate Certificate

I had an SSL certificate in place in an https server, but whenever I connected to the site, I would see a certificate error. I tried verifying the certificate and got the following error:

$ openssl verify cert.pemcert.pem: [details removed]
error 20 at 0 depth lookup:unable to get local issuer certificate

I stumbled across a reference to Verisign requiring an “intermediate certificate” in order to verify an issued certificate. Consequently, I downloaded the following intermediate certificate from Verisign, based on the type of certificate I was working with. Storing this certificate into a file I called “verisign_intermediate.crt,” I was now able to verify my certificate:

$ openssl verify -CAfile verisign_intermediate.crt cert.pemcert.pem: OK

The final hurdle was to get the https server (nginx) to play ball. Per nginx documentation here, I simply appended the intermediate certificate to my main certificate file, reloaded the nginx configuration, et voilà! No more certificate error.

Verisign Intermediate CA Installation Instructions

Auto-completion in OS X (10.4) Mail!

Imagine my surprise at 0722 on a Friday morning when I’m typing an email but my fingers are not awake yet…

In the body of the message, I typed “R” then was trying to press “option-e” in order to put an accent aigu on the “e” I was about to type. Accidentally, I pressed “option-escape” and it popped a list of words that start with R!

Yes, I still need more coffee, but coming from a Java IDE and Visual Studio which does auto-completion in code, this is a very welcome discovery!