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
(defmulti draw (fn [ shape & rest ] shape)) | |
(defmethod draw ::shape [x y] "shape") | |
(derive ::shape ::rect) | |
(defmethod draw ::rect [x y w h] "rect") | |
(derive ::shape ::eclipse) | |
(defmethod draw ::rect [x y w h] "eclipse") |
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
(.format (new java.text.SimpleDateFormat "EEE, dd MMM yyyy HH:mm:ss Z" java.util.Locale/US) | |
(new java.util.Date (+ 3600000 (java.lang.System/currentTimeMillis)))) |
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
;; functions under test | |
(defn xx [a b] | |
10) | |
(defn yy [z] | |
20) | |
(defn fn-under-test [] | |
(xx 1 2) |
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 products-resource | |
(resource | |
:method-allowed? #(some #{(% :request-method)} [:get :post]) | |
:content-types-provided { "text/html" :to_html, "text/plain" :to_text } | |
:created (fn [_ req _] (str "Product " (add-product (slurp-body req)) " created.")) | |
:to_html (fn [_ req _] | |
(html [:html | |
[:head [:title "All Products"]] | |
[:body [:h1 "All Products"] | |
[:ul (map (fn [p] [:li [:a { :href (p :id)} (p :title)]]) |
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 hello-resource | |
(resource | |
:content-types-provided { "text/html" :to_html ; lookup | |
"text/markdown" :please_make_markdown ;double lookup | |
"text/plain" "Plaintext" ; literal | |
"x/y" (fn [rmap req status] (str "Status " status)) ; function | |
"foo/bar" [500 "Experimental Server Error"] } ; | |
:to_html (html [:body [:h1 "This is HTML!"]] | |
:please_make_markdown :please_please_markdown | |
:please_please_markdown "Yes, this is markdown")) |
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 jabba {:name "Jabba the Hutt" | |
:age 441 | |
:numbers [1 2 -1] | |
:location {:planet "Tattoine"} | |
:foos [{:name "b"} {:name "ab" :size 5}]}) | |
(def expected | |
{:validator :all, | |
:level :error, |
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 jabba {:name "Jabba the Hutt" | |
:age 441 | |
:numbers [1 2 -1] | |
:location {:planet "Tattoine"} | |
:foos [{:name "b"} {:name "ab" :size 5}]}) | |
(def expected | |
{:validator :all, | |
:level :error, | |
:reason |
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
(function(){ | |
jQuery.fn.tpl = function(f) { | |
var sTpl = function(f) { | |
var nodeInDocument = $(this); | |
var tpl = nodeInDocument.clone(); | |
return { | |
apply: function(data) { |
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
;; [1 2 3 4] -> [[[] [1 2 3 4]] [[1] [2 3 4]] [[2 3] [3 4]] ... [[1 2 3 4] []]] | |
(defn sublists [xs] | |
(map (fn [i] [(take i xs) (drop i xs)]) | |
(range (inc (count xs))))) | |
(defn gist-me [xs] | |
(map (fn [[preds succs]] | |
{:preds (reduce + preds) ;; image costly reduction function | |
:succs (reduce * (reverse succs))}) ;; imagine costly reduction function | |
(sublists xs))) |
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
;;; eager permutations | |
(defn pop-nth [coll i] | |
[(nth coll i) (concat (take i coll) (drop (inc i) coll))]) | |
(defn perms [items] | |
(letfn [(p [previous rest] | |
(if (empty? rest) | |
[previous] | |
(mapcat (fn [i] |
OlderNewer