This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn mkscope | |
"Create a rule which contains the scope of the given rule. Bindings | |
made in rule do not escape this rule's scope. | |
<code>mkscope</code> creates a scope protector around a rule so that | |
bindings that the given rule creates do not leak into the current | |
scope. This function should be used around your own rules. | |
Example: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function autoCurry(n, f) { | |
return function() { | |
var args1 = Array.prototype.slice.apply(arguments), | |
len = args1.length; | |
if(len === n) { | |
return f.apply(this, args1); | |
} else if(len > n) { | |
throw 'Too many arguments.'; | |
} else { | |
return autoCurry(n - len, function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn sub | |
[s form] | |
(cond | |
(= '<&> form) s | |
(seq? form) (map (partial sub s) form) | |
(list? form) (map (partial sub s) form) | |
(vector? form) (mapv (partial sub s) form) | |
(map? form) (into {} (for [[k v] form] [(sub s k) (sub s v)])) | |
(set? form) (into #{} (map (partial sub s) form)) | |
:else form)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn arities [f] | |
(sort (for [m (.getDeclaredMethods (class f)) | |
:when (= "invoke" (.getName m))] | |
(alength (.getParameterTypes m))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def ts (time/formatters :date-time-no-ms)) | |
(defn git-hash [] | |
(let [p (.exec (Runtime/getRuntime) (into-array String ["/bin/sh" "-c" | |
"git rev-list --format=format:'%ct' --max-count=1 `git rev-parse HEAD`"]))] | |
(.waitFor p) | |
(let [s (-> (.getInputStream p) | |
slurp | |
string/trim) | |
_ (prn s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def logger (agent nil)) | |
(def logfile (java.io.FileWriter. "output.edn")) | |
(defn log [a x] | |
(binding [*out* logfile | |
*print-length* 200] | |
(prn x))) | |
(defn wrap-logging [hdlr] | |
(fn [req] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn lens [getter setter] | |
(fn [fmap vf in] | |
(fmap (partial setter in) | |
(vf (getter in))))) | |
(defn lupdate [lens f in] | |
(lens (fn [f a] (f a)) | |
f | |
in)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn- truth [then else] (then)) | |
(defn- falsehood [then else] (else)) | |
(def boolness {false falsehood nil falsehood}) | |
(defn if* [condition then-fn else-fn] | |
((get boolness condition truth) then-fn else-fn)) | |
(defmacro my-if [test then else] | |
`(if* ~test (fn [] ~then) (fn [] ~else))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edntester; | |
import us.bpsm.edn.Keyword; | |
import us.bpsm.edn.parser.Parseable; | |
import us.bpsm.edn.parser.Parser; | |
import us.bpsm.edn.parser.Parsers; | |
import us.bpsm.edn.printer.Printers; | |
import java.util.ArrayList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"big-feed-index": { | |
"mappings": { | |
"listings": { | |
"properties": { | |
"asin": { | |
"type": "string", | |
"index": "not_analyzed" | |
}, | |
"categories": { |