View alias_task.rake
def alias_task(name, old_name)
t = Rake::Task[old_name]
desc t.full_comment if t.full_comment
task name, *t.arg_names do |_, args|
# values_at is broken on Rake::TaskArguments
args = { |a| args[a] }
View db_redo.rake
def interesting_tables
rval = ActiveRecord::Base.connection.tables.sort
rval.reject! do |tbl|
['schema_migrations','schema_info', 'sessions', 'public_exceptions'].include?(tbl)
namespace :db do
namespace :backup do

SSL upgrades on and RubyInstaller versions

UPDATE 2014-12-21: RubyGems 1.8.30, 2.0.15 and 2.2.3 have been released. It requires manual installation, please see instructions below.


If you reached this page, means you've hit this SSL error when trying to

View email_validator.rb
# blog post:
class EmailValidator < ActiveModel::EachValidator
# Domain must be present and have two or more parts.
def validate_each(record, attribute, value)
address = value
record.errors[attribute] << (options[:message] || 'is invalid') unless (address.address == value && address.domain && address.__send__(:tree).domain.dot_atom_text.elements.size > 1 rescue false)
View benchmark_downcase_vs_enum_downcase.rb
# "[A]pplying downcase once is better than calling it (possibly) multiple times?"--sawa
# via
# "How to make a string 1st letter caps, 2nd letter noncaps, 3rd letter caps, 4th letter noncaps…?"
require "benchmark"
n = 1_000_000
Benchmark.bmbm do |x|" {|c,i| i%2==0 ? c.upcase : c}.join") do
n.times {
"Stackoverflow is awesome!" {|c,i| i%2==0 ? c.upcase : c}.join


Have you ever wanted to send a secret message?

The Plan

Today we use computers to mask messages every day. When you connect to a website that uses "https" in the address, it is running a special encoding on your transmissions that makes it very difficult for anyone to listen in between you and the server.

View gist:4a0a3ad089ce08f3476d025bea7361b4
# each_with_index, each_with_object and inject({}) are all %50 slower then #each
# simple each with an addition noop
[4] pry(main)> puts Benchmark.measure { (1..10_000_000).each { |i| i + 1 } }
0.450000 0.000000 0.450000 ( 0.448808)
# each_with_index
[5] pry(main)> puts Benchmark.measure { (1..10_000_000).each_with_index { |i, index| i + 1 } }
0.650000 0.000000 0.650000 ( 0.645812)
View benchmark_dead_horse.rb
require 'benchmark'
N = 1000000
nums ={ rand(N) }
enum = [1, 2, 'string', {}, [], false, true, nil]
def process(v)
View gist:da94e895d50c6bf2d41c
@import "compass/css3/images";
// CSS-only multi-line ellipsis with generated content
// yields `position:relative`, so remember to declare an eventual `position:absolute/fixed` *after* including this mixin
@mixin limitLines(
$maxLinesPortrait, // Mandatory: The number of lines after which the clipping should take action.
$maxLinesLandscape: $maxLinesPortrait, // You may provide a different line limit for landscape orientation.
// Note that 'portrait' is our default orientation. However, if you omit $maxLinesLandscape,
// the value of $maxLinesPortrait is used for whatever orientation (that is, without a media query).
View gist:10936593
# Example of how to test a module included into multiple models
require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
describe Featurable do
class FeaturableObject
include Featurable
attr_accessor :sport, :featured_at