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 plumbing.letters | |
(:use plumbing.core)) | |
(def letters | |
(array-map "A" 0.03559596939643605 "B" 0.08791477424094518 "C" 0.07694824074741784 "D" 0.04579860597727158 "E" 0.018669123556424614 "F" 0.034505834128967044 "G" 0.05439868577642196 "H" 0.07268753217954918 "I" 0.003955862892091837 "J" 0.03025983302791189 "K" 0.03294327720020791 "L" 0.04848650695769241 "M" 0.09608053808826617 "N" 0.018547007013788936 "O" 0.014720280137130485 "P" 0.049319930077139015 "Q" 0.002206565702878153 "R" 0.05763521983707609 "S" 0.09580978699464698 "T" 0.035309842314786705 "U" 0.002210911090800405 "V" 0.015875707643636012 "W" 0.05861438058222256 "X" 2.4144758019273616E-4 "Y" 0.006166216881876424 "Z" 0.005097919974221793)) | |
(defn best [n-parts] | |
(let [letters (vec letters) | |
target (/ (sum second letters) n-parts)] | |
((memoized-fn |
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 plumbing.resource | |
(:refer-clojure :exclude [with-open]) | |
(:require | |
[schema.core :as s] | |
[plumbing.core :as plumbing] | |
[plumbing.fnk.pfnk :as pfnk] | |
[plumbing.fnk.schema :as schema] | |
[plumbing.graph :as graph] | |
[plumbing.logging :as log] | |
[plumbing.map :as map] |
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-client.schema-extensions | |
"Schemas representing abstract classes and subclasses" | |
(:use plumbing.core) | |
(:require | |
[clojure.string :as str] | |
[plumbing.map :as map] | |
[schema.core :as s] | |
[schema.utils :as utils] | |
[schema.macros :as sm])) |
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
(defmacro ->> | |
([x form] `(~@(if (seq form) form [form]) ~x)) | |
([x form & more] `(->> (->> ~x ~form) ~@more))) |
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
;; support code | |
(defn heap-mb | |
"Report approx heap size in megabytes." | |
[] | |
(System/gc) (System/gc) | |
(quot (- (.totalMemory (Runtime/getRuntime)) | |
(.freeMemory (Runtime/getRuntime))) | |
1000000)) | |
(defn mb-seq |
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 coercer [schema coercion-matcher] | |
(s/start-walker | |
(fn [s] | |
(comp (s/walker s) | |
(or (coercion-matcher s) identity))) | |
schema)) |
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 both [schema] | |
(reify Schema | |
(walker [this] | |
(let [sub-walkers (mapv subschema-walker schemas)] | |
(fn [x] | |
(reduce | |
(fn [x sub-walker] | |
(if (utils/error? x) | |
x | |
(sub-walker x))) |
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 both [schemas] | |
(reify Schema | |
(check [this x] | |
(first (keep #(check % x) schemas))))) |
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 comment-coersion-matcher [api-version user-lookup] | |
(fn [schema] | |
(when (= schema ClientComment) | |
(partial clientize-comment api-version user-lookup)))) |
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 '[schema.coerce :as coerce]) | |
(def parse-comment-request | |
(coerce/coercer CommentRequest coerce/json-coercion-matcher)) | |
(= +good-request+ (parse-comment-request +bad-request+)) | |
;; ==> true |
NewerOlder