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 n01se.externs-for-cljs | |
(:require [clojure.java.io :as io] | |
[cljs.compiler :as comp] | |
[cljs.analyzer :as ana])) | |
(defn read-file [file] | |
(let [eof (Object.)] | |
(with-open [stream (clojure.lang.LineNumberingPushbackReader. (io/reader file))] | |
(vec (take-while #(not= % eof) | |
(repeatedly #(read stream false eof))))))) |
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
;;; 13 June 2013: Clojure 1.5.1, Nippy mpenet/2.0.0-alpha3 (nio) | |
{:reader {:freeze 23491, :thaw 26074, :round 49720, :data-size 22956}} | |
{:defaults {:freeze 4080, :thaw 2432, :round 5961, :data-size 12403}} | |
{:encrypted {:freeze 5725, :thaw 3791, :round 9310, :data-size 12421}} | |
{:fast {:freeze 3479, :thaw 1981, :round 5462, :data-size 13343}} | |
;;; 13 June 2013: Clojure 1.5.1, Nippy 2.0.0-alpha1 | |
{:reader {:freeze 23124, :thaw 26469, :round 47674, :data-size 22923}} | |
{:defaults {:freeze 4007, :thaw 2520, :round 6038, :data-size 12387}} | |
{:encrypted {:freeze 5560, :thaw 3867, :round 9157, :data-size 12405}} |
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 declare-remote | |
"Declares the given ns-qualified names, preserving symbol metadata. Useful for | |
circular dependencies." | |
[& names] | |
`(do ~@(map (fn [n] | |
(let [ns (namespace n) | |
v (name n) | |
m (meta n)] | |
`(do (in-ns '~(symbol ns)) | |
(declare ~(with-meta (symbol v) m))))) names) |
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
(let [new-fn (ƒ [{:keys [more] :as args}] | |
(apply println (prefixed-message args) more))] | |
(set-config! [:appenders :standard-out :fn] new-fn) | |
(set-config! [:appenders :standard-out-or-err :fn] new-fn)) |
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
(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)] |
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
(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 |
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 oget | |
"Like `aget` for JS objects, Ref. https://goo.gl/eze8hY. Unlike `aget`, | |
returns nil for missing keys instead of throwing." | |
([o k] (when o (gobj/get o k nil))) | |
([o k1 k2] (when-let [o (oget o k1)] (gobj/get o k2 nil))) ; Optimized common case | |
([o k1 k2 & ks] (when-let [o (oget o k1 k2)] (apply oget o ks)))) ; Can also lean on optimized 2-case |
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
;; | |
;; LATEST UPDATE: 25 July 2015 | |
;; | |
;; **************************************************************** | |
;; ** NB false alarm! My original benchmarks showing large perf ** | |
;; ** improvements with tuples turned out to be noise, ** | |
;; ** unfortunately. Current (+more reliable) numbers seem[1] to ** | |
;; ** show no consistent significant advantage using currently ** | |
;; ** available tuple implementations against real-world code. ** | |
;; ** ** |
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 mutabots | |
"Reimplementation of transducers, in terms of processing functions instead | |
of reducing functions. | |
tl;dr: reducing-fn based transducers are a special case, influenced by reducers, | |
of processing-fn based transducers. | |
In Clojure 1.7.0-alpha2, transducers are expressed in terms of the existing | |
concept of reducing functions. | |
To sum it up, a transducer has currently the signature : |
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
(comment | |
;; Bug report for CLJS-721 (support :include-macros true modifier in :require), | |
;; Ref. http://dev.clojure.org/jira/browse/CLJS-721, | |
;; http://goo.gl/MQ3fWd (GitHub commit de6ee41b3) | |
;; desugar-ns-specs from clojurescript/src/clj/cljs/analyzer.clj | |
;; (`cljs.analyzer` ns) | |
(desugar-ns-specs '[(:require [foo.bar :as bar :include-macros true])]) | |
;; => |