Skip to content

Instantly share code, notes, and snippets.

View Raynes's full-sized avatar

Anthony Grimes Raynes

View GitHub Profile
;;; 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)]
(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"]])
(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]
@Raynes
Raynes / p86.clj
Created November 4, 2011 06:24 — forked from daveray/p86.clj
4clojure problem 86 issue
; 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))))))
@Raynes
Raynes / gist:6643618
Last active December 23, 2015 13:39 — forked from bitemyapp/gist:6643575
(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)))))
(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)]