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
| Original Gem: | |
| https://github.com/Lytro/multi_db/blob/master/lib/multi_db/connection_proxy.rb#L74 | |
| Alvin and My fix: | |
| https://github.com/alvinlai/multi_db/blob/bugfix-load-wrong-slave-db/lib/multi_db/connection_proxy.rb#L74 | |
| see ^ | |
| look closer... diff: | |
| https://github.com/alvinlai/multi_db/commit/3c5d15a3a9cd2d759f89426f290aef63f6758b77#lib/multi_db/connection_proxy.rb |
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 add_1_to_n(n) | |
| return n <= 0 ? 0 : n + add_1_to_n( n - 1 ) | |
| end | |
| puts add_1_to_n(10) #=> 55 |
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
| $> ./linked_list.rb | |
| Run options: | |
| # Running tests: | |
| ...... | |
| Finished tests in 0.000599s, 10016.6945 tests/s, 20033.3890 assertions/s. | |
| 6 tests, 12 assertions, 0 failures, 0 errors, 0 skips |
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
| module BinaryTree | |
| class Node | |
| attr_reader :word, :count, :left, :right | |
| include Enumerable | |
| def initialize(word) | |
| @word, @count = word, 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
| #!/usr/bin/env ruby -wKU | |
| require "test/unit" | |
| class Stock | |
| # To change this template use File | Settings | File Templates. | |
| def self.find_longest_run(prices=[]) | |
| return {:low=>{0.0=>0},:high=>{0.0=>0}} if prices.nil? || prices.size == 0 | |
| result = {} | |
| # start at the end | |
| #find the highest value |
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
| # >---------------------------------------------------------------------------< | |
| # | |
| # _____ _ _ __ ___ _ | |
| # | __ \ (_) | \ \ / (_) | | | |
| # | |__) |__ _ _| |___\ \ /\ / / _ ______ _ _ __ __| | | |
| # | _ // _` | | / __|\ \/ \/ / | |_ / _` | '__/ _` | | |
| # | | \ \ (_| | | \__ \ \ /\ / | |/ / (_| | | | (_| | | |
| # |_| \_\__,_|_|_|___/ \/ \/ |_/___\__,_|_| \__,_| | |
| # | |
| # This template was generated by RailsWizard, the amazing and awesome Rails |
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 "pp" | |
| os_versions = {} | |
| Dir['logs/*'].each do |path| | |
| IO.readlines(path).each do |line| | |
| %r/\b(?<os>mac os x \d{1,}_\d{1,}_\d{1,})\b|\b(?<os>osversion=\d{1,}\.\d{1,}\.\d{1,})\b/i =~ line | |
| if os | |
| os_versions[os] = os && os_versions[os] && os_versions[os] >= 1 ? os_versions[os] + 1 : 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
| #!/usr/bin/env bash | |
| # login as root and run this script via bash & curl: | |
| apt-get update | |
| apt-get install -y build-essential bison openssl libreadline6 libreadline6-dev curl \ | |
| git-core zlib1g zlib1g-dev libopenssl-ruby curl libcurl4-openssl-dev libssl-dev \ | |
| libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev | |
| bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer) |
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 perform(user_id, class_name) | |
| user = eval class_name + '.find(' + user_id.to_s + ')' | |
| 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
| module AnotherCalc | |
| def perform(product) | |
| case product | |
| when "firstcase" | |
| do_something | |
| when "secondcase" | |
| do_something_else | |
| when "thirdcase" | |
| do_something_more | |
| when "fourthcase" |