Nathan Wilmes's blog



Nathan WilmesNathan Wilmes
Standup 2/24/2001-2/25/2001
edit Posted by Nathan Wilmes on Friday February 25, 2011 at 09:16AM

Ask for Help

"bundle install seems very slow everytime, but bundle check seems fast. Why doesn't bundle install use bundle check before doing its thing?"

Consensus was that this seemed like a good idea.

"When setting up a cc.rb box, the box could not connect to Github, yielding the 'You don't exist, go away!' message. How do we fix this situation? We can get to github through the command line without any issues."

  • One thing to check is your protocol. The git protocol is closest to SSH and obeys most of the settings SSH does.
  • Also check your agent forwarding settings. Is your box explicitly doing everything that it should?

"In Rails 2.3, we tried mocking a has_one association. However, it looks like the association isn't mocking. Why?"

Rails 2.3 associations have a proxy object that delegate to lower level objects. This proxy isn't mockable, but the target (proxy_target) is.

"What is the current best of breed passenger config beyond what you get from the passenger site?"

Recommendations were given for mod_speed.

"What are some easy ways to implement CSS spriting on my site?"

For a quick definition of CSS sprites, look here. Recommendations included Compass/SASS.

Interesting Things

  • jQuery 1.5.1 is out! It is the first jQuery that explicitly supports IE 9, so it's recommended for next generation web site development.

Nathan WilmesNathan Wilmes
Standup 2/23/2011 - mocking AJAX for jQuery 1.5
edit Posted by Nathan Wilmes on Wednesday February 23, 2011 at 10:31AM

Ask for Help

"When I tried to clear cookies on IE8, the cookies stuck around anyway. I was only able to delete them through the developer toolbar. What's going on?"

The consensus theory was that the developer toolbar might be affecting IE8's cookie behavior (IE8 is not known for its robust extensions). More investigation seems in order.

Interesting Things

  • After upgrading to Bundler 1.0.10/Rubygems 1.5.2, build time on one of our projects shrank by 2 minutes. Hurrah for caching!
  • jQuery 1.5 changed its AJAX implementation, causing us to upgrade our mock Jasmine library. Our jQuery 1.5 fork is here.

Interesting Things

  • One of our clients had a large production issue due to a long-standing bug in Rails with case sensitivity.

Here's the situation: Rails validates_uniqueness_of has a flag called :case_sensitive. This flag defaults to 'true', but can be flipped.

MySQL's default collation is case-insensitive. As a result, queries will, in general, ignore case unless specifically overridden.

So one might imagine that setting :case_sensitive to false would be completely harmless in a standard MySQL application.

One would be wrong. Setting case_sensitive to false changes the query to lowercase the field in question, causing the MySQL database to ignore any indices it may have and turning the validates_uniqueness_of operation from something cheap and quick to something requiring a full table scan.

The open Lighthouse ticket on this issue is: https://rails.lighthouseapp.com/projects/8994/tickets/2503-validates_uniqueness_of-is-horribly-inefficient-in-mysql

Nathan WilmesNathan Wilmes
Standup 5/20/2010: More about SEO routes
edit Posted by Nathan Wilmes on Thursday May 20, 2010 at 09:13AM

Ask for Help

"Any clever ways to catch out of bounds exceptions from Solr?"

This is a follow-up to yesterday's Solr question. After some investigation, it looks like none of the major providers catch out of bound exceptions for very large numbers. Rather than instrumenting every Ruby call with validations to prevent these numbers from getting into Solr, are there any other brilliant ideas?

Interesting Things

  • Follow-up to the help from 5/19/2010's SEO routing question. The latest hotness appears to be FriendlyId (http://github.com/norman/friendly_id) This plugin makes human-friendly slugs and comes with a variety of interesting features, including versioning and slug scoping.

  • Power RubyMine commands:

Goto File + line #: If you use ctrl-shift-N to go to a file, try typing in a line number after a colon, something like "my_file:30". You'll end up on that line.

Analyze stack trace: This tool lets you paste in an external stack trace, and gives you the ability to browse to all of the pieces of that stack trace.

Nathan WilmesNathan Wilmes
Standups 5/18/2010 and 5/19/2010: SEO routes
edit Posted by Nathan Wilmes on Wednesday May 19, 2010 at 09:19AM

Ask for Help

"Our site requires crafting URLs in a very particular SEO-friendly way. Rails doesn't seem to give us a good solution for our URLs. Any suggestions?"

One of our clients needs to make their app accept and generate compound URLs that look something like the following:

http://my.site/jkrowling-series-harrypotter-book-1

where author, series, and book are all different domain concepts. Rails RESTful resources don't really support this format. There wasn't an immediate solution, but among the peanut gallery of ideas:

  • Hyphens are better than slashes in URL crafting, but Rails doesn't separate on slashes at all

  • to_param solutions - Overriding to_param to something that starts with an integer ID generates URLs that look very slug-like, but can use standard Rails Domain.find mechanisms. For example, a book.to_param might be overridden to be "1-bookname", which works for all purposes. The problem with this solution is that it doesn't quite fit the requirements here, and doesn't cover the compound needs.

  • Custom routes are always a possibility. You can hook up a special (non-resource) controller that understands flexible browse-y routes like the one above, parses them, and delegates to the more standard resource controllers. The problem here is that you have to figure out a decent delegate pattern and route generation pattern.

  • In general, URL crafting is a separate art from domain model crafting, and Rails doesn't really cater to this. You will have to design URL-centric code to suit your URL crafting.

"Any ideas on ways to performance test IE7?"

No immediate ideas, but potentially more later.

"When users enter very large search parameters for numbers we get the following exception out of RSolr:"

RSolr::RequestError: Solr Response: For_input_string_11111111111111111111__javalangNumberFormatException

