Skip to content

Instantly share code, notes, and snippets.


Roman Liutikov roman01la

View GitHub Profile
View aoc_2021_3.clj
(defn part-1 [input]
(->> input
(map seq)
(apply map list)
(map #(vals (into (sorted-map) (set/map-invert (frequencies %)))))
(apply map list)
(map (comp #(Integer/parseInt % 2) str/join))
(apply *)))
View aoc_2021_2.clj
(defn parse-input [input]
(->> input
(map #(let [[v n] (str/split % #" ")]
[v (Integer/parseInt n)]))))
(defn part-1 [input]
(->> (parse-input input)
(reduce (fn [[h d] [v n]]
(case v
View aoc_2021_1.clj
(defn part-1 [input]
(->> input
(partition 2 1)
(filter #(apply < %))
(defn part-2 [input]
(->> input
(partition 3 1)
(map #(apply + %))

This example illustrates an intersting side effect of Clojure's lazy sequences when used in re-frame subscriptions. The behaviour described below takes place only on initial subscribe call

(reg-sub :test/x-2
  (constantly [])
  (fn [_ _]
    (prn "evaluating body of " :test/x-2)
    (map #(do (prn "evaluating lazy seq returned from " :test/x-2) (inc %)) (range 3))))

(reg-sub :test/x-1
roman01la / analyze.clj
Created March 18, 2021 01:42
analyzing unused and undefined re-frame subscriptions via clj-kondo
View analyze.clj
(ns analyze.core
(:require [clj-kondo.core :as clj-kondo]
[clojure.set :as set]))
;; checks re-frame's :<- syntax
;; to mark dependency subscriptions as used
(def analyze-reg-sub
"(require '[clj-kondo.hooks-api :as api])
(fn [{node :node}]
(let [[_ kw & children] (:children node)
roman01la / core.clj
Created December 3, 2020 13:57
Day 2 - Advent of Code 2020
View core.clj
(->> (clojure.string/split (slurp "input_02") #"\n")
(map #(re-find #"(\d+)-(\d+) (\w): (\w+)" %))
(filter (fn [[_ min max char string]]
(>= (Integer/parseInt max)
(count (re-seq (re-pattern char) string))
(Integer/parseInt min))))
(->> (clojure.string/split (slurp "input_02") #"\n")
(map #(re-find #"(\d+)-(\d+) (\w): (\w+)" %))
roman01la / core.clj
Last active December 1, 2020 12:19
Day 1 - Advent of Code 2020
View core.clj
(def nums
(->> (str/split (slurp "input_01") #"\n")
(map #(Integer/parseInt %))))
(->> (for [x nums
y nums
:when (= 2020 (+ x y))]
(* x y))
(some identity))
roman01la / re-frame.clj
Last active October 21, 2020 11:32
Debugging re-frame subscriptions
View re-frame.clj
(:require [cljs.compiler :as cljsc]))
(defn- anonymous-function-declaration? [form]
(and (list? form)
(= 'fn (first form))
(vector? (second form))))
(defn- query-id->js-fn-name [query-id]
(let [ns-part (when-let [ns-part (namespace query-id)]
roman01la /
Last active June 29, 2020 12:39
Rum 0.12.0 release notes

Rum 0.12.0 release notes

Happy to announce that Rum 0.12.0 has been released.

Sablono -> Daiquiri

A major change in this release is Daiquiri — reworked fork of Sablono. The reason we went with a fork is to own the compiler/interpreter. Daiquiri removes input field wrappers, this was causing weird bugs with jumping caret. Similarly to Sablono, Daiquiri makes use of ClojureScript's type inference to reduce number of generated interpret calls when compiling Hiccup. This applies to primitive types such as number, string, array and function, and also anything that is hinted as js/React.Element, Rum components include the type hint implicitly.

Removed rAF based scheduling mechanism

Sablono's input wrappers exist because some ClojureScript React wrappers have their own update scheduling mechanism built on top of js/requestAnimationFrame which doesn't play well with input fields. In this release we've removed Rum's scheduler, which allowed us to remove input wr

View is-cljs-value.js
function googIsObject(v) {
var type = typeof v;
return "object" == type && null != v || "function" == type;
function isPrototype(v) {
return v === v.constructor.prototype;
function isCLJSType(v) {