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 | |
## NOTE: Make sure `bell.oga' actually exists and adjust accordingly. | |
for (( ; ; )) | |
do | |
ping -w 5 -c 1 8.8.8.8 &> /dev/null | |
if [ $? -ne 0 ]; then | |
paplay /usr/share/sounds/freedesktop/stereo/bell.oga |
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
;;; Add this in your project.clj to enable direct linking | |
;; | |
;; :jvm-opts ["-Dclojure.compiler.direct-linking=true"] | |
;; ..and now observe how this changes things: | |
; CIDER 0.11.0snapshot (package: 20160119.836) (Java 9-ea, Clojure 1.9.0-master-SNAPSHOT, nREPL 0.2.12) | |
user> (defn a [] (println "a")) |
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
;;; Move a file atomically in Clojure. | |
;; This will also replace the target file if it exists since REPLACE_EXISTING is included in the options at the end. | |
;; user.dir == current working directory (on Linux at least). | |
(let [source-filename (str (System/getProperty "user.dir") "/source.txt") | |
target-filename (str (System/getProperty "user.dir") "/target.txt") | |
source-file (java.nio.file.Paths/get (java.net.URI/create (str "file://" source-filename))) | |
target-file (java.nio.file.Paths/get (java.net.URI/create (str "file://" target-filename)))] | |
(java.nio.file.Files/move source-file target-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
(import 'com.google.common.collect.EvictingQueue) | |
(let [queues (atom {})] | |
(defn ohlc-circular-cache [size seconds ^String id ^Fn get-ohlc-data-fn] | |
"`size`: Size of circular buffer. | |
`seconds`: Time frame of data series. I.e. number of seconds between OHLC .open and .close. | |
`id`: Unique ID string used to identify this circular buffer. | |
`get-ohlc-data-fn`: (fn [timestamp] ...) Get the most recent data series from timestamp. If timestamp is NIL get as much data as possible. In both cases the data returned will include the most recently closed OHLC entry (candle). Note that `get-ohlc-data-fn` will only be called once – so if stale data is returned you must deal with this either there or in code that depends on OHLC-CIRCULAR-CACHE directly or indirectly." | |
(let [seconds (long seconds) | |
^com.google.common.collect.EvictingQueue | |
queue (locking queues |
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
;; This stuff is pretty useful in many contexts. | |
... | |
(:import (com.google.common.cache CacheBuilder CacheLoader)) | |
... | |
quantataraxia.core> (with (-> (CacheBuilder/newBuilder) | |
(.weakKeys) |
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
quantataraxia.core> (let [m1 (HashBiMap/create {1 :a 2 :b 3 :c}) | |
m2 (HashMap. {:a 1 :b 2}) | |
m1inv (.inverse m1)] | |
(with (Maps/difference m1inv m2) | |
(.removeAll (.keySet m1inv) (.keySet (.entriesOnlyOnLeft it))) | |
(pprint (into {} m1)) | |
(pprint (into {} m1inv)))) | |
{1 :a, 2 :b} | |
{:a 1, :b 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
;;; www.Quanto.ga | |
;;;;;;;;;;;;;;;;; | |
;; Test from https://www.bitmex.com/app/apiKeysUsage#Full-sample-calculation | |
(letfn [(sign [^String api-secret ^String s] | |
(let [h (com.google.common.hash.Hashing/hmacSha256 (.getBytes api-secret))] | |
(.toString (.hashString h s com.google.common.base.Charsets/UTF_8))))] | |
(let [apiKey "LAqUlngMIQkIUjXMUreyu3qn" | |
apiSecret "chNOOS4KvNXR_Xq4k4c9qsfoKWvnDecLATCRlcBwyKDYnWgO"] | |
;; Simple GET |
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 [f (future | |
(try | |
(Thread/sleep 10000) | |
(catch Throwable e | |
(println e) | |
(println "isInterrupted:" (.isInterrupted (Thread/currentThread))) | |
(println "isAlive:" (.isAlive (Thread/currentThread))) | |
(println "interrupted:" (Thread/interrupted)))))] | |
(Thread/sleep 500) | |
(future-cancel f) |
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
;; I keep forgetting how to do this stuff for some reason, so here goes: | |
(let [c (async/chan 1 (map #(* % 2)))] | |
(async/go | |
(loop [] | |
(when-let [e (async/<! c)] | |
(println "async/go, e:" e) | |
(recur)))) | |
(async/>!! c 1) | |
(async/>!! c 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
;; Performance of with-local-vars vs. atom vs. volatile vs. unsynchronized-mutable field. | |
(definterface IOObject | |
(setVal [new-val]) | |
(getVal []) | |
(oswap [f]) | |
(oswap [f x]) | |
(oswap [f x y]) | |
(oswap [f x y z])) |
OlderNewer