Skip to content

Instantly share code, notes, and snippets.

tm() {
[[ -n "$TMUX" ]] && change="switch-client" || change="attach-session"
if [ $1 ]; then
tmux $change -t "$1" 2>/dev/null || (tmux new-session -d -s $1 && tmux $change -t "$1"); return
fi
session=$(tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf --exit-0) && tmux $change -t "$session" || echo "No sessions found."
}
@zshihang
zshihang / fzf.zsh
Last active June 10, 2018 06:28 — forked from junegunn/functions.sh
Key bindings for fzf
# required
# -------------
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
export FZF_DEFAULT_COMMAND='fd -t f'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_ALT_C_COMMAND='fd -t d'
export FZF_COMPLETION_TRIGGER=''
bindkey '^T' fzf-completion
bindkey '^I' $fzf_default_completion
@zshihang
zshihang / trie.py
Created October 13, 2017 01:59
Trie
__author__ = "Shihang Zhang"
__status__ = "Prototype"
class TrieNode(object):
""" Trie Node Class
@attrs:
children: a dictionary contains all children nodes
count: an integer indicates the number of occurence of current word
@zshihang
zshihang / simplegraph.py
Created March 8, 2016 03:52
Simple implementation of graph
class SimpleGraph(object):
def __init__(self, edges, weights=None):
self._edges = edges
self._weights = weights
def neighbors(self, id):
return self._edges[id]
def cost(self, start, end):
@zshihang
zshihang / hashtable.py
Last active March 1, 2016 16:23
Simple Implementation of HashTable in Python
class HashTable(object):
def __init__(self, size=100):
self._size=size
self._table=[[] for i in range(self._size)]
def get(self, key):
hash = self._hash(key)
bucket = self._table[hash]
for x in bucket: