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
; add this to your project.clj file to suppress compilation warnings | |
:injections | |
[(alter-var-root clojure.lang.RT/ERR | |
(constantly | |
(java.io.PrintWriter. | |
(org.apache.commons.io.output.NullWriter.))))] |
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 zip-entries [^ZipInputStream input] | |
(let [last (atom nil)] | |
(letfn [(inner [stream] | |
(lazy-seq | |
(let [previous @last] | |
(when previous (.closeEntry stream)) | |
(if-some [entry (.getNextEntry stream)] | |
(cons (reset! last entry) (inner stream)) | |
(.close stream)))))] | |
(inner input)))) |
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
(ns file-scraper.core | |
(:require | |
[skyscraper :refer :all] | |
[clojure.string :as strings] | |
[clj-http.client :as client] | |
[net.cgrand.enlive-html :refer :all] | |
[clojure.java.io :as io]) | |
(:import (java.util UUID) | |
(java.io FileOutputStream) | |
(java.net URLDecoder))) |
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
(defmacro defmethodset | |
[multifn dispatch-vals & fn-tail] | |
`(for [dispatch-val# ~dispatch-vals] | |
(defmethod ~multifn dispatch-val# ~@fn-tail))) |
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
; in util.clj | |
(ns project.util) | |
(defmacro create-test-class [name x] | |
(let [prefix (str name "-")] | |
`(do | |
(gen-class | |
:name ~(with-meta name `{Deprecated true}) | |
:prefix ~(symbol prefix) | |
:methods [[~(with-meta 'getValue `{Deprecated true}) [] Integer]]) |
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
(defmacro ? [form] | |
(let [f (first form) args (rest form)] | |
`(let [_# (list ~@args)] | |
(when (every? some? _#) | |
(apply ~f _#))))) |
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 restful-routes | |
"Consumes vectors in the form of [node [child1 [innerChild1]] [child2 [innerChild2]] sibling1] | |
and produces a set of vectors that make up a bidi route structure. Path variables for ids are | |
automatically created and :$resource-name$-many keyword is used as a placeholder for the 'many' | |
endpoint and :$resource-name$-single keyword is used as a placeholder for the 'single' endpoint. | |
The intention is that after generating these routes, you can traverse the structure using clojure.walk | |
to swap placeholders for implementations." | |
[tree] | |
(letfn [(inner-generate-routes [tree] |
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 pairs [tree] | |
(letfn [(one-node [depth node] | |
(if (list? node) | |
(map (partial one-node (inc depth)) node) | |
(vector node depth)))] | |
(into [] (partition 2 (flatten (map (partial one-node 0) tree)))))) | |
(defn foreach [f coll] | |
(dorun (map f coll))) |
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 subtrees [tree] | |
(if (or (nil? tree) (empty? tree)) | |
'() | |
(let [parent (first tree) children (take-while list? (rest tree))] | |
(if (not-empty children) | |
(concat | |
(map #(list parent %) children) | |
(mapcat subtrees children) | |
(subtrees (drop (inc (count children)) tree))) | |
(subtrees (next tree)))))) |
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 aliasing [& keys-and-values] | |
"Creates a map from pairs of vector/value entries. Each entry in the vector is used as a key for the corresponding value." | |
(loop [result {} entries (into [] (partition 2 keys-and-values))] | |
(let [entry (first entries) keys (first entry) value (second entry)] | |
(if (empty? entries) | |
result | |
(recur (merge result (zipmap keys (repeatedly #(identity value)))) (rest entries)))))) |