Skip to content

Instantly share code, notes, and snippets.

View suewonjp's full-sized avatar

Suewon Bahng suewonjp

View GitHub Profile
@suewonjp
suewonjp / selectFromArray.bash
Last active January 10, 2018 09:29
General Bash function that creates selection interface from arbitrary array (See comment below for usage example)
selectFromArray() {
if [ "$1" ]; then
local IFS=$'\n' selected= idx=$2 tmp=()
eval "local arr=( \${$1[*]} )"
if [ ${#arr[@]} -eq 1 ]; then
selected="${arr[0]}"
elif [ ${#arr[@]} -gt 1 ]; then
select a in "QUIT!" "${arr[@]}"; do
[ "${a}" = "QUIT!" ] && break
@suewonjp
suewonjp / killProcess.bash
Last active March 10, 2018 00:26
Bash function that lets you interactively kill arbitrary process with pattern matching (See the comment below for an example usage)
killProcess() {
if [ $# -lt 1 ]; then
echo "Usage: ${FUNCNAME[0]} [pattern for process name]"
return
fi
local procs=() selected=
case "$( uname )" in
Darwin*|CYGWIN*) mapfile -t procs < <( pgrep -fil "${1}" ) ;;
*) mapfile -t procs < <( pgrep -fl "${1}" ) ;;
@suewonjp
suewonjp / source-code-line-counter.sh
Last active March 10, 2018 00:31
Count the number of source code lines using lf.sh
### Count lines in every Python source file in the current project
count=0
for f in `lf . .py`; do count=$(( $count + `cat $f | wc -l` )); done
echo $count
@suewonjp
suewonjp / .gitconfig
Created October 1, 2019 13:39
gitconfig
[user]
name = your_name
email = your@email
[alias]
unstage = reset HEAD --
last = log -1 --stat
co = checkout
b = branch
l = log -10 --pretty=format:\"%h - %ar : %s\"
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %Cblue<%an>%Creset' --abbrev-commit --date=relative --all