Skip to content

Instantly share code, notes, and snippets.

View ztellman's full-sized avatar
💭
boiling the ocean

Zach Tellman ztellman

💭
boiling the ocean
View GitHub Profile

Keybase proof

I hereby claim:

  • I am ztellman on github.
  • I am ztellman (https://keybase.io/ztellman) on keybase.
  • I have a public key whose fingerprint is 48C0 998F 1CA0 2F62 928D 6DC8 5E23 CF68 58E9 BE47

To claim this, I am signing this object:

(ns advent17.core
(:require
[clojure.java.io :as io]
[clojure.string :as str]))
(defn neighbors [[x y z w]]
(->
(for [x' (range (dec x) (+ 2 x))
y' (range (dec y) (+ 2 y))
z' (range (dec z) (+ 2 z))
var text = new PointText({
position: view.center + [0, 200],
fillColor: 'black',
justification: 'center',
fontSize: 20
});
var originals = new Group({ insert: false }); // Don't insert in DOM.
var square = new Path.Circle({
(defmacro if-in-str [haystack & clauses]
`(do
~@(map
(fn [clause]
(let [needle (first clause)
is-present-form (second clause)
is-not-present-form (nth clause 2 nil)]
`(if (> (.indexOf ~haystack ~needle) -1)
~is-present-form
~is-not-present-form)))
(defn kafka-sink []
(let [s (s/stream)]
(s/consume-async
(fn [msg]
(d/future (synchronous-put-to-kafka msg))))
s))

This relates to work I'm doing on a system for distributed outlier detection, as described here.

In this system, the count-min sketch is used as a distributed filter. Over some interval, the CMS is populated on all the edge nodes, sent to a server for merging, and the merged CMS is broadcast back out to the edges. On the following interval, each new key is run through the "global" CMS, and if it's over some threshold, it is added to the set of potential outliers, which are precisely counted.

This is, as described so far, an adaptation of this 2003 paper from single-node to multi-node. However, that paper assumes that the threshold is known ahead of time.

In most cases, though, what constitutes an "outlier" is a moving target. We'd like to adapt as the distribution changes. Previously, I was using a consistent uniform sample of the keys to identify the threshold, but we'd have to take a very

(require '[manifold.deferred :as d])
(defn wrap-async-handler [f]
(fn [req]
(let [rsp (d/deferred)]
(f req #(d/success! rsp %) #(d/error! rsp %))
rsp)))
public final class Netty {
private Netty() {
}
private static final Field QUEUE;
private static final Class BITS;
private static final Class VM;
@ztellman
ztellman / cljx.clj
Last active November 20, 2015 22:24
(defn- queue []
#+clj clojure.lang.PersistentQueue/EMPTY
#+cljs cljs.core/PersistentQueue.EMPTY)
(defn matching-inputs
"Returns a lazy sequence of input sequences which the automaton will match."
[fsm]
(let [fsm (-> fsm ->dfa final-minimize)
accept? (set (accept fsm))
q (atom (conj (queue) [(start fsm) []]))]
local function delta(t0, t1)
return ((t1[1] - t0[1]) * 1000000) + (t1[2] - t0[2])
end
local t0,t1
local s1 = redis.call("get", KEYS[1])
local s2 = ARGV[1]
if s1 == false then
redis.call("set", KEYS[1], s2)