Skip to content

Instantly share code, notes, and snippets.

View ericnormand's full-sized avatar

Eric Normand ericnormand

View GitHub Profile
@ericnormand
ericnormand / version.clj
Created March 6, 2014 17:46
Insert a version string into ClojureScript output
(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)
@ericnormand
ericnormand / wrap-logging.clj
Last active August 29, 2015 14:02
A middleware to log Ring request/response to a file.
(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]
@ericnormand
ericnormand / lens.clj
Last active August 29, 2015 14:03
Clojure Lens Implementation
(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))
@ericnormand
ericnormand / unconditional.clj
Created October 14, 2014 04:31
Who needs conditionals in Clojure?
(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)))
@ericnormand
ericnormand / EdnTester.java
Created November 28, 2014 21:27
Examples how to handle EDN messages to/from sente
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;
@ericnormand
ericnormand / mapping.json
Created February 19, 2015 16:14
Elasticsearch Help
{
"big-feed-index": {
"mappings": {
"listings": {
"properties": {
"asin": {
"type": "string",
"index": "not_analyzed"
},
"categories": {
@ericnormand
ericnormand / Mapping.json
Created February 19, 2015 17:07
Elasticsearch Help 2
{
"amazon-cache": {
"mappings": {
"listings": {
"properties": {
"asin": {
"type": "string",
"index": "not_analyzed"
},
"categories": {
#
#Fri Mar 20 11:05:40 CDT 2015
root=/Users/eric/dw/ballot-scout
classpath=/Users/eric/dw/ballot-scout/test\:/Users/eric/dw/ballot-scout/dev-src\:/Users/eric/dw/ballot-scout/src\:/Users/eric/dw/ballot-scout/dev-resources\:/Users/eric/dw/ballot-scout/env-configs/ballot-scout/dev/resources\:/Users/eric/dw/ballot-scout/dev-resources\:/Users/eric/dw/ballot-scout/config\:/Users/eric/dw/ballot-scout/resources\:/Users/eric/dw/ballot-scout/target/classes\:/Users/eric/.m2/repository/ns-tracker/ns-tracker/0.2.1/ns-tracker-0.2.1.jar\:/Users/eric/.m2/repository/com/datomic/datomic-lucene-core/3.3.0/datomic-lucene-core-3.3.0.jar\:/Users/eric/.m2/repository/org/apache/pdfbox/fontbox/1.8.8/fontbox-1.8.8.jar\:/Users/eric/.m2/repository/clj-tuple/clj-tuple/0.1.7/clj-tuple-0.1.7.jar\:/Users/eric/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.1.1/jackson-databind-2.1.1.jar\:/Users/eric/.m2/repository/org/jgroups/jgroups/3.2.12.Final/jgroups-3.2.12.Final.jar\:/Users/eric/.m2/repository/org/apache/tomcat/tomcat-juli
@ericnormand
ericnormand / app.properties
Last active August 29, 2015 14:17
Running> lein with-profile test immutant test -j ~/dw/wildfly-8.1.0.Final
#
#Fri Mar 20 11:38:40 CDT 2015
root=/Users/eric/dw/ballot-scout
classpath=/Users/eric/dw/ballot-scout/test\:/Users/eric/dw/ballot-scout/src\:/Users/eric/dw/ballot-scout/test-resources\:/Users/eric/dw/ballot-scout/config\:/Users/eric/dw/ballot-scout/resources\:/Users/eric/dw/ballot-scout/target/classes\:/Users/eric/.m2/repository/ns-tracker/ns-tracker/0.2.1/ns-tracker-0.2.1.jar\:/Users/eric/.m2/repository/com/datomic/datomic-lucene-core/3.3.0/datomic-lucene-core-3.3.0.jar\:/Users/eric/.m2/repository/org/apache/pdfbox/fontbox/1.8.8/fontbox-1.8.8.jar\:/Users/eric/.m2/repository/clj-tuple/clj-tuple/0.1.7/clj-tuple-0.1.7.jar\:/Users/eric/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.1.1/jackson-databind-2.1.1.jar\:/Users/eric/.m2/repository/org/jgroups/jgroups/3.2.12.Final/jgroups-3.2.12.Final.jar\:/Users/eric/.m2/repository/org/apache/tomcat/tomcat-juli/7.0.27/tomcat-juli-7.0.27.jar\:/Users/eric/.m2/repository/com/cemerick/piggieback/0.1.0/piggieback-0.1.0.jar\:/Users/eric/.m2/repository/com/cogni
;; this one looks much cleaner, but it holds onto the heads of the lists
(defn filter-collecting [predicate collector & lists]
(let [tuples (apply map vector lists)
filtered (filter #(apply predicate %) tuples)]
(map #(apply collector %) filtered)))
;; less garbage, but uglier
(defn filter-collecting [predicate collector & lists]