Skip to content

Instantly share code, notes, and snippets.

Avatar

Stefaan Lippens soxofaan

View GitHub Profile
@soxofaan
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="http://25.media.tumblr.com/tumblr_m9le7kBGy51rf54jjo1_400.gif";var o=i.style;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="http://25.media.tumblr.com/tumblr_m9le7kBGy51rf54jjo1_400.gif",n.id="pinkbouncingpony";var t=n.style;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
soxofaan / pre-receive
Created Sep 23, 2013
Git pre-receive hook to entertain the pusher with a random fact
View pre-receive
#!/bin/sh
# Echo a random fun fact for the pusher's pleasure.
rand=$(( $RANDOM % 5 ))
case "$rand" in
0)
echo "--- Did you know? randomfunfacts.com says: -----------------------------------"
wget --timeout=1 randomfunfacts.com/ -O - 2>/dev/null | grep \<strong\> | sed "s;^.*<i>\(.*\)</i>.*$;\1;"
echo "------------------------------------------------------------------------------"
;;
@soxofaan
soxofaan / phantomjs-revealjs-slide-capture.js
Last active Jul 1, 2017
PhantomJS script to capture/render screenshots of the slides of a Reveal.js powered slideshow.
View phantomjs-revealjs-slide-capture.js
/**
* PhantomJS script to capture/render screenshots of the slides of a Reveal.js powered slideshow.
*/
var page = require('webpage').create();
var args = require('system').args;
// Get url to render from command line.
var url;
if (args.length < 2) {
@soxofaan
soxofaan / entities.php
Last active Dec 24, 2015
Some weird PHP magic going on here
View entities.php
<?php
class A
{
public function whoami() { return 'A'; }
public function __call($method, array $args)
{
return 'A::__call::' . $method;
}
View AsynchronousFileReader-py2.py
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
View AsynchronousFileReader-py3.py
import sys
import subprocess
import random
import time
import threading
from queue import Queue
import collections
class AsynchronousFileReader(threading.Thread):
'''
View 9line-collaborative-filtering.py
# 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']
@soxofaan
soxofaan / launch-ipython-notebook-in-screen.sh
Last active Aug 29, 2015
Gnu screen trick to launch ipython notebook within screen session non interactively
View launch-ipython-notebook-in-screen.sh
#!/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"
@soxofaan
soxofaan / timinglogger.py
Last active Aug 29, 2015
TimingLogger context manager
View timinglogger.py
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 / index.html
Last active May 14, 2019
d3-plugins sankey cycle support
View index.html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://d3js.org/d3.v2.js"></script>
<script type="text/javascript" src="./sankey.js"></script>
<title>Sankey Diagram</title>
<style>