Create a valid RSS feed in Rails

Valid RSS output in Rails needs strict XML formatting and proper feed metadata; Atom builder can be a safer alternative for syndication feeds.

Get Your C On

Getting started with Ruby extensions in C.

JQuery CSS Emoticons Plugin

Converts plain text emoticons into CSS3 smiley faces with a jQuery plugin and stylesheet, avoiding image files entirely.

Rename hash keys

Ruby hash keys can be renamed with a small initializer, making it easier to migrate data or adjust naming without rewriting every lookup.

Use the new Google Images as a German user

In july Google announced a new version of their image serach tool Google Images. But you won't find it on the German google.de site. To reach the new - as I may say, very much better - tool from germany, you have to surf to images.google.com. Et voilà!

clemens's delocalize at master - GitHub

delocalize provides localized date/time and number parsing functionality for Rails.

Install RubyGems on Ubuntu/Debian

Install a newer RubyGems on Ubuntu or Debian without the outdated APT package, preserving gem access and existing gems when possible.

Remove resource fork files from a FAT volume on MacOS

Hidden ._ resource fork files on FAT volumes clutter car stereos and similar devices. Deleting the AppleDouble metadata from the mounted volume removes them.

Understand ActiveRecord::ReadOnlyRecord error

Records loaded with SQL fragments in :select or :joins become read-only in ActiveRecord to avoid saving rows with noncolumn attributes. :readonly => false overrides the safeguard.

When sessions, cookies and Clearance tokens expire and how to change it

Rails session and cookie lifetime defaults can be surprising, and Clearance authentication tokens expire separately. Changing expiry settings requires different configuration points or a patch to sign_in.

Flash SWF movie bleeds into an element covering it

Embedded Flash movies do not always obey element order and z-index.

To fix this, set the wmode attribute to transparent in both <object> and <embed> tags:

<object ... >
  <param name="wmode" value="transparent" />
  <embed ... wmode="transparent" />
</object>

Strip carriage returns in submitted textareas

When submitting textareas, browsers sometimes include carriage returns (\r) instead of just line feeds (\n) at the end of each line. I don't know when this happens, and most of the time it doesn't matter.

In cases where it does matter, use the attached trait to remove carriage returns from one or more attributes like this:

class Note
  does 'strip_carriage_returns', :prose, :code
end

Here is the test that goes with it:

describe Note do

  describe 'before_validation' do...

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):

  1. File → Settings
  2. Editor → Editor Tabs
  3. Check "Show tabs in single row"

Seriously.

Fan control for Dell notebooks

  1. sudo apt-get install i8kutils
  2. Reboot
  3. 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.