Skip to content

Instantly share code, notes, and snippets.

@tlrobinson
tlrobinson / boilerplate.es6
Created March 4, 2015 20:03
node-webworker-threads + workerstream + browserify + babel
import ParentStream from "workerstream/parent";
global.stream = ParentStream();
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()) {
@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');
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 / 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))"
@tlrobinson
tlrobinson / docker-pull.sh
Last active October 18, 2023 21:59
Quick and dirty "docker pull"-like shell script.
#!/usr/bin/env bash
set -eu
name="library/redis"
tag="latest"
registry="https://registry-1.docker.io"
blobs="blobs"
data="images/$name/$tag"
@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 / firebase-utils.coffee
Last active January 14, 2023 23:11
Higher-level classes for synchronizing a nested Firebase ref, FirebaseEventEmitter and FirebaseImmutable. Work in progress.
Firebase = require "firebase"
Immutable = require "immutable"
{ EventEmitter } = require "events"
# Recursively listens to Firebase ref for modifications and emits "add",
# "change", and "remove" events with a path and value (except for "remove")
class FirebaseEventEmitter extends EventEmitter
constructor: (url) ->
EventEmitter.call(@)
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 / 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