Skip to content

Instantly share code, notes, and snippets.

@Deraen
Deraen / queries.cljs
Last active October 4, 2024 19:07
Cljs and TanStack Query
(ns foo.queries
(:require [foo.query :as q])
;; I suggest having a simple JS Fetch wrapper or something.
;; Maybe one which works with route-names (from Reitit route-data?) and renders the paths
;; with given parameters.
(defn get-todo-query [id]
#js {:queryKey #js ["todo" id]
:enabled id
(ns cursive.llm.api.malli-repro
(:require [clojure.data.json :as json]
[clojure.string :as str]
[malli.core :as m]
[malli.transform :as mt]))
(defn decode-type
"This is required for decoding :type fields, otherwise they are not
converted and don't dispatch properly."
[x]
@Deraen
Deraen / spread_props.clj
Created December 13, 2023 09:48
UIx spread props
(ns common.util
(:require [clojure.string :as str]
[uix.compiler.attributes :as attr]
[uix.compiler.js :as js]))
;; Could also just emit Object.assign, a bit simpler and doesn't need js*.
;; Spread operator might be a bit faster in some cases, but depends on
;; the browser and many variables probably.
;; https://clojurians.slack.com/archives/CNMR41NKB/p1701179422380989
;; We might not want to keep this optimized version in the repo and
@Deraen
Deraen / linters.clj
Created December 13, 2023 09:40
UIx MUI linter
(ns dev.linters
(:require [cljs.analyzer :as ana]
[clojure.string :as str]
[uix.linter :as linter])
(:import (cljs.tagged_literals
JSValue)))
(defn mui-component? [tag]
;; TODO: Could check better if it looks like a MUI component
(symbol? tag))
@Deraen
Deraen / reagent-latency.cljs
Created November 10, 2022 18:45
Testing React vs Reagent update latency
(def start (atom nil))
(def log (atom []))
(defn latency-test []
(let [a (r/atom 0)]
(fn []
(let [[b update-b] (react/useState 0)]
(react/useEffect
(fn []
alias: TV valot
description: ""
trigger:
- platform: state
entity_id:
- media_player.tv
not_to:
- unknown
for:
seconds: 5
@Deraen
Deraen / shadow.clj
Created May 4, 2022 12:13
Shadow CLJS and Dart Sass
(ns app.dev.shadow
(:require [shadow.cljs.devtools.api :as shadow]
[clojure.edn :as edn]))
;; Run this with:
;; npx shadow-cljs clj-run app.dev.shadow/watch
(set! *warn-on-reflection* true)
(defn watch
@Deraen
Deraen / test.js
Last active April 25, 2021 13:02
react-use-context-test.js
var vm = require("vm");
var fs = require("fs");
function nodeGlobalRequire(file) {
var _module = global.module,
_exports = global.exports,
exportedRequire = false;
// to circumvent Node.js environment detection in bundled libraries
global.module = undefined;
@Deraen
Deraen / linting_ideas.md
Last active October 4, 2019 13:43
Ideas for linter checks

Merge with map literal

(merge a {:a 1 :b 2}) -> (assoc a :a 1 :b2)

(-> foo (merge {:foo :bar}) -> (-> foo (assoc :foo :bar))

Reasoning:

  • Performance
  • Easier to read?
@Deraen
Deraen / react-konva-image.cljs
Last active May 29, 2019 07:34
React Konva example with Reagent
(ns example.react-konva-image
(:require [reagent.core :as r]
;; This presumes Shadow-cljs (or cljsjs packages with correct definitions)
[react-konva :refer [Stage Layer Image]]
[use-image :as use-image]))
(defn lion-image []
(let [[image] (use-image "https://konvajs.org/assets/lion.png")]
(r/as-element [:> Image {:image image}])))
;; or, without Reagent hiccup -> React elements step, directly creating React element: