Skip to content

Instantly share code, notes, and snippets.

View jcorbin's full-sized avatar

Joshua T Corbin jcorbin

View GitHub Profile
var isFunction = require('lodash.isFunction');
function oneAtATime(func) {
var running = false;
var queue = [];
function done() {
for (var i=0, n=queue.length; i<n; i++)
queue[i].apply(this, arguments);
running = true;
Markov.prototype.merge = withReady(function merge(other, callback) {
var self = this;
if (!other.ready) {
return other.init(function(err) {
if (err) return callback(err);
self.merge(other, callback);
});
}
if (this.stateSize !== other.stateSize) {
return callback(new Error('cannot merge markovs with differing state size'));
// Inspired by http://blog.plover.com/prog/monad-search-2.html
// S E N D
// + M O R E
// -----------
// M O N E Y
function toNumber(digits) {
var r = 0;
for (var i = 0; i < digits.length; i++) {
@jcorbin
jcorbin / division_demo.py
Created January 30, 2012 23:51
Division Demo
#!/usr/bin/python
# Example usage:
# $ ./division_deom.py 1 7
# 0 1
# .
# 1 3
# 4 2
# 2 6
# 8 4
@jcorbin
jcorbin / d3_nest_tags.coffee
Created November 19, 2012 04:20
First pass at some convenience for turning d3.nest into tags with less boilerplate...
basicGroupTag = (tag) ->
[name, klass] = tag.split('.')
(sel, data) ->
sel = sel.selectAll(tag).data(data)
enter = sel.enter().append(name)
enter.attr('class', klass) if klass?
sel.exit().remove()
sel
ensureTag = (tag) ->
@jcorbin
jcorbin / graphite_to_pandas.py
Created January 15, 2014 19:32
Simple functions for converting raw graphite data to pandas time series / frame. Reasonably fast too; my test set was a 16MiB 350 metric dump, timing on my machine to parse is ~400ms.
import numpy as np
import pandas as pd
from cStringIO import StringIO
def parse_raw_graphite_metric(line):
head, body = line.rstrip('\n').split('|', 1)
name, since, until, freq = head.replace('\n', '').split(',')
since = float(since) * 1e9
until = float(until) * 1e9
freq = '%ss' % int(freq)
@jcorbin
jcorbin / scalar_zip.diff
Created March 14, 2016 18:29
Dask Scalar Zip
diff --git a/dask/bag/core.py b/dask/bag/core.py
index dc8a04d..47535c1 100644
--- a/dask/bag/core.py
+++ b/dask/bag/core.py
@@ -6,6 +6,7 @@ import math
import bz2
import os
import uuid
+from collections import Iterable
from fnmatch import fnmatchcase
$ go test -c ./internal/marshaled
$ { sleep 5; pkill -QUIT marshaled.test }& # because timeout -s QUIT 5s ... doesn't correctly trigger a goroutine dump
$ ./marshaled.test -debug -numWatchers 1 -test.v -test.bench .
=== RUN TestDataSource_Watch_activation
--- PASS: TestDataSource_Watch_activation (0.00s)
PASS
BenchmarkDataSource_Watch_json-8 watcher[0] wants 1
put 0
wait for items
got "{\"i\":0,\"word\":\"the\"}"
panic: net: inconsistent fdMutex
goroutine 1145194 [running]:
panic(0x126cc0, 0xc94cf02860)
/usr/local/Cellar/go/1.6/libexec/src/runtime/panic.go:464 +0x3e6
net.(*fdMutex).RWLock(0xc8200620e0, 0x0, 0xc94d37f61e)
/usr/local/Cellar/go/1.6/libexec/src/net/fd_mutex.go:136 +0x20c
net.(*netFD).writeLock(0xc8200620e0, 0x0, 0x0)
/usr/local/Cellar/go/1.6/libexec/src/net/fd_unix.go:194 +0x39
net.(*netFD).Write(0xc8200620e0, 0xc94cf02848, 0x7, 0x8, 0x0, 0x0, 0x0)
2017/11/06 08:59:13 Kaksi
['\x00' '\x00'] => "c"
['\x00' 'c'] => "r"
['c' 'r'] => "e"
['r' 'e'] => "i"
['e' 'i'] => "l"
['i' 'l'] => "u"
['l' 'u'] => "e"
['u' 'e'] => "s"
['e' 's'] => "a"