Skip to content

Instantly share code, notes, and snippets.

View hkupty's full-sized avatar

Henry John Kupty hkupty

View GitHub Profile
@hkupty
hkupty / oneliner_dict.py
Created March 25, 2014 20:27
Dict intersection one-liner
# Get the intersected dict from x and y
lambda x,y: {i:x[i] for i in set(x.keys()) & set(y.keys())}
# Get from x only the keys in list y, assuming y is a list, tuple or set..
lambda x,y: {i:x[i] for i in set(x.keys()) & set(y)}
@hkupty
hkupty / oneliner_querystring.py
Created March 25, 2014 20:29
Querystring from dict oneliner
lambda filters: "&".join(map(lambda kv: '%s=%s' % kv, filters.iteritems()))
@hkupty
hkupty / curry.py
Last active August 29, 2015 14:04
Currying python functions
from functools import partial
curry = lambda f, g: partial(
lambda F, G, *args, **kwargs: F(G(*args,**kwargs)),
f, g
)
@hkupty
hkupty / profile.py
Created August 20, 2014 12:41
Profiling Decorator
import cProfile
import pstats
def measure(func):
""" The decorator. """
def profiling(*args, **kwargs):
""" The profiler. """
prof = cProfile.Profile()
prof.enable()
def time[A](a: => A) = {
val now = System.nanoTime
val result = a
val micros = (System.nanoTime - now) / 1000
println("%d microseconds".format(micros))
result
}
" Code Completion
Plug 'shougo/deoplete.nvim'
" Plug 'roxma/nvim-completion-manager'
" Snippets
Plug 'shougo/neosnippet.vim'
Plug 'shougo/neosnippet-snippets'
" Ctags
@hkupty
hkupty / git-fzchk
Created April 9, 2019 09:04
Fuzzy-find branches to git checkout
#!/bin/env bash
# Requires https://github.com/junegunn/fzf
git checkout "$(git branch | awk '{print $NF}' | fzf)"
@hkupty
hkupty / ceq
Created December 18, 2019 08:18
jq for edn
#!/bin/sh
#_(
DEPS=''
OPTS='
-J-Xms256m -J-Xmx256m -J-client
'
exec clojure $OPTS -Sdeps "$DEPS" "$0" "$@"
)
(require '[clojure.edn :as edn]
@hkupty
hkupty / git-chk
Created December 18, 2019 08:19
Fuzzy-find branches in git repo
#!/bin/bash
set -euo pipefail
# TODO Fix multiple remotes
readarray LOCAL <<< $(git branch --no-color | awk '{print $NF}')
readarray REMOTE <<< $(git branch -r | sed 's/.*origin\///g')
REMOTE_ONLY=($(echo ${LOCAL[@]} ${LOCAL[@]} ${REMOTE[@]} | tr ' ' '\n' | sort | uniq -u))
@hkupty
hkupty / select-oath
Created December 18, 2019 08:21
Select yubikey oath on rofi - so I don't have to go to the terminal
#!/bin/bash
set -euo pipefail
ykman info > /dev/null
SELECTED=$(ykman oath list | rofi -dmenu)
if [ -n "${SELECTED}" ]; then
ykman oath code ${SELECTED} | awk '{ print $NF }' | xsel -b
fi