Archive for April 2008

ActsAsInsertOrUpdate

Problem

With high volume Rails applications, entities with unique constraints are expensive and error prone to create/update. ActsAsInsertOrUpdate helps solve that problem (if you’re using MySQL), by leveraging the “INSERT … ON DUPLICATE KEY UPDATE” functionality.

Scenario
Lets say you have a Person, and Entity, and a Rating. Each user can rate each entity only once, and [...]

MySQL Stored Function: parsing a JSON encoded string

For analytics purposes, we ended up storing JSON-encoded data as a column in a mysql table. Although we don’t often need to query it directly, from time to time, it makes things a bit easier/faster. Below is a MySQL stored function that takes two parameters (a JSON encoded string, and the name of [...]

Curb your Net::HTTP

Curb is a ruby binding for libcurl. We’ve had sporadic issues with Net::HTTP, which this might aleviate via native dns, native timeouts, performance improvements, etc. It wouldnt be hard to re-implement ActiveResource, rfacebook, myspace-ruby, etc to use it instead. Anyone using this already?

sudo gem install curb

require ‘rubygems’
require ‘curb’
require "net/http"
require ‘benchmark’

iterations = 40
Benchmark.bm [...]