(def ds (into-array [:willie :barnabas :adam])) ;; not a vector
(seq ds)
;=> (:willie :barnabas :adam)
(def ds1 (aset ds 1 :quentin))
(seq ds1)
;=> (:willie :quentin :adam)
This file contains hidden or 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.cache :as cache] | |
[clojure.string :as string] | |
[cb-statsd :as statsd]]) | |
(def STATSD_SAMPLE_RATE 0.01) | |
(defn get-statsd-path | |
[f] | |
(as-> (str (type f)) fname ;; returns something like "class namespace$foo" | |
(last (string/split fname #" ")) ;; parse out the "class " |
This file contains hidden or 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 time, sched | |
scheduler = sched.scheduler(time.time, time.sleep) | |
def do_stuff(): | |
scheduler.enter(3, 1, do_stuff, ()) | |
print "hi" | |
scheduler.enter(3, 1, do_stuff, ()) | |
scheduler.run() |
This file contains hidden or 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 values | |
[ 8 2 22 97 38 15 0 40 0 75 4 5 7 78 52 12 50 77 91 8 | |
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 4 56 62 0 | |
81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 3 49 13 36 65 | |
52 70 95 23 4 60 11 42 69 24 68 56 1 32 56 71 37 2 36 91 | |
22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80 | |
24 47 32 60 99 3 45 2 44 75 33 53 78 36 84 20 35 17 12 50 | |
32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70 | |
67 26 20 68 2 62 12 20 95 63 94 39 63 8 40 91 66 49 94 21 | |
24 55 58 5 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72 |
This file contains hidden or 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
;; todo move this into library | |
(require ...) | |
(def rc (connect [...]) | |
(import '[com.basho.riak.client.api.RiakCommand ListBuckets$Builder]) | |
(.execute rc (.build (ListBuckets$Builder. "hud_link_index"))) |
This file contains hidden or 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
<canvas id="display"/> | |
<script> | |
var ctx = document.getElementById('display').getContext('2d'); | |
var speed = 5; | |
var fps = 60; | |
var circle = { | |
r: 10, | |
x: ctx.canvas.width / 2, | |
y: ctx.canvas.height / 2, |
The following is a function which, when called without arguments, creates an incrementing sequence of numbers where iterating from n to n+1 takes about 2^n seconds.
(defn slow-nums
([]
(slow-nums 0 0))
([n sleep-for]
(Thread/sleep (* sleep-for 1000))
(cons n (lazy-seq (slow-nums (inc n) (Math/pow 2 n))))))
This file contains hidden or 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.test :refer [run-tests]]) | |
(do (require 'cb-riak.cb-riak-test :reload-all) (run-tests 'cb-riak.cb-riak-test)) |
This file contains hidden or 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
jq -c '[.["@timestamp"], .levelname, .path, .message]' |
This file contains hidden or 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
class ExceptionCatcher(): | |
def __enter__(self): | |
self.msg = None | |
def __exit__(self, type, value, traceback): | |
if type is Exception: | |
self.msg = value | |
return True # if you return a truthy value then the exception isn't raised |