Skip to content

Instantly share code, notes, and snippets.

@firthh
firthh / lazy_gzipped_tar.clj
Last active April 16, 2019 13:46
Lazily read a gzipped tar archive
(require [clojure.data.xml :as xml])
(import [java.io FileInputStream]
[java.util.zip GZIPInputStream]
[org.apache.commons.compress.compressors.gzip GzipCompressorInputStream]
[org.apache.commons.compress.archivers.tar TarArchiveInputStream TarArchiveEntry])
(defn get-s3-file-stream [bucket key]
(-> (s3/get-object {:endpoint "eu-west-1"}
:bucket-name bucket
:key key)
@firthh
firthh / core.clj
Last active January 16, 2019 09:11
Shutdown
(defn -main [& args]
(.addShutdownHook (Runtime/getRuntime)
(Thread. (fn []
(println "Shutting down application"))))
(while true
(Thread/sleep 500)))
(defn m-error-handling [f]
(fn [& args]
(try
(let [res (apply f args)]
(if res
(right res)
(left {:message (str "nil returned calling " f " with " args)})))
(catch Exception e
(left {:exception e :message (str "Exception thrown calling " f " with " args)})))))
(defn with-error-handling [f]
(fn [& args]
(try
(if-let [res (apply f args)]
[res nil]
[nil {:message (str "Had nil returned calling " f " with " args)}]
(catch Exception e
[nil {:exception e :message (str "Had exception calling " f " with " args)}]))))
(defn our-comp
(defn with-error-handling [f]
(fn [& args]
(try
(let [res (apply f args)]
(if-not res
(log/error (str "Had nil returned calling " f " with " args)))
res)
(catch Exception e
(log/error e "An exception was thrown processing: " args)
(airbrake/notify config/airbrake e)
@firthh
firthh / verify.clj
Last active August 29, 2015 14:26
Midje verify mock
(defn something [x]
x)
(defn fun [x]
(something)
x)
(fact "something"
(fun 5) => 5
(provided