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
(defrecord FakeTimeout [current-time time-chans]) | |
(defn timeout-fn | |
[{:keys [current-time time-chans]}] | |
(fn [time] | |
(let [ch (async/chan)] | |
(swap! time-chans merge-with into {(+ @current-time time) #{ch}}) | |
(println time-chans) | |
ch))) |
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 data-chan (async/chan)) | |
(defn webview-writer [chan] | |
(let [istream (PipedInputStream.) | |
ostream (PipedOutputStream. istream)] | |
(async/thread | |
(loop [] | |
(when-some [s (async/<!! chan)] | |
(let [event (str "event: test\ndata: "s"\n\n")] |
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 float | |
"Generates a floating point number which shrinks towards zero" | |
(fmap core/float ratio)) | |
(defn float-in-range | |
"Generates a floating point number with a given start/end | |
point (inclusive)" | |
[range-start range-end] | |
(let [gen-float-0-to-1 (sized (fn [size] | |
;; We can't have 0 as our bound, would give NaN |
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
;; Clojure example: | |
(defn test-locks [this] | |
(locking this | |
2)) |
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
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.blah.rah" | |
android:versionCode="{{version-code}}" | |
android:versionName="{{version-name}}" > | |
<uses-sdk android:minSdkVersion="15" /> | |
{{#debug-build}} | |
<uses-permission android:name="android.permission.INTERNET"/> |
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 locals [] (zipmap (map #(list 'quote %) (keys &env)) (keys &env))) | |
(defn remove-autogenerated-locals | |
"Remove any locals generated by macros (heuristic - named something | |
with underscores in it). When we're doing something other than | |
println with the data, these could be left in but it's a bit noisy | |
at the moment" | |
[coll] | |
(into {} (remove (fn [[k v]] (re-find #"[_]" (name k))) coll))) |
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 dump [^ByteBuffer b] | |
(let [readcopy (.asReadOnlyBuffer b)] | |
(.rewind readcopy) | |
(for [i (range (/ (.limit readcopy) 4))] | |
(.getInt readcopy)))) | |
(defmethod print-method ByteBuffer | |
[v ^java.io.Writer w] | |
(.write w (str "#<ByteBuffer" (pr-str (dump v)) ">"))) |
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 logcat-appender | |
{:doc (str "Appends to android logcat. Obviously only works if " | |
"running within the android runtime, either on a device " | |
"or an emulator") | |
:min-level :debug | |
:enabled? true | |
:async? false | |
:limit-per-msecs nil | |
:prefix-fn :ns | |
:fn (fn [{:keys [level prefix throwable message]}] |
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 map-vals "Map from a thing to a thing" | |
[f m] | |
(into {} (for [[k v] m] [k (f v)]))) |
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 handle [binds & body] | |
(concat (conj body 'try) | |
(for [[ex-type ex-fn] (partition 2 binds) | |
:let [ex-sym (gensym "exception")]] | |
(if (= ex-type :finally) | |
(list 'finally (list ex-fn)) | |
(list 'catch ex-type ex-sym (list ex-fn ex-sym)))))) | |
(defmacro handle-fn [binds f] | |
`(fn [& args#] (handle ~binds (apply ~f args#)))) |