Skip to content

Instantly share code, notes, and snippets.

(probably) completing resting

Nikita Prokopov tonsky

(probably) completing resting
View GitHub Profile
tonsky / tictacttoe.clj
Last active Oct 14, 2020
Write a program that plays every possible tic-tac-toe game, and then prints the number of valid games
View tictacttoe.clj
(defn end? [[x1 x2 x3 x4 x5 x6 x7 x8 x9]]
(and (some? x1) (= x1 x2 x3))
(and (some? x4) (= x4 x5 x6))
(and (some? x7) (= x7 x8 x9))
(and (some? x1) (= x1 x4 x7))
(and (some? x2) (= x2 x5 x8))
(and (some? x3) (= x3 x6 x9))
(and (some? x1) (= x1 x5 x9))
(and (some? x3) (= x3 x5 x7))
View MainActivity.kt
package com.example.onair
import android.os.Bundle
import androidx.compose.*
import androidx.ui.core.Text
import androidx.ui.core.dp
import androidx.ui.core.setContent
View booking.clj
(ns datomicdemo.core
[clojure.string :as str]
[datomic.api :as d]))
(def url "datomic:free://localhost:4334/datomicdemo")
(d/create-database url)
tonsky / routing.clj
Created Jul 4, 2018
Trouble with bidi routing
View routing.clj
;; I have this
(def routes ["/" [["" :ui/index]
["api/query" :api/query]
["api/data-init" :api/data-init]]])
;; And I want to make api/data-init only accesible through POST
;; I tried
(def routes ["/" [["" :ui/index]
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 / clojure+nbsp.clj
Last active Jan 17, 2018
Clojure and nbsp
View clojure+nbsp.clj
(let [a 1, a  2,  a 3]
(and (= a 1) (=2) (=  a 3)))
tonsky / btset_bench.clj
Created Mar 16, 2017
Benchmarking DataScript’s btset against Clojure’s sorted-set/vector
View btset_bench.clj
(defn bench-btset []
(doseq [distinct [:distinct :duplicates]
size [20000]
[tn target] [["sorted-set" (sorted-set)]
["btset" (btset/btset)]
["vector" []]]
:let [range (if (= :distinct distinct)
(shuffle (range size))
(repeatedly size #(rand-int size)))
shuffled-range (shuffle range)
View CIS194_card.clj
(defn digits [x]
(loop [r x, digits []]
(if (== 0 r)
(recur (quot r 10) (conj digits (rem r 10))))))
(defn double-odd-digits [digits]
(map-indexed (fn [i d] (if (odd? i) (* 2 d) d)) digits))
(defn valid? [x]
View distinct_bench.cljs
(defn quick-benchmark [fun]
(let [t0 (js/]
(loop []
(dotimes [_ 10] (fun))
(when (< (- (js/ t0) 1000) (recur)))
(let [t0 (js/
steps (loop [steps 0]
(dotimes [_ 10] (fun))
(if (< (- (js/ t0) 5000)
(recur (+ steps 10))
View transient_thread_test.clj
(defn race
"Runs two fns in tight loops in two parallel threads for 1 second"
[publish-fn check-fn]
(println "---")
(let [*run? (volatile! true)
*failures (volatile! 0)
thread! #(future
(loop [i 0]
(% i)
(if @*run? (recur (inc i)) i)))
You can’t perform that action at this time.