Skip to content

Instantly share code, notes, and snippets.

Avatar

Stefaan Lippens soxofaan

View GitHub Profile
View AsynchronousFileReader-py3.py
import sys
import subprocess
import random
import time
import threading
from queue import Queue
import collections
class AsynchronousFileReader(threading.Thread):
'''
@soxofaan
soxofaan / pandas-timeindex-secondary-y-issue.ipynb
Last active Dec 13, 2017
pandas-timeindex-secondary-y-issue.ipynb
View pandas-timeindex-secondary-y-issue.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@soxofaan
soxofaan / zequals.py
Last active Nov 28, 2017
"Zequals" ruthless rounding: just keep one leading digit.
View zequals.py
import math
def zequals(x):
"""
"Zequals" ruthless rounding: just keep one leading digit.
examples:
123 -> 100
4567 -> 5000
-0.0345 -> -0.03
@soxofaan
soxofaan / .block
Last active Aug 15, 2017
Four-dimensional hypersphere packing
View .block
license: mit
border: no
@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 / screen-ssh-agent-fix.sh
Created Jan 16, 2017
Script to fix SSH agent environment variables on a remote server after reconnecting to a screen session
View screen-ssh-agent-fix.sh
#!/bin/bash
# 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 ~/screen-ssh-agent-fix.sh, create this alias to have it available easily:
# alias screenfix='source ~/screen-ssh-agent-fix.sh'
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)
@soxofaan
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(m.group(1)), m.group(2)) for m in re.finditer('([0-9.]*):(.*?);', raw)]
# Take latest.
$SSH_AUTH_SOCK = max(candidates)[1]
@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;
}
@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 / 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);
You can’t perform that action at this time.