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 } |
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
# in Norway | |
module Calendar | |
module Holiday | |
FEBRUARY = 2 | |
NOVEMBER = 11 | |
def mothersday(year) | |
second_sunday_in(FEBRUARY, year) | |
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
$ exuberant_ctags -e testdata/ruby/dog.rb | |
$ cat TAGS | |
^L | |
(null),142 | |
module Animal^?Animal^A1,0 | |
class Base^?Base^A5,34 | |
class Dog < Animal::Base^?Dog^A8,54 | |
def speak(string)^?speak^A11,111 | |
def wag^?wag^A15,165 |
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/env ruby | |
# -*- ruby -*- | |
begin | |
require 'rubygems' | |
rescue LoadError | |
end | |
exts = ['.rb', '.rhtml', '.erb', '.builder', '.haml', '.css', '.js', '.coffee', '.yml', '.yaml' ] | |
if ARGV[0] =~ /^(\+|\.[a-zA-Z0-9]+)$/ |
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
loop do | |
section = parse_section_from_binary_buffer(data) | |
break if section.nil? | |
data = data[section.size .. -1] | |
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
# I'm guessing that MRI and JRuby don't copy the array elements | |
# when making a slice, they just reference the original copy with | |
# new index bounds. | |
$ rvm use ruby-1.9.3-p286 | |
Using /Users/jim/.rvm/gems/ruby-1.9.3-p286 | |
$ ruby mem.rb | |
Before: 12716 | |
After: 12744 |
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 Bowling | |
def score_rolls(rolls) | |
init_rolls(rolls) | |
score = 0 | |
frame = 0 | |
while frame < 10 | |
if strike? | |
score += sum_of_next_rolls(3) | |
consume(1) | |
elsif spare? |
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 RomanNumeralConverter | |
CONVERTS = { | |
"I" => 1, | |
"V" => 5, | |
"X" => 10, | |
"L" => 50, | |
"C" => 100, | |
"D" => 500, | |
"M" => 1000, | |
} |