Skip to content

Instantly share code, notes, and snippets.

@dunghuynh
dunghuynh / vim_italic.md
Created June 22, 2017 00:09
[vim italic] #vim #iterm2 #terminal #maxos

Copy the following into a file (which I named "xterm-256color.terminfo.txt")

xterm-256color|xterm with 256 colors and italic,
  sitm=\E[3m, ritm=\E[23m,
  use=xterm-256color,

Next execute the following comand:

@dunghuynh
dunghuynh / misc.md
Last active June 18, 2017 03:24
[SIP Misc.] phone forwarding - SIP

To find out the source ip of SIP forwarding: Start a dummy sip server (on Digital Ocean):

nc -l -u -v 5060

Then choose to forward the sip to sip@do-server-ip When the SIP forward the package, in the console log there will be its details being dumped

@dunghuynh
dunghuynh / misc.md
Created June 15, 2017 06:14
[Postgresql misc.] #postgresql

Restore db

pg_restore --verbose --clean --no-acl --no-owner -h 127.0.0.1 -d db_name ~/Downloads/2017-06-14-15h-12m-49s.dump
@dunghuynh
dunghuynh / misc.md
Created June 15, 2017 05:50
[Git misc.] #git

Search for a string in all commits

git log -S <whatever> --source --all

Create patches

git format-patch <sha>
git format-patch -1 <sha>
@dunghuynh
dunghuynh / misc.md
Last active June 15, 2017 05:46
[Docker misc.] #docker

Delete all container

sudo docker ps -a -q | xargs -n 1 -I {} sudo docker rm {}

Remove dangling images

docker rmi $(docker images -q --filter "dangling=true")

Remove stopped containers

@dunghuynh
dunghuynh / misc.md
Created June 15, 2017 05:40
[Bundler misc] #bundler

Remove all gems

bundle list | ruby -e 'ARGF.readlines[1..-1].each {|l| g = l.split(" ");  puts "Removing #{g[1]}"; `gem uninstall --force #{g[1]} -v #{g[2].gsub(/\(|\)/, "")}`; }'
@dunghuynh
dunghuynh / decode_mobile_keypad.rb
Last active June 14, 2017 06:17
[decode mobile keypad]
#!/usr/bin/env ruby
# Usage: ./decode_mobile_keypad.rb 44 33 555 555 666
KEYS = {
"1" => [], "2" => ['a','b','c'], "3" => ['d','e','f'],
"4" => ['g','h','i'], "5" => ['j','k','l'], "6" => ['m','n','o'],
"7" => ['p','q','r','s'], "8" => ['t','u','v'], "9" => ['w','x','y','z']
}
ARGV.each do|a|
size = a.size - 1
print KEYS[a[0]][size]
@dunghuynh
dunghuynh / rbenv-install-system-wide.sh
Last active June 14, 2017 06:18 — forked from jnx/rbenv-install-system-wide.sh
[install rbenv system wide] #rbenv
# Update, upgrade and install development tools:
apt-get update
apt-get -y upgrade
apt-get -y install build-essential libssl-dev
apt-get -y install git-core
apt-get -y install autoconf bison build-essential libssl-dev\
libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev
# Install rbenv
git clone git://github.com/sstephenson/rbenv.git /usr/local/rbenv
@dunghuynh
dunghuynh / node nginx configuration
Last active June 14, 2017 06:19
[nodejs nginx configuration] Configuration for nodejs on nginx #nginx #nodejs
# Load balancer configuration
upstream exampleApp {
# Directs to the process with least number of connections.
least_conn;
# One failed response will take a server out of circulation for 20 seconds.
server 127.0.0.1:10080 fail_timeout=20s;
#server 127.0.0.1:10081 fail_timeout=20s;
#server 127.0.0.1:10082 fail_timeout=20s;
#server 127.0.0.1:10083 fail_timeout=20s;
@dunghuynh
dunghuynh / rails_ssl_localhost.sh
Last active June 14, 2017 06:21 — forked from trcarden/gist:3295935
[Rails SSL Localhost] #ssl #rails #localhost #openssl
# SSL self signed localhost for rails start to finish, no red warnings.
# 1) Create your private key (any password will do, we remove it below)
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key