This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns weighted-rand | |
(:import clojure.lang.PersistentQueue)) | |
(defprotocol Rand | |
(nextr [_ rng])) | |
;; Vose's alias method | |
;; http://www.keithschwarz.com/darts-dice-coins/ | |
(deftype Vose [n ^ints alias ^doubles prob] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Reimplementation of Java's (.split Pattern) to be zero-allocation, similar | |
;; to JDK 8 splitAsStream | |
;; Discards trailing "" | |
;; respects `clojure.core.reduced` | |
(defn split-string | |
[^CharSequence s ^java.util.regex.Pattern re] | |
(reify clojure.core.protocols/CollReduce | |
(coll-reduce [_ f init] | |
(let [m (re-matcher re s) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.string :as str]) | |
(defn rename-underscore [sym] | |
[(symbol (str/replace (name sym) \_ \-)) | |
(keyword sym)]) | |
(defn udestructure [[lhs expr]] | |
(if (and (map? lhs) | |
(vector? (:_keys lhs))) | |
(let [msym (gensym) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns fancie-queues | |
(:import [java.util.concurrent BlockingQueue | |
LinkedBlockingQueue])) | |
;; see queue-chain at the bottom | |
;; (queue-chain (range 20) (map (partial * 5)) (map vector) (map pr-str)) | |
;; (queue-chain (range 20) (remove odd?) (map pr-str)) | |
;; for more fun: | |
;; (queue-chain (range 20) (remove odd?) (map (fn [i] (Thread/sleep 150) (pr-str i)))) | |
;; throwing an exception in the middle will not be fun, fyi also queues don't take nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns cljdojo.coin | |
(:require [clojure.test :refer :all])) | |
(def coins (sorted-set-by > 50 25 10 5 1)) | |
(defn min-coins [total] | |
(letfn [(step [[remaining tallies] coin] | |
(let [decrements (->> (iterate #(- % coin) remaining) | |
(take-while #(>= % coin)) | |
count) |