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
| # Encoding: UTF-8 | |
| # | |
| require 'fiber' | |
| # This accepts generated frames and prints them. | |
| # | |
| target = Fiber.new do | |
| loop do | |
| frame = Fiber.yield | |
| puts "Frame received: #{frame}." |
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
| # puts (s="puts (s=%s)%%s.dump")%s.dump | |
| require 'rspec' | |
| RSpec::Core::Runner.disable_autorun! | |
| describe "foo" do | |
| it "bar" do | |
| end | |
| it "baz", :banane => true do | |
| 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
| require 'rubygems' | |
| require 'rack' | |
| class Object | |
| def webapp | |
| def call(env) | |
| func, *attrs = env['REQUEST_PATH'].split('/').reject(&:empty?) | |
| [200, {}, send(func, *attrs)] | |
| end | |
| self |
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 Kernel | |
| def memory_consumption | |
| `ps -o rss= -p #{Process.pid}`.to_i | |
| end | |
| alias :require_without_profiling :require | |
| def require(file,*args) | |
| mem_before = memory_consumption | |
| require_without_profiling(file, *args) |
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 FooError < StandardError; end | |
| module BulletProof | |
| def self.included(base) | |
| base.extend ClassMethods | |
| end | |
| # blatantly stolen: http://blog.codefront.net/2008/01/14/retrying-code-blocks-in-ruby-on-exceptions-whatever/ | |
| def retryable(options = {}, &block) |
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 LazyProxy | |
| instance_methods.each do |method| | |
| undef_method(method) if method !~ /^__/ | |
| end | |
| def initialize &lazy_proxy_block | |
| @lazy_proxy_block = lazy_proxy_block | |
| 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
| class Floppy | |
| def method_missing(method, *args) | |
| super unless args.length > 0 && method.to_s[-1..-1] == "=" | |
| if args.first.is_a?(Proc) | |
| (class << self; self; end).class_eval do | |
| define_method(method.to_s[0..-2].to_sym, args.first) | |
| end | |
| else | |
| (class << self; self; end).send(:attr_accessor, method.to_s[0...-1]) |
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 'minitest/unit' | |
| require 'minitest/spec' | |
| MiniTest::Unit.autorun | |
| # This walks the given stub strings and sets up partial stub responder chains. | |
| # | |
| class StubBuilder | |