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 / 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
@apparentlymart
apparentlymart / ec2-example.pad
Last active August 29, 2015 14:23
Example configs for Terraform-based build tool (codename Padstone)
provider "aws" {
region = "us-west-2"
}
provider "aws" {
region = "us-west-1"
alias = "us-west-1"
}
temporary_resource "aws_instance" "source" {
// ..
@apparentlymart
apparentlymart / iptables-round-robin.sh
Last active August 30, 2023 21:45
round robin to three ports on the same host with iptables
# The following example shows a way to use iptables for basic round-robin load balancing, by redirecting
# packets two one of three ports based on a statistic counter.
#
# TCP packets for new sessions arriving on port 9000 will rotate between ports 9001, 9002 and 9003, where
# three identical copies of some application are expected to be listening.
#
# Packets that aren't TCP or that related to an already-established connection are left untouched, letting
# the standard iptables connection tracking machinery send it to the appropriate port.
#
# For this to work well, connections need to be relatively short. Ideally there would be an extra layer
@apparentlymart
apparentlymart / README.md
Last active August 29, 2015 14:26
AngularJS-Server with Browserify example

angularjs-server with browserify example

This is a basic example of using AngularJS-server with browserify. Since browserify requires bundling, unlike the plain example in the AngularJS-Server readme we need to provide a bundle to both the server-side Angular context and to the browser.

The two bundles can be created using browserify:

@apparentlymart
apparentlymart / Proposal.md
Created December 5, 2015 20:17
HTML Social Network

HTML Social Network

Back in July of 2008 I started thinking about HTML microformats for linking together and discovering social objects on the web.

I later discussed this with folks at the Internet Identity Workshop and after a few rounds of discussion we ended up working on Activity Streams instead, which shifted the focus to machine-readable descriptions of actions on social objects. However, the social object research here was the initial basis of what went on to become the "Object Types" in Activity Base Schema, after many iterations.

@apparentlymart
apparentlymart / write_vfat.go
Created December 20, 2015 06:24
Make VFAT filesystem from Go
package main
import (
"encoding/binary"
"fmt"
"io"
"os"
)
const bytesPerSector = 512