Skip to content

Instantly share code, notes, and snippets.

Avatar

Anthony Grimes Raynes

View GitHub Profile
View when-let-lol.clj
(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)]
View gist:6643618
(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)))))
@Raynes
Raynes / p86.clj
Created Nov 4, 2011 — forked from daveray/p86.clj
4clojure problem 86 issue
View p86.clj
; 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))))))
View gist:1262815
(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"]])
View gist:1262750
(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]
View Destructuring Examples.clj
;;; 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)]
You can’t perform that action at this time.