Skip to content

Instantly share code, notes, and snippets.

View soxofaan's full-sized avatar

Stefaan Lippens soxofaan

View GitHub Profile
@soxofaan
soxofaan / python-version-dump.py
Last active August 29, 2015 14:23
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 https://gist.githubusercontent.com/soxofaan/cc4986cc507cb10f962d/raw/python-version-dump.py | python
@soxofaan
soxofaan / timinglogger.py
Last active August 29, 2015 14:06
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
soxofaan / launch-ipython-notebook-in-screen.sh
Last active August 29, 2015 14:00
Gnu screen trick to launch ipython notebook within screen session non interactively
#!/bin/sh
# set -x
# set -e
sessionname=ipython-notebook
if screen -list | grep $sessionname ; then
echo "Screen session $sessionname is already running."
echo "not doing anything"
# The original code at http://tungwaiyip.info/2012/Collaborative%20Filtering.html
# 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']
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