Skip to content

Instantly share code, notes, and snippets.

(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
@w01fe
w01fe / resource.clj
Last active August 29, 2015 14:23
resource.clj
(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]
(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]))
(defmacro ->>
([x form] `(~@(if (seq form) form [form]) ~x))
([x form & more] `(->> (->> ~x ~form) ~@more)))
@w01fe
w01fe / leak.clj
Created February 15, 2014 00:32
locals clearing bug?
;; 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
(defn coercer [schema coercion-matcher]
(s/start-walker
(fn [s]
(comp (s/walker s)
(or (coercion-matcher s) identity)))
schema))
(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)))
(defn both [schemas]
(reify Schema
(check [this x]
(first (keep #(check % x) schemas)))))
(defn comment-coersion-matcher [api-version user-lookup]
(fn [schema]
(when (= schema ClientComment)
(partial clientize-comment api-version user-lookup))))
(require '[schema.coerce :as coerce])
(def parse-comment-request
(coerce/coercer CommentRequest coerce/json-coercion-matcher))
(= +good-request+ (parse-comment-request +bad-request+))
;; ==> true