Skip to content

Instantly share code, notes, and snippets.

View ciscou's full-sized avatar

Francis Pérez Padilla ciscou

View GitHub Profile
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
@ciscou
ciscou / commit-msg
Last active December 30, 2015 05:49
commit-msg hook to ensure we're adding the Pivotal Tracker story id
#!/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)
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
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)
@ciscou
ciscou / rubik.rb
Created November 12, 2011 21:42
calculate the order of a Rubik's cube sequence
class Rubik
attr_reader :edges, :corners
def initialize
@edges = {
:position => (1..12).to_a,
:orientation => [0] * 12
}
@corners = {
:position => (1..8).to_a,
@ciscou
ciscou / QR Creator.pdf
Created November 2, 2011 20:26
Extracts a section of a page of a PDF into a JPG image
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ciscou
ciscou / fibonacci.rb
Created September 30, 2011 19:25
Efficient yet beautiful ruby fibonacci implementation
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}" }