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
{ | |
"swagger": "2.0", | |
"info": { | |
"title": "DR API", | |
"version": "1.0", | |
"description": "Dr Jan Itor at your service" | |
}, | |
"produces": [ |
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 someas-> | |
"A mixture of some-> and as-> allowing more flexibility in the step forms" | |
[expr name & forms] | |
(let [pstep (fn [step] `(if (nil? ~name) nil ~step))] | |
`(let [~name ~expr | |
~@(interleave (repeat name) (map pstep forms))] | |
~name))) |
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 distinctive | |
"Like clojure.core/distinct, but can take a function f by which distinctiveness is calculated, | |
giving similar semantics to sort-by" | |
([coll] (distinctive identity coll)) | |
([distinction-fn coll] | |
(let [step (fn step [xs seen] | |
(lazy-seq | |
((fn [[f :as xs] seen] | |
(when-let [s (seq xs)] | |
(if (contains? seen (distinction-fn f)) |
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 condas-> | |
"A mixture of cond-> and as-> allowing more flexibility in the test and step forms" | |
[expr name & clauses] | |
(assert (even? (count clauses))) | |
(let [pstep (fn [[test step]] `(if ~test ~step ~name))] | |
`(let [~name ~expr | |
~@(interleave (repeat name) (map pstep (partition 2 clauses)))] | |
~name))) |
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 bidi.bidi-test | |
(:require [clojure.test :refer :all] | |
[bidi.bidi :refer :all] | |
[ring.mock.request :refer :all])) | |
(deftest route-params-hygiene-test | |
(testing "other request constraints" | |
(let [handler | |
(make-handler [["/blog/user/" :userid "/article"] |
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
(def prices {:muffin 5 :milkshake 3 :chocolate 2 :gingerbread 1}) | |
(clojure.pprint/pprint (shop 10 prices)) | |
({:muffin 0, :chocolate 0, :milkshake 0, :gingerbread 10} | |
{:muffin 0, :chocolate 0, :milkshake 1, :gingerbread 7} | |
{:muffin 0, :chocolate 0, :milkshake 2, :gingerbread 4} | |
{:muffin 0, :chocolate 0, :milkshake 3, :gingerbread 1} | |
{:muffin 0, :chocolate 1, :milkshake 0, :gingerbread 8} | |
{:muffin 0, :chocolate 1, :milkshake 1, :gingerbread 5} | |
{:muffin 0, :chocolate 1, :milkshake 2, :gingerbread 2} |
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
;; binary-like count with n 'bits' which can have values between from and to | |
;; e.g. (permutations 3 0 3) -> ([0 0] [0 1] [0 2] [1 0] [1 1] [1 2] [2 0] [2 1] [2 2]) | |
(defn permutations [n from to] | |
(let [symbols (into [] (take n (repeatedly gensym))) | |
ranges (take n (repeatedly #(into [] (range from to)))) | |
bindings (into [] (interleave symbols ranges))] | |
(eval `(for ~bindings ~symbols)))) |
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
(deftest customisable-threading | |
(is (= "hello" (->>> :a (% {:a :h}) (name %) (cons % "ello") (clojure.string/join %))))) |
NewerOlder