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
;; (require '[clojure.string :as str] '[clojure.java.shell :as shell] '[taoensso.timbre :as timbre]) | |
(defn with-free-port! | |
"Attempts to kill any current port-binding process, then repeatedly executes | |
nullary `bind-port!-fn` (which must return logical true on successful | |
binding). Returns the function's result when successful, else throws an | |
exception. *nix only. | |
This idea courtesy of Feng Shen, Ref. http://goo.gl/kEolu." | |
[port bind-port!-fn & {:keys [max-attempts sleep-ms] |
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
#!/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))))))) |
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 async-test.throttle.core | |
(:require [cljs.core.async :refer [chan close!o sliding-buffer]] | |
[clojure.string :as string]) | |
(:require-macros | |
[cljs.core.async.macros :as m :refer [go alts!]])) | |
(def c (chan (sliding-buffer 1))) | |
(def loc-div (.getElementById js/document "location")) | |
(.addEventListener js/window "mousemove" |
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
(ns whatever.cljs | |
(:require [cljs.compiler :refer (munge)]) | |
(:refer-clojure :exclude (munge defonce))) | |
(defmacro defonce | |
[vname expr] | |
(let [ns (-> &env :ns :name name munge) | |
mname (munge (str vname))] | |
`(when-not (.hasOwnProperty ~(symbol "js" ns) ~mname) | |
(def ~vname ~expr)))) |
OlderNewer