Skip to content

Instantly share code, notes, and snippets.

View bkirkbri's full-sized avatar

Brian Kirkbride bkirkbri

View GitHub Profile
@bkirkbri
bkirkbri / core-async-helpers.clj
Last active December 21, 2015 12:59
Interfacing synchronous systems with core.async
(require [clojure.core.async
:refer [chan dropping-buffer thread <!! >!! >!]])
(defmacro try! [ch & body]
`(let [ch# ~ch]
(try ~@body (catch Throwable t#
(when ch# (>! ch# t#))))))
(defmacro try!! [ch & body]
`(let [ch# ~ch]
@bkirkbri
bkirkbri / gist:2984680
Created June 24, 2012 19:57
Named route example
;; Higher-order fns that wrap handlers need to preserve the route metadata
;; No problem: just generate a version that does
(def for-host+ (preserve-routes for-host))
(def make-REST-handlers+ (preserve-routes make-REST-handlers))
;; Naming is optional can be arbitrarily deep in the tree as long as all
;; composition along the branch preserves route metadata.
;; This syntax is a rough first cut, another option is (GET :name "/" [] handler)
(def app
(routes (for-host+ "opp-admin.com"
@bkirkbri
bkirkbri / gist:2628163
Created May 7, 2012 14:44
Sketch for named routes
(ns named-routes
(:require [compojure.core :as c])
(:require [clojure.string :as str])
(:import [java.net URLEncoder]))
(defn add-meta
"Merges metadata from maps ms into current metadata for obj."
[obj & ms]
(with-meta obj (apply merge (meta obj) ms)))