Skip to content

Instantly share code, notes, and snippets.

Rick van Hattem WoLpH

Block or report user

Report or block WoLpH

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View clean-merged-branches.sh
#!/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 Apr 6, 2012
Some functions to convert arrays/hstore to json :)
View to_json.sql
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 Jun 19, 2012
Screen reattach script for bash/zsh/etc..
View screen.sh
# 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 Jul 23, 2012
Global git garbage collect
View .gitconfig
[alias]
global-gc = !git-global-gc.sh
@WoLpH
WoLpH / .zshrc
Last active Dec 10, 2017
Tmux start script which automatically reconnects or starts a new session
View .zshrc
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 Oct 25, 2012
Ontology Engineering Sesame Wrapper
View sparql.py
#!/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 Dec 15, 2015
Passing functions in C with function return type casting
View test.c
#include <stdio.h>
int a(){
return 42;
}
double b(){
return 3.141592653589793;
}
@WoLpH
WoLpH / proxy.py
Created Jul 14, 2013
Gevent based proxy server for non http compliant webserver
View proxy.py
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 Aug 29, 2015
Simple script to copy zfs vdevs (partitions) from one zpool to another with a progress bar :)
View zfs_copy.sh
#!/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 Mar 9, 2014
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.
View to_images.sh
#!/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
You can’t perform that action at this time.