This file contains hidden or 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 hidden or 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 hidden or 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]) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
# proposal 1: re-use `class`-statement and just hook into return value in build_class | |
let result: | |
x, y = 10, 20 | |
return x * y | |
assert result == 30 | |
# proposal 2: not sure the exact steps, but shouldn't be much more difficult than above | |
result = foo.x * foo.y where foo: | |
x, y = 10, 20 |
This file contains hidden or 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 cffi import FFI | |
from textwrap import dedent | |
from os import getpid | |
from sys import version_info | |
if __name__ == '__main__': | |
from sys import argv | |
print('Host is: %s (%s)' % (version_info, getpid())) |
This file contains hidden or 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 hidden or 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
#define _GNU_SOURCE | |
#include <stdio.h> | |
#include <dlfcn.h> | |
# define LM_ID_BASE 0 /* Initial namespace. */ | |
# define LM_ID_NEWLM -1 /* For dlmopen: request new namespace. */ | |
void __attribute__ ((constructor)) init(void); |
This file contains hidden or 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/python | |
from cffi import FFI | |
from textwrap import dedent | |
from sys import exit | |
if __name__ == '__main__': | |
ffi = FFI() | |
ffi.cdef(''' | |
void *dlmopen (long int __nsid, const char*, int); | |
void *dlopen (const char*, int); |
This file contains hidden or 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 textwrap import dedent | |
if __name__ == '__main__': | |
from sys import stdin | |
exec dedent(''.join(stdin)) in locals(), globals() |