Skip to content

Instantly share code, notes, and snippets.

View wolph's full-sized avatar

Rick van Hattem wolph

View GitHub Profile
@wolph
wolph / clean-merged-branches.sh
Created January 13, 2012 06:58
clean-merged-branches
#!/bin/sh
#/ Usage: clean-merged-branches [-f]
#/ Delete merged branches from the origin remote.
#/
#/ Options:
#/ -f Really delete the branches. Without this branches are shown
#/ but nothing is deleted.
#/ -n Dry-run, only show what would be removed.
set -e
@wolph
wolph / to_json.sql
Created April 6, 2012 10:35
Some functions to convert arrays/hstore to json :)
CREATE OR REPLACE FUNCTION escape_json (text) RETURNS text AS $$
SELECT replace($1, '''', '\'''); $$ LANGUAGE SQL IMMUTABLE;
CREATE OR REPLACE FUNCTION to_json(text) RETURNS text AS $$
SELECT escape_json($1) $$ LANGUAGE SQL IMMUTABLE;
CREATE OR REPLACE FUNCTION to_json(KEY text, value text) RETURNS text AS $$
SELECT '''' || to_json($1) || ''': ''' || to_json($2) || ''''; $$ LANGUAGE SQL IMMUTABLE;
@wolph
wolph / screen.sh
Created June 19, 2012 16:41
Screen reattach script for bash/zsh/etc..
# If we're not in screen, resume the existing session
if [[ "$TERM" != screen* ]]; then
# Clean up old sessions
screen -wipe > /dev/null
# See if there are sessions available
screen -q -ls
if [[ "$?" -ge "10" ]]; then
# Reconnect if there are
exec screen -x
@wolph
wolph / .gitconfig
Created July 23, 2012 13:47
Global git garbage collect
[alias]
global-gc = !git-global-gc.sh
@wolph
wolph / .zshrc
Last active December 10, 2017 02:30
Tmux start script which automatically reconnects or starts a new session
function auto_activate(){
name=$(basename "$PWD")
project_dir="$HOME/workspace/$name"
env_dir="$HOME/envs/$name"
if [ -d "$env_dir" ]; then
workon "$name"
fi
}
auto_activate
@wolph
wolph / sparql.py
Created October 25, 2012 13:36
Ontology Engineering Sesame Wrapper
#!/usr/bin/env python
import os
import sys
import subprocess
import fileinput
os.chdir(os.path.dirname(__file__))
process = subprocess.Popen(
@wolph
wolph / test.c
Last active December 15, 2015 12:19
Passing functions in C with function return type casting
#include <stdio.h>
int a(){
return 42;
}
double b(){
return 3.141592653589793;
}
@wolph
wolph / proxy.py
Created July 14, 2013 16:14
Gevent based proxy server for non http compliant webserver
from gevent.local import local
from gevent.pywsgi import WSGIServer
from gevent import monkey
import socket
import pprint
import sys
def application(environ, start_response):
url = environ['PATH_INFO']
@wolph
wolph / zfs_copy.sh
Last active August 29, 2015 13:57
Simple script to copy zfs vdevs (partitions) from one zpool to another with a progress bar :)
#!/bin/sh
source=$1
dest=$2
snapshot=$3
size=$(zfs send -nP $source@$snapshot 2>&1 | grep size | awk '{print $2}')
echo "$source@$snapshot -> $dest: $size"
zfs send $source@$snapshot | pv --timer --progress --eta --rate --average-rate --bytes --size $size --cursor --name $source | zfs receive -Fvu $dest
@wolph
wolph / to_images.sh
Created March 9, 2014 16:59
Script to automatically convert directories to sparse images on OS X. Since I have noticed a pretty obvious slowdown in OS X when having lots (many millions) of files on the filesystem, this has given me quite a significant speedup.
#!/bin/bash -e
function image_all(){
echo "Processing $1"
test -d "$1" || return 1
cd "$1"
for i in *; do
if [ "$i" == "utils" ]; then
continue