Skip to content

Instantly share code, notes, and snippets.

View suewonjp's full-sized avatar

Suewon Bahng suewonjp

View GitHub Profile
@suewonjp
suewonjp / prefix_suffix.js
Created June 7, 2016 08:04
[JavaScript snippet] string prefix, suffix
function prefix(str, sep) {
// prefix("foo.bar.txt", ".") => foo
return str && str.substring(0, str.indexOf(sep));
}
function suffix(str, sep, excludeSep) {
// suffix("foo.bar.txt", ".") => .txt
// suffix("foo.bar.txt", ".", true) => txt
return str && str.substring(str.lastIndexOf(sep) + (excludeSep === true ? sep.length : 0));
}
@suewonjp
suewonjp / mappings-for-windows-and-tabs.vim
Last active October 4, 2017 02:05
[vim tip] key mappings for conveniently traversing windows and tabs
" These mappings are based on the default key movement scheme of Vim (h, j, k, l)
" For example, when you want to move to the left tab, press Alt + h
" When you want to move to the window underneath, press Shift + Alt + j
" Paste the below code to your Vim settings file ( ~/.vimrc )
" Map Alt(Meta) key combinations
execute "set <M-l>=\el"
execute "set <M-h>=\eh"
execute "set <M-L>=\eL"
execute "set <M-H>=\eH"
@suewonjp
suewonjp / backup-functions.sh
Last active May 22, 2017 06:14
Bash Functions for Simple Directory Backup
checkBackupTarget() {
[ ! "$1" ] \
&& echo "Usage: $FUNCNAME [ directory-to-backup ]" \
&& echo "Note: the path should be relative" \
&& return 2
local tgtPath=$1
[ ! -d "$tgtPath" ] \
&& printf "$FUNCNAME : \"%s\" does NOT exist!!!\n" "$tgtPath" \
@suewonjp
suewonjp / Open_iTerm2.txt
Last active July 28, 2016 13:45
[Mac OS X Tip] Open a new iTerm tab from the current folder in Finder
on run {input, parameters}
tell application "Finder"
set dir_path to quoted form of (POSIX path of (folder of the front window as alias))
end tell
CD_to(dir_path)
end run
on CD_to(theDir)
tell application "iTerm"
activate