Skip to content

Instantly share code, notes, and snippets.

View rmfbarker's full-sized avatar

Richard Barker rmfbarker

View GitHub Profile
;; add lein dep:
;; [org.bouncycastle/bcpg-jdk15on "1.51"]
;; export gpg public & private keys to armored files:
;; gpg -ao pub.asc --export XXXXXXXX
;; gpg -ao pk.asc --export-secret-keys XXXXXXXX
;; usage:
;; (encrypt "foo.txt" "foo.gpg" (pub-key "pub.asc"))
;; (decrypt "foo.gpg" (io/output-stream "foo.txt") (secret-key "ks-pk.asc") "passphrase")
(defn ignore-trailing-slash
"Modifies the request uri before calling the handler.
Removes a single trailing slash from the end of the uri if present.
Useful for handling optional trailing slashes until Compojure's route matching syntax supports regex.
Adapted from http://stackoverflow.com/questions/8380468/compojure-regex-for-matching-a-trailing-slash"
[handler]
(fn [{uri :uri :as request}]
(handler (assoc request :uri (cond (= "/" uri) uri
(.endsWith uri "/") (apply str (butlast uri))