Split nested block parameters
If you iterate over a collection of arrays, you can destructure the arrays within the block parameters:
movies_and_directors = [
['The Big Lebowski', 'Coen Brothers'],
['Fight Club', 'David Fincher']
]
movies_and_directors.each do |movie, director|
# do something
end
For nested array (e.g. when you use each_with_index), you can use parentheses for destructuring:
movies_and_directors.each_with_index do |(movie, director), index|
# do something
end
Fix a spec that only runs when called directly
RSpec examples that run only when invoked directly often need a proper _spec.rb filename; a plain .rb file may be skipped in the full suite.
Using RSpec stubs and mocks in Cucumber
Cucumber can use RSpec doubles instead of Mocha; loading the integration in env.rb keeps stubs and mocks available after other After hooks.
Enable tab dragging in RubyMine
Since RubyMine 3.1 you can drag tabs across panes/windows and out of the main window to create new windows.
For any version below 3.1 do it like this (will only allow dragging tabs inside their pane, not across panes):
- File → Settings
- Editor → Editor Tabs
- Check "Show tabs in single row"
Seriously.
Fan control for Dell notebooks
sudo apt-get install i8kutils- Reboot
- You can now run the i8k tools such as
i8kmon
Setting the fan speed to high (2) will only work shortly as the fan is somehow controlled automatically.\
This helps you out in bash:
while true; do i8kfan - 2; sleep 0.2; done
There should be a better solution and it will be posted as soon as it's found.
Install a local Gemfile on a remote server
Run bundle install on a remote host using a local Gemfile, even for vendored gems or a different BUNDLE_GEMFILE.
wmd - The Wysiwym Markdown Editor
Lightweight browser text editor for comments, forum posts, and basic CMS text with live preview and minimal setup.
Embed a favicon properly
The following Haml will do:
%head{ :profile => 'http://www.w3.org/2005/10/profile' }
%link{ :href => image_path('favicon.ico'), :rel => 'icon', :type => 'image/vnd.microsoft.icon' }
Note that while you can link to icon formats other than .ico, Internet Explorer is too stupid for that.
Exclude your staging site from Google with robots.txt and not shoot yourself in the foot
Staging sites can be kept out of Google with robots.txt while avoiding a forgotten block on launch by serving a separate exclude file on staging only.
Override e-mail recipients in ActionMailer
Our gem Mail Magnet allows you to override e-mail recipients in ActionMailer so all mails go to a given address.
This is useful for staging environments where you want to test production-like mail delivery without sending e-mails to real users.
Use Shoulda's validate_uniqueness_of matcher correctly
validate_uniqueness_of in Shoulda needs an existing record; without it, RSpec can raise “Could not find first Keyword” during uniqueness checks.
Automatically run bundle exec if required
There will probably be better solutions as we become more experienced with using Bundler, and more command line tools become Bundler-aware.
b will use bundle exec if there is a Gemfile in the working directory, and run the call without Bundler otherwise.
b spec spec
This script is part of our geordi gem on github.
jQuery Countdown
A jQuery plugin that sets a div or span to show a countdown to a given time
Automatic Flushing: The Rails 3.1 Plan « Katz Got Your Tongue?
This post explains, in some detail, how we will implement a nice performance boost for Rails developers. Understanding the details might help gain the full benefits of the optimization, but you will gain some benefits even if you have no idea how it works.
lib/bundler/capistrano.rb at master from carlhuda's bundler - GitHub
Capistrano task for Bundler.
jQuery Captify (v1.1.3) / Simple Animated Image Captions
jQuery plugin for attractive image rollover captions on hover, adding simple animated text overlays to images.
rhulse's rails-css-views at master - GitHub
This gem is designed to provide CSS views to Rails, and a process to concatenate and minify these files to one file for production.
GoRuCo 2010 - James Golick - Scaling to Hundreds of Millions of Requests on Vimeo
Physical servers worked, EC2 did not.
Unstage an added file in Git
Remove a mistakenly added file from the staging area while keeping local changes; git reset HEAD path/to/file also works for conflicted files.
Retrieve exchange rates
The ECB has an XML feed with EURO exchange rates to other currencies. It is updated daily.
Airbrake notification in Rake tasks
Rake tasks can report exceptions to Airbrake without notifying in development or test environments, using the usual notification rules for tasks that depend on :environment.
The dangers of url_for in Rails applications
In a great post about named routes in Rails, path vs. url, Viget Labs ponders which variant is best used.<br />
<br />
Most often we use foo_path, which when used in Rails URL helpers will generate a relative path, where foo_url generates a full URL. In most cases the path makes most sense, but not always.
Make box shadows look the same in IE and other browsers
The box shadows created rendered in IE by CSS3PIE look darker and are blurred differently than in browsers that render box-shadow natively.
If possible, try to be OK with this. If not, make an IE-only stylesheet that uses a different color and blur radius:
// Real browsers:
+box_shadow("0 4px 10px #bbb")
// IE with PIE:
+box_shadow("0 5px 15px #888")
We should try to package this solution in a neat way so we don't need different stylesheets.
See also this [cross-browser box-shadow comparison]...
Scope to records with a given state in state_machine
with_state from state_machine can break in complex scope chains; a custom having_state scope keeps record filtering reliable.