Jay Phillips's blog
Interesting Things
If you want to override how an object is stored in a Hash internally, you can override the Object#hash and Object#eql? methods. Hash always uses Object#hash in its internal hashtable. Try to keep this assertion in mind too:
foo.hash.should == bar.hash if foo.eql?(bar)
Instead of inventing some reliable algorithm to generate your hash code, you can call #hash on a object that can serve as a proxy hash generator. For example, if your object has a #name method, your #hash method could return name.hash.
Ask for Help
"Is there any way to do cookie-less sessions in Rails?"
Josh Susser mentioned Rails used to support this (by encoding the session ID in all links like PHP can do) but no longer offers this feature and may try to fight your attempts to do it.
This pattern is discouraged because links which are shared with someone else through copy-and-paste would effectively log them in as that user. Very dangerous.
"Is there any way to take an element widgetized by a jQuery plugin and reinitialize everything (i.e. call the initializer again as if it's an untouched element)?"
jQuery plugins ultimately do lower-level, destructive modifications to the DOM so, unless the plugin supports some kind of resetting, there's no jQuery feature to do this directly. You can do a reset at the application layer through something like this:
var unmodified = $("#overlay").clone();
$("#overlay").overlay();
$("#overlay").replaceWith(unmodified);
$("#overlay").overlay();
Interesting Things
- Use jQuery UI's
$.widget.bridgeto create new$.fnwidget functions that wrap a more object-oriented Javascript function.
Here is an example:
var widget = function(options, element){
this.name = "ACME Widget #42";
this.options = options;
this.element = element;
};
widget.prototype = {
wizbang: function(){
console.log("wizbang called!");
},
_secret_sauce: function(){
console.log("Protect me jQuery UI!")
}
};
$.widget.bridge("acme_widget", widget);
var widget = $("#victim").acme_widget();
widget.data("acme_widget").name; // => "ACME Widget #42"
widget.acme_widget("wizbang"); // => "wizbang called!"
widget.acme_widget("_secret_sauce"); // Just returns #victim, does not execute _secret_sauce.
For more information, see this blog post.
Devise 1.1.6 has been released, fixing a security hole and a compatibility issue with versions of Rails earlier than 3.0.4. More Info
You can use the new CSS3 "flexible box model" to get Tracker-like panes. It works only in modern browsers (sorry IE, you're no longer "modern").
Interesting Things
- To run tests in parallel, one pivot experimented with two libraries:
hydraandparallel_tests. He found thathydrawas difficult to setup and eventually gave up to tryparallel_tests. Setting upparallel_teststurned out to be quite simple and gave him about a 3x performance boost on an 8 core machine. Not linear with the number of cores but still significant. - Nate Clark recently released a new version of the Selenium RC gem which, among other things, fixes an issue causing tests to hang during initialization.
- The RSpec
=~matcher (which asserts two arrays should contain the same elements) is still awesome.
Here is an example of using the =~ matcher:
[1,2,3].should =~ [1,2,3] # => green
[1,2,3].should =~ [3,2,1] # => green
[1,2,3,4].should =~ [3,2,1] # => red
[1,2].should =~ [3,2,1] # => red
It also gives you a really useful failure message:
Failure/Error: [1,2,3,4].should =~ [3,2,1] # => red
expected collection contained: [1, 2, 3]
actual collection contained: [1, 2, 3, 4]
the extra elements were: [4]
Ask for Help
"Is there a way to implement interactive Tracker-like panes with pure CSS?"
One pivot suggested using tables but said that it might lead to problems with IE compatibility. The CSS3 flexible box model was ruled out because it does not have good backwards compatibility.
Interesting Things
- One pivot changed the username and password for a Heroku account and noticed that it caused the API key to stop working. He removed the key and added it again and it fixed the issue.
Overview
"Could someone quickly explain the pros and cons of using
git rebaseovergit merge?""Has anyone had a problem with NodeJS not seeing libraries installed with its package manager
npm?"
Interesting Things
Switching to Bundler 0.9.x?
If your old gem definitions use :lib => false, don't forget to change it to :require => false
Additionally, older versions of Bundler use the deprecated named argument :require_as (instead of Rails' :lib and Bundler 0.9's :require) to override the path that Bundle requires for you.
Here is an example of how to tell Bundler 0.9.x not to require a gem automatically:
gem "leetsauce", :require => false
Ask for Help
"How can Rails' IP spoof attack safeguards be disabled when its guesses give false positives that block out important users?"
When Rails has this safeguard in place, it may block out users behind poorly configured firewalls and some mobile devices.
The safeguard causes Rails to return a 500 and log the following message:
ActionController::ActionControllerError: IP spoofing attack?! HTTP_CLIENT_IP="16.89.XX.XXX" HTTP_X_FORWARDED_FOR="15.243.YY.YYY"
Rails 2.3 and later lets you easily disable this by overriding a setting in your environment.rb initializer:
Rails::Initializer.run do |config|
config.action_controller.ip_spoofing_check = false
end
As always, be sure you understand the implications of disabling this security feature!
Ask for Help
"Does anyone have any recommendations for how to crawl web pages and check certain pages have certain things?"
Pivots suggested two main approaches:
- Mechanize: Mechanize is a library that lets you write Ruby scripts which load pages, fill out forms, click links, and do arbitrarily sophisticated things with the DOM. Its API is very Rubyish and probably works well for most needs.
- Typhoeus: Unlike Mechanize, Typhoeus is designed for high volume fetching of web pages with good support for concurrent requests. It's not designed to poke around at content on the page so you'll need to use Nokogiri/LibXML/Hpricot in combination with Typhoeus if you want that level of functionality.

