Skip to content

Instantly share code, notes, and snippets.

View apparentlymart's full-sized avatar
⌨️
I may be slow to respond.

Martin Atkins apparentlymart

⌨️
I may be slow to respond.
View GitHub Profile
@apparentlymart
apparentlymart / Makefile
Last active August 29, 2015 14:03
mbed LPC1768 LLVM GPIO Example
all: blink.bin
blink.bc: blink.ll
opt-3.4 blink.ll -o blink.bc -basiccg -domtree -reg2mem -inline -constprop -die -adce -mem2reg
blink.s: blink.bc
llc-3.4 -march=thumb blink.bc -o blink.s
%.o: %.s
arm-none-eabi-as $< -o $@
@apparentlymart
apparentlymart / Makefile
Created July 20, 2014 16:36
mbed LPC1768 pyLLVM GPIO
all: blink.bin
blink.ll: genblink.py
python genblink.py >blink.ll
blink.bc: blink.ll
opt-3.4 blink.ll -o blink.bc
blink.s: blink.bc
llc-3.4 -march=thumb blink.bc -o blink.s
@apparentlymart
apparentlymart / aggregate.go
Last active August 29, 2015 14:05
Channel item aggregation in Go
// Example of aggregating channel values into sets based on a key.
// In this case, we aggregate strings by their first letter.
// Aggregated groups are emitted as slices when one of the following is true:
// - the buffer capacity is reached (set to 2 in this demo so we can hit it easily with the test data)
// - no new items have shown up for that group for two seconds
// - the source channel is closed
//
// The primary use case for this sort of thing is in forming higher-level transactions from an event stream,
// such as aggregating a log of actions by userid into a set of events that represents a session.
@apparentlymart
apparentlymart / pack.py
Last active August 29, 2015 14:05
Compact radix tree as a set of strings in C
# This generates tree.h by packing a set of strings into a Radix Tree structure.
words = [
"martin",
"martina",
"mark",
"matthew",
"adriana",
"adrian",
@apparentlymart
apparentlymart / Makefile
Created September 7, 2014 06:30
Python C API from LLVM IR
libfoo.so: foo.o
gcc foo.o -shared -o libfoo.so
foo.o: foo.ll
llc-3.3 -filetype=obj -relocation-model=pic foo.ll
@apparentlymart
apparentlymart / streamjson.c
Created September 15, 2014 02:05
Streaming JSON into a struct
// This is incomplete. Only supports strings and ints, and doesn't correctly handle the end of an object.
#include <stdio.h>
#include <stddef.h>
struct Person {
char name[50];
int age;
bool has_account;
bool has_vip_account;
@apparentlymart
apparentlymart / results.rst
Last active August 29, 2015 14:07
JavaScript (V8) benchmarking strategies for cloning a known object

Fastest Way to Clone a Known Object in JavaScript (V8)

This is a benchmark of various different strategies for creating clones of an object whose structure is known ahead of time.

In this test we assume that we always want to produce a clone of the same object and that the object contains no circular references, outside pointers, or non-JSON-serializable objects.

The use-case for such cloning is to have a "template" data structure that then gets copied and mutated for each request, leaving the template untouched. This is useful if only a small part of the data structure gets altered on each request and most of it remains set to what is in the template.

In all cases the functions were written to do as much as possible ahead of time so that the copy function could execute as quickly as possible. (Some variants on pre-processing were tried and eliminated before arriving at this final test set. The rejected variants are not reflected in the results or the

@apparentlymart
apparentlymart / README.rst
Created November 2, 2014 05:35
Prototype Alamatic Driver for BMP183

Prototype Alamatic Driver for BMP183

This is just an exploration of what a real-world (if incomplete) BMP183 driver might look like with the current iteration of Alamatic's featureset.

It makes extensive use of the worker concept, which effectively creates a protothread that processes a queue of requests one at a time. A worker can await a promise, just like a Task can, but unlike a normal function.

This example seems to demonstrate that even this relatively simple example leads to a proliferation of workers, suggesting that if this concept is to work the protothreads must be very lightweight or else the program's memory and CPU usage could easily become dwarfed by protothread bookkeeping.

@apparentlymart
apparentlymart / README.rst
Last active August 29, 2015 14:21
ncsvc on 64-bit Ubuntu

Turn libncui.so into a standalone executable:

sudo apt-get install gcc-multilib lib32z1
cd ~/.juniper_networks/network_connect
gcc -m32 -Wl,-rpath,`pwd` -o ncui libncui.so

Log in to the VPN UI and get the DSID cookie value.

Run ncui to connect:

@apparentlymart
apparentlymart / graph.gif
Last active August 29, 2015 14:23
Terraform providers instantiated too early
graph.gif