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 / 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

@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 / 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 / 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 / parallel_spec_test.md
Last active December 10, 2015 13:08
Testing Parallel block in RSpec

Problem:

We have the following Parallel block which spin up multiple parallel processes

  Parallel.map(
    servers,
    :in_processes     => servers.size,
    :preserve_results => false,
 ) do |server|
@tancnle
tancnle / patch_font.sh
Last active December 11, 2015 02:08
Font patching for Vim
brew install fontforge
mkdir ~/.fonts
wget -P ~/.fonts https://gist.github.com/baopham/1838072/raw/5fa73caa4af86285f11539a6b4b6c26cfca2c04b/Monaco%20for%20Powerline.otf
git clone https://github.com/Lokaltog/vim-powerline.git /tmp/vim-powerline
cd /tmp/vim-powerline && fontforge -script fontpatcher/fontpatcher ~/.fonts/Monaco+for+Powerline.otf
echo -e "set encoding=utf-8\nset guifont=Monaco-Powerline\nlet g:Powerline_symbols = 'fancy'" >> ~/.vimrc
# And make sure you install Monaco-Powerline.otf on Mac and use that font for your Terminal/iTerm app as well
@tancnle
tancnle / ctags_vim.md
Last active July 24, 2017 05:47
Steps to install ctags on vim
  • brew install ctags
  • Install ctags.vim bundle via git://github.com/vim-scripts/ctags.vim.git
  • Add the following line to your .vimrc
let Tlist_Ctags_Cmd="/usr/local/bin/ctags"
let Tlist_WinWidth=50
map <F8> :!/usr/local/bin/ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
map <F4> :TlistToggle<cr>
@tancnle
tancnle / remove_mysql.sh
Last active December 17, 2015 08:39
Remove MySQL from MacOSX
# Credit: http://akrabat.com/computing/uninstalling-mysql-on-mac-os-x-leopard/
# Use mysqldump to backup your databases to text files!
# Stop the database server
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
sudo sed -i '.bak' 's/^MYSQLCOM.*//g' /etc/hostconfig
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
@tancnle
tancnle / install_libv8.sh
Created July 19, 2013 00:20
Installing libv8 gem on Mountain Lion 10.8.4
$ RUBYOPT="-r rubygems" gem install libv8 -v '3.3.10.4'
@tancnle
tancnle / check_used_space_limit.sh
Last active December 20, 2015 21:38
Detect used space over 90% threshold
#!/bin/bash
OK=0
WARNING=1
ERROR=2
UNKNOWN=3
used_space_limit=90
used_space=`df -k /dev/xvde1 | awk '{print $5}' | tail -1 | sed 's/%//g'`