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 / sort_vs_sort_by.rb
Created March 12, 2014 22:26
sort vs sort_by for intensive operation
require 'benchmark'
root_directories = Dir.glob("/*")
n = 5000
Benchmark.bm do |x|
x.report("sort") do
n.times{ root_directories.sort { |a, b| File.ctime(a) <=> File.ctime(b) } }
end
@tancnle
tancnle / setup_ack.md
Created January 31, 2014 11:52
Setup ack on MacOSX
$ brew install ack
$ ack --version

Create ~/.ackrc (Below is my ackrc example, modify as you see fit)

# Options
--smart-case
--sort-files

Exclusions

@tancnle
tancnle / setup_mosh_centos.sh
Last active December 5, 2019 03:01
Setup mosh on Centos 6.x
#!/bin/sh
# Update latest epel
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
sudo rpm -Uvh epel-release-6-8.noarch.rpm
# Download and build mosh
sudo yum -y install rpm-build rpmdevtools protobuf-compiler protobuf-devel libutempter-devel zlib-devel ncurses-devel openssh-clients perl-IO-Tty openssl-devel gcc gcc-c++
rpmdev-setuptree
cd ~/rpmbuild/SOURCES
@tancnle
tancnle / date_time_parser.rb
Created August 12, 2013 03:57
Date time parser
\A(\d{4})(-?)(\d{2})\2(\d{2})(?:[T\s-](\d{2})(:?)(\d{2})(?:\6(\d{2}))?)?\z
@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'`
@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 / 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 / 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 / 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 / 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|