Sam Pierson's blog



Sam PiersonSam Pierson
Standup 8/19/2010: Bundler and RVM Gemsets, Rails 3 and JQuery, Why Day
edit Posted by Sam Pierson on Thursday August 19, 2010 at 10:03AM

Interesting

  • Bundler and RVM Gemsets work! For a while now, Bundler has been putting gems in the system gems location (instead of a private folder as it did previously). This means that it now works well with RVM Gemsets. Use It.
  • Rails 3 & JQuery: Someone has written a nice generator that will unplug Prototype from Rails 3 and install JQuery.
  • Ruby 1.9.2 was released yesterday.
  • Today is international Why Day, commemorating the day that Why the Lucky Stiff disappeared from the online community. Interestingly August 19th is also the day that 3 witches where put on trial in Samlesbury, England in 1612 and that 5 witches where executed in Salem, Massachusetts in 1692. Coincidence? I think not.

Sam PiersonSam Pierson
Standup 8/18/2010: Time#to_json in milliseconds, Encoded vs. encrypted Session Cookies
edit Posted by Sam Pierson on Wednesday August 18, 2010 at 09:11AM

Interesting

  • Make Ruby Time#to_json always return time in milliseconds: It turns out that while Firefox and Chrome can, Safari cannot parse the default time format that Time#to_json produces. The team decided to override Time#as_json to return an integer number of milliseconds, which to_json will then render into a string (JavaScript can easily work with number-of-milliseconds-since-the-start-of-the-epoch).
  • A pivot wanted to remind everyone that in Rails 2.x, session cookies are not encrypted. Reassuringly, all present were already aware of this. Session cookies are Base64 encoded, and if you ever need to take a look at their contents, here's how. If you want to encrypt your session cookies, there are Rails plugins available for that purpose.

Sam PiersonSam Pierson
Standup 8/17/2010: RubyMine shortcuts, client visible Cucumber results
edit Posted by Sam Pierson on Tuesday August 17, 2010 at 09:23AM

Help

  • RubyMine Keyboard Shortcuts:

    • How do I move from one side of a split editor window to the other side? Answer: Ctrl-Tab.
    • So how do I figure this out for myself? Helpful-Non-Answers: Cmd-Shift-A pulls up a search box that you can type in commands (e.g. "move") and get suggestions. Preferences -> Keymap has an even better search box, and also a reverse-search (click the funnel next to the search box) that lets you type in a keystroke and see what command it is. Of course, unless you know that the thing you need is called the "Switcher", you're still not going to find out. Sometimes you just have to resort to interacting with another human (let's call it "using the meat-net"). Company wide standups FTW.
  • How do I make the results of our integration tests (e.g. using cucumber) easily visible to a non-technical product owner by putting them on a web-page, a là Fit? One answer: use the --format html option, capture the output and copy to a web server. One project also has a url that a client can visit that will cause the cucumber tests to be run.

Sam PiersonSam Pierson
Standup 9/24/2009: Hiring a Sysadmin, Rails Security Patches
edit Posted by Sam Pierson on Thursday September 24, 2009 at 01:40PM

Help

Interesting

  • Mouseophobics - Ctrl-Enter on the RubyMine Commit Changes dialog will commit without you having to grab your mouse.

  • Rails Security Patches - The Rails team recently came out with 2.3.4 featuring security patches to fix the recently discovered vulnerabilities. Apparently the plan was to also upgrade 2.2.2 to 2.2.3 with these patches, but they forgot to push the gems. They should be coming to a gem server near you soon.

Sam PiersonSam Pierson
Standup 9/23/2009: Multiple Rubygems Versions, Abstract AR Classes
edit Posted by Sam Pierson on Wednesday September 23, 2009 at 09:14AM

Help

How do you deal with an old, soon to be retired codebase that requires old versions of rubygems and rake, and a new codebase that requires new version of rubygems and rake, on the same machine?

Suggestions:

  1. Have two separate Ruby installations (each with its own gems).
  2. Don't. Use two machines. Optimize for developer resources rather than hardware, the former being much more expensive than the latter.

ActiveRecord Abstract Class doesn't work with validations?

AR allows you to set abstract_class = true. The makes the class uninstantiable, i.e. you can't create instance of the class, you have to create a subclass of it and create an instance of that.

However, if you create an abstract class that contains validations, then subclass it, the subclass produces errors when attempting to validate. This features does not seem well thought out.

Has anyone used Capistrano to deploy to a load balanced EC2 cluster?

Suggestions:

  • Follow the "deploy to localhost" path.
  • Use Cap for bootstrapping and Chef for configuration.

Sam PiersonSam Pierson
Standup 9/21/2009: Cabulous
edit Posted by Sam Pierson on Monday September 21, 2009 at 01:36PM

Interesting

  • Cabulous is going into beta: UpStart Mobile, makers of Find my Friend are releasing the beta of Cabulous: "A mobile application that gives cab drivers and their passengers the peace of mind of seeing exactly where each other are from hail to pick-up.". Now that's what I call handy. The Cabulous beta is being held in San Francisco, California in November/December 2009.

Help

  • JQuery ajax post with no data: If you use JQuery to POST with no data element, it will work fine in development mode (with mongrel) but Nginx will will respond with a HTTP 411 "Length Required" response code, as JQuery is not adding a Content-length header. This solution is to add an empty data hash to the call. Anybody have a better solution? Post-standup-research: Several People have encountered this issue and spoken of filing it as a JQuery bug, but I could find no followup that it got filed or fixes.

