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
# do this first: | |
! sudo apt-get install cpulimit | |
from os import getpid | |
from resource import setrlimit, RLIMIT_RSS, RLIM_INFINITY, getrusage, RUSAGE_SELF | |
# limit CPU: use only 1% of 1 CPU | |
pid = getpid() | |
! cpulimit -b -p $pid -c 1 -l 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
#!/usr/bin/env python | |
from imp import new_module | |
class IPythonModule(type(new_module(''))): | |
from json import loads | |
from imp import new_module | |
loads = staticmethod(loads) | |
new_module = staticmethod(new_module) | |
def __init__(self, name, path): |
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 numpy.random import randint | |
from numpy import sqrt | |
# Newton's method: | |
# `x' is input, `y' is iteratively refined answer | |
# solve for square root of x: y**2 = x | |
# f (y) = y^2 - x | |
# f'(y) = 2y | |
# y[1] = y[0] - f(y[0]) / f'(y[0]) |
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
CC=gcc -std=c99 -Wall | |
dlmopen-test: dlmopen-test.c | |
${CC} -o $@ $^ -ldl |
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
CC=gcc -std=c99 -Wall | |
didyoumean.so: didyoumean.c didyoumean-safe.c | |
${CC} `python-config --cflags` `python-config --includes` -Wl,--export-dynamic -fPIC -shared -o $@ $^ -ldl `python-config --libs` |
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 sys import version_info | |
# assert version_info.major == 3 | |
candidates = ['dontusethiscode', 'roguelynn', ] # ... | |
from time import sleep | |
slp = lambda n, sleep=sleep: lambda: sleep(n) | |
from itertools import chain, repeat | |
sleeps = chain(repeat(slp(.01), 1000), |
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
#!/usr/bin/env python3 | |
class Swapped(type): | |
def __new__(cls, name, bases, body): | |
if not bases: | |
t = type.__new__(cls, name, bases, body) | |
t.__type = name, bases, body | |
return t | |
if len(bases) == 1: | |
st = type.__new__(cls, name, bases[1:], body) |
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
#!/usr/bin/env python3 | |
from ast import parse | |
from ast import AST, FunctionDef, Lambda, Call | |
from collections import Iterable | |
# some notes | |
# kwargh: | |
# when you're using matplotlib or pandas | |
# and you do help(func) to figure out what |
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 itertools import count, cycle | |
from collections import Iterable | |
from functools import wraps | |
class genmethod: | |
def __init__(self, g): | |
self.g = g | |
def __get__(self, instance, owner): | |
gi = self.g(instance) | |
@wraps(self.g) |
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
REPOS = jupyter/jupyter \ | |
jupyter/jupyter_core \ | |
jupyter/jupyter_client \ | |
jupyter/notebook \ | |
jupyter/nbformat \ | |
jupyter/nbconvert \ | |
ipython/ipython | |
BINARIES = python3 node | |
TARBALL_python3 = https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tar.xz | |
TARBALL_node = https://nodejs.org/dist/v4.2.1/node-v4.2.1.tar.xz |