Skip to content

Instantly share code, notes, and snippets.


Stefaan Lippens soxofaan

View GitHub Profile
import sys
import subprocess
import random
import time
import threading
import Queue
class AsynchronousFileReader(threading.Thread):
Helper class to implement asynchronous reading of a file
# The original code at
# does not seem to work on my setup (python 2.7.2, numpy 1.6.1, pandas 0.13.1)
# The version below works for me.
import numpy as np;
import pandas as pd;
rating = pd.read_csv('movie_rating.csv')
rp = rating.pivot_table(cols=['critic'], rows=['title'], values='rating')
rating_toby = rp['Toby']
soxofaan /
Last active Aug 29, 2015
Gnu screen trick to launch ipython notebook within screen session non interactively
# set -x
# set -e
if screen -list | grep $sessionname ; then
echo "Screen session $sessionname is already running."
echo "not doing anything"
soxofaan /
Last active Aug 29, 2015
TimingLogger context manager
import datetime
import logging
class TimingLogger(object):
Simple timer context manager to log the time spent in the context
to given logger (logging api).
Usage example:
soxofaan /
Last active Aug 29, 2015
python version dump snippet
Snippet to list Python installation/packaging related version information.
Execute it with the Python executable you want to inspect.
Usage example with curl/wget tricks straight from this github gist
(optionally replace `python` at the end with the desired alternative):
curl -s | python
soxofaan / gist:5561683
Last active Dec 17, 2015
bookmarklet to add bouncing pony
View gist:5561683
// permanent version
/*javascript:*/(function(e,t){var i=t.createElement("img");i.src="";var;o.position="fixed",o.bottom="0",o.left="20%",o["z-index"]=1e4,t.body.appendChild(i)})(window,document);
// on/of version
/*javascript:*/(function(n,e){function t(){var n=e.createElement("img");n.src="","pinkbouncingpony";var;t.position="fixed",t.bottom="0",t.left="20%",t["z-index"]=1e4,e.body.appendChild(n)}function i(){e.body.removeChild(e.getElementById("pinkbouncingpony"))}function o(){t(),n.setTimeout(m,5e3)}function m(){i(),n.setTimeout(o,1e4)}o()})(window,document);
soxofaan / pre-receive
Created Sep 23, 2013
Git pre-receive hook to entertain the pusher with a random fact
View pre-receive
# Echo a random fun fact for the pusher's pleasure.
rand=$(( $RANDOM % 5 ))
case "$rand" in
echo "--- Did you know? says: -----------------------------------"
wget --timeout=1 -O - 2>/dev/null | grep \<strong\> | sed "s;^.*<i>\(.*\)</i>.*$;\1;"
echo "------------------------------------------------------------------------------"
soxofaan / entities.php
Last active Dec 24, 2015
Some weird PHP magic going on here
View entities.php
class A
public function whoami() { return 'A'; }
public function __call($method, array $args)
return 'A::__call::' . $method;
soxofaan / ssh_reconnect.xonsh
Created Sep 7, 2016
.xonshrc snippet with alias to reconnect SSH sockets (after reconnecting a screen session)
View ssh_reconnect.xonsh
def _reconnect_ssh_agent_socket(args, stdin=None):
import re
print("Updating ssh-agent socket environment. Current value: $SSH_AUTH_SOCK = %s" % $SSH_AUTH_SOCK)
# Use find to list candidate paths with timestamp (as float).
raw = $(find /tmp/ssh-* -user @$(whoami) -name 'agent*' -printf '%T@:%p;')
candidates = [(float(, for m in re.finditer('([0-9.]*):(.*?);', raw)]
# Take latest.
$SSH_AUTH_SOCK = max(candidates)[1]
soxofaan /
Created Jan 16, 2017
Script to fix SSH agent environment variables on a remote server after reconnecting to a screen session
# Script to fix the SSH agent environment variable after reconnecting to a running screen session.
# Usage: *source* this script (don't just execute).
# For example, if you store it at ~/, create this alias to have it available easily:
# alias screenfix='source ~/'
echo "Updating ssh-agent socket environment.."
echo "Current value: $SSH_AUTH_SOCK"
export SSH_AUTH_SOCK=$(find /tmp/ssh-* -user `whoami` -name agent\* -printf '%T@ %p\n' 2>/dev/null | sort -k 1nr | sed 's/^[^ ]* //' | head -n 1)