This file contains hidden or 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
| ## 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' |
This file contains hidden or 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
| $ 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 |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| Gem.clear_paths | |
| Gem.path.unshift(File.join(ROOT, 'vendor', 'gems')) |
This file contains hidden or 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
| 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" |
This file contains hidden or 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
| # :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 |
This file contains hidden or 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
| # 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 |
This file contains hidden or 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 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 |
This file contains hidden or 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
| 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 |
This file contains hidden or 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 '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}} |