Ewout blogt.

Web development, ruby, and rails

Category: Uncategorized

Testing in Seoul

When dealing with time in a rails application, there are three time zones to be concerned with. UTC Time.zone Local time zone By convention, all times are stored in the database as UTC. ActiveRecord abstracts this by converting dates from UTC to Time.zone when a timestamp is read from the database and doing the opposite [...]

iCloud POP access, a developer’s way

So I got an email from Apple stating it’s time to upgrade my MobileMe account to iCloud. Working in IT for a few years made me trade my early-adopters-enthusiasm for an if-it-ain’t-broken-don’t-fix-it-mentality. But mighty Apple said it’s time now, so I pushed the upgrade button. I opened Powermail and discovered that it did not receive my new [...]

Local scope bug in IE9 javascript evaluator

I recently experienced a what-the-fuck-moment when testing some javascript code on internet explorer. All ran well on IE6 upto 8, but not in IE9. After a bit of fiddling, I was able to create a small failing example. function fail() { var p = {} var c = p.c = []; c.push({r: (c = [])}) [...]

Do not store database backups in git

Some people use revision control systems like git or svn for storing and managing backups. The idea sounds appealing, because consecutive backups only differ slightly and revision control systems can optimize the space required to store them. The following paragraphs will explain why this is just plain wrong. Data retention An RCS is built for [...]

Optimize GROUP BY a ORDER BY b in mysql

The following query took 150 ms on a dataset of a few thousand rows, even though there were indexes on companies.id, companies.name and people.company_id. SELECT companies.id, count(people.id) FROM companies LEFT JOIN people on companies.id = people.company_id GROUP BY companies.id ORDER BY companies.name Explain revealed “Using index; Using temporary”. Turns out that mysql can only use a [...]

Selenium integration testing: optimize login

Integration tests for highly dynamic web applications are currently bound to happen in the browser. There exist in-memory solutions that execute javascript, but none of them seem to have a fully accurate DOM implementation at the moment. Testing in the browser is slow and every optimization is welcome. A logged in user is a prerequisite for [...]

JDBC access with distributed ruby

JDBC, java database connectivity, is the standard database driver interface on the java platform. Since java is ubiquitous, most database vendors provide JDBC drivers to access their data. When a ruby application requires using a legacy data source, sometimes the only option is going through JDBC. The database toolkit Sequel can use JDBC data sources, but [...]

Using arel with rails 2.3.4+

Arel, a relational algebra, allows expressing complex relational (SQL) queries in ruby. It is used underneath ActiveRecord 3 for generating queries, where it is underapreciated in my opinion. Arel is extremely powerful and should become a weapon of choice for query manipulation in ruby. Although it is still in beta, it is very stable and [...]

HTTP Basic Authentication with Devise

Devise is becoming a popular gem for adding modular authentication to a rails application. It builds on top of warden, which provides a pluggable architecture for multiple authentication strategies at the rack level. Since the cool kids are using it, we did not want to be left out and ported our main application from restful_authentication. [...]

Generic deep merge for ActiveRecord

A while ago, a client asked us for a way to find and remove duplicate companies from his database. The mysql database behind the rails application contained over 10,000 companies, each having related contacts, phone numbers, email addresses, notes, … The data was imported from multiple sources and inevitably contained a lot of duplicates. We [...]