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 murmur3 | |
"Implementation of clojure.lang.Murmur3 in clojurescript (assuming javascript numerics). | |
by Francis Avila 2014-02-24") | |
(def imul | |
"32-bit signed integer multiply with overflow; alias of js/Math.imul. | |
Does not follow unchecked-multiply-int semantics! Only two args accepted; if | |
args are missing returns 0." | |
(if (exists? (aget js/Math "imul")) | |
(aget js/Math "imul") |
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
(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
(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
(defmacro test-> | |
"Takes an expression and a set of test/form pairs. Threads expr (via ->) | |
through each form for which the corresponding test expression (not threaded) is true." | |
[expr | |
& clauses] | |
(assert (even? (count clauses))) | |
(let [g (gensym) | |
pstep (fn [[test step]] `(if ~test (-> ~g ~step) ~g))] | |
`(let [~g ~expr | |
~@(interleave (repeat g) (map pstep (partition 2 clauses)))] |
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 cljs-uuidv4 | |
"Generator for a v4/random UUID that works with cljs.core/UUID" | |
(:require [goog.string.StringBuffer])) | |
(defn UUIDv4 | |
"Returns a new randomly generated (version 4) cljs.core/UUID, | |
like: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx | |
as per http://www.ietf.org/rfc/rfc4122.txt. | |
Usage: |
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
(defmacro iff [test & {:keys [then else]}] `(if ~test ~then ~else)) | |
(comment (iff false | |
:then (println "true") | |
:else (println "false"))) | |
(defmacro iff-let [bindings & {:keys [then else]}] `(if-let ~bindings ~then ~else)) | |
(comment (iff-let [x true] :else "false" :then x)) | |
(defmacro if-lets | |
"Like `if-let` but binds multiple values iff all tests are true." |
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
#!/bin/bash | |
rediscli=`which redis-cli` | |
s3cmd=`which s3cmd` | |
lsave=`$rediscli lastsave` | |
echo "LASTSAVE $lsave" | |
saved="`$rediscli config get dir | xargs | cut -d ' ' -f 2`/`$rediscli config get dbfilename | xargs | cut -d ' ' -f 2`" | |
$rediscli bgsave | |
while [ $lsave -eq `$rediscli lastsave` ]; do |
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))))))) |
OlderNewer