Skip to content

Instantly share code, notes, and snippets.

@ttesmer
ttesmer / AD.hs
Last active December 27, 2025 06:03
Automatic Differentiation in 38 lines of Haskell using Operator Overloading and Dual Numbers. Inspired by conal.net/papers/beautiful-differentiation
{-# LANGUAGE TypeSynonymInstances #-}
data Dual d = D Float d deriving Show
type Float' = Float
diff :: (Dual Float' -> Dual Float') -> Float -> Float'
diff f x = y'
where D y y' = f (D x 1)
class VectorSpace v where
zero :: v
@pmonks
pmonks / java-members.clj
Last active June 29, 2026 07:49
Pretty prints results from clojure.reflect/reflect on an object or class in an idiomatic Clojure fashion
;
; Copyright © 2023 Peter Monks
;
; This Source Code Form is subject to the terms of the Mozilla Public
; License, v. 2.0. If a copy of the MPL was not distributed with this
; file, You can obtain one at https://mozilla.org/MPL/2.0/.
;
; SPDX-License-Identifier: MPL-2.0
;
(ns app.mappy
#?(:cljs (:require-macros app.mappy))
(:require #?(:clj [datascript.core :as d]) ; database on server
#?(:clj [clojure.data.csv :as csv])
[hyperfiddle.electric :as e]
[hyperfiddle.electric-dom2 :as dom]
[hyperfiddle.electric-ui4 :as ui]
#?(:cljs ["@openlayers-elements/core/ol-map" :as ol-map])
#?(:cljs ["@openlayers-elements/maps/ol-layer-openstreetmap" :as ol-layer-openstreetmap])
#?(:cljs ["@openlayers-elements/core/ol-layer-vector" :as ol-layer-vector])
(venv) # Exit:0 2023-03-12 16:59:27 [r2q2@Reformer#[:~/opt/llama.cpp]
$(: !605 ) ./main -m ./models/65B/ggml-model-q4_0.bin -t 8 -n 128
main: seed = 1678658429
llama_model_load: loading model from './models/65B/ggml-model-q4_0.bin' - please wait ...
llama_model_load: n_vocab = 32000
llama_model_load: n_ctx = 512
llama_model_load: n_embd = 8192
llama_model_load: n_mult = 256
llama_model_load: n_head = 64
llama_model_load: n_layer = 80
@jacobobryant
jacobobryant / deps.edn
Created April 18, 2023 17:16
Get # of unique slack channel participants per month
{:deps {clj-http/clj-http {:mvn/version "3.12.3"}
org.jsoup/jsoup {:mvn/version "1.11.3"}}}
@eneroth
eneroth / rama_electric.clj
Last active September 8, 2023 15:39
Rama + Electric
;; ## General helpers
(ns app.helpers.rama
(:require
[missionary.core :as m]
[taoensso.timbre :as timbre])
(:import
[com.rpl.rama Depot PState Path ProxyState$Callback RamaModule]
[com.rpl.rama.test InProcessCluster LaunchConfig]
[hyperfiddle.electric Failure Pending]))
@kitlangton
kitlangton / kyo.scala
Last active March 19, 2024 23:55
Kyo (Alt. Encoding Explorations)
package zero
import izumi.reflect.Tag
import Kyo.*
import scala.collection.View.FlatMap
type Id[T] = T
type Const[T] = [U] =>> T
type MX[T] = Any
@awwx
awwx / event_listener.cljc
Created March 27, 2024 03:48
A version of Electric's dom/on! which only needs to attach the event listener on mount and remove on unmount
; The goal here is to provide a coupling between Electric
; and JavaScript event listeners that's more idiomatic on the
; JavaScript side: namely, that the event listener can be
; attached only once on mount and only needs to be removed on
; unmount.
;
; The strategy is to use e/fn to convert the reactive event
; listener fn into a continuous flow of event listener functions,
; which we can then sample to get the latest listener function
; when an event occurs.
@awwx
awwx / mobserve.cljc
Last active October 24, 2025 02:28
observe Missionary task and flow events
;; SPDX-License-Identifier: EPL-2.0 OR MIT
(ns mobserve
(:require
[missionary.core :as m])
(:import
missionary.Cancelled))
;; Encapsulate differences between Clojure and ClojureScript
;; on how IFn and IDeref are implemented.
@GulgDev
GulgDev / example.js
Last active June 29, 2026 10:51
33-byte JS signal implementation
// Usage
const foo = signal();
// subscribe (callback must return a nullish value)
foo(() => console.log("subscriber #1"));
foo(() => console.log("subscriber #2"));
// fire and reset
foo(); // subscriber #1, subscriber #2
foo(); // nothing