Skip to content

Instantly share code, notes, and snippets.

@wagjo
wagjo / gist:6743885
Created September 28, 2013 16:41
reducible slurp
(require '[clojure.java.io :as jio])
(deftype Slurp [filename]
clojure.core.protocols/CollReduce
(coll-reduce [this f1]
(clojure.core.protocols/coll-reduce this f1 (f1)))
(coll-reduce [_ f1 init]
(with-open [#^java.io.Reader r
(apply jio/reader filename nil)]
(loop [ret init
@wagjo
wagjo / 01-original.c
Last active December 23, 2015 10:09 — forked from Janiczek/01-original.c
// original
int CheckExtension (char *filename, char *ext)
{
char *s;
if (!filename) return(0);
if (strlen(filename) == 0) return(0);
s = strrchr(filename,'.');
if (!s) return(0);
if (!strcmp(s,ext)) return(1);
@wagjo
wagjo / gist:6442931
Created September 4, 2013 21:10
benchmarking string splitting
;; machine: amd64 Linux 2.6.32-48-server 16 cpu(s)
;; Java HotSpot(TM) 64-Bit Server VM 23.25-b01
;;
;; == without lazy seq realization
;; regex split: 258.567183 ms
;; parallelized regex split: 65.053176 ms - lazy seqs are not realized!
;; correct reduce: 623.541446 ms
;; correct fold: 252.817020 ms
;;
;; == lazy seq realization with (into [] %)
@wagjo
wagjo / lazy seq from reducers
Last active December 21, 2015 16:39
lazy seq and interleave from reducers with core.async
(defn lazy-seq* [reducible]
(let [c (chan)
NIL (Object.)
encode-nil #(if (nil? %) NIL %)
decode-nil #(if (identical? NIL %) nil %)
reduce-fn (fn [r v] (>!! c (encode-nil v)))]
(thread
(reduce reduce-fn nil reducible)
(close! c))
(->> #(<!! c)