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 Fixnum | |
@@fibo_cache = Hash.new { |h, k| h[k] = k < 2 ? k : h[k-2] + h[k-1] } | |
def fibo | |
@@fibo_cache[self] | |
end | |
end | |
puts (0..500).map { |n| "#{n.to_s.rjust(3, ' ')} => #{n.fibo}" } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 Rubik | |
attr_reader :edges, :corners | |
def initialize | |
@edges = { | |
:position => (1..12).to_a, | |
:orientation => [0] * 12 | |
} | |
@corners = { | |
:position => (1..8).to_a, |
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 A | |
def self.foo ; "foo" ; end | |
def self.bar ; "bar" ; end | |
end | |
class B | |
def self.foo ; "another foo" ; end | |
def self.method_missing(method_id, *args, &block) | |
if A.respond_to?(method_id) | |
A.send(method_id, *args, &block) |
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
import java.io.File; | |
import javax.xml.transform.*; | |
import javax.xml.transform.stream.*; | |
import javax.xml.validation.*; | |
/* | |
* Usage: download xsd's and sitemap | |
* $ wget http://www.google.com/schemas/sitemap-news/0.9/sitemap-news.xsd | |
* $ wget http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd |
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 | |
# This is a git hook that checks commit messages for validity | |
# This file must live in your project's .git/hooks/ folder | |
# and have execution permission | |
message_file = ARGV[0] | |
message = File.read(message_file) | |
def valid_commit_message?(message) |
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 DateRange | |
def initialize(from, to, step) | |
@from, @to, @step = from, to, step | |
end | |
def each | |
current = @from | |
while current < @to do | |
yield(current) | |
current += @step |
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
module ActiveRecord | |
class Base | |
def self.scope(name, callable) | |
define_singleton_method name do | |
options = callable.respond_to?(:call) ? callable.call : callable | |
puts "Fetching records with options #{options.inspect}" | |
end | |
end | |
end | |
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
2.0.0-p451 :016 > def omg(foo: 42, bar: "hello world!") | |
2.0.0-p451 :017?> puts [foo, bar].inspect | |
2.0.0-p451 :018?> end | |
=> nil | |
2.0.0-p451 :019 > omg | |
[42, "hello world!"] | |
=> nil | |
2.0.0-p451 :020 > omg(1, "one") |
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
is 1 == 1? <%= yesno 1 == 1 %> | |
is 1 == 2? <%= yesno 1 == 2 %> |
OlderNewer