This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# rename.sh [-n] [-r] <regex> [file [...]] | |
notreally= | |
sedopts= | |
while getopts ":nr" opt ; do | |
case $opt in | |
n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from IPython.parallel import Client | |
import threading | |
import time | |
import contextlib | |
class SafeClient(object): | |
"""Wrapper for IPython.parallel.Client adding callbacks for AsyncResults. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From http://stackoverflow.com/a/1914798/711380 | |
class _PickleableStaticMethod(object): | |
def __init__(self, fn, cls=None): | |
self.cls = cls | |
self.fn = fn | |
def __call__(self, *args, **kwargs): | |
return self.fn(*args, **kwargs) | |
def __get__(self, obj, cls): | |
return _PickleableStaticMethod(self.fn, cls) | |
def __getstate__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import contextlib | |
pad = '' | |
@contextlib.contextmanager | |
def call(): | |
global pad | |
pad += " " | |
yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* quaternion from matrix */ | |
/* from Id Software, From Quaternion to Matrix and Back, 2005 */ | |
float ReciprocalSqrt(float x) | |
{ | |
long i; | |
float y, r; | |
y = x * 0.5f; | |
i = *(long*)&x; | |
i = 0x5f3759df - (i >> 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def file_is_binary(filename): | |
with open(filename) as fp: | |
return chr(0) in iter(fp.read(8000)) |