Skip to content

Instantly share code, notes, and snippets.

(probably) completing resting

Nikita Prokopov tonsky

(probably) completing resting
View GitHub Profile
tonsky / xmas.clj
Created Dec 19, 2016
Xmas decoration with AnyBar and Clojure
View xmas.clj
(import '[ InetAddress DatagramPacket DatagramSocket])
(defonce socket (DatagramSocket.))
(defn send-message [text port]
(let [host (InetAddress/getLocalHost)
packet (DatagramPacket. (.getBytes text) (.length text) host port)]
(.send socket packet)))
View comparisons_bench.clj
(require '[criterium.core :as c])
(defn new_=
"Equality. Returns true if x equals y, false if not. Same as
Java x.equals(y) except it also works for nil, and compares
numbers and collections in a type-independent manner. Clojure's immutable data
structures define equals() (and thus =) as a value, not an identity,
{:inline (fn [x y] `(. clojure.lang.Util equiv ~x ~y))
:inline-arities #{2}
tonsky / uploader.cljs
Last active Sep 16, 2016
Rum file uploader
View uploader.cljs
(ns uploader
[clojure.string :as str]
[goog.dom :as gdom]
[goog.userAgent :as ua]
[rum.core :as rum]))
(defonce supports-dragndrop?
(let [el (js/document.createElement "div")]
View gist:0e90dde5b1cea02c2de0dbf1377bb41c
[~/Dropbox/ws/rum] lein perf
--- Testing page1.html (1 kB) ---
Evaluation count : 4656 in 6 samples of 776 calls.
Execution time mean : 127.518354 µs
Execution time std-deviation : 3.729988 µs
Execution time lower quantile : 124.490218 µs ( 2.5%)
Execution time upper quantile : 132.649851 µs (97.5%)
Overhead used : 2.051537 ns
tonsky / user.clj
Last active Sep 16, 2015
Querying DataScript database for entities with 3+ tags
View user.clj
(require '[datascript :as d])
(defn count-vals [db e a]
(count (d/datoms db :eavt e a)))
(let [db (-> (d/empty-db {:link/tags {:db/cardinality :db.cardinality/many}})
(d/db-with [[:db/add 1 :link/tags "a"]
[:db/add 1 :link/tags "b"]
[:db/add 1 :link/tags "c"]
[:db/add 2 :link/tags "x"]
tonsky / gist:9da339f87113e1f1a395
Last active Aug 29, 2015
DataScript 0.11.4 perftests (clj/cljs comparison)
View gist:9da339f87113e1f1a395

CLJ/CLJS perf comparison on DataScript 0.11.4


test: q, method: d/q1, size: 100
{:unit μs, :min 61.923, :median 76.887, :max 161.738}

test: q, method: d/q2, size: 100
{:unit μs, :min 200.32, :median 213.523, :max 251.318}

tonsky / perf.html
Created May 24, 2015
Comparing perf and memory of mutable/immutable data structures
View perf.html
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
var hex_chars = "0123456789abcdef";
function rand_int(max) {
return Math.floor(Math.random() * max);
tonsky / .profile.boot
Created Mar 2, 2015
boot-clj plugin to report build status to AnyBar
View .profile.boot
(defn- send-udp [s port]
(with-open [socket (]
(let [group ( "localhost")
bytes (.getBytes s)
packet ( bytes (count bytes) group port)]
(.send socket packet)
(.close socket))))
(deftask anybar [p port VAL int "AnyBar port"]
(let [port (or port 1738)]
tonsky / Results
Created Jul 22, 2014
Transit performance comparison
View Results
[~/work/dataserver-perf] lein run -m transit-perf
Reflection warning, /private/var/folders/5b/l86qswcd6x55f8scs4xv16ch0000gn/T/form-init1230410416827476545.clj:1:949 - call to static method invokeStaticMethod on clojure.lang.Reflector can't be resolved (argument types: unknown, java.lang.String, unknown).
WARNING: Final GC required 8.516571405051678 % of runtime
Evaluation count : 4842 in 6 samples of 807 calls.
Execution time mean : 127.405503 µs
Execution time std-deviation : 2.807037 µs
Execution time lower quantile : 124.163041 µs ( 2.5%)
Execution time upper quantile : 130.326300 µs (97.5%)
tonsky / user.keymap
Created Jun 4, 2014
LightTable keymap of Sublime shortcuts
View user.keymap
{ :+
{ :editor
{ "pmeta-/" [:toggle-comment-selection]
"ctrl-shift-up" [:editor.sublime.selectLinesUpward]
"ctrl-shift-down" [:editor.sublime.selectLinesDownward]
"pmeta-d" [:editor.sublime.selectNextOccurrence]
"ctrl-m" [:editor.sublime.goToBracket]
"ctrl-shift-m" [:editor.sublime.selectBetweenBrackets]
"shift-pmeta-space" [:editor.sublime.selectScope]
"ctrl-pmeta-up" [:editor.sublime.swapLineUp]
You can’t perform that action at this time.