Skip to content

Instantly share code, notes, and snippets.

View borkdude's full-sized avatar

Michiel Borkent borkdude

View GitHub Profile
@borkdude
borkdude / tictactoe.cljs
Created December 14, 2023 18:57
squint_react_tictactoe.cljs
(require '["react" :as react])
(require '["react-dom" :as rdom])
(def empty-board [[\- \- \-]
[\- \- \-]
[\- \- \-]])
(def init-state {:board empty-board :player \X})
(defn get-board-cell
@borkdude
borkdude / aoc23_01.cljs
Last active December 7, 2023 19:53
AOC 2023 day 3 in squint + TC39 Tuples
;; Helper functions:
;; (fetch-input year day) - get AOC input
;; (append str) - append str to DOM
;; (spy x) - log x to console and return x
;; original solution:
;; https://github.com/russmatney/advent-of-code/blob/master/src/_2023/_03/core.clj
(require '["https://unpkg.com/@bloomberg/record-tuple-polyfill" :as tc39])
@borkdude
borkdude / aoc_ui.cljs
Last active December 5, 2023 16:15
AOC ui boilerplate
(require '[clojure.string :as str])
#_(assoc-in! (js/document.querySelector "#compiledCode") [:style :display] :none)
(when-not (js/document.querySelector "#aoc_token")
(let [create-element (fn create-element [tag attributes]
(let [element (js/document.createElement tag)]
(doseq [[key value] attributes]
(aset element key value))
element))
@borkdude
borkdude / pinball.cljs
Last active November 17, 2023 23:54
Squint pinball
;; Adapted from: https://thegeez.net/2023/03/01/pinball_scittle.html
#_(do #_:clj-kondo/ignore (warn-on-lazy-reusage!))
(defn element [tag id child-of prepend?]
(or (js/document.getElementById id)
(let [elt (js/document.createElement tag)
parent (if child-of (js/document.querySelector child-of)
js/document.body)]
(set! (.-id elt) id)
@borkdude
borkdude / wordle.cljs
Created November 16, 2023 12:18
Squint wordle
(ns wordle)
(def board-state (atom []))
(def counter (atom 0))
(def attempt (atom 0))
(def word-of-the-day (atom "hello"))
(defn write-letter [cell letter]
(set! (.-textContent cell) letter))
@borkdude
borkdude / hoplon_demo.cljs
Last active October 27, 2023 12:28
hoplon demo
(ns view.index
(:require
[hoplon.core :as h]
[javelin.core :as j]))
(defn my-list [& items]
(h/div :class "my-list"
(apply h/ul (map #(h/li (h/div :class "my-list-item" %)) items))))
(defonce clicks (j/cell 0))
@borkdude
borkdude / uuidv1.clj
Created September 15, 2023 09:18
UUID v1 in babashka / Clojure
;; based on code from https://www.baeldung.com/java-uuid
;; translated to Clojure by ChatGPT, minus the hex numbers which I evaluated in jshell
(defn get-64-least-significant-bits-for-version1 []
(let [random (java.util.Random.)
random-63-bit-long (bit-and (.nextLong random) 4611686018427387903)
variant-3-bit-flag -9223372036854775808]
(bit-or random-63-bit-long variant-3-bit-flag)))
(defn get-64-most-significant-bits-for-version1 []
(defmacro <-
[& טופסים]
(let [[x & טופסים] (reverse טופסים)]
(loop [x x, טופסים טופסים]
(if טופסים
(let [טופס (first טופסים)
מתארגן (if (seq? טופס)
(with-meta `(~(first טופס) ~x ~@(next טופס)) (meta טופס))
(list טופס x))]
(recur מתארגן (next טופסים)))
@borkdude
borkdude / main.ts
Created February 24, 2023 20:34
Nbb with deno 1.31
import { loadString } from 'npm:nbb@1.2.168'
await loadString(`(prn (+ 1 2 3))`);
@borkdude
borkdude / test_args.clj
Created November 8, 2022 12:15
Clojure deftest with arguments
;; {:deps {org.babashka/cli {:mvn/version "0.5.40"}
;; babashka/fs {:mvn/version "0.1.11"}}}
(ns test-args
{:clj-kondo/config '{:lint-as {test-args/deftest clojure.core/defn}}}
(:require
[babashka.cli :as cli]
[clojure.test :as t :refer [is]]))
(def ^:dynamic *test-args* (cli/parse-opts *command-line-args*))