Skip to content

Instantly share code, notes, and snippets.

@machinaut
machinaut / Makefile
Created July 2, 2012 10:06
gccgo Toolchain Makefile
GCC = gcc-4.7.1
GMP = gmp-5.0.5
MPFR = mpfr-3.1.0
MPC = mpc-0.9
PARALLEL="-j8"
PREFIX=$(PWD)
all: $(GCC)
@machinaut
machinaut / a.c
Created February 9, 2013 17:26
Syscall timing test (vs function calls)
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <termios.h>
#include <time.h>
#include <sys/ioctl.h>
int b(int a, struct winsize *w);
int main()
f = open("sowpods.txt", "r")
canonized_words = {}
word1 = ""
word2 = ""
max_len = 0
for line in f:
if len(line) > max_len:
sorted_word = ''.join(sorted(line))
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)[
@machinaut
machinaut / fm_example.grc
Created August 12, 2014 21:15
FM Receiver gnuradio example for the HackRF One SDR
<?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>
@machinaut
machinaut / nchain-custom.py
Created May 6, 2016 18:35
Run a custom-parameterized openai/gym environment. (using 'nchain' environment from Pull Request #61)
#!/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)
@machinaut
machinaut / rand.py
Created May 10, 2016 21:06
Random agent (run with environment name as argument) for OpenAI gym.
#!/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):
@machinaut
machinaut / util.py
Created August 16, 2016 20:13
Various utilities for solving project euler problems
# Useful stuff
from operator import mul
def prod(x):
""" Product reducer """
return reduce(mul, x, 1)
@machinaut
machinaut / logger.c
Created September 28, 2016 16:07
printf() style output through python's logger in python c extension
// 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) {
@machinaut
machinaut / atest.py
Created January 24, 2017 09:57
Passing cython function pointers through python
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)