Skip to content

Instantly share code, notes, and snippets.

View tancnle's full-sized avatar
🌸
Living The Dream ᕙ༼*◕_◕*༽ᕤ

Tan Le tancnle

🌸
Living The Dream ᕙ༼*◕_◕*༽ᕤ
View GitHub Profile
@tancnle
tancnle / single_vs_double_quotes.rb
Created October 3, 2012 00:32
Benchmark single and double quotes
require "benchmark"
n = 1000000
Benchmark.bm do |x|
x.report("assign single") { n.times do; c = 'a string'; end}
x.report("assign double") { n.times do; c = "a string"; end}
x.report("assign interp") { n.times do; c = "a #{n} string"; end}
x.report("concat single") { n.times do; 'a string ' + 'b string'; end}
x.report("concat double") { n.times do; "a string " + "b string"; end}
x.report("concat interp") { n.times do; "a #{n} string " + "b #{n} string"; end}
@tancnle
tancnle / shuffle_vs_sample.rb
Created October 3, 2012 00:25
Benchmark shuffle and sample
require "benchmark"
foo = (1..100).to_a
n = 1000000
Benchmark.bm do |x|
x.report("shuffle") { n.times do; bar = foo.shuffle.first ; end}
x.report("sample") { n.times do; bar = foo.sample ; end}
end
@tancnle
tancnle / metrics.sh
Created June 22, 2012 07:16
Commit generated metric-fu report to metrics repo
#!/bin/bash
set -e
set -v
# RVM shenanigans
source "$HOME/.rvm/scripts/rvm"
rvm --create use ree-1.8.7-2011.03@studio
# Setup database connection
@tancnle
tancnle / gist:2969692
Created June 22, 2012 01:32
Fix incorrect Nokogiri loaded libraries

Every time I upgrade libxml2 via Homebrew, running cucumber test will post an annoying warning message

WARNING: Nokogiri was built against LibXML version 2.7.3, but has dynamically loaded 2.8.0

To fix it:

$ gem uninstall nokogiri
$ brew link libxml2

$ gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.8.0/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.8.0/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26