Skip to main content

Benjamin Oakes

Photo of Ben Oakes

Hi, I'm Ben Oakes and this is my geek blog. Currently, I'm a Ruby/JavaScript Developer at Liaison. Previously, I was a Developer at Continuity and Hedgeye, a Research Assistant in the Early Social Cognition Lab at Yale University and a student at the University of Iowa. I also organize TechCorridor.io, ICRuby, OpenHack Iowa City, and previously organized NewHaven.rb. I have an amazing wife named Danielle Oakes.

Filtering for the month November, 2010. Clear

MySQL console tip

by Ben

If you terminate statements with \G instead of ;, the MySQL console will print the result set vertically rather than as a horizontal table.

For example, instead of:

+----+--------+--------+
| id | foo_id | bar_id |
+----+--------+--------+
| 1  | 6      | 2      |
+----+--------+--------+

You will have:

*************************** 1. row ***************************
                         id: 186
                     foo_id: 6
                     bar_id: 2

It’s really useful for wide tables, or ones with text columns.

I’m always surprised that the MySQL docs don’t make it easier to find this — it’s one of the better tricks for using the database console.

Clever Spam

by Ben

I got this spam email at my old university address today. I thought it was pretty clever (it definitely had me chuckling). Much too long for a tweet, so here it is:

DEAR RECEIVER,

You have just received a Taliban virus. Since we are not so technologicaly advanced in Afghanistan, this is a MANUAL virus. Please delete all the files on your hard disk yourself and send this mail to everyone you know.

Thank you very much for helping us.

Thanks & Regard’s

Ken

Rails Timezones

by Ben

I ran into a Rails 3.0.1 timezone issue today that I didn’t see discussed many other places.

Basically, I just want to have a page in my app that shows the time in different time zones. That seems simple and something tailor suited for timezone support.

I started with this:

>> Time.now.in_time_zone('EST')
=> Tue, 23 Nov 2010 11:09:42 EST -05:00

Okay, so far so good. Next:

>> Time.now.in_time_zone('PST')
NoMethodError: undefined method `period_for_utc' for nil:NilClass
[...]
>> Time.now.in_time_zone('CST')
NoMethodError: undefined method `period_for_utc' for nil:NilClass
[...]

Wait, that’s odd… why doesn’t that work? After searching, I found you could use some city names like so:

>> Time.now.in_time_zone('Tokyo')
=> Wed, 24 Nov 2010 01:04:54 JST +09:00

But of course JST won’t work:

>> Time.now.in_time_zone('JST')
NoMethodError: undefined method `period_for_utc' for nil:NilClass
[...]

And neither will major American cities:

>> Time.now.in_time_zone('New York')
NoMethodError: undefined method `period_for_utc' for nil:NilClass
[...]
>> Time.now.in_time_zone('Chicago')
NoMethodError: undefined method `period_for_utc' for nil:NilClass
[...]

Nothing too relevant came up when I googled the above errors and phrases (part of why I’m posting this), but then I came across the rake time:zones:us and rake time:zones:all Rake tasks. They list valid timezones for you.

The thing that gets me is that 'EST' and 'Tokyo' work as expected, but 'PST' and 'New York' don’t. These are what I ended up with:

>> Time.now.in_time_zone('Eastern Time (US & Canada)')
=> Tue, 23 Nov 2010 11:08:12 EST -05:00
>> Time.now.in_time_zone('Central Time (US & Canada)')
=> Tue, 23 Nov 2010 10:06:08 CST -06:00
>> Time.now.in_time_zone('Pacific Time (US & Canada)')
=> Tue, 23 Nov 2010 08:06:23 PST -08:00

Ironically, it lists EST, CST, and PST in the results. It’s still confusing to me why the longhand version is the preferred notation here (sometimes), but at least you’re given the tools to look it up.

Like always, let me know if this post helps you through an error. We’re all in this together.

Update: The good people over at Airbnb found this post helpful when upgrading from Rails 2.3 to 3.0. I’m glad it helped you out!