Skip to content

Instantly share code, notes, and snippets.

@joshnuss
joshnuss / index.html
Last active January 7, 2025 03:13
Signals experiment
<html>
<body>
<h1></h1>
<button onclick="decrement()">-</button>
<button onclick="increment()">+</button>
<script>
function signal(initial, callback = null) {
let value = initial
@joshnuss
joshnuss / epd1in54_V2.py
Created November 27, 2024 13:04
MicroPython driver for WaveShare 1.54" V2
from time import sleep_ms
from machine import SPI, Pin
from framebuf import FrameBuffer, MONO_HLSB
'''
Driver for Waveshare e-Paper 1.54in V2
Note: This is for V2, check for V2 sticker on back of module.
Datasheet: https://files.waveshare.com/upload/e/e5/1.54inch_e-paper_V2_Datasheet.pdf
@joshnuss
joshnuss / robots.txt
Created September 23, 2024 07:13
Block AI crawlers
User-agent: GPTBot
Disallow: /
User-agent: Google-Extended
Disallow: /
User-agent: Amazonbot
Disallow: /
User-agent: Applebot
@joshnuss
joshnuss / draggable.js
Created September 6, 2024 19:26
Draggable action for Svelte
/*
* Usage:
*
* <element use:draggable/>
*/
export function draggable(node) {
const bounds = node.getBoundingClientRect()
node.draggable = true
node.style.position = 'absolute'
@joshnuss
joshnuss / vite-plugin-sql.js
Last active July 10, 2024 17:20
Vite SQL plugin
import fs from 'node:fs/promises'
export function sql(url) {
return {
name: 'vite-plugin-sql',
// expose an import called 'sql:runtime'
resolveId(id) {
if (id.startsWith('sql:runtime')) {
return id
@joshnuss
joshnuss / NOTES.md
Last active June 16, 2024 03:11
Converting a JavaScript SvelteKit app to TypeScript

Converting a JavaScript SvelteKit app to TypeScript

  • Install typescript, tslib, and svelte-check for dev mode
pnpm i -D typescript tslib svelte-check
  • Add a tsconfig.json
@joshnuss
joshnuss / setup.js
Last active February 5, 2024 07:01
Vitest matchers for SvelteKit errors and redirections
import { expect } from 'vitest'
expect.extend({
async toError(promise, status, message=null) {
try {
await promise
return { pass: false, message: () => 'Expected an error to be raised.'}
} catch (actual) {
if (actual?.constructor?.name !== 'HttpError') {
@joshnuss
joshnuss / README.md
Last active November 18, 2023 06:02
Excellon drill format
<script>
import * as THREE from 'three'
import { SVGLoader } from 'three/examples/jsm/loaders/SVGLoader.js'
import { T, useThrelte } from '@threlte/core'
import { onMount } from 'svelte'
const { invalidate } = useThrelte()
const loader = new SVGLoader()
let wrapper
@joshnuss
joshnuss / .projections.json
Created May 5, 2023 21:48
vim-projectionist example for SvelteKit
{
"src/routes/*page.svelte": {
"alternate": [
"src/routes/{}page.js",
"src/routes/{}page.server.js"
],
"template": [
"<script>",
" export let data",
"</script>"