Skip to content

Instantly share code, notes, and snippets.

View ataggart's full-sized avatar

Alexander Taggart ataggart

  • Toronto, Ontario, Canada
View GitHub Profile
@ataggart
ataggart / project.clj
Last active June 16, 2020 14:48
Example log4j2 project setup.
(defproject example "0.1.0"
:description "Example configuration for using log4j2 as the concrete logging
implementation. Libraries that depend on other well-known java
logging abstractions (e.g., SLF4J) will be logged with log4j2.
Also configures tools.logging to choose log4j2."
:dependencies [; Provide the log4j2 logging implementation:
[org.apache.logging.log4j/log4j-api "2.13.0"]
[org.apache.logging.log4j/log4j-core "2.13.0"]
; Provide log4j2 adapters for other java logging abstractions:
@ataggart
ataggart / left-join.clj
Last active April 12, 2022 20:15
left-join analog of clojure.set/join
(defn left-join
"When passed 2 rels, returns the rel corresponding to the natural
left-join. When passed an additional keymap, joins on the corresponding
keys."
([xrel yrel]
(if (and (seq xrel) (seq yrel))
(let [ks (intersection (set (keys (first xrel)))
(set (keys (first yrel))))
idx (index yrel ks)]
(reduce (fn [ret x]
@ataggart
ataggart / arities.clj
Last active September 19, 2019 09:25
(defn arities
"Returns a vector of the arities of function f, or of the dispatch
function if f is a multifn.
Example:
=> (arities (fn ([]) ([x]) ([x y & z])))
[0 1 2 :more]"
[f]
(let [f (if (instance? clojure.lang.MultiFn f) (.dispatchFn f) f)
methods (.getDeclaredMethods (class f))
@ataggart
ataggart / take-util.clj
Last active August 29, 2015 14:02
take-until
(defn take-until
"Returns a lazy sequence of successive items from coll until
(pred item) returns true, including that item. pred must be
free of side-effects.
E.g., (take-until zero? [1 2 0 3]) => (1 2 0)"
[pred coll]
(lazy-seq
(when-let [s (seq coll)]
(if (pred (first s))
(cons (first s) nil)
; Released under the Apache License, Version 2.0
; http://www.apache.org/licenses/LICENSE-2.0.html
(defmacro try-let
"A combination of try and let such that exceptions thrown in the binding or
body can be handled by catch clauses in the body, and all bindings are
available to the catch and finally clauses. If an exception is thrown while
evaluating a binding value, it and all subsequent binding values will be nil.
Example: