Skip to content

Instantly share code, notes, and snippets.

View ghadishayban's full-sized avatar

Ghadi Shayban ghadishayban

View GitHub Profile
@ghadishayban
ghadishayban / foldtest.clj
Created April 1, 2014 20:18
pathological fold performance
(ns foldtest
(:require [clojure.core.reducers :as r]))
;; redefined to parameterize the threshold to r/fold
(defn foldcat [n coll]
(r/fold n r/cat r/append! coll))
(defn benchmark [n]
(let [x (into [] (range 1e8))]
(println "init vec")
@ghadishayban
ghadishayban / lb.clj
Last active August 29, 2015 13:58
LB 4/3 qry
-- these are for daily
-- generated by accompanying code
select * from delivery_stats where delivery_id in
(66124923, 66124925, 66124927, 66124929, 66124931, 66124933, 66124935, 66124937, 66124939, 66124941, 66124943, 66124945, 66124947, 66124949, 66124951, 66124953, 66124955, 66124957, 66124959, 66129249, 66129251, 66129253, 66129255, 66129257, 66129259, 66129261, 66129263, 66129265, 66129267, 66129269, 66129271, 66129273, 66129275, 66129277, 66129279, 66129281, 66129283, 66129285, 66129287, 66129289, 66129291, 66129293, 66129299, 66129301, 66129303, 66129305, 66129307, 66129311, 66124879, 66124883, 66124885, 66124887, 66124889, 66124891, 66124893, 66124895, 66124897, 66124899, 66124901, 66124903, 66124905, 66124907, 66124915, 66124919, 66124921, 66128365, 66128383, 66128255, 66128257, 66128259, 66128261, 66128263, 66128265, 66128269, 66128271, 66128273, 66128275, 66128281, 66128283, 66128285, 66128287, 66128289, 66128291, 66128293, 66128295, 66128297, 66128301, 66128305, 66128307, 66128309, 66128313, 661
docker@boot2docker:~$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere 172.17.0.3 tcp dpt:smtp
ACCEPT tcp -- anywhere 172.17.0.2 tcp dpt:smtp
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
ACCEPT all -- anywhere anywhere
@ghadishayban
ghadishayban / flow_control.clj
Last active August 29, 2015 14:04
"turnstile" for flow-control
(ns flow-control
(:require [clojure.core.async :as async :refer :all
:exclude (map merge partition-by partition unique take into reduce split)]))
;; flow control through a "turnstile"
;; kind of like an extensible circuit breaker
;; Overview --
;; Your program's processes are like people entering a subway,
;; but the central authority only allows certain tickets in.
@ghadishayban
ghadishayban / resultset.clj
Created September 8, 2014 18:10
result sets
(defn result-set
[^ResultSet rs & {:keys [identifiers]
:or {identifiers str/lower-case}}]
(reify clojure.lang.IReduce
(reduce [this f]
(reduce [this f (f)]))
(reduce [this f init]
(let [rsmeta (.getMetaData rs)
idxs (range 1 (inc (.getColumnCount rsmeta)))
@ghadishayban
ghadishayban / doseq.clj
Last active August 29, 2015 14:06
doseq expansion
(let*
[c__6072__auto__
(clojure.core.async/chan 1)
captured-bindings__6073__auto__
(clojure.lang.Var/getThreadBindingFrame)]
(clojure.core.async.impl.dispatch/run
(clojure.core/fn
[]
(clojure.core/let
[f__6074__auto__
@ghadishayban
ghadishayban / XFIterator.java
Created November 6, 2014 03:38
Transducers <3 Iterators
import clojure.lang.RT;
import clojure.lang.IFn;
import clojure.lang.AFn;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.NoSuchElementException;
public class XFIterator implements Iterator {
@ghadishayban
ghadishayban / llp.server.cljs
Created December 17, 2011 22:06
HL7 LLP wire protocol receiver, ClojureScript on node.js. No ACKs yet
(ns llp.server
(:require [cljs.nodejs :as node]
[clojure.string :as str]))
(def net (node/require "net"))
(def events (node/require "events"))
(defn bufs->string [bufs]
(loop [acc ""
rst bufs]
@ghadishayban
ghadishayban / json.clj
Created October 1, 2015 19:30
Pex JSON grammar
(def JSON '{json [whitespace value EOI]
value (/ string number object array jtrue jfalse jnull)
object [(:ws "{")
(:join [string (:ws ":") value] ",")
(:ws "}")
(action capture-object)]
@ghadishayban
ghadishayban / gist:2636413
Created May 8, 2012 15:37
Lazily distinct list
(defn lazily-distinct [coll]
"Returns a lazy distinct list of possibly infinite collection.
Does not realize the whole collection."
(letfn [(lazystep [seen l]
(lazy-seq
(when (seq l)
(loop [next-item (first l) lazy-list (rest l)]
(if (get seen next-item)
(recur (first lazy-list) (rest lazy-list))
(cons next-item (lazystep (conj seen next-item)