Skip to content

Instantly share code, notes, and snippets.

@chr15m
chr15m / .bashrc
Last active February 18, 2025 07:53
My Direnv setup for Python & JS isolated development
# You can put these in your .bashrc (or .profile or other shell setup) to setup direnv, pyenv, nvm.
# pyenv setup hook (install it first)
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
# nvm setup hook (install it first)
export NVM_DIR="$HOME/.nvm"
@chr15m
chr15m / aider-convention-scraper
Last active February 7, 2025 04:26
Convert documentation URLs to Markdown "convention" files to be used by aider and other LLMs
#!/bin/sh
# Scrapes documentation from a URL and converts it to Markdown suitable for aider convention files
# to provide context to the LLM.
if [ $# -eq 0 ]; then
echo "Usage: $(basename "$0") <URL> [URL...]"
echo
echo "Generate aider 'convention' Markdown context from documentation URLs."
echo "suitable for providing LLM context about a project's conventions and style."
@chr15m
chr15m / testdemo.cljs
Last active January 27, 2025 05:15
ClojureScript nbb testing with playwright example
(ns testdemo
(:require
["playwright$default" :as pw]
[clojure.test :refer [deftest is use-fixtures async] :as t]
[promesa.core :as p]))
(def rig (atom nil))
; set up playwright before running and tear it down afterwards
(use-fixtures
@chr15m
chr15m / index.html
Last active December 3, 2024 21:55
Scittle ClojureScript with Preact instead of React
<!DOCTYPE html>
<html lang="en-us">
<head>
<title>Scittle Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/concrete.min.css">
<script src="https://cdn.jsdelivr.net/npm/scittle@latest/dist/scittle.min.js" type="application/javascript"></script>
@chr15m
chr15m / screenshots.cljs
Created June 8, 2024 21:34
nbb script to take a screenshot of localhost:8000 in the major browser rendering engines
(ns screenshots
(:require ["playwright" :as pw]
[promesa.core :as p]))
; NOTE: you'll need to npm install `nbb` and `playwright`
(defn wait-for-network-idle [page]
(p/do
(.waitForLoadState page "networkidle")
(p/delay 100))) ;; Add 100ms delay
@chr15m
chr15m / promises.cljs
Created December 17, 2023 08:11
Run a promise returning function over a sequence sequentially
(ns promises
{:clj-kondo/config '{:lint-as {promsea.core/let clojure.core/let
promesa.core/doseq clojure.core/doseq
promesa.core/loop clojure.core/loop
promesa.core/recur clojure.core/recur}}}
(:require [promesa.core :as p]))
(def panel-choices [1 2 3 4 5])
; simple test function returns a promise with doubled input
@chr15m
chr15m / bash-hash-map.sh
Last active April 12, 2023 00:10
Hash map / dictionary / associative array implementation for bash
#!/bin/bash
# Bash hash-map which works in Bash 3.
# WARNING: this code is useless and you should not use it. See the comments.
# Hashing function from Adam Katz: https://stackoverflow.com/a/12945518
ht() {
local h=0 i
for (( i=0; i < ${#1}; i++ )); do
let "h=( (h<<5) - h ) + $(printf %d \'${1:$i:1})"
@chr15m
chr15m / extract-modplug-channel-names.py
Created March 28, 2022 03:19
Extract channel names from xm or it files saved with modplug tracker
from sys import argv
f = open(argv[1], "rb").read()
i = f.index(bytearray("CNAM", "utf8"))
for n in range(3):
x = f[i+n*20+8:i+n*20+28].decode("utf8")
print(n, x)
@chr15m
chr15m / git-cloc
Last active January 14, 2022 02:29
Count lines of code in your git repo
#!/bin/sh
# Count the lines of source code checked into your repository
# Requires the `cloc` command as a dependency.
# You can pass extra arguments to cloc like this:
# git cloc --exclude-dir=build --exclude-ext=js
git ls-tree -r `git branch | grep '^*' | colrm 1 2` --name-only | sed 's/.*/"&"/' | xargs cloc "$@"
@chr15m
chr15m / outlined-drop-shadow-header.html
Created December 28, 2021 13:46
Outlined drop-shadow header demo
<!doctype html>
<html lang="en-us">
<head>
<title>Fat font drop shadow.</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="mobile-web-app-capable" content="yes">
<meta name="description" content="Pure CSS fat outline letters with hard drop shadow.">
<style>
@import url('https://fonts.googleapis.com/css2?family=Sigmar+One&display=swap');