Use Sass without Rails

Generate CSS from Sass on a static site without Rails by watching source files and rewriting stylesheets automatically.

Recent RSpec features you might not know about

Less-known RSpec features simplify expectation style, chained stubs, and restoring stubbed methods while using double as the preferred mock object.

A quick guide to pull requests

It’s pretty common for projects hosted on GitHub to receive “pull requests”: requests from people who have cloned your project, made a modification to it and then asking you to merge their changes back into the main project.

There are a lot of ways you can handle these pull requests, here are some of them.

Adding Stroke to Web Text

Because they are vector, it would make sense if we could do things that other vector programs (e.g. Adobe Illustrator) can do with vector text, like draw a stroke around the individual characters. Well, we can! At least in WebKit

Check that a text field is empty with Cucumber

Empty-field checks can pass unexpectedly in Cucumber because "" becomes a regular expression that matches any string. Use ^$ in Capybara or be_blank in Webrat.

Define an array condition that selects on dynamic columns

Safely build dynamic SQL conditions from user-supplied column names and values; sanitize_sql_array works where placeholder syntax fails in MySQL.

Run a rake task in all environments

Use like this:

power-rake db:migrate VERSION=20100913132321

By default the environments development, test, cucumber and performance are considered. The script will not run rake on a production or staging environment.


This script is part of our geordi gem on github.

Run a single example group in RSpec

Run one RSpec example group or a single it example by line number in a long spec without executing the whole file.

Ruby: How to collect a Hash from an Array

Map an array or enumerable to a hash in Ruby using to_h, index_by, group_by, index_with, or a custom collect_hash helper.

Find files modified since a given timestamp

Find files changed after a specific time or within the last day using find age tests and a reference timestamp file.

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