Skip to content

Instantly share code, notes, and snippets.

View remram44's full-sized avatar

Remi Rampin remram44

View GitHub Profile
@remram44
remram44 / ipython_callbacks.py
Last active December 19, 2015 05:09
Subclass of IPython.parallel.Client providing a thread-safe callback mechanism
from IPython.parallel import Client
import threading
import time
import contextlib
class SafeClient(object):
"""Wrapper for IPython.parallel.Client adding callbacks for AsyncResults.
@remram44
remram44 / QtWrapper.py
Created July 12, 2013 16:17
PySide/PyQt4 abstraction module
"""Adapted from http://askubuntu.com/a/141641
This compatibility layer allows to use either PySide or PyQt4 as the Qt
binding. It will choose what's available, defaulting on PySide, unless the
QT_API environment variable is set.
"""
import os
import sys
@remram44
remram44 / disapproval.html
Last active December 19, 2015 17:38
Look of disapproval
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Look of disapproval</title>
</head>
<body>
<p style="position: absolute; top: 50%; left: 50%; margin-left: -180px; margin-top: -111px;"><canvas class="jsdisapproval" width="360" height="222"></canvas></p>
<script type="text/javascript" src="disapproval.js"></script>
@remram44
remram44 / timeprefix.py
Created July 22, 2013 15:28
Prefixes command output with time
import sys
import time
if __name__ == '__main__':
begin = time.time()
l = sys.stdin.readline()
while l:
sys.stdout.write("%f %s" % (time.time() - begin, l))
l = sys.stdin.readline()
@remram44
remram44 / color.py
Created August 20, 2013 17:33
HSV color generator
def rgb2hsv(rgb):
"""Converts RGB to HSV.
Note that H may be None when S is 0 (for grey colors).
"""
r, g, b = rgb
minimum = min(r, g, b)
maximum = max(r, g, b)
v = maximum
@remram44
remram44 / animated-logo.js
Last active December 21, 2015 15:59
Logo de Federez - www.federez.net
// shim layer with setTimeout fallback
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function( callback ){
window.setTimeout(callback, 1000 / 60);
};
#!/bin/sh
# rename.sh [-n] [-r] <regex> [file [...]]
notreally=
sedopts=
while getopts ":nr" opt ; do
case $opt in
n)
@remram44
remram44 / ipython-errors.py
Created August 30, 2013 23:39
Formatting IPython remote errors
def print_compositeerror(e):
sys.stderr.write("Got %d exceptions from IPython engines:\n" %
len(e.elist))
for e_type, e_msg, formatted_tb, infos in e.elist:
sys.stderr.write("Error from engine %d (%r):\n" % (
infos['engine_id'], infos['engine_uuid']))
sys.stderr.write("%s\n" % strip_ansi_codes(formatted_tb))
def print_remoteerror(e):
@remram44
remram44 / .gitmodules
Last active December 22, 2015 01:19
All my handy gists as submodules!
[submodule "c-matrix_to_quaternion"]
path = c-matrix_to_quaternion
url = https://gist.github.com/5260578.git
[submodule "c-stringify"]
path = c-stringify
url = https://gist.github.com/5109330.git
[submodule "general-color"]
path = general-color
url = https://gist.github.com/6284607.git
[submodule "general-file_is_binary"]
@remram44
remram44 / http_directory.py
Last active September 16, 2022 00:14
Recursively download a directory with Python
from HTMLParser import HTMLParser
import urllib2
import os
import re
re_url = re.compile(r'^(([a-zA-Z_-]+)://([^/]+))(/.*)?$')
def resolve_link(link, url):
m = re_url.match(link)