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 'rubygems' | |
require 'active_support' | |
class Logbook | |
def initialize | |
@entries = {} | |
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
# Creates test stubs for logic in methods | |
require 'rspec' | |
require File.expand_path('../../test_stubs.rb', __FILE__) | |
describe TestStubs do | |
let(:sut) { TestStubs.new(@code) } | |
describe "#generate" do |
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 'thor' |
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
# Here's the code being evaluated | |
# rubinius-2.0.0dev | |
html_class = build_class("") {|c| c << "required" if required } | |
# => "required" | |
### FIRST EXAMPLE | |
# Symbolic expression tree with no arguments to build_class | |
'html_class = build_class() {|c| c << "required" if required }'.to_sexp |
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
p SexpBuilder.parse File.read(__FILE__) if $0 == __FILE__ | |
# => [s(:call, nil, :require, s(:str, "sexp_processor")), s(:call, nil, :require, s(:str, "ripper")), s(:call, nil, :require, s(:call, s(:const, :File), :expand_path, s(:str, "./../nodes/all"), s(:str, "(string)"))), s(:class, :SexpBuilder, s(:colon2, s(:const, :Ripper), :SexpBuilderPP), s(:defs, s(:self), :parse, s(:args, :code, :filename, s(:block, s(:lasgn, :filename, s(:str, "(string)")))), s(:lasgn, :ast, [:super, [s(:lvar, :code), s(:lvar, :filename)]]), s(:call, s(:lvar, :ast), :[], s(:lit, 1))), s(:cdecl, :KEYWORDS, s(:array, s(:str, "true"), s(:str, "false"), s(:str, "self"), s(:str, "nil"))), s(:cdecl, :BINARY, s(:hash, s(:lit, :"&&"), s(:colon2, s(:const, :Nodes), :BooleanAnd), s(:lit, :and), s(:colon2, s(:const, :Nodes), :LogicalAnd), s(:lit, :"||"), s(:colon2, s(:const, :Nodes), :BooleanOr), s(:lit, :or), s(:colon2, s(:const, :Nodes), :LogicalOr), s(:lit, :"||="), s(:colon2, s(:const, :Nodes), :OptionalAssignment))), s(:cdecl, :MAGIC_VARI |
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 route_to(start_x, start_y, end_x, end_y, path=[], last_routes=[]) | |
possible_routes = sorted_routes(start_x, start_y, end_x, end_y) | |
if r = possible_routes.find {|route| route == [end_x, end_y]} | |
return path + [[*r, new_item_height(*r)]] | |
else | |
possible_routes.each do |(possible_x, possible_y)| | |
next if last_routes.include? [possible_x, possible_y] | |
new_path = path + [[possible_x, possible_y, new_item_height(possible_x, possible_y)]] | |
used_routes = (last_routes + possible_routes).uniq | |
new_route = route_to(possible_x, possible_y, end_x, end_y, new_path, used_routes) |
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 SetupTestCase < Test::Unit::TestCase | |
def self.test(test_name, *setups, &block) | |
test_with_setups = lambda do | |
setup_procs = setups.map {|setup_func_name| respond_to?(setup_func_name) ? method(setup_func_name) : nil }.compact | |
setup_procs.each(&:call) | |
block.bind(self).call | |
end | |
super(test_name, &test_with_setups) | |
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
lazy_expensive_sequence = Enumerator.new do |y| | |
offset = 0 | |
amount_to_retrieve = 50 | |
loop do | |
## This may not be memory safe if we try to retrieve all at once, so we safely retrieving an amount that we know will fit in memory | |
retrieve_memory_hogs(offset, amount_to_retrieve).each do |i| | |
y << i | |
end | |
offset += amount_to_retrieve | |
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 fib(n) | |
if (n < 2) | |
n | |
else | |
fib(n-1) + fib(n-2) | |
end | |
end | |
JRuby 1.7.2 |
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 CommitScore | |
ScoreValue = Struct.new(:email, :score) | |
def initialize(commit_values) | |
@commit_values = commit_values | |
end | |
def score | |
grouped_commits_by_email.map {|(email, commits) score_value(email, commits) } |
OlderNewer