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
(s/defn parse-comment-request :- CommentRequest | |
[raw-request] | |
(update-in | |
(if (contains? raw-request :parent-comment-id) | |
(update-in raw-request [:parent-comment-id] long) | |
raw-request) | |
[:share-services] | |
(partial mapv keyword))) | |
(= +good-request+ (parse-comment-request +bad-request+)) |
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 schema-examples (:require [schema.core :as s])) | |
(def CommentRequest | |
{(s/optional-key :parent-comment-id) long | |
:text String | |
:share-services [(s/enum :twitter :facebook :google)]}) | |
(def +good-request+ | |
{:parent-comment-id 2128123123 | |
:text "This is awesome!" |
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 user | |
(:require | |
[criterium.core :as criterium] | |
[hiphip.double :as d])) | |
(do | |
(def ^:const sz 10000) | |
(defmacro print-time | |
"Better, but involves external lib." | |
[expr] |
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 async.core | |
(:require [clojure.core.async :as a])) | |
(def c (a/chan 10)) | |
(a/go | |
(loop [i 0] | |
(println "putting" i) | |
(a/>! c i) | |
(if (< i 100) |
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
;; Clear Leiningen's default jvm-opts. | |
:jvm-opts ^:replace [] |
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
;; Initialize xs to (range (alength xs)). | |
(afill! [[i x] xs] i) |
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 fill-string-pointwise-product | |
[^{:tag "[Ljava.lang.String;"} os ^doubles xs ^longs ys] | |
(array/afill! String [_ os x xs y ys] (str (* x y)))) |
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 top-k | |
"Return the top k elements of xs according to score-fn" | |
[k score-fn xs] | |
(let [n (count xs) | |
scores (dbl/amake [i n] (score-fn (nth xs i))) | |
^ints idxs (dbl/amax-indices scores k)] | |
(seq (hiphip.array/amake Object [i k] (nth xs (aget idxs (- n i 1))))))) |
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 standard-deviation [xs] | |
(let [mean (dbl/amean xs) | |
mean-sq (/ (dbl/asum [x xs] (* x x)) | |
(dbl/alength xs))] | |
(Math/sqrt (- mean-sq (* mean mean))))) | |
(= 1 (dbl/amax-index (double-array [1.0 3.0 2.0]))) | |
(defn max-normalize [xs] | |
(let [m (dbl/amax xs)] |
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 pointwise-product | |
"Produce a new double array with the product of corresponding elements of xs and ys" | |
[xs ys] | |
(dbl/amap [x xs y ys] (* x y))) |