Skip to content

Instantly share code, notes, and snippets.

@devn
Created March 24, 2010 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devn/342095 to your computer and use it in GitHub Desktop.
Save devn/342095 to your computer and use it in GitHub Desktop.
(set! *print-length* 50)
(set! *warn-on-reflection* true)
;; stuart sierra's multimap
(defn add
"Adds key-value pairs to the multimap."
([mm k v]
(assoc mm k (conj (get mm k #{}) v)))
([mm k v & kvs]
(apply add (add mm k v) kvs)))
(defn del
"Deletes key-value pairs from the multimap."
([mm k v]
(assoc mm k (disj (get mm k) v)))
([mm k v & kvs]
(apply del (del mm k v) kvs)))
(defn mm-merge
"Merges the multimaps, taking the union of values."
[& mms]
(apply (partial merge-with union) mms))
;; psykotic's trace-seq functions
(defn trace-seq* [name xs printer]
(for [x xs]
(do (println name "->" (printer x))
x)))
(defmacro trace-seq [xs & [printer]]
`(trace-seq* ~(str xs) ~xs ~(or printer identity)))
(defn find-lines-in-file [#^String text file]
(filter (fn [#^String line]
(< 0 (.indexOf line text)))
(line-seq (reader file))))
(defn parse-outside-ips [coll]
(flatten
(remove empty?
(pmap
#(rest (re-find #"Deny tcp src outside:(\d+\.\d+\.\d+\.\d+)" %))
coll))))
; => (("127.0.0.1") ("127.0.0.1") ("123.456.789.0")...) ;; Pre-flatten
; => ("127.0.0.1" "127.0.0.1" ...) ;; After adding flatten (performance?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment