Skip to content

Instantly share code, notes, and snippets.

(probably) Eating sandwich

Nikita Prokopov tonsky

(probably) Eating sandwich
Block or report user

Report or block tonsky

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ini.clj
(ns ini
(require [clojure.string :as str]
[ :as log])
(use clojure.test))
(defn read [content]
(-> content
(str/replace #"\\\s*($|\n\s*)" "")
View read-chunks.clj
(def ^:dynamic chunk-size 17)
(defn next-chunk [rdr]
(let [buf (char-array chunk-size)
s (.read rdr buf)]
(when (pos? s)
(java.nio.CharBuffer/wrap buf 0 s))))
(defn chunk-seq [rdr]
(when-let [chunk (next-chunk rdr)]
View config-parse.clj
(require '[clojure.string :as str])
(defn parse-line [line]
(let [line (str/replace line #"[\\]\s*(\n\s*|$)" "")]
(when-not (str/blank? line)
(let [[k v] (str/split line #"=" 2)]
[(str/trim k) (when-not (str/blank? v) (str/trim v))]))))
(defn parse [text]
(let [lines (str/split text #"(?<![\s\\])\s*\n")]
View react.cljs
(defn component [ref render-fn & {:keys [on-mount on-unmount]}]
(let [comp (React/createClass (clj->js
{ :render (fn [] (crate/html (render-fn @ref)))
:componentDidMount (or on-mount identity)
:componentWillUnmount (or on-unmount identity) }))]
(add-watch ref :react
(fn [_ _ old new]
(when (not= old new) (.forceUpdate comp))))
View network.clj
(:use [task02 helpers query])
(:require [ :as io]
[clojure.string :as str])
(:import [ Socket ServerSocket InetAddress InetSocketAddress SocketException]))
(def inactive-timeout 20000)
;; Объявить переменную для синхронизации между потоками. Воспользуйтесь promise
(def ^{:private true :dynamic true} *should-be-finished* nil)
View in_threads.clj
(defn opening? [sym]
(when (symbol? sym)
(.endsWith (name sym) ">")))
(defn closing? [sym]
(when (symbol? sym)
(.startsWith (name sym) "<")))
(defn split-closing [t exprs]
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]
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 / .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 / 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);
You can’t perform that action at this time.