Skip to content

Instantly share code, notes, and snippets.

View OBdA's full-sized avatar

Olf OBdA

View GitHub Profile
@OBdA
OBdA / helper.py
Last active October 13, 2015 14:05
python helpers
# vim: syntax=python fileencoding=utf-8 ts=4 sts=4 sw=4 expandtab
def dict_from_list(lst):
"""
Takes a list of objects and returns it as a dict(). Does what dict(lst) is expected to do.
"""
if len(lst) % 2: lst.append(None)
# a short form for:
# i = iter(lst)
# zip(i, i)
return dict(zip(*[iter(lst)]*2))
# Needed for commit logs
git config --global user.name "$name"
git config --global user.email "$email"
# Aliases
git config --global alias.dc "diff --cached"
# I prefer an shell alias for 'git status'
echo 'alias gst="git status"' >> $HOME/.bashrc
@OBdA
OBdA / .vimrc
Last active December 14, 2015 09:18
Practical VIM resources
" Enable file configuration, eg. "# vim: ts=4"
set modeline
" Set statusline and enable it permanently
" Entry format (see :help statusline): %-0{minwid}.{maxwid}{item}
set statusline=%<%f%h%m%r%=%b\ 0x%B\ \ %l,%c%V\ %P
set laststatus=2
" create backup file
set backup
@OBdA
OBdA / retouch
Created January 18, 2013 12:23
#! /bin/sh
[ -e "$1" ] || exit 1
[ -e "$1.retouch" ] && ( touch -r "$1.retouch" "$1"; rm -f "$1.retouch"; : ) && exit 0
touch -r "$1" "$1.retouch" && exit 0
#EOF
@OBdA
OBdA / libtemplate.sh
Last active October 10, 2015 12:38
Templates
#! /bin/sh
set -Cefu
__check_for_help()
{
set +u
if test $(basename -- $0) = 'libtemplate.sh' -a \( '--help' = "$1" -o '-h' = "$1" \); then
exec sed -n '/^#--/ {s/^#--//; p}' $0 | less -+S -FRX && exit 0
fi
}
@OBdA
OBdA / collapse-log-line.sed
Created June 26, 2012 13:15
sed: collapse logical lines
#! /bin/sed -f
# SED script to concatenate logical lines sepaated by
# backslashes (\) at the end of the "physical" line
# set branch target 't'
:t
# apply the following on all lines ending with an '\'
/\\$/ {
# concatenate actual line with the next in pattern space
N;
@OBdA
OBdA / script-with-inline-documentation.sh
Created May 25, 2012 14:29
Inline manual in shell scripts
#! /bin/sh
__check_for_help()
{
set +u # disable 'nounset' because positional parameters may be unset
# check $0 against the file name because of scripts sourcing shell libraries
# with inline documentation
test $(basename $0) = 'libUMI.sh' -a \( '--help' = "$1" -o '-h' = "$1" \) \
&& exec sed -n '/^#--/ {s/^#--//; p}' $0 | less -+S -FRX && exit 1