Skip to content

Instantly share code, notes, and snippets.

View gist:11384481
require 'spec/environment_spec_helper'
describe 'UsersController' do
describe 'GET /new' do
it { expect(:get => '/users/new').to be_routable }
it {
get '/users/new'
expect(last_response.status).to eq 200
View gist:11260367
def with_model(m, &block)
w =
w.define_singleton_method :model do
w.instance_eval &block
def property(name)
puts model.to_s + name.to_s
View gist:11259853
def outer(&b)
foo = 1
def inner(v)
puts foo + v
# Is there a way to make 'foo' available in the scope of `inner`?
fj / gist:9691518
Last active Aug 29, 2015
"Your Mission", by Ellen M. H. Gates (1865)
View gist:9691518
If you cannot, on the ocean, sail among the swiftest fleet,
Rocking on the highest billows, laughing at the storms you meet,
You can stand among the sailors, anchored yet within the bay,
You can lend a hand to help them, as they launch their boats away.
If you are too weak to journey up the mountain steep and high,
You can stand within the valley, while the multitudes go by;
You can chant in happy measure, as they slowly pass along;
Though they may forget the singer, they will not forget the song.
fj / bf.rb
Created Mar 18, 2014
Brainfuck interpreter in Ruby
View bf.rb
____[______[__]]=___[__];(__+=$_)==_____ ?____:_[]})[]}
___[_[__][$.]]=_[__][$_];(__+=$_)==____ ?___:_____[]})[]}
fj / gist:8541477
Created Jan 21, 2014
Hypothetical pattern-matching API in Ruby.
View gist:8541477
(1..100).match do |i|
pattern(i%3, i%5) {
match [0, 0], "FizzBuzz" # match i%3 == 0, i%5 == 0
match [0, _], "Fizz" # match i%3 == 0, i%5 == anything
match [_, 0], "Buzz" # match i%3 == anything, i%5 == 0
# => [nil, nil, "Fizz", nil, "Buzz", "Fizz", ...]
View gist:8393399
// SymSpell: 1000x faster through Symmetric Delete spelling correction algorithm
// The Symmetric Delete spelling correction algorithm reduces the complexity of edit candidate generation and dictionary lookup
// for a given Damerau-Levenshtein distance. It is three orders of magnitude faster and language independent.
// Opposite to other algorithms only deletes are required, no transposes + replaces + inserts.
// Transposes + replaces + inserts of the input term are transformed into deletes of the dictionary term.
// Replaces and inserts are expensive and language dependent: e.g. Chinese has 70,000 Unicode Han characters!
// Copyright (C) 2012 Wolf Garbe, FAROO Limited
// Version: 1.6
View gist:8243261
# In a context somewhere, we'd like to do this:
u =
u.extend Passworded
# Unfortunately, this doesn't work:
module Passworded
include ActiveModel::Model # Can't do this because ActiveModel::Model wants to be included
# on classes, not modules.
View gist:8240093
> class Naked; end
=> nil
> Naked.ancestors
=> [Naked, Object, Kernel, BasicObject]
> Naked.ancestors.count
=> 4
> require 'active_record'
View gist:7949010 --format=format:"%C(yellow bold)%h%Creset @ %C(blue)%cd%C(reset) » %C(white)%s%C(reset) (%C(green)%cN%C(reset)) %+d" --topo-order --graph --date=iso