Skip to content

Instantly share code, notes, and snippets.

View jsnikeris's full-sized avatar

Joe Snikeris jsnikeris

  • Guaranteed Rate
  • NH, USA
View GitHub Profile
(def *expected-selectors* [[:id] [:published] [:updated]
[[:link (e/attr= :rel "edit")]]
[[:link (e/attr= :rel "alternate")]]])
(def *entry-template* (e/xml-resource "templates/entry.xml"))
(defn normalize-entry [entry]
(e/transform entry [:entry]
(e/do->
(for [sel (filter #(empty? (e/select entry %)) *expected-selectors*)]
How can I remove the repetition found in the last two lines?
(require '[net.cgrand.enlive-html :as e])
(e/at entry
[:id] (e/content id)
[#{:published :updated}] (e/content (str pub-date))
[[:link (e/attr= :rel "edit")]] (e/set-attr :href (str edit-url))
[[:link (e/attr= :rel "alternate")]] (e/set-attr :href (str edit-url)))))
@jsnikeris
jsnikeris / gist:1105641
Created July 26, 2011 00:42
Convert "jun" -> 06 and vice versa
(require '[clj-time.format :as tf])
(defn format-month [month]
(let [letter-fmt (tf/formatter "MMM")
num-fmt (tf/formatter "MM")
converter (fn [month from-fmt to-fmt]
(->> month
(tf/parse from-fmt)
(tf/unparse to-fmt)
public class FieldLengthIT extends BaseTest {
@Factory(dataProvider = "fieldLengths")
public Object[] createTest(String fieldName, Integer length) {
return new Object[] {
new FieldLengthTst<EntityCollection>(fieldName, length,
client, ecBuilder.build())
};
}
@jsnikeris
jsnikeris / gist:3386949
Created August 18, 2012 13:47
Macro for defining Datomic database functions
(require '[datomic.api :as d])
(defn maybe-assoc [m k v]
(if v (assoc m k v) m))
(defmacro defn-db [name & args]
(let [[doc-string & args] (if (string? (first args)) args (cons nil args))
[attr-map & args] (if (map? (first args)) args (cons {} args))
[[& params] & body] args