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 'rubygems' | |
require 'yard' | |
libs = {} | |
gems = {} | |
base = ENV['GEM_PATH'].split(':')[1][%r{^.+(?=/.+@global$)}] rescue nil | |
if base | |
Gem.paths = { | |
'GEM_PATH' => Dir["#{base}/ruby-*"].join(':'), |
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
redefine_on_receiver do |old| | |
lambda do |*args| | |
args[0] = "\e[0;31m#{args[0]}\e[0m" | |
old.call(*args) | |
end | |
end |
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
I just stuck that in the spec_helper.rb. |
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
File.expand_path('~/etc/pry').tap do |base| | |
%w(core_ext custom_commands).each { |f| require File.join(base, f) } | |
end | |
require File.expand_path('~/etc/pry/pry-rspec.rb') | |
require File.expand_path('~/etc/pry/pry-helpers.rb') | |
Pry.config.should_load_plugins = false | |
Pry.config.auto_indent = false | |
Pry.config.correct_indent = false |
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
FIB = [0, 1] | |
def fib(n, seed = nil) | |
seed = FIB.take(n).each { |x| puts x } unless seed | |
seed << (seed[-1] + seed[-2]).tap { |x| puts x; FIB << x } if seed.size == n | |
while s = seed.size and s < n | |
fib(s, seed) | |
end |
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
-spec timestamp(atom(), binary(), object()) -> object(). | |
%% Facebook Timestamp (eg. <<"2011-11-21T22:37:44+0000">>) | |
timestamp(Field, <<Year:4/binary, $-, Month:2/binary, $-, Day:2/binary, $T, | |
Hour:2/binary, $:, Minute:2/binary, $:, Second:2/binary, Offset:5/binary>>, Acc = #fb_object{}) -> | |
Date = {?BIN_TO_INT(Year), ?BIN_TO_INT(Month), ?BIN_TO_INT(Day)}, | |
Time = {?BIN_TO_INT(Hour), ?BIN_TO_INT(Minute), ?BIN_TO_INT(Second)}, | |
DateTime = case Offset of | |
<<"+0000">> -> % UTC | |
{Date, Time}; | |
_ -> |
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
app = Rails.application | |
session_store_class = app.config.session_store | |
begin | |
app = app.instance_variable_get :@app | |
end until app.class == session_store_class |
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
# Allows you to easily make a full closure in ruby | |
# Examples: | |
def bork | |
x = 'abc' | |
closure { x } | |
end | |
f = bork | |
f.call |
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
module Enumerable | |
def lazy_map mapper = nil, &block | |
return to_enum(:lazy_map, block) unless mapper | |
return to_enum(:lazy_map, mapper) unless block | |
each do |*args| | |
yield mapper.call(*args) | |
end | |
end | |
end |
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 config/initializers | |
ActiveRecord::Relation.class_eval do | |
include EachRow | |
end |