Skip to content

Instantly share code, notes, and snippets.

View tennisonchan's full-sized avatar

Tennison Chan tennisonchan

  • Truewind
  • San Francisco
View GitHub Profile
git-create() {
repo_name=`basename $(git config --local --get remote.origin.url)`
dir_name=`basename $(pwd)`
invalid_credentials=0
if [ "$repo_name" = "" ]; then
echo " Repo name (hit enter to use '$dir_name')?"
read repo_name
fi
@tennisonchan
tennisonchan / object_unique_id.js
Last active July 25, 2016 02:40
generate unique id for object without modifying Object.prototype #js
var __next_objid = 1;
function objectId(obj) {
if (!obj) return obj;
if (!obj.__obj_id) obj.__obj_id = __next_objid++;
return obj.__obj_id;
}
@tennisonchan
tennisonchan / dropkick.sh
Created December 19, 2015 17:24
Detect and Disconnect the DropCam and Withings devices some people are using to spy on guests in their home, especially in AirBnB rentals.
#!/bin/bash
#
# DROPKICK.SH
#
# From http://julianoliver.com/output/log_2015-12-18_14-39
#
# Detect and Disconnect the DropCam and Withings devices some people are using to
# spy on guests in their home, especially in AirBnB rentals. Based on Glasshole.sh:
#
# http://julianoliver.com/output/log_2014-05-30_20-52
@tennisonchan
tennisonchan / undo-git-commit-amend
Last active July 25, 2016 02:39
#undo the #git commit amend #sh
# Move the current head so that it's pointing at the old commit
# Leave the index intact for redoing the commit.
# HEAD@{1} gives you "the commit that HEAD pointed at before
# it was moved to where it currently points at". Note that this is
# different from HEAD~1, which gives you "the commit that is the
# parent node of the commit that HEAD is currently pointing to."
git reset --soft HEAD@{1}
# commit the current tree using the commit details of the previous
# HEAD commit. (Note that HEAD@{1} is pointing somewhere different from the
@tennisonchan
tennisonchan / check_branch.sh
Last active August 3, 2022 04:19
Check if branch exists in #git
# if branch_name exists, it will return its hash
# if not, it will returns null
git rev-parse --verify --quiet branch_name
@tennisonchan
tennisonchan / pathname_manipulation.sh
Last active April 12, 2016 03:43
To extract the path and the file name from a fullpath
fullpath_name="/usr/local/a-file-name"
filename1=${fullpath_name##*/}
pathname1=${fullpath_name%/*}
absolute_path=$(readlink -f "$0")
echo $filename1 # return a-file-name
echo $pathname1 # return /usr/local/
echo $absolute_path # return /usr/local/a-file-name
### OR using basename and dirname
@tennisonchan
tennisonchan / parameter-expansion.sh
Created April 12, 2016 03:35
Bash Parameter Expansion - To set default value to a variable in sh
### variable doesn't exist
echo $variable1
variable1="${variable1:-default value}"
echo $variable1
# return default value
### variable exists
variable2="a"
echo $variable2
@tennisonchan
tennisonchan / iterm2-preference-setting.txt
Last active July 25, 2016 02:36
#iterm2 preference setting
# http://stackoverflow.com/questions/6205157/iterm2-how-to-get-jump-to-beginning-end-of-line-in-bash-shell
FOR ACTION SEND
⌘← "HEX CODE" 0x01
⌘→ "HEX CODE" 0x05
⌥← "SEND ESC SEQ" b
⌥→ "SEND ESC SEQ" f
@tennisonchan
tennisonchan / russian_roulette.sh
Last active July 25, 2016 02:36
Russian Roulette in terminal #sh
[ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "Click"
@tennisonchan
tennisonchan / enable_ airport.sh
Last active July 25, 2016 02:37
#airport Wireless Tool in #mac #osx
# /bin/bash
# To create a symbolic link to the airport command.
# Make sure /usr/local/sbin is in your PATH
# echo $PATH
sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/local/sbin/airport
# Display detailed information on wireless signal quality, noise, security, and other WiFi network attributes.
airport -I