Skip to content

Instantly share code, notes, and snippets.

@nichoth
nichoth / base64.ts
Last active November 14, 2025 20:48
Base64 tricks
function fromUrlEncoded (base64url:string):Record<string, any> {
const base64Url = token.split('.')[1];
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
return JSON.parse(atob(base64));
}
@nichoth
nichoth / crypto.ts
Created November 11, 2025 04:04
Perform Diffie-Hellman Key Exchange with the web crypto API (in a browser)
// Generate X25519 key pairs
async function generateX25519KeyPair(): Promise<CryptoKeyPair> {
return await crypto.subtle.generateKey(
{
name: "X25519"
},
true, // extractable
["deriveKey", "deriveBits"]
);
}
@nichoth
nichoth / constants.ts
Last active October 13, 2025 17:22
Some Constants, em dashes and things
export const NDASH = '\u2013'
export const EM_DASH = '\u2014'
export const NBSP = '\u00A0'
export const ELLIPSIS = '\u2026'
@nichoth
nichoth / grid.css
Last active September 17, 2025 03:56
Responsive grid
/*
see https://smolcss.dev/#smol-css-grid
*/
.smol-css-grid {
--min: 15ch;
--gap: 1rem;
display: grid;
grid-gap: var(--gap);
@nichoth
nichoth / index.html
Created August 17, 2025 02:00 — forked from pvh/index.html
Automerge unbundled vanilla example
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Automerge (Vanilla JS, Unbundled) Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<script type="module">
// The ?bundle-deps here is very dodgy...
@nichoth
nichoth / signals.html
Created August 13, 2025 21:57 — forked from KonnorRogers/signals.html
Lite Signals
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Signals</title>
</head>
<body>
<button id="decrement">
-
@nichoth
nichoth / puuppeteer3.js
Last active June 11, 2025 21:52
more puppeteer
// @ts-check
import puppeteer from 'puppeteer'
import fs from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const ANIMATION_FRAMES = 30 // 1/2 second
const outputDir = path.join(__dirname, '..', 'screenshots')
@nichoth
nichoth / puppeteer2.js
Created June 11, 2025 19:11
Puppeteer again
// @ts-check
import puppeteer from 'puppeteer'
import fs from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const URL = 'https://nolaai.webflow.io/'
@nichoth
nichoth / index.js
Last active June 11, 2025 18:52
puppeteer
import puppeteer from 'puppeteer'
import fs from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const URL = 'https://nolaai.webflow.io/'
const browser = await puppeteer.launch({