This file contains 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
# if else then in one line | |
[ $condition ] && echo 'true' || echo 'false' | |
# if argument empty then | |
local arg | |
echo ${arg:-default_value} # => default_value | |
arg=present | |
echo ${arg:-default_value} # => present | |
# if argument not empty then replace the text |
This file contains 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
#!/usr/bin/bash | |
# under Mac | |
nslookup -type=mx DOMAIN_NAME |
This file contains 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
-- Applications -> AppleScript Editor | |
choose color | |
-- Now, save it as an application (File -> Save As, and set the File Format pop-up to Application) | |
-- Reference: http://hints.macworld.com/article.php?story=20060408050920158 |
This file contains 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
ini_set('display_errors',1); | |
ini_set('display_startup_errors',1); | |
error_reporting(-1); |
This file contains 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
burn_iso () { | |
if [[ -z $1 ]] || [[ -z $2 ]]; then | |
echo 'usage: burn_iso IDENTIFIER PATH_TO_ISO' | |
echo 'hint: you could use `diskutil list` to find out the desired identifier.' | |
return | |
fi | |
# @see http://osxdaily.com/2015/06/05/copy-iso-to-usb-drive-mac-os-x-command/ | |
# 1. find out the identifier using `diskutil list` |
This file contains 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
usb_installer () { | |
if [[ -z $1 ]]; then | |
echo 'usage: usb_install PATH_TO_VOLUME' | |
return | |
fi | |
sudo /Applications/Install\ OS\ X\ El\ Capitan.app/Contents/Resources/createinstallmedia --volume $1 --applicationpath /Applications/Install\ OS\ X\ El\ Capitan.app/ --nointeraction | |
} |
This file contains 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
# All data types that ActiveRecord supports | |
PostgresqlModel.connection.type_map.try do |type_map| | |
type_map.instance_variable_get('@mapping').keys.map do |key| | |
key.is_a?(String) ? key : nil # others are oid type | |
end.compact.uniq | |
end | |
# PostgreSQL | |
# [ "bit", "bool", "box", "bpchar", "bytea", "char", "cidr", "circle", "citext", "date", "float4", "float8", "hstore", | |
# "inet", "int2", "int4", "int8", "interval", "json", "jsonb", "line", "lseg", "ltree", "macaddr", "money", "name", "numeric", |
This file contains 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
# Execute the following commands in terminal to see its output: | |
# $ curl -L -o resume.rb https://gist.github.com/tian-im/510644be3c5453f81bc86c8515d2d48b/raw && gem install rspec -N | |
# $ rspec resume.rb --format documentation --color | |
module Resume | |
puts <<~CONTACT | |
name: Tianwen "Tian" Chen | |
email: me at tian.im | |
github: https://github.com/tian-im | |
linkedin: http://www.linkedin.com/in/tian-im |
This file contains 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
#!/usr/bin/env bash | |
source $HOME/.rvm/scripts/rvm || source /etc/profile.d/rvm.sh | |
rvm use --default --install $1 | |
shift | |
if (( $# )) | |
then gem install $@ |
This file contains 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
# to add | |
netsh interface portproxy add v4tov4 listenport=3000 listenaddress=127.0.0.1 connectport=3000 connectaddress=10.0.2.2 | |
# to remove | |
netsh interface portproxy delete v4tov4 listenport=3000 listenaddress=127.0.0.1 |
OlderNewer