.

Coffee Powered

code and content

Monthly Archives: March 2009

Quick tip: Strip URLs before parsing!

Rather than roll my own URL regexes, I prefer to let the existing libraries do the heavy lifting. Ruby has a uri library which is fantastic for parsing (and validating) URLs.
For example, something like this might be used in a model validation:

require 'uri'

def validate_url(url)
parsed_uri = URI::parse(url)
rescue URI::InvalidURIError
errors.add :url, "Sorry, that doesn't look like a valid [...]

Announcing Scrap

Things to do when upgrading to Rails 2.3

Monitoring Rails: Getting instant monitoring alerts

Installing the fauna libmemcached gem on Fedora Core 6

Syntactic sugar will occassionally kick your puppies.