Skip to content

Instantly share code, notes, and snippets.

View havenwood's full-sized avatar
:octocat:

Shannon Skipper havenwood

:octocat:
View GitHub Profile
@havenwood
havenwood / smurfize.rb
Created September 28, 2011 15:29
Need to see your code, gsub! works generally.
def smurfize(code)
puts code.gsub!("s", "smurfy")
end
code = "Lions and tigers and bears, oh my!"
smurfize code
#=> Lionsmurfy and tigersmurfy and bearsmurfy, oh my!
@havenwood
havenwood / stardate.rb
Created October 10, 2011 23:02
Stardate
def captains_log
time = Time.now
puts "Captains log,", "Stardate #{time.year}.#{time.yday}"
"#{time.year}.#{time.yday}".to_f
end
@havenwood
havenwood / mod.rb
Created November 17, 2011 22:47
Find smallest common multiple
∞ = 1.0 / 0
(1..∞).each do |check_eet|
break check_eet if (1..20).all? do |against_this|
check_eet % against_this == 0
end
end
#=> 232792560
@havenwood
havenwood / xday.rb
Created December 1, 2011 19:23
Yesterday, Today, Tomorrow
#!/usr/bin/env ruby
class Time
WEEKDAYS = %w[ Sunday Monday Tuesday Wednesday Thursday Friday Saturday ]
def day_before_yesterday
xday -2
end
def yesterday
@havenwood
havenwood / mag.rb
Created December 6, 2011 05:56
"Mag" is Maglev shortcuts for those who forget, what was I saying?
module Kernel
def push
Maglev.commit_transaction
end
def pull
Maglev.abort_transaction
end
def box
@havenwood
havenwood / gsub.rb
Created December 6, 2011 07:36
Rbx gsub! implementation
def gsub!(pattern, replacement=undefined)
# Because of the behavior of $~, this is duplicated from gsub! because
# if we call gsub! from gsub, the last_match can't be updated properly.
if undefined.equal? replacement
unless block_given?
return to_enum(:gsub, pattern, replacement)
end
tainted = false
@havenwood
havenwood / regex_syntax_issue.rb
Created December 23, 2011 21:54
regex methods
class Parser
def split_pattern text
text.split(/(?:[^|]), /)
end
def match_escape_pattern text
text.match(/\|([,{}])/)
end
def replace_tricky_end_pattern text
@havenwood
havenwood / de-us-money.rb
Created January 6, 2012 00:02
Germans Got Commas and Periods Confused
def scrub character
results.delete("#{character}").to_i
end
case results[-3]
when "."
scrub ","
when ","
scrub "."
else
@havenwood
havenwood / README.md
Created January 13, 2012 10:34
Chess

TODO:

  • Rook, Bishop, Queen able to move multiple squares...
  • Pass en passent.
  • Promotion of pawn to piece other than Queen.
  • Castling.
  • Check, Checkmate, Draw.
@havenwood
havenwood / perl6-vs-ruby-iteration.rb
Created February 26, 2012 20:59
Comparing sentence capitalization in Perl6 and Ruby
perl6:
my $sentence = "an acorn fell here."
#=> an acorn fell here.
my @words = $sentence.split(" ")
#=> an acorn fell here.
say @words.capitalize
An Acorn Fell Here.
ruby: