Speeding up Rails tests with Spring
I found Rails tests were running slow, these things helped. Instrumenting application.rb First, I added some logging to application.rb ruby < view plain text > def logg(m) puts "#{DateTime.now}...
View ArticleHow to use different favicons for development, staging, and production
It’s useful to have different favicons for each environment during development, as Pamela recently pointed out. Here’s how I do it. First, generate the images. Most graphics editor have some kind of...
View ArticleLoad-balancing Rails with Nginx
Well this was some fine undocumented black magic. I’ve got Player FM behind a load balancer now, using the following Nginx config. I’ll explain some more about the overall upgrade later. # App load...
View ArticleLogging an error with Exceptional
Here’s a quick utility for people using Exceptional to track errors. It lets you force an exception to be logged and without having to rescue it. Example: exceptional “read_file”, “file not found” The...
View ArticleDefer and Recur with Rails, Redis, and Resque
I’ve put off some scaling related issues about as long as possible, and am now proceeding to introduce a deferred-job stack. I’ll explain what I’ve learned so far, and with the caveat: this isn’t in...
View ArticleTesting HTTPS Locally
As I’m migrating the player over to HTTPS, one challenge is partial content, leading to an incomplete padlock and strikethrough domain warning like this: And the harsh but fair warning, upon...
View ArticleMonkey-patching a sample() method in Rails
It’s useful while debugging to choose a random sample. Thus you can include something like this in application.rb or an initializer. Now you can say Post.sample to get a single post or Post.sample(5)...
View ArticlePrivate resources with ElasticSearch and Tire
I’m adding private channels to Player FM and one consideration is search results. Tire’s activerecord does a great job at making updates transparent, but in this case some manual overriding is...
View ArticleRails Cache Sweeper Gotchas
As you’ll see here, Rails cache sweepers are a tricky subject. Here are some general things I’ve learned. Sweepers are dual creatures. “Here’s the scoop: sweepers observe both your models and your...
View ArticleFirefighting an RSS Aggregator’s Performance
That’s a before-and-after shot of the database server’s CPU! I was watching it slowly creep up, planning to inspect it after some other work, before receiving mails from Linode that the virtual server...
View ArticleSorting a Rails log file by SQL duration
Rails’ ActiveRecord logger writes log files like: Post Load (735.8ms) SELECT posts.* FROM posts where post.title = 'foo' You may want to know the longest SQL queries for performance optimsation...
View ArticleThe Weirdness of Ajax Redirects: Some Workarounds
I've been dealing with the situation when your server redirects after a DELETE. Which is actually a fairly common use case. User deletes a blog post, redirect them to the index of all posts. The...
View ArticleRails Default Date Gotcha
This had me going for a while! I wanted to default a field to the epoch, i.e. some decades ago, or older. That's because a batch process will work on the records with the oldest such field, so setting...
View ArticlePreventing a Rails (Mongrel App) from Crashing
I've had a Rails website which works fine for about 12-18 hours, then starts giving out intermittent 500 errors because the mongrels die. After searching around, I ended up fixing it on two levels....
View ArticleRails JSON, JSON Rails
< p style="clear:both; margin-top: 2em; "> Man, JSON has come out of nowhere! I first came across it amid the Javascript hype in early '05, now it's everywhere. Not only in your Ajax apps, but...
View ArticleRuby/Rails: Overriding NilClass
Rails uses "whiny nil", which means if you call a method on an object that happens to be nil (null), you get an exception. This is good. But with strings in a web app (in any language), you often don't...
View ArticleIf HTML Used Convention Over Configuration …
Browsers would automatically pull in CSS and JS according to the filename and I would no longer have to look for an example every time I need a link or script tag. In the absence of any other spec,...
View ArticleRuby is Rails is … REST
Will the peripheral IT community come to view REST and Rails as equivalent? It might sound ridiculous, but consider: Unix==Linux, Wiki==Wikipedia, Ajax=Web 2.0, blogging==RSS, podcast==spoken MP3. Last...
View Article