Skip to content

Instantly share code, notes, and snippets.

View dedeibel's full-sized avatar

Benjamin Peter dedeibel

View GitHub Profile
@dedeibel
dedeibel / mget.py
Last active December 19, 2016 13:21
python get with nested structures and default
def mget(dic, *keys):
ret = dic
last_key = keys[-1]
for key in keys[:-1]:
ret = ret.get(key, {})
return ret[last_key]
def mgetd(dic, *keys):
ret = dic
last_key = keys[-2]
@dedeibel
dedeibel / vcs_status
Last active October 8, 2019 19:04
git or svn status via keybindung in zsh
# .zsh/function/vcs_status
#
# Modify .zshrc:
#
# fpath=(~/.zsh/function $fpath)
#
# autoload vcs_status
# zle -N vcs_status
# bindkey '\es' vcs_status
#
@dedeibel
dedeibel / vcs_commit
Last active October 8, 2019 19:00
zsh widget that prepares a git or svn commit command with message containing the jira ticket number if applicable
# save as ~/.zsh/function/vcs_commit
#
# In your ~/.zshrc
#
# fpath=(~/.zsh/function $fpath)
# autoload vcs_commit
# zle -N vcs_commit
# bindkey '\ec' vcs_commit
#
# Loads the widget and also binds it to Alt+c
@dedeibel
dedeibel / commit.fish
Last active May 23, 2017 10:01
fish function that prepares a git commit command with message containing the jira ticket number
# save as ~/.config/fish/functions/commit.fish
# Use:
# Assuming you are in a git repository of a bitbucket / jira branch using the atlassian jira git flow conventions
# example "feature/EXP-1337-cool-new-feature
#
# MAC USERS CHANGE "sed -r" to "sed -E"
#
# > commit
# will expand to
# > git commit -m 'EXP-1337: '
@dedeibel
dedeibel / push-line.fish
Last active May 24, 2019 21:09
fish shell function to emulate zsh's push-line feature := store the current command and run one in between - restore the last command afterwards
# Save this file to ~/.config/fish/functions/push-line.fish
# Bind the function by using this in ~/.config/fish/functions/fish_user_key_bindings.fish
# function fish_user_key_bindings
# # For example alt+q
# bind \eq push-line
# end
function push-line
commandline -f kill-whole-line
@dedeibel
dedeibel / Makefile
Created May 30, 2016 21:21
make print automatic variables
foo: foo.cpp bar.o
$(info @ is $@ )
$(info % is $% )
$(info < is $< )
$(info ? is $? )
$(info ^ is $^ )
$(info + is $+ )
$(info | is $| )
$(info * is $* )
${CXX} ${CXXFLAGS} -o $@ $<
@dedeibel
dedeibel / dummy_java.sh
Last active May 22, 2016 18:41
install a dummy java so debian or ubuntu apt will be happy with an install oracle jdk - in this case for octave but should work for others too
#!/bin/bash
# deps:
# - have oracle jdk >= 7 build with java-package
# see https://wiki.debian.org/JavaPackage if you don't know how
# - apt-get install equivs
#
# Debian actually kind of suggests it but the doc ist kind of old:
# https://www.debian.org/doc/manuals/debian-java-faq/ch13.html
#
# inspired by RJ <[email protected]>
@dedeibel
dedeibel / access_report.sh
Created May 21, 2016 22:51
Create a goaccess report with the input of all access logs, including zipped ones in a given range e.g. the last week
#!/bin/bash
set -e
#set -x
# Tested on debian jessie
# Install goaccess
# Define your log format in /etc/goaccess.conf
# e.g log-format %h %^[%d:%^] "%r" %s %b "%R" "%u"
@dedeibel
dedeibel / sqlite-backup.sh
Created May 15, 2016 10:45
seafile sqlite db backup skript
#!/bin/bash
set -e
BASEDIR=/opt/seafile/mysite
OUTDIR=${BASEDIR}/backup/db
mkdir -p ${OUTDIR}
SUFFIX=.`date +"%Y-%m-%d-%H-%M-%S"`
sqlite3 ${BASEDIR}/ccnet/GroupMgr/groupmgr.db .dump | gzip > ${OUTDIR}/groupmgr.db.bak${SUFFIX}.gz
sqlite3 ${BASEDIR}/ccnet/PeerMgr/usermgr.db .dump | gzip > ${OUTDIR}/usermgr.db.bak${SUFFIX}.gz
sqlite3 ${BASEDIR}/seafile-data/seafile.db .dump | gzip > ${OUTDIR}/seafile.db.bak${SUFFIX}.gz
@dedeibel
dedeibel / make_my_icons.sh
Created May 15, 2016 09:37
Create an icons.c file for minidlna from a png instead of svg (modified original)
#!/bin/bash
#
# Generate a free icons.c for minidlna from Debian's SVG logo
#
# Copyright (C) 2011 Benoît Knecht <[email protected]>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright