=> (binding [clojure.pprint/*print-right-margin* 30]
(clojure.pprint/pprint {:a :b :c {:e :f :g :h :i :j :k :l} :m :n :o {:p {:q :r :s :t}}}))
{:a :b,
:c
{:e :f,
:g :h,
:i :j,
:k :l},
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 lambda-model | |
"Crude model. rps is requests per second, len is a function that returns the | |
execution length in seconds, until is the number of seconds to run the simulation, | |
spawn is a function returning the number of ping sub requests, duty is the max age | |
for a container, keep-alive is the number of seconds before decommissioning a | |
container. | |
Returns a map with: the number of user perceived cold starts and the number of | |
billable seconds." | |
[{:keys [rps len until spawn duty keep-alive] | |
:or {rps 10 |
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 ssh-repl.client | |
(:require [clojure.java.io :as io])) | |
(defn connect | |
([user host repl-port {:as options | |
:keys [ssh-port repl-host key password] | |
:or {ssh-port 22 | |
repl-host "localhost"}}] | |
(let [client (doto (org.apache.sshd.client.SshClient/setUpDefaultClient) .start) | |
session (-> client (.connect user host ssh-port) (doto .await) .getSession)] |
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
; there are some obvious micro optimizations, I left them out for clarity (see the other file for an optimized version) | |
; the relative ordering of read and writes with volatile and plain array should be thread-safe (if not, point it out) | |
; @wagjo asked "Have you found use for such concept? Must be pretty slow compared to unchunked one" | |
; The idea came out of a discussion on transducers so not used for real, yet. | |
; Once you optimize it (remove the boxing induced by the volatile, switch to unchecked math) there should not be much | |
; of an overhead. | |
; When you have one big composed reducing fn (eg several mapping stages) then each item is going to be processed in | |
; each stage, each stage of the mapping may evict from the data cache stuff used by previous stages. So you have cache | |
; misses for each item. |
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
; with the setting that values are indented by two if they are at the start of a line | |
=> (doseq [w (range 20)] | |
(prn 'width w 'non-strict) | |
(render (best-layout (spans '{1 2 3 (a b) 5 6}) w)) | |
(newline) | |
(prn 'width w 'strict) | |
(render (best-layout (spans '{1 2 3 (a b) 5 6}) w true)) | |
(newline)) | |
width 0 non-strict | |
{1 |
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
=> (doseq [w (range 32)] | |
(prn 'width w) | |
(render (best-layout (spans '(1 2 3 4 (a b c) 5 6)) w)) | |
(newline)) | |
width 0 | |
width 1 | |
width 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
; ported from https://en.wikipedia.org/wiki/De_Bruijn_sequence#Algorithm | |
(defn- de-bruijn "generate de-bruijn sequences of size n and with elements in 0..k (k excluded)." [k n] | |
(let [a (into [] (repeat (* k n) 0)) | |
db (fn db [a t p] | |
(if (> t n) | |
(into a (when (zero? (mod n p)) (subvec a 1 (inc p)))) | |
(let [a (assoc a t (nth a (- t p))) | |
a (db a (inc t) p)] | |
(reduce | |
(fn [a j] |
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 foami.core | |
"FOreign Asynchronous Mechanism Interop" | |
(:require [clojure.core.async :as async])) | |
(defn put! | |
"Takes a `ch`, a `msg`, a single arg function that when passed `true` enables backpressure | |
and when passed `false` disables it, and a no-arg function which, when invoked, closes the | |
upstream source." | |
[ch msg backpressure! close!] | |
(let [status (atom :sending] |
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 doc | |
"Returns a spec which acts in all points like the provided spec, | |
expect for describe/form where the docstring appears." | |
[docstring spec] | |
`(doc-impl ~docstring '~spec (delay (spec/spec ~spec)))) | |
(defn doc-impl [docstring form delayed-spec] | |
(reify spec/Spec | |
(conform* [_ x] (spec/conform* @delayed-spec x)) | |
(unform* [_ y] (spec/unform* @delayed-spec y)) |
// assuming b is a local
// rewrite
function(a) { return a + b; }
// to
Object.defineProperty(function(a) { return a + b; }, "$scope", {value: function() { return {"b": b}; }})