Skip to content

Instantly share code, notes, and snippets.

@chrisdone
chrisdone / trigger-href.js
Created November 27, 2024 10:00
htmx trigger-href extension
// Define the custom HTMX extension
htmx.defineExtension('trigger-href', {
onEvent: function(name, evt) {
// <https://htmx.org/events/#htmx:afterProcessNode>
if (name == 'htmx:afterProcessNode') {
const es = evt.detail.elt.querySelectorAll('a[hx-trigger-href]');
for (const e of es) {
if (typeof e.href == 'string') {
e.addEventListener('click',(e) => {
e.stopPropagation();
@chrisdone
chrisdone / variants.hs
Created November 17, 2024 20:29
variants fragment
--------------------------------------------------------------------------------
-- Variants
-- NB: By the types here, you can't construct a @Variant NilL@.
data Variant xs where
LeftV :: forall k a xs. a -> Variant (ConsL k a xs)
RightV :: Variant xs -> Variant (ConsL k a xs)
-- Construction:
bar :: Variant (ConsL "String" Text (ConsL "Number" Double NilL))
@chrisdone
chrisdone / 0readme.md
Last active October 12, 2024 20:48
GHC JS backend
BUILDKIT_PROGRESS=plain docker image build . -t ghc-javascript:2024-10-10
$ docker run -v`pwd`:`pwd` -w`pwd` --rm ghc-javascript:2024-10-10 ghcjs HelloJS.hs
[1 of 2] Compiling Main             ( HelloJS.hs, HelloJS.o )
[2 of 2] Linking HelloJS.jsexe
@chrisdone
chrisdone / hell-http.hs
Created June 30, 2024 21:17 — forked from chrisdone-artificial/hell-http.hs
hell-http.hs demo
#!/usr/bin/env hell
-- How to run this:
--
-- socat TCP-LISTEN:8081,fork,reuseaddr,max-children=20 EXEC:"./handler.hell"
main = do
line <- Text.getLine
let content =
Text.concat ["<h1>Hello, World!</h1><p>This is generated by Hell.</p><pre>", line, "</pre>"]
@chrisdone
chrisdone / great.md
Created September 28, 2023 19:14
My experience trying out GHC webassembly
23-09-28 20:13:14.751 $ nix shell https://gitlab.haskell.org/ghc/ghc-wasm-meta/-/archive/master/ghc-wasm-meta-master.tar.gz --extra-experimental-features nix-command  --extra-experimental-features flakes
error: flake 'https://gitlab.haskell.org/ghc/ghc-wasm-meta/-/archive/master/ghc-wasm-meta-master.tar.gz' does not provide attribute 'packages.x86_64-linux.defaultPackage.x86_64-linux', 'legacyPackages.x86_64-linux.defaultPackage.x86_64-linux' or 'defaultPackage.x86_64-linux'
@chrisdone
chrisdone / shoe.el
Created July 13, 2023 16:01
shoe.el
(defun shoe-write-script (script)
"Write SCRIPT to the proper place."
(let* ((script-dir (shoe-script-dir script))
(script-path (shoe-script-file-path "/" script-dir)))
(with-temp-file script-path (insert script))))
(defun shoe-script-file-path (script &optional dir)
"Produce the file path for SCRIPT."
(concat (or dir (shoe-script-dir script))
"/"
{-
Examples:
> reify @Int $ eval $ A (reflect (abs :: Int -> Int)) (I (-9))
9
> reify @Int $ eval $ A (A (reflect ((*) :: Int -> Int -> Int)) (reflect @Int 3)) (reflect @Int 5)
15
FROM ubuntu:20.04
RUN apt-get update -y
RUN apt-get install -y python pip
COPY . /home/chris/Work/alphacephei/vosk-server
WORKDIR /home/chris/Work/alphacephei/vosk-server
RUN pip install -r requirements.txt && pip3 install sounddevice
RUN apt-get install -y libportaudio2
import System.Posix.Signals
main = do
mainId <- RIO.myThreadId
_ <-
installHandler
softwareTermination
(CatchOnce
(do S8.putStrLn "Received SIGTERM. Killing main thread."
killThread mainId))
@chrisdone
chrisdone / cell-load.hs
Last active May 4, 2022 08:45
Document cell-load pipeline
-- | Load a renamed cell.
resolveRenamedCell ::
Map Hash (Either LoadError LoadedExpression)
-> FillerEnv LoadError
-> IsRenamed (Expression Renamed)
-> RIO DocumentReader (Either LoadError (IsResolved (Expression Resolved)))
resolveRenamedCell globalTypes globalHashes isRenamed = do
hasConstraints <-
pure $
first LoadGenerateError $