This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def with_model(m, &block) | |
w = Object.new | |
w.define_singleton_method :model do | |
m | |
end | |
w.instance_eval &block | |
end | |
def property(name) | |
puts model.to_s + name.to_s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def outer(&b) | |
foo = 1 | |
block.call | |
end | |
def inner(v) | |
puts foo + v | |
end | |
# Is there a way to make 'foo' available in the scope of `inner`? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$_=$$/$$;@_=$_+$_;$-_=$_-@_ | |
$__=->_{_==[]||_==''?$.:$_+$__[_[$_..$-_]]} | |
@__=->_,&__{_==[]?[]:[__[_[$.]]]+@__[_[$_..$-_],&__]} | |
$_____=->_{@__[[*_],&->__{__[$.]}]} | |
@_____=->_{@__[[*_],&->__{__[$-_]}]} | |
$______=->_{___,______=$_____[_],@_____[_];_____=$__[___];____={};__=$.;(_=->{ | |
____[______[__]]=___[__];(__+=$_)==_____ ?____:_[]})[]} | |
@______=->_,__{_=[*_]+[*__];____=$__[_];___={};__=$.;(_____=->{ | |
___[_[__][$.]]=_[__][$_];(__+=$_)==____ ?___:_____[]})[]} | |
$_______=->_{$___=[];@___=$__[_];__=___=____=$.;$____,@____={},[] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 | |
} | |
end | |
# => [nil, nil, "Fizz", nil, "Buzz", "Fizz", ...] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In a context somewhere, we'd like to do this: | |
u = User.new | |
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> class Naked; end | |
=> nil | |
> Naked.ancestors | |
=> [Naked, Object, Kernel, BasicObject] | |
> Naked.ancestors.count | |
=> 4 | |
> require 'active_record' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias.gl=log --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 |