Skip to content

Instantly share code, notes, and snippets.

View davegolland's full-sized avatar

Dave Golland davegolland

  • San Francisco, CA
View GitHub Profile
(defn subs-to
"Like subs, but does not throw if index is out of range"
([s start]
(subs-to s start (count s)))
([s start end]
(if (or (<= (count s) start) (<= end start))
""
(subs s start (min (count s) end)))))
@davegolland
davegolland / threading-example.clj
Created June 16, 2014 21:50
threading-example
(->> [1 2 3 4 5] ; the initial vector
(filter odd?) ; after this step we have: (1 3 5)
(take 2) ; (1 3)
last ; 3
inc) ; 4
(inc (last (take 2 (filter odd? [1 2 3 4 5]))))
@davegolland
davegolland / double-arrow.clj
Last active August 29, 2015 14:02
FE-Blogpost-Threading
(defmacro ->>
([x form] (if (seq? form)
(with-meta `(~(first form) ~@(next form) ~x) (meta form))
(list form x)))
([x form & more] `(->> (->> ~x ~form) ~@more)))
@davegolland
davegolland / gist:10508289
Created April 11, 2014 23:00
ClojureCompetancies
I did a lot of my initial learning with https://www.4clojure.com/problems
The Joy of Clojure book is a great reference.
A nice basic tutorial on how to use common macros:
http://cjohansen.no/clojure-to-die-for
I still spend a lot of time on:
http://clojuredocs.org/quickref/Clojure%20Core to get an overview of
the functions that exist and examples using them.
@davegolland
davegolland / entrieshandlerinfo.clj
Last active August 29, 2015 13:57
fnhouse blogpost gists
{;; HTTP-related info
:path "/entries/"
:method :post
:description
"Add a new entry to the guestbook"
;; information about the HTTP request that the handler expects
:request
{:body Entry