Skip to content

Instantly share code, notes, and snippets.

(probably) pixel hunting

Nikita Prokopov tonsky

(probably) pixel hunting
View GitHub Profile
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 / .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);
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 / 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"]
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))))
You can’t perform that action at this time.