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
(defroutes chapter-routes | |
;; Example story-slug: 42-my-first-story | |
;; Example chapter-slug: 99-introduction | |
;; (util/parse-uid "42-my-first-story") -> 42 | |
;; (util/parse-uid "99-introduction") -> 99 | |
(GET "/chapters/:chapter-slug" [story-slug chapter-slug] | |
(when-let [story-uid (util/parse-uid story-slug)] | |
(when-let [chapter-uid (util/parse-uid chapter-slug)] | |
(when-let [story (db/find-story-by-uid story-uid)] | |
(when-let [chapter (db/find-chapter-by-uid chapter-uid)] |
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
(defn ?assoc-transform | |
"(?assoc-transform {:a 1} :a 2 sequential? vector) => {:a [1 2]}" | |
[m k v test transform] | |
(let [val (m k)] | |
(assoc m k | |
(if-let [okay (test val)] | |
v | |
(transform val v))))) |
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
; http://www.4clojure.com/problem/86 | |
(fn [n] | |
(letfn [(ds [n] | |
(if (pos? n) | |
(conj (ds (int (/ n 10))) (mod n 10))))] | |
(loop [n n nss #{}] | |
(cond | |
(nss n) false | |
(= 1 n) true | |
:e (recur (->> (ds n) (map #(* % %)) (reduce +)) (conj nss n)))))) |
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
(defproject ustate "0.0.1-SNAPSHOT" | |
:description "A state aggregation daemon" | |
:tasks [protobuf.tasks] | |
:dependencies [[org.clojure/clojure "1.2.1"] | |
;[classlojure "0.6.1"] | |
[clojure-protobuf "0.4.6"]] | |
:cake-plugins [[cake-protobuf "0.5.0-alpha5"]]) |
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
(defproject ustate "0.0.1-SNAPSHOT" | |
:description "A state aggregation daemon" | |
:tasks [protobuf.tasks] | |
:dependencies [ | |
[org.clojure/clojure "1.2.1"] | |
[clojure-protobuf "0.4.6"]] | |
:dev-dependencies [ | |
[cake-protobuf "0.5.0-alpha5"]] | |
:tasks [ | |
cake-protobuf.tasks] |
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
;;; All Kinds of Destructuring ;;; | |
(let [foo 1] foo) | |
; => 1 | |
(let [[foo bar] [1 2 3]] [foo bar]) | |
; => [1 2] | |
(let [[foo bar & baz] [1 2 3]] [foo bar baz]) | |
; => [1 2 (3)] |