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
# -*- coding: utf-8 -*- | |
Sqrt = ->(n) { | |
guess = n / 2.0 | |
loop do | |
if (guess**2 - n) < 0.0001 | |
return guess | |
end | |
guess = (guess + n/guess) / 2.0 | |
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 'date' | |
# Trivial collection of valid attributes for Active Record objects. | |
# | |
# Usage: | |
# | |
# emp = Employee.new(Attrs.for(:employee)) | |
# | |
module Attrs | |
Attributes = { } |
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 'given/natural_assertion' | |
require 'given/line_extractor' | |
class Object | |
def self._Gvn_location_of(block) | |
eval "[__FILE__, __LINE__]", block.binding | |
end | |
end | |
module Given |
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 'rspec/given' | |
class Array | |
def ===(other) | |
size == other.size && | |
zip(other).all? { |a, b| a === b } | |
end | |
end | |
describe "Arg Matching" 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
$ gem push minitest-given-3.0.0.beta.3.gem | |
Pushing gem to https://rubygems.org... | |
You do not have permission to push to this gem. | |
$ |
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 'rbconfig' | |
# Based on a script at: | |
# http://stackoverflow.com/questions/891537/ruby-detect-number-of-cpus-installed | |
class CpuCounter | |
def self.count | |
new.count | |
end | |
def count |
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
printf "Latitude? " | |
latitude_degrees = gets.to_f | |
latitude = latitude_degrees * Math::PI / 180.0 | |
angular_velocity = 2 * Math::PI / (24 * 60 * 60) # Radians per second | |
radius_at_equator = 6_371_000 # meters | |
radius_at_latitude = radius_at_equator * Math.cos(latitude) |
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
describe 'EventBus methods cascade' do | |
Invariant { result.should == EventBus } | |
context 'clear' do | |
When(:result) { EventBus.clear } | |
Then { } | |
end | |
context 'publish' do | |
When(:result) { EventBus.publish('aa123bb', {}) } |
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
#!/usr/bin/ruby -wKU | |
if ARGV.empty? | |
puts "Usage: pullrequest user:branch" | |
exit 1 | |
end | |
url = `git config --get remote.origin.url` | |
unless %r{([^/]+)\.git$} =~ url | |
puts "Unable to determine repo from url (#{url})" |
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 'parslet' | |
class Expressions < Parslet::Parser | |
rule(:operator) { match("[+*/-]").as(:op) } | |
rule(:operation) { operator >> space >> vector.as(:args) } | |
rule(:space) { match('\s').repeat(1) } | |
rule(:numbers) { space >> number } | |
rule(:vector) { (number >> numbers.repeat(1)).as(:vec) } | |
rule(:number) { match("[0-9]").repeat(1).as(:number) } | |
rule(:expr) { vector | number | operation } |