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
/* | |
* uCAN.h | |
* | |
* Created on: Dec 1, 2013 | |
* Author: nick | |
*/ | |
#ifndef UCAN_H_ | |
#define UCAN_H_ |
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
import bitstring | |
class StructValueError(Exception): pass | |
class Member(object): | |
creation_counter = 0 | |
abstract = False |
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
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') |
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 | |
# -*- coding: utf-8 -*- | |
import codecs | |
import csv | |
import itertools | |
import sys | |
country_codes = { | |
"AF": "AFGHANISTAN", |
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
typedef void (*command_handler)(char*); | |
struct command_t { | |
char *command; | |
command_handler handler; | |
} commands[] = { | |
{"command1", func1}, | |
{"command2", func2}, | |
{NULL, NULL} | |
}; |
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 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) |
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 | |
# -*- 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 |
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
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: |
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
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))) |
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
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))) |