Skip to content

Instantly share code, notes, and snippets.

View konsumer's full-sized avatar

David Konsumer konsumer

View GitHub Profile
@konsumer
konsumer / ThemeSelect.jsx
Last active December 12, 2025 10:18
Switches daisyui theme (body:data-theme). Optionally, it will follow user's media-preference, and persists their choice.
import { component$, useSignal, useVisibleTask$ } from '@builder.io/qwik'
// switches daisyui theme (body:data-theme)
// optionally, it will follow user's media-preference, and persists their choice
export default component$(({ themeDark = 'dark', themeLight = 'light', useDarkPref }) => {
const theme = useSignal(true)
useVisibleTask$(() => {
if (localStorage.theme) {
document.body.dataset.theme = localStorage.theme
@konsumer
konsumer / d1_diff_migrate.sh
Last active November 7, 2025 00:47
Say you have a remote D1 database called "DB". You can run this to produce a diff-migration for structure.sql: `./d1_diff_migrate.sh feature1 DB structure.sql`, then run `npx -y wrangler d1 migrations apply DB`
#!/bin/bash
# this will create a D1 migration that diffs the current remote database
set -eo pipefail
if ! command -v npx &> /dev/null; then
echo "npx needs to be in your path." >&2
exit 1
fi
// for https://www.tztstore.com/goods/show-7983.html
// put this in Arduino/libraries/TFT_eSPI/
#define USER_SETUP_INFO "CYD"
#define ILI9341_2_DRIVER
#define TFT_INVERSION_ON
#define TFT_WIDTH 240
#define TFT_HEIGHT 320
@konsumer
konsumer / pi-gen.sh
Created July 8, 2025 21:43
Basic pi-gen config for arm64 pi image (lite)
git clone https://github.com/RPi-Distro/pi-gen.git
cd pi-gen
git checkout arm64
cat << EOF > config
IMG_NAME=nullos-pi-lite-bookworm-aarch64
PI_GEN_RELEASE="NullOS Pi"
RELEASE=bookworm
TARGET_HOSTNAME=nullos
KEYBOARD_KEYMAP=us
@konsumer
konsumer / fflatefs.js
Last active June 21, 2025 09:17
Stupidly-minimal fs that uses fflate on the zip. It's just enough to load js carts, and read files, but not much else.
// stupidly-minimal fs that uses fflate on the zip
// it's just enough to load js carts, and read files, but not much else
import * as fflate from 'fflate' // https://esm.sh/fflate/esm/browser.js
const FILETYPE_REGULAR_FILE = 4
const FILETYPE_DIRECTORY = 3
export default async function fflatefs(cartUrl) {
const info = {}
@konsumer
konsumer / fflate.js
Created June 21, 2025 09:14
stupidly-minimal fs that uses fflate on the zip
// stupidly-minimal fs that uses fflate on the zip
// it's just enough to load js carts, and read files, but not much else
import * as fflate from 'fflate' // https://esm.sh/fflate/esm/browser.js
const FILETYPE_REGULAR_FILE = 4
const FILETYPE_DIRECTORY = 3
export default async function fflatefs(cartUrl) {
const info = {}
@konsumer
konsumer / 0_toolgen.py
Last active October 20, 2024 00:16
Generate AI tool description from a python file
from docstring_parser import parse
import tools
def tool_parse(tools):
"""
build AI tools-definition from python functions & docs
"""
toolsOut = []
for fname in dir(tools):
if not fname.startswith('__'):
@konsumer
konsumer / mime.c
Created September 24, 2023 11:37
Rudimentary mimetype detection, from first few bytes, in C.
#include "stdio.h"
// Get more from https://en.wikipedia.org/wiki/List_of_file_signatures
const char* detectMime(unsigned char* bytes) {
if (bytes[0] == 0xFF && bytes[1] == 0xD8 && bytes[2] == 0xFF) {
return "image/jpeg";
}
if (bytes[0] == 0x89 && bytes[1] == 0x50 && bytes[2] == 0x4E) {
return "image/png";
import 'https://cdn.jsdelivr.net/pyodide/v0.23.4/full/pyodide.js'
import setup from 'https://konsumer.js.org/raylib-python-web/python-raylib-web.js'
class RaylibPythonComponent extends HTMLElement {
constructor () {
super()
this.shadow = this.attachShadow({ mode: 'open' })
this.canvas = document.createElement('canvas')
this.style.display = 'none'
window.addEventListener('resize', this.onResize.bind(this))
@konsumer
konsumer / demo.sh
Last active September 4, 2023 07:14
Quick wasm demo with raylib
#!/bin/bash
wget https://github.com/raysan5/raylib/releases/download/4.5.0/raylib-4.5.0_webassembly.zip
unzip raylib-4.5.0_webassembly.zip
cd raylib-4.5.0_webassembly/
wget https://raw.githubusercontent.com/raysan5/raylib/master/examples/core/core_basic_window.c
emcc -Os -I./include -s USE_GLFW=3 -s ASYNCIFY -DPLATFORM_WEB -o index.html core_basic_window.c lib/libraylib.a
npx -y live-server