Skip to content

Instantly share code, notes, and snippets.

View roman01la's full-sized avatar
🇺🇦

Roman Liutikov roman01la

🇺🇦
View GitHub Profile
(defn part-1 [input]
(->> input
(partition 2 1)
(filter #(apply < %))
count))
(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
roman01la / analyze.clj
Created March 18, 2021 01:42
analyzing unused and undefined re-frame subscriptions via clj-kondo
(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
roman01la / core.clj
Created December 3, 2020 13:57
Day 2 - Advent of Code 2020
(->> (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))))
count)
(->> (clojure.string/split (slurp "input_02") #"\n")
(map #(re-find #"(\d+)-(\d+) (\w): (\w+)" %))
@roman01la
roman01la / core.clj
Last active December 1, 2020 12:19
Day 1 - Advent of Code 2020
(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
roman01la / re-frame.clj
Last active October 21, 2020 11:32
Debugging re-frame subscriptions
(ns utils.re-frame
(: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
roman01la / rum-0.12.0.md
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

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) {
var icons = [
"<svg height=\"32\" class=\"octicon octicon-mark-github text-white\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"32\" aria-hidden=\"true\"><path fill-rule=\"evenodd\" d=\"M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z\"></path></svg>",
"<svg height=\"24\" class=\"octicon octicon-x text-gray\" viewBox=\"0 0 12 16\" version=\"1.1\" width=\"18\" aria-hidden=\"true\"><path fill-rule=\"evenodd\" d=\"M7.48 8l3.75 3.75-1.48 1.48L6 9.48l-3.75 3.75-1.48-1.48L4.52 8 .77 4.25l1.48-1.48L6
(ns core-test
(:import [goog.net Jsonp]
[goog Uri]))
(def x "123")
(def y "456")
(def url
(str x y))