.

Coffee Powered

code and content

Category Archives: Uncategorized

FlexAuth: Portable authentication for Battle.net

I’ve just released my first Android app, called FlexAuth. It’s mostly an excuse to learn Android development, but it does something useful, too – it serves as a souped-up mobile authenticator for Blizzard’s Battle.net login infrastructure. If you’d like the gory details, there’s a specification floating around on the internet that’ll help you understand the [...]

Serving files out of GridFS, part 2

Since my initial experiments with GridFS and nginx-gridfs, I discovered a rather downer of a dealbreaker: compiling Passenger and nginx-gridfs into the same nginx binary makes nginx very unhappy. It hard-freezes (as in, blocks forever) when you request a GridFS file with Passenger enabled. Oops. So, I sat down and fixed gridfs-fuse. You can grab [...]

Serving files out of GridFS

GridFS is a nifty little feature in MongoDB that allows you to store files of all shapes and sizes in Mongo itself, getting the benefits of Mongo’s sharding and replication. However, since they’re in a database, and not on the filesystem directly, how do we serve them? There are lots of benchmarks and numbers under [...]

counter_cache for MongoMapper

I’ve started playing with MongoMapper, and it’s quite excellent, but it does suffer very much from being young. There are lots of pieces missing that veterans of ActiveRecord will take for granted. I’ve been working around or patching them, for the most part, but I felt that my solution to `:counter_cache` deserved a post. In [...]

Safe action caching with Memcached

I’ve started using action caching more aggressively, to handle a large volume of not-signed-in search traffic. It composes a significant chunk of my site’s total traffic, but there’s no good reason to be recomputing full pages for all those long-tail hits. So, the obvious thing is to just implement a quick action cache. # Controller [...]

Multibyte string slicing for fun and profit

Ran into a small issue in one of my user models. I was using a helper to display a user’s first name, last initial. It looked something like this: def display_name(user) "user.first_name #{user.last_name.slice(0,1)}" end Seems innocent enough, sure. Except…it doesn’t work in multibyte character sets. The first Cyrillic speaker to sign up blew that all [...]

System date considered important

I’ve been slamming my head against the wall for the past two hours. I had an OAuth connection to a remote service working just dandy in development, but as soon as I tried to use that exact same code with the exact same config and exact same gems in production…I was getting “401 unauthorized” errors [...]

Sweet-ass performance hacks: better_assets

HTTP overhead is expensive. DNS lookups are expensive. Start dropping a bunch of Twitter widgets, Google ads, and GetSatisfaction buttons into your killer new Web 2.0 social networking site and you’ll find that your painstakingly-optimized site has slowed to a crawl while the server sits there waiting on Amazon S3 to get its act together [...]

Fine tuning your garbage collector

If you’re familiar with Ruby at all, you know that it can be a little wacky when it comes to memory usage. Most of us have observed a Mongrel/Passenger instance that starts out small and then grows by leaps and bounds, eventually settling on some uncomfortably high number. We’re going to fix that with Ruby [...]

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, [...]