Skip to content

Instantly share code, notes, and snippets.

accordion-group {
background-color: #f7f7f7;
border-radius: 0.25em;
display: block;
margin-block-end: 1.5em;
padding: 0.5em 1em;
width: 100%;
}
accordion-group [accordion-trigger] {
@nichoth
nichoth / demo.ts
Created December 27, 2024 04:19 — forked from vedantroy/demo.ts
SQLite-backed key-value store with JS-like object manipulation and automatic JSON serialization.
import Database from 'better-sqlite3';
import { createDatabaseClient } from './proxy.ts';
// 1) Create an in-memory DB and your table(s).
const db = new Database(':memory:');
db.exec(`
CREATE TABLE users (
id TEXT PRIMARY KEY,
data JSON
);
@nichoth
nichoth / webtorrent_demo.js
Created December 11, 2024 19:01 — forked from swapnilshrikhande/webtorrent_demo.js
WebTorrent Configure Custom STUN / TURN Server
var client = window.client = new WebTorrent({
tracker: {
rtcConfig: rtcConfig
}
})
client.on('warning', onWarning)
client.on('error', onError)
torrent = client.add(TORRENT, onTorrent)
@nichoth
nichoth / fflate.md
Last active November 30, 2024 00:06 — forked from 101arrowz/README.md
How FFlate works

FFlate is the fastest, smallest, and most effective JavaScript compressor/decompressor currently; to create it, I used a variety of modified or optimized algorithms.

Part 1: The DEFLATE spec

The core of most popular compressed file formats is DEFLATE, or RFC1951. GZIP data, Zlib data, .zip files, PNG images, and more all use some variant of DEFLATE under the hood. At its core, the DEFLATE format is actually not too complex: it's merely a combination of Huffman coding and LZ77 compression.

If you don't understand either of these concepts, feel free to read the following subsections, or skip to Part 2 if you already know what these are and just want to get to implementation details.

Section I: Huffman Coding

Computers think of basically everything as numbers. The smallest unit of information in a computer is a single bit, which can only be either a 0 or a 1. When multiple bits are stringed together, they can be interpreted as a ba

@nichoth
nichoth / force-sync-jazz-state.ts
Created November 19, 2024 19:00 — forked from Schniz/force-sync-jazz-state.ts
force sync jazz state
async function forceSync(account: Account) {
const { syncManager } = account._raw.core.node;
const peer = Object.values(syncManager.peers)[0];
if (!peer) {
throw new Error("no peer");
}
const values = Object.values(account._raw.core.node.coValues).flatMap((x) => {
if ("coValue" in x.state) {
@nichoth
nichoth / crypto-pbkdf2.js
Created October 25, 2024 21:03 — forked from chrisveness/crypto-pbkdf2.js
Uses the SubtleCrypto interface of the Web Cryptography API to hash a password using PBKDF2, and validate a stored password hash against a subsequently supplied password. Note that both bcrypt and scrypt offer better defence against ASIC/GPU attacks, but are not available within WebCrypto.
/**
* Returns PBKDF2 derived key from supplied password.
*
* Stored key can subsequently be used to verify that a password matches the original password used
* to derive the key, using pbkdf2Verify().
*
* @param {String} password - Password to be hashed using key derivation function.
* @param {Number} [iterations=1e6] - Number of iterations of HMAC function to apply.
* @returns {String} Derived key as base64 string.
*
@nichoth
nichoth / building-sync-systems.md
Created June 24, 2024 17:28 — forked from pesterhazy/building-sync-systems.md
Building an offline realtime sync engine

So you want to write a sync system for a web app with offline and realtime support? Good luck. You might find the following resources useful.

Overview articles

@nichoth
nichoth / CYPHERLINK.md
Created March 15, 2024 22:40 — forked from dominictarr/CYPHERLINK.md
Cypherlinks
@nichoth
nichoth / Weekly Summary.md
Last active February 4, 2024 22:35 — forked from paprikka/Weekly Summary.md
Weekly Summary Template (Obsidian)

Carried Over

  • share a new drawing this week

Main Focus

[!NOTE] Progress on work. Don't rush.

It's Friday. I have a rough timeline for my work with XXX and we're discussing the specifics. I'm feeling tired, but not burned out. I feel like I have balance. I published every day. I learned something new (a piece of tech/concept) and I wrote about it. We planned our trip to XXX. I've spoken with my brothers.