Skip to content

Instantly share code, notes, and snippets.

## usage #####################################################################
#
# patch-tester.rb <ticket_id>
#
# specify which branches to test against below (TEST_BRANCHES)
# creates <ticket_id>-<branch> branches with the latest patch on the ticket
# applied
require 'open-uri'
require 'rexml/document'
$ jruby script/server
=> Booting WEBrick
=> Rails 2.3.2 application starting on http://0.0.0.0:3000
/private/tmp/TestApp/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:76:in `establish_connection': Please install the jdbcsqlite3 adapter: `gem install activerecord-jdbcsqlite3-adapter` (no such file to load -- active_record/connection_adapters/jdbcsqlite3_adapter) (RuntimeError)
from /private/tmp/TestApp/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:60:in `establish_connection'
from /private/tmp/TestApp/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in `establish_connection'
from script/../config/../vendor/rails/railties/lib/initializer.rb:417:in `initialize_database'
from script/../config/../vendor/rails/railties/lib/initializer.rb:141:in `process'
from script/../config/../vendor/rails/railties/lib/initializ
@ddollar
ddollar / gist:135492
Created June 24, 2009 20:08
Fibonacci
def fib(n)
return n if n < 2
fib(n-1) + fib(n-2)
end
def fib_with_caching(n)
@fib_cache ||= {}
@fib_cache[n] ||= fib_without_caching(n)
end
Gem.clear_paths
Gem.path.unshift(File.join(ROOT, 'vendor', 'gems'))
teststringex> Contact.delete_all
Contact Delete all (13.3ms) DELETE FROM "contacts" WHERE 1=1
=> 2
teststringex> Contact.find(:all)
Contact Load (0.2ms) SELECT * FROM "contacts"
=> []
teststringex> contact = Contact.new
=> #<Contact id: nil, name: nil, url: nil, phone: nil, created_at: nil, updated_at: nil>
teststringex> contact.name = "Happy Trails"
=> "Happy Trails"
# :PUBLISHER: markdown, shell, { command: 'rdiscount' }
# :BRACKET_CODE: '[ruby]', '[/ruby]'
# :TEXT:
#
# Have you ever started a long operation and walked away from the computer, and
# come back half an hour later only to find that the process is hung up waiting
# for some user input? It's a sub-optimal user experience, and in many cases it
# can be avoided by having the program choose a default if the user doesn't
# respond within a certain amount of time. One example of this UI technique in
# the wild is powering off your computer - most modern operating systems will
@ddollar
ddollar / template.rb
Created July 20, 2009 15:51
Rails Template
# Rails Template
require 'open-uri'
def download(from, to = from.split("/").last)
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"
exit!
end
class Symbol
def to_proc
Proc.new { |*args| args.shift.send(self, *args) }
end
end
class Fixnum
def is_a_multiple_of?(multiples)
multiples.detect { |multiple| (self % multiple).zero? }
end
def flatten_with_sums(triangle)
row_index = triangle.length - 2
while row_index >= 0
row = triangle[row_index]
next_row = triangle[row_index + 1]
row.each_with_index do |value, index|
row[index] = [value + next_row[index], value + next_row[index + 1]].max
end
row_index -= 1
end
require 'benchmark'
NUM_ROWS = 23
T = (1..NUM_ROWS).map do |row_index|
(1..row_index).map { rand(100) }
end
#T = DATA.readlines("\n").map {|x| x.split(' ').map {|i| i.to_i}}