This file contains 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 RedirectTo | |
def initialize(expected, session) | |
@expected = expected | |
@session = session | |
end | |
def matches?(visit_proc) | |
instance_eval(&visit_proc) | |
@status = @session.status_code |
This file contains 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
cap() { | |
bundle exec cap $@ | |
if [ $? -eq 0 ]; then | |
growlnotify --image=$HOME/Pictures/success.png -m 'Success!' "cap $@" | |
else | |
growlnotify --image=$HOME/Pictures/failure.png -m 'Failure!' "cap $@" | |
fi | |
} |
This file contains 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
before(:each, :capybara_feature => true) | |
@cache_store = ActionController::Base.cache_store | |
ActionController::Base.perform_caching = true | |
ActionController::Base.cache_store = :memory_store | |
end | |
after(:each, :capybara_feature => true) | |
ActionController::Base.perform_caching = false | |
ActionController::Base.cache_store = @cache_store | |
end |
This file contains 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
# | |
# start of solution | |
# | |
MyString = Class.new(String) | |
MyString.define_singleton_method(:alphabet) { 'abc' } | |
MyString.class_eval { | |
exclaim_method = proc { |*args| | |
count = args.first || 1 |
This file contains 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 'zipruby' | |
require 'csv' | |
csv = CSV.generate do |csv| | |
csv << ['i', '2i'] | |
1.upto(10) do |i| | |
csv << [i, i*2] | |
end | |
end |
This file contains 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 foo(*args) | |
@memoized_foo ||= {} | |
@memoized_foo[args] ||= begin | |
some_expensive_method | |
end | |
end |
This file contains 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 'net/http' | |
require 'uri' | |
random_url = URI('http://www.random.org/integers/?num=1&min=1&max=6&col=1&base=10&format=plain&rnd=new') | |
ints = [] | |
resp = Ne |
This file contains 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
namespace :resque do | |
task :setup do | |
ENV["MY_CUSTOM_KEY"] = "MY CUSTOM VALUE" | |
end | |
end |
This file contains 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
Thread.start do | |
loop do | |
objects = Hash.new(0) | |
ObjectSpace.each_object { |obj| objects[obj.class] += 1 } | |
File.open("/tmp/top_ten_objects.txt", "a") do |file| | |
file.puts "-" * 50 | |
file.puts "PID: #{Process.pid} - #{Time.now.strftime("%c")}" | |
file.puts "-" * 50 |
This file contains 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
source "https://rubygems.org" | |
gem "em-http-request" | |
gem "eventmachine" | |
gem "json" | |
gem "rack" | |
gem "thin" |