Skip to content

Instantly share code, notes, and snippets.

@tlrobinson
tlrobinson / loopInto.coffee
Last active August 29, 2015 13:55
"loopInto" for Substack's "binary" parsing toolkit
block = ->
@word32lu("version").tap (vars) ->
throw new Error("version="+vars.version) if vars.version isnt 1
@buffer "previous", 32
@buffer "merkle", 32
@word32lu "timestamp"
@word32lu "difficulty"
@word32lu "nonce"
varInt @, "txCount"
@tlrobinson
tlrobinson / curtain
Last active August 29, 2015 13:55
Arduino Yún version of @jwz's Arduino curtain project (http://www.jwz.org/curtain/)
#!/bin/sh
HOST="arduino.local"
USER="root"
PASSWORD="arduino"
COMMAND="$1"
curl -u "$USER:$PASSWORD" "http://$HOST/arduino/$COMMAND"

Keybase proof

I hereby claim:

  • I am tlrobinson on github.
  • I am tlrobinson (https://keybase.io/tlrobinson) on keybase.
  • I have a public key whose fingerprint is C2D4 28B0 AE9F FF85 6DC6 0C40 160E 586D 7CC3 44C6

To claim this, I am signing this object:

@tlrobinson
tlrobinson / docker-logs-all
Last active August 29, 2015 14:02
CLI: tail all Docker processes' logs with pretty colored labels and timestamps, using Foreman
#!/usr/bin/env bash
docker inspect --format='{{.Name}}' $(docker ps -q | xargs) | \
sed 's/[^a-zA-Z0-9-]//' | \
awk '{ printf "%s: docker logs -f %s\n", $1, $1 }' | \
foreman start -f /dev/stdin
var Future = require('fibers/future');
function Lock() {
this.futures = [];
}
Lock.prototype.enter = function() {
this.futures.push(new Future);
if (this.futures.length > 1) {
this.futures[this.futures.length - 2].wait();
}
@tlrobinson
tlrobinson / net.tlrobinson.mute.plist
Created December 26, 2014 05:41
Mac OS X mute at night, unmute in the morning
launchctl load ~/Library/LaunchAgents/net.tlrobinson.mute.plist
launchctl load ~/Library/LaunchAgents/net.tlrobinson.unmute.plist
@tlrobinson
tlrobinson / full-disk-check
Created January 23, 2015 10:18
OS X tool (easily portable to other *nixes) that writes random data to a disk (e.x. SD card) and reads it back, comparing hashes of the data. Use with caution.
#!/usr/bin/env bash
set -eu
disk_file="$1"
bytes="$(diskutil info "$disk_file" | grep -Eo '\(\d+ Bytes\)' | grep -Eo '\d+')"
block_size="$((1024 * 1024))"
blocks="$((bytes / block_size))"
var fbp = require("../..")
, InputPort = require('../../core/InputPort')
, InputPortArray = require('../../core/InputPortArray')
, OutputPort = require('../../core/OutputPort')
, OutputPortArray = require('../../core/OutputPortArray')
, IP = require('../../core/IP');
function sort() {
var inPort = InputPort.openInputPort('IN');
var outPort = OutputPort.openOutputPort('OUT');
@tlrobinson
tlrobinson / collate.js
Last active August 29, 2015 14:15
Proof-of-concept "classical" FBP using JavaScript streams/promises, and optionally generators via Bluebird's "coroutine" method.
// Runs in iojs or node.js versions >= 0.11.2
//
// npm install bluebird
// node collate.js
//
var Promise = require('bluebird');
var stream = require('stream');
var util = require('util');
import Promise from "q"
function* getAsyncIterator() {
for (let i = 0; i < 10; i++) {
yield Promise.resolve(i).delay(250);
}
}
Promise.async(function*() {
for (let p of getAsyncIterator()) {