Is there an elegant solution to this aside from validating that all input parameters aren't larger than max int?

Interesting Things

  • When using named scope methods that refer to other named scope methods, you may discover that your SQL has some redundant condition clauses. This is a bug in Rails 2, and has been true for several versions. However, it's a harmless bug - MySQL will understand the extraneous condition clauses just fine, without performance implications.

  • Mocking Paperclip for tests is a careful art. See our other blog post: Stubbing out Paperclip ImageMagick in Tests

Nathan WilmesNathan Wilmes
Standup 12/28/2009: Rspec 1.2.9 and mocking flash
edit Posted by Nathan Wilmes on Monday December 28, 2009 at 09:24AM

Ask for Help

"Ever since we upgraded to RSpec 1.2.9, we haven't seen any stack traces. What gives?"

One of our projects lost stack traces as soon as they upgraded to RSpec 1.2.9. Reverting to RSpec 1.2.8 fixed the problem. No other projects have reported the issue yet.

Interesting Things

  • Working with Rails for several years means that, as Rails advances, our testing/mocking codes get stale. We just discovered that one of our old mocks for representing the 'flash' object no longer works as designed with the current version of Rails.

Nathan WilmesNathan Wilmes
Standup 12/23/2009: Load/require and Rails reloading
edit Posted by Nathan Wilmes on Wednesday December 23, 2009 at 09:27AM

Ask for Help

"What's a good design for sharing a page cache across multiple servers?"

One of our clients would like to have a distributed server environment share its page cache. At this point, they're relying on GFS to do this.. but this solution appears to have problems with reliability.

Several engineers questioned the necessity for such a thing, but memcached appeared to be the solution of choice.

"Any information on RabbitMQ?"

One of our engineers is beginning to play with RabbitMQ. Anyone who has good comments about this technology, please feel free to chime in.

Interesting Things

  • load "location" and require "location" do not play nicely with Rail's automatic class reloading.

Rails maintains an internal array of files that it 'knows' about for this purpose. However, load and require bypass this mechanism, and lock files into place.

If you'd like to add a require that will class-reload, use the command 'require_dependency "location"'. This command, added by Rails, will require the file AND add it to ActiveSupport.

Nathan WilmesNathan Wilmes
Standup 12/21/2009: Bundler and symbol.to_proc
edit Posted by Nathan Wilmes on Monday December 21, 2009 at 09:47AM

Ask for Help

"How do I make attachment_fu use both the file system and S3 as storage backends?"

One of our clients would like to migrate attachments from the file system to S3. They want a clever way to make attachment_fu look in S3 or the filesystem, where new files are in S3 and old files are in the filesystem.

Their current solution, which they're not super happy with, is to monkeypatch the S3 backend by extending it with file system methods. This solution doesn't really seem to work too well, since the two backends share some of the same methods, and calling "extend FileSystemBackend" doesn't give them the freedom to pick and choose their methods. In addition, their patch makes the S3 backend not be an S3 backend any more, which could cause problems for maintenance down the road.

A better solution is to define a new backend object, based on the S3 backend but falling back to file system-style methods. Attachment_fu supports defining custom backend modules; a class using :storage => :my_storage would look for a backend module called Technoweenie::AttachmentFu::Backends::MyStorageBackend.

Attachment_fu still has a design problem. The backend objects are all modules, not classes. As a result, it's not easy to make a new backend descend from one of the existing backends.

Interesting Things

  • The new version of the bundler gem, version 0.7.2, does not seem to be Ruby 1.8.6 compliant. The gem relies on symbol.to_proc, which is part of Ruby 1.8.7 (and Rails). A native Ruby 1.8.6 without Rails does not support this method.

Issue tracking: http://github.com/wycats/bundler/issues/#issue/134

Nathan WilmesNathan Wilmes
Standup 10/10/2008
edit Posted by Nathan Wilmes on Friday October 10, 2008 at 04:21PM

One interesting thing this morning:

The RailsEnvy blog had a segment talking about a team of engineers building a series of social network plugins using the Pivotal Lab's technology: Dessert.

Those of us used to Desert (one 's') were wondering what Dessert might be, leading to this quip from Adam:

"Dessert is Desert with a lot of syntactic sugar."

Nathan WilmesNathan Wilmes
Standup 10/8/2008 - testing Flash and routing helpers
edit Posted by Nathan Wilmes on Wednesday October 08, 2008 at 04:17PM

Ask for Help

One of our clients is looking for high-quality third-party chat services/libraries.

Interesting Things

10.5.5 and screen sharing

The Mac screen sharing application includes a host of interesting power features. Unfortunately, upgrading to Mac 10.5.5 causes these features to go away. Workarounds at this point are to store off the application and re-install it. Or to pay $300 for the official solution. Whichever.

Additional routing-related helper methods

It can be useful to create helper methods designed to extend the routing helpers offered by routes.rb.. power "_path" and "_url" methods. While the easy solution is to define these methods in your view helper layer (the most common client of these methods), a more complete solution is to use a pattern like this:

in routes.rb:

          ActionController::Routing::Routes.draw do |map|
               ... normal routes ...
          end

          ActionController::Routing::Helpers.module_eval do
             def additional_method_name
              ...
             end
          end

Any methods added to ActionController::Routing::Helpers will be available in all of the same places that named routes are defined - controllers, views, and ActionController::UrlWriter includers.

Testing Flash in Selenium

Most Flash applications render an inline image in addition to the Flash itself. This image updates as the Flash updates, and appears to be used for caching purposes.

When you're test-driving, you can make assertions about when this inline image updates to test Flash behavior. The image is binary, so it's hard to make assertions about exactly what has changed.. but it's a start.

Other articles: