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 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
(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
; 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 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
(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
(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
; 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 attach-channel-cleanup [chan f] | |
(add-watch (.closed chan) | |
"channel-resource-cleanup" | |
(fn [_ _ old-state new-state] | |
(when (and (not old-state) new-state) | |
(f)))) | |
chan) |
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 nor [& more] | |
(conj `~(partition 2 (interleave (repeat 'not) more)) 'and)) |