Skip to content

Instantly share code, notes, and snippets.

@henryw374
henryw374 / tanstack-importmap-demo.js
Created November 7, 2023 16:50
tanstack react-router no build step
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>demo</title>
</head>
<body>
<div id="app" style="min-height:100%">
Hello world!
(ns com.widdindustries.kaocha-cljs2-ns-pattern-hook
"the only way I can find to filter kaocha-cljs2 tests by pattern. see comment block for usage"
(:require [kaocha.core-ext :as core-ext]
[kaocha.load :as load]))
(defn ns-filter [plan]
;(def plan plan)
;(println "About to start loading!")
(update plan :kaocha.test-plan/tests
(ns protocol-proxy
"for when you have an object foo, which satisfies some protocols and you want to make adhoc changes to
one or more of the protocol methods, but just on foo.
Can be handy for testing.
"
(:refer-clojure :exclude [proxy])
(:require [clojure.string :as string]))
;(remove-ns 'protocol-proxy)
(ns contiguous-spans
"takes pre-sorted dates and returns contiguous periods contained therein.
see comment block for demo
"
(:require [tick.core :as t]))
(defn contiguous-spans
"takes pre-sorted dates and returns contiguous periods contained.
dates a and b are contiguous if a plus span-length is equal to b "

hardware & os

  • dotfiles?
  • terminal & shell
  • editor
  • env setup - dbs, etc
  • how do you start you REPL?
  • deps or leningen?
  • new project template?
  • tasks automation - babashka?
  • how do you navigate in project?
@henryw374
henryw374 / kroki-read.bb
Last active July 4, 2022 17:50
encode and decode files as kroki url diagrams https://kroki.io/#try
#!/usr/local/bin/bb
(import '[java.io ByteArrayOutputStream])
(import '[java.util Base64]) ;
(import '[java.util.zip Inflater]) ;
(defn uncompress [source-bytes]
(let [inflater (doto (Inflater.)
(.setInput source-bytes))
outputStream (new ByteArrayOutputStream (count source-bytes))
@henryw374
henryw374 / adhoc_file_server.bb
Last active July 5, 2022 09:51
babashka adhoc file server
#!/usr/bin/env bb
; run the script from any dir to serve its files
(require '[babashka.deps])
(def deps '{:deps {io.github.babashka/http-server
{:git/sha "b38c1f16ad2c618adae2c3b102a5520c261a7dd3"}}})
(babashka.deps/add-deps deps)
@henryw374
henryw374 / same_thread_executor.clj
Created June 8, 2022 08:18
clojure executorservice concurrency testing
(ns same-thread-executor
"handy in unit tests to have things happen straight away"
(:import (java.util.concurrent ExecutorService Future)))
(defn executor []
(reify ExecutorService
(^Future submit [_ ^Callable f]
(let [r (f)]
(reify Future
(get [_] r))))))
@henryw374
henryw374 / kaocha-coverage-repl.clj
Created March 23, 2022 10:28
kaocha coverage repl
(slingshot.slingshot/try+
(kaocha.plugin.cloverage/cloverage-main-hook (kaocha.repl/config))
(catch :kaocha/early-exit m
(prn m)))
@henryw374
henryw374 / reagent_interval.cljs
Last active June 9, 2022 06:05
clojure reagent interval subscription
(ns com.widdindustries.reagent-interval
"functions to create reagent reactions (ie ratoms) whose value changes
as an argument function is called periodically"
(:require [reagent.ratom :as ratom]
[reagent.core :as r]))
(defn interval-async
"create ratom whose value will initially be initial-state,
and thereafter may change as f is called with the 'state' atom every delay-ms"
[f delay-ms initial-state]