Skip to content

Instantly share code, notes, and snippets.

View tian-im's full-sized avatar
🌅
WFH

Tianwen (Tian) Chen tian-im

🌅
WFH
View GitHub Profile
@tian-im
tian-im / one_liner.sh
Created October 23, 2011 07:28
Shell script programming practices
# 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
@tian-im
tian-im / command.sh
Created September 23, 2012 23:51
Query the MX records
#!/usr/bin/bash
# under Mac
nslookup -type=mx DOMAIN_NAME
@tian-im
tian-im / ColorPicker.applescript
Last active December 15, 2015 14:39
Make the OS X Color Picker into an application
-- 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
@tian-im
tian-im / error_report.php
Created July 13, 2014 06:52
PHP Error Report
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
@tian-im
tian-im / burn.sh
Last active October 26, 2015 17:25
Burn ISO to external volume in Mac
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`
@tian-im
tian-im / usb_installer.sh
Created October 26, 2015 17:29
Create USB installer for El Capitan
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
}
@tian-im
tian-im / activerecord_types.rb
Last active April 24, 2016 16:58
Find out all data types that ActiveRecord supports.
# 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",
@tian-im
tian-im / resume.rb
Last active January 2, 2024 07:10
Resume written in Ruby which can be run as RSpec test.
# 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
@tian-im
tian-im / install-ruby.sh
Created July 23, 2017 01:01
Vagrant setup
#!/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 $@
@tian-im
tian-im / port_forwarding.exe
Created July 26, 2017 23:56
Port forwarding in Windows
# 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