Skip to content

Instantly share code, notes, and snippets.

@programmarchy
programmarchy / SirenProtocol.swift
Created July 16, 2016 18:15
The Siren specification in Swift protocols
// Siren: a hypermedia specification for representing entities
// https://github.com/kevinswiber/siren
protocol SirenRoot: SirenEntity {}
protocol SirenEntity {
var classNames: [String]? { get }
var properties: [String: AnyObject]? { get }
var entities: [SirenSubEntityType]? { get }
var links: [SirenLink]? { get }
@programmarchy
programmarchy / ember_auth.html
Created July 15, 2016 00:39
Extracts ember auth info from localStorage
<pre id="credentials"></pre>
<button onClick="javascript:sendRequest()">Send Request</button>
<script>
function getEmberSessionCredentials() {
var data = localStorage['ember_simple_auth:session']
if (!data) { return null }
var session = JSON.parse(data)
if (!session) { return null }
@programmarchy
programmarchy / cube-leap.js
Created December 6, 2013 23:15
Controlling Cubelets with the Leap Motion
if (process.argv.length < 3) {
console.log('Usage: node run.js PORT [ID1] [ID2]');
return;
}
var device = process.argv[2];
var SerialPort = require('serialport').SerialPort;
var bluetoothCubelet = new SerialPort(device, { baudrate: 38400 });
var cubelets = require('cubelets');
@programmarchy
programmarchy / mocha-serial.js
Last active December 29, 2015 03:48
mocha in your serial
var assert = require('assert');
var SerialPort = require('serialport').SerialPort;
var device = require('./config.json')['device'];
describe('opening and closing a serial port', function() {
var serialport;
this.timeout(10000);
before(function() {
@programmarchy
programmarchy / cpp1ts.sh
Last active December 21, 2015 13:49
C++: The One True Style
astyle --style=1tbs --indent=spaces=4 --indent-classes --indent-switches --break-blocks --pad-oper --pad-header --delete-empty-lines --fill-empty-lines --align-pointer=name --align-reference=name --break-closing-brackets --add-brackets --add-one-line-brackets --close-templates --convert-tabs --max-code-length=120 --break-after-logical --unpad-paren *.hpp *.cpp
@programmarchy
programmarchy / choose.js
Last active August 29, 2015 14:25
choices choices choices
function choices(n) {
var map = {}
var rand = function (n) {
return Math.floor(n * Math.random())
}
var stride = (n / 2)
var i = rand(n)
var max = 0
@programmarchy
programmarchy / high_water_mark.c
Last active August 29, 2015 14:22
flow control test
#include <asf.h>
#include <avr/io.h>
#include <avr/wdt.h>
#include <stdint.h>
#define PIN_SET_OUTPUT(ddr, id) ddr |= _BV(id)
#define PIN_SET_INPUT(ddr, id) ddr &= ~_BV(id)
#define PIN_SET_HIGH(port, id) port |= _BV(id)
#define PIN_SET_LOW(port, id) port &= ~_BV(id)
#define PIN_IS_HIGH(pins, id) bit_is_set(pins, id)
@programmarchy
programmarchy / repeat.c
Last active August 29, 2015 14:21
flow control test
#include <asf.h>
#include <avr/io.h>
#include <avr/wdt.h>
#include <stdint.h>
#define PIN_SET_OUTPUT(ddr, id) ddr |= _BV(id)
#define PIN_SET_INPUT(ddr, id) ddr &= ~_BV(id)
#define PIN_SET_HIGH(port, id) port |= _BV(id)
#define PIN_SET_LOW(port, id) port &= ~_BV(id)
#define PIN_IS_HIGH(pins, id) bit_is_set(pins, id)
env = Environment()
env.Append(CPPPATH = ['.', 'lib/websocketpp', 'lib/cpp-json/include'])
env.Append(LIBS = ['boost_system'])
env.Append(CXXFLAGS = ['-std=c++11', '-stdlib=libc++', '-D_WEBSOCKETPP_CPP11_STL'])
env.Append(FRAMEWORKS = ['Foundation', 'IOBluetooth'])
program = env.Program(target = 'server', source = ["main.cpp", "bluetooth_serial.mm"])

Keybase proof

I hereby claim:

  • I am programmarchy on github.
  • I am programmarchy (https://keybase.io/programmarchy) on keybase.
  • I have a public key whose fingerprint is B996 22F1 D7FC C095 E86F 9E09 9238 2733 3ABD 81AD

To claim this, I am signing this object: