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 'webrick/utils' | |
| # The initialize below is augmented to stall the @timeout_info iteration. | |
| # The fix is uncommenting TimeoutMutex.synchronize{} around the @timeout_info iteration. | |
| class WEBrick::Utils::TimeoutHandler | |
| def initialize | |
| @timeout_info = Hash.new | |
| Thread.start{ | |
| while true | |
| now = Time.now |
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' | |
| def repeat(n=10_000_000, &blk); n.times {yield}; end | |
| string = 'string' | |
| Benchmark.bm do |x| | |
| x.report("warm-up single quotes") { repeat {'this is a string'} } | |
| x.report("interpolated double quotes with variable") { repeat {"this is a #{string}"} } | |
| x.report("double quotes") { repeat {"this is a string"} } | |
| x.report("single quotes") { repeat {'this is a string'} } |
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 'nokogiri' | |
| require 'open-uri' | |
| require 'uri' | |
| def search(query_string) | |
| Nokogiri::HTML(open("http://www.google.com/search?q=#{URI.encode(query_string)}")) | |
| .css("h3[class=r] a").map {|node| {:url => node["href"], :title => node.inner_html} } | |
| end | |
| puts search('ruby') |
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
| var baseline_question_id_by_improvement_plan_option_id = { | |
| // Was a history and physical documented in the medical record? | |
| '4c570625b49164349b000002': '4c05a95eb491640c0600000e', | |
| // Is an AJCC stage in the medical record? | |
| '4c570625b49164349b000003': '4c05a95eb491640c06000011', | |
| // Is the pathology noted in the consultation note? | |
| '4c570625b49164349b000004': '4c05a95eb491640c06000015', | |
| // Was the intent of the treatment documented? | |
| '4c570625b49164349b000005': '4c05a95eb491640c06000015', | |
| // Was the treatment based upon clinical practice guidelines or published data? |
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
| # Git aliases | |
| alias g="git" | |
| alias ga="git add" | |
| alias gb="git branch" | |
| alias gs="git status" | |
| alias gm="git merge" | |
| alias grm="git rm" | |
| alias gci="git commit" | |
| alias gca="git commit --amend" | |
| alias gco="git checkout" |
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
| # 1. Use two spaces instead of tabs | |
| # 2. Avoid using 'return' when not necessary. It's unnecessary. | |
| # before | |
| def current_user | |
| return session[:user] | |
| end | |
| # after | |
| def current_user |
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 lambda_mem(f, cache=nil) | |
| cache = {} if cache.nil? | |
| lambda do |h| | |
| return cache[h] if cache[h] | |
| cache[h] = f.call( lambda {|n| lambda_mem(f, cache).call(n) } ).call(h) | |
| end | |
| end | |
| def fib(g) | |
| raise(ArgumentError, "Argument must be positive") if g < 0 |
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 MozRepl | |
| require 'base64' | |
| require 'net/telnet' | |
| PROMPT = /\nrepl>\s/ | |
| class Telnet < Net::Telnet | |
| alias_method :old_cmd, :cmd | |
| def cmd(options, &blk) | |
| old_cmd(options, &blk).gsub!(MozRepl::PROMPT, '') |
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
| ['rubygems', 'rack'].each { |lib| require lib } | |
| app = lambda { |env| [200, {'Content-Type' => 'text/html'}, env.inspect] } | |
| Rack::Handler::WEBrick.run(app, :Port => 4004) |
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 'base64' | |
| require 'test/unit' | |
| module B64 | |
| CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split '' | |
| # === Encode Non-MIME | |
| # convert string to binary | |
| # copy groups of 8 bits to 6 bits | |
| # add b64 padding - 0 fill (to 6) the right side of the last bit grouping |
NewerOlder