View domino.go
This file contains 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
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"strings" | |
) |
View insert.clj
This file contains 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 insert-after | |
[pred coll x] | |
(let [[before after] (split-with (complement pred) coll)] | |
(concat before (take 1 after) x (drop 1 after)))) | |
(defn insert-before | |
[pred coll x] | |
(let [[before after] (split-with (complement pred) coll)] | |
(concat before x after))) |
View split.clj
This file contains 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 split-after | |
[pred coll] | |
(let [post-accum (fn [accum x] | |
(update accum :after conj x)) | |
pre-accum (fn [accum x] | |
(cond-> (update accum :before conj x) | |
(pred x) (assoc :f post-accum)))] | |
((juxt :before :after) | |
(reduce (fn [{:keys [f] :as accum} x] (f accum x)) | |
{:before [] :after [] :f pre-accum} |
View sliding-window-counter.clj
This file contains 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 sliding-window-counter.core | |
(:refer-clojure :exclude [inc])) | |
(defprotocol ICounter | |
(reset [this]) | |
(inc [this]) | |
(value [this])) | |
(defrecord SlidingWindowCounter [window-size bucket-size num-buckets buckets] | |
ICounter |
View HornetQ Test
This file contains 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 hornetq-test.core | |
(:require [immutant.messaging :as msg] | |
[immutant.util]) | |
(:gen-class)) | |
(def running? (atom true)) | |
(def uniq (rand-int 1000000)) | |
(defn do-stuff [] |
View merge.clj
This file contains 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
(def xs (sort (repeatedly 30 #(rand-int 20)))) | |
(def ys (sort (repeatedly 25 #(rand-int 20)))) | |
(defn merge-sorted-seqs | |
[xs ys] | |
(lazy-seq (cond | |
(empty? xs) (seq ys) | |
(empty? ys) (seq xs) | |
:else (let [x (first xs) y (first ys)] |
View gist:6ba102fb09e59a1af3a4
This file contains 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 titanium-demo.core | |
(:require [clojure.java.io :as io] | |
[clojurewerkz.titanium.graph :as tg] | |
[clojurewerkz.titanium.schema :as scm] | |
[clojurewerkz.titanium.vertices :as tv])) | |
(defn generate-config | |
"Generate a configuration map to use BerkeleyDB and Lucene | |
with data stored in the given directory." | |
[dir] |
View gist:68f4feb328c4d68b7b1e
This file contains 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 playground.explode | |
(:require [clojure.math.combinatorics :refer [cartesian-product]] | |
[clojure.string :as str])) | |
(def ambiguous-chars [#{\O \0} #{\I \L \1}]) | |
(defn ambiguate | |
[c] | |
(or (first (filter #(contains? % c) ambiguous-chars)) | |
[c])) |
View rollup.clj
This file contains 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 rollup.core | |
(:require [clojure.core.async :refer [go chan <! put! timeout alt! alts!]])) | |
(def ch (chan)) | |
(go | |
(loop [stash []] | |
(let [[v c] (alts! [ch (timeout 3000)])] | |
(if (= c ch) |
View square_roots.clj
This file contains 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 square-roots | |
(:require [criterium.core :refer [bench]])) | |
(defn square [x] (* x x)) | |
(defn abs [x] (if (< 0 x) (- x) x)) | |
(defn sqrt-repeated-average | |
[x lo hi tolerance] | |
(if (<= (- hi lo) tolerance) |
NewerOlder