Skip to content

Instantly share code, notes, and snippets.

View Arachnid's full-sized avatar

Nick Johnson Arachnid

View GitHub Profile
/*
* uCAN.h
*
* Created on: Dec 1, 2013
* Author: nick
*/
#ifndef UCAN_H_
#define UCAN_H_
import bitstring
class StructValueError(Exception): pass
class Member(object):
creation_counter = 0
abstract = False
@Arachnid
Arachnid / parse.py
Last active December 29, 2015 07:49
class MessageHeader(object):
def __init__(self, priority, protocol):
self.priority = priority
self.protocol = protocol
self.sender = None
def decode(bits):
priority = bits.read('uint:2')
broadcast = bits.read('bool')
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import codecs
import csv
import itertools
import sys
country_codes = {
"AF": "AFGHANISTAN",
typedef void (*command_handler)(char*);
struct command_t {
char *command;
command_handler handler;
} commands[] = {
{"command1", func1},
{"command2", func2},
{NULL, NULL}
};
from datetime import datetime, timedelta
import time
def check_sleep(func, amt):
start = datetime.now()
func(amt)
end = datetime.now()
delta = end-start
return abs(delta.seconds + delta.microseconds/1000000.0 - amt)
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""# piclang: A Python EDSL for making paths of interesting shapes. #
Nick Johnson and Kragen Javier Sitaker
<https://gist.github.com/2555227>
This is a simple calculus for easily composing interesting 2-D
parametric curves. There are three fundamental curves, called
`circle`, `line`, and constant; everything else is built up from these
import math
sintable = [int(math.sin(x*math.pi/512)*32768+32768) for x in range(256)]
def fp_sin(a):
"""Fixed point sine. Input range is [0-2^16), output range likewise."""
a = a & 0xffff
quadrant = a >> 14
index = (a >> 6) & 0xff
if quadrant == 1 or quadrant == 3:
def _make_skel_func(code, num_closures):
""" Creates a skeleton function object that contains just the provided
code and the correct number of cells in func_closure. All other
func attributes (e.g. func_globals) are empty.
"""
#build closure (cells):
cellnew = ctypes.pythonapi.PyCell_New
cellnew.restype = ctypes.py_object
cellnew.argtypes = (ctypes.py_object,)
dummy_closure = tuple(map(lambda i: cellnew(None), range(num_closures)))
import copy_reg
import cPickle
import marshal
import types
def restorefunction(func_name, dump):
return types.FunctionType(marshal.loads(dump), globals(), func_name)
def reducefunction(func):
return (restorefunction, (func.func_name, marshal.dumps(func.func_code)))