Skip to content

Instantly share code, notes, and snippets.

View ptaoussanis's full-sized avatar
🦎
Hey! Hope you're having an awesome day :-)

Peter Taoussanis ptaoussanis

🦎
Hey! Hope you're having an awesome day :-)
View GitHub Profile
@ptaoussanis
ptaoussanis / resource_modified.clj
Created June 15, 2012 11:48
Fn to check for modified resource files
(def some-file-resources-modified?
"Returns true iff any of the files backing given resources have changed
since this function was last called."
(let [times (atom {})]
(fn modified?
([resource-name & more] (some modified? (cons resource-name more)))
([resource-name]
(when-let [^File file (try (->> resource-name io/resource io/file)
(catch Exception _ nil))]
(let [last-modified (.lastModified file)]
@ptaoussanis
ptaoussanis / smart_memoize.clj
Created June 14, 2012 11:19
More powerful memoize for Clojure
(def ^:private gc-sm-cache!
"Maintains maximum cache size by intelligently pruning less valuable items."
(let [gc-running? (atom false)]
(fn [cache ttl max-items now]
(when-not @gc-running?
(reset! gc-running? true)
(let [snapshot @cache