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 itertools import combinations, chain | |
import numpy as np | |
from pyhull.convex_hull import ConvexHull | |
from stl import Mode | |
from stl.mesh import Mesh | |
def subdivide(shape): | |
''' Take a triangulated sphere and subdivide each face. ''' |
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 | |
# Useful when combined with: http://pythoncentral.io/validate-python-function-parameters-and-return-types-with-decorators/ | |
class Maybe(type): | |
''' Metaclass to match types with optionally none. Use maybe() instead ''' | |
maybe_type = type(None) # Overridden in derived classes | |
def __instancecheck__(self, instance): | |
return isinstance(instance, self.maybe_type) or instance is None |
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 numpy as np | |
from scipy.linalg import expm | |
def rot_euler(v, xyz): | |
''' Rotate vector v (or array of vectors) by the euler angles xyz ''' | |
# https://stackoverflow.com/questions/6802577/python-rotation-of-3d-vector | |
for theta, axis in zip(xyz, np.eye(3)): | |
v = np.dot(np.array(v), expm(np.cross(np.eye(3), axis*-theta))) | |
return v |
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 pyximport | |
import numpy as np | |
pyximport.install() | |
cmap = pyximport.load_module('cmap', 'cmap.pyx') | |
cadd = pyximport.load_module('cadd', 'cadd.pyx') | |
a = np.arange(6, dtype='i') | |
print('start', a) | |
cmap.pymap(a, cadd.pyadd_one) | |
print('add_one', a) |
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
// logger.c - hook into python's logging module | |
#include <Python.h> | |
#include <stdarg.h> | |
#include "logger.h" | |
static PyObject *logger; | |
// logger = logging.getLogger('libvncdriver') | |
int logger_init(void) { |
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
# Useful stuff | |
from operator import mul | |
def prod(x): | |
""" Product reducer """ | |
return reduce(mul, x, 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 | |
import gym | |
import sys | |
env = gym.make(sys.argv[1]) | |
num_episodes = 200 | |
max_timestep = 1000 | |
env.monitor.start(sys.argv[1]) | |
for _ in xrange(num_episodes): |
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 | |
import gym | |
import gym.envs | |
import numpy as np | |
gym.envs.register(id='NChainCustom-v0', | |
entry_point='gym.envs.toy_text:NChainEnv', | |
kwargs={'large':100}, | |
timestep_limit=200) |
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
<?xml version='1.0' encoding='ASCII'?> | |
<flow_graph> | |
<timestamp>Tue Aug 12 14:13:51 2014</timestamp> | |
<block> | |
<key>options</key> | |
<param> | |
<key>id</key> | |
<value>fm_receiver</value> | |
</param> | |
<param> |
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
void printx(char *s, uint8_t *x, int n) { | |
char buf[PS]; | |
for (int i = 0; i < PS; i++){ | |
if(*s == '%'){ | |
for(int j = n-1; j >= 0; j--){ | |
buf[i++%128] = ((*(x+j)>>4)&0xf)[ | |
"0123456789ABCDEF" | |
]; | |
buf[i++%128] = (*(x+j)&0xf)[ |