Interesting

  • Git merge strategy "ours" is destructive: When doing a git merge that causes a conflict, picking "ours" as the merge strategy causes git to choose our changes for ALL files, not just those with a conflict, i.e. it ignores the changes in the other branch. From git-merge(1): "ours": This resolves any number of heads, but the result of the merge is always the current branch head. It is meant to be used to supersede old development history of side branches.

  • New Relic RPM GEM problem: We encountered a case where using the GEM version of RPM in a project caused no telemetry to get logged. This may be an interaction with Desert or Geminstaller (or the GEM may be broken but we consider that unlikely). After switching from the GEM to the plugin, everything worked fine.

  • Collectl is a system performance data gathering tool. From it's website: "Unlike most monitoring tools that either focus on a small set of statistics, format their output in only one way, run either interatively or as a daemon but not both, collectl tries to do it all." Kinda like sar+top and user friendly too.

  • MySQL Analyze Table - no substitute for Explain: From the MySQL 5.0 docs: "ANALYZE TABLE analyzes and stores the key distribution for a table. MySQL uses the stored key distribution to decide the order in which tables should be joined when you perform a join on something other than a constant. In addition, key distributions can be used when deciding which indexes to use for a specific table within a query." Sounds great huh. However we found a case here where using FORCE INDEX to get a select statement to use the right index caused a 2 order of magnitude speed increase. Moral: There is No Substitute for Explain and a Brain.

Sam PiersonSam Pierson
Standup 04/30/2009: perform_caching and Rails.cache, W3C DTDs and IE, Range#min/max
edit Posted by Sam Pierson on Thursday April 30, 2009 at 04:06PM

Help

  • Perform_caching is not respected by Rails.cache methods. config.action_controller.perform_caching does not appear to affect the Rails.cache methods. Rails 2.1 introduced a new custom caching mechanism:
result = Rails.cache.fetch('key') do
  # create and return item for this key
end

It would be really nice if, for testing, you could set a configuration variable that would force a cache miss every time and always execute the block associated with the fetch. However it appears that, understandably, action_controller.perform_caching only affects the kinds of caching implemented by ActionController (page, action, fragment) and not this caching mechanism that is implemented by ActiveSupport::Cache::Store. Looking at the code, is appears there is no way to disable this caching mechanism other than supplying :force => true to the fetch call to force a cache miss.

  • W3C refusing to serve DTDs to 'misbehaving' clients. One of our applications that has not been deployed for a while is starting to see issues from IE users. After digging, we found this: W3C's Excessive DTD Traffic and this w3.org DTD/xhtml1-strict.dtd blocks Windows IE users?. To summarize, w3.org got tired of getting slammed with non-cached DTD requests, and cut off misbehaving user agents (ones that do not cache the DTD). IE is one of these.

We have several things so far, none of which work:

  1. Forcing xhtml DTD to be a SYSTEM dtd, and load the DTD files off the local server. This didn't work - IE serve the pages as raw unrendered html (must have thought it was XML?)

  2. Use a PUBLIC doctype pointing to the DTD served on our server. Alas, this had the same problem as the SYSTEM doctype in #1 - raw unrendered HTML.

  3. Not using XHTML (e.g. have as root tag). This didn't work (haven't looked into why yet).

Ideas are welcome.

Interesting

  • Range#min, Range#max: Don't use them. Use Range#first and Range#last. Min and max are not overridden by Range so fall back onto Enumerable which then converts the Range into an Array first!

Sam PiersonSam Pierson
Standup 04/29/2009: Shared examples pollute; SWFObjects + Asset Packager
edit Posted by Sam Pierson on Wednesday April 29, 2009 at 04:16PM

Interesting

  • It looks like Rubymine 1.0 is out.

  • Shared examples pollute! If you import a shared example into an RSpec group, the before :each appears to run for all examples in that spec, not just the ones in the current scope.

  • SWFObject + AssetPackager = :(
    SWFObject stops working on some platforms (IE, FF2 on Windows, and others) when used in conjunction with AssetPackager. This will make you sad; don't do it.

Sam PiersonSam Pierson
Standup 04/28/2009: Handling failures in SQS; SF.TUG; Aviary.com; Delicious Monster.
edit Posted by Sam Pierson on Tuesday April 28, 2009 at 04:06PM

Help

"Anyone have experience dealing with failures in Amazon SQS?"

  • Amazon Simple Queue Service is a reliable, highly scalable, hosted queue for storing messages as they travel between computers. You can place tasks in a queue and have worker systems extract and process them. However processing a queue item does not delete that item; you have to explicitly delete a queue item. The problem occurs when a persistent catastrophic failure occurs during processing of an item, e.g. a process core dump (say RMacick encounters an Image of Death) that does not produce an exception. Eventually SQS will timeout and mark the task as requiring processing again. Eventually all yor workers will try to process the queue item and die. There was a lot of discussion (e.g. communicate task status back to app server - too chatty, not scalable) but no obvious solutions arose that will work in the particular environment.

Interesting

  • SF.TUG: The first Tracker User Group will meet tomorrow. This one is somewhat exploratory, to see what the community wants out of it, so it is being kept purposefully small.

  • should_not is not the same as !=. Apparently, it is a feature of Ruby that you can override == but you cannot override !=. Rspec implements == but cannot implement !=. Sometimes you will get objects that will give different results when compared using should != as opposed to should_not. Use should_not.

  • Aviary.com is an online Photoshop-like too. They also have a vector editor. It is free, however they may reuse images you store on their site.

  • Pivotal Library: We are getting a tool from Delicious Monster to automate our library. It will scan barcodes, categorize books and allow people to check books in and out.

Other articles: