Skip to content

Instantly share code, notes, and snippets.

@guest271314
guest271314 / javascript_engines_and_runtimes.md
Last active October 23, 2025 13:24
A list of JavaScript engines, runtimes, interpreters

V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++. It is used in Chrome and in Node.js, among others. It implements ECMAScript and WebAssembly, and runs on Windows 7 or later, macOS 10.12+, and Linux systems that use x64, IA-32, ARM, or MIPS processors. V8 can run standalone, or can be embedded into any C++ application.

SpiderMonkey is Mozilla’s JavaScript and WebAssembly Engine, used in Firefox, Servo and various other projects. It is written in C++, Rust and JavaScript. You can embed it into C++ and Rust projects, and it can be run as a stand-alone shell. It can also be [compiled](https://bytecodealliance.org/articles/making-javascript-run-fast-on

@steveruizok
steveruizok / cache.ts
Last active May 8, 2025 03:01
weak map gist
export class Cache<T extends object, K> {
items = new WeakMap<T, K>()
get<P extends T>(item: P, cb: (item: P) => K) {
if (!this.items.has(item)) {
this.items.set(item, cb(item))
}
return this.items.get(item)!
}
@pesterhazy
pesterhazy / building-sync-systems.md
Last active October 25, 2025 03:18
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

@oranoran
oranoran / MarkdownField.ts
Last active August 18, 2023 19:35
Payload CMS - alternative rich text editor using rich-markdown-editor
import React, { useCallback, FunctionComponent } from 'react'
import { useField } from 'payload/components/forms'
import { Field } from 'payload/types'
import Editor from 'rich-markdown-editor'
// Make sure to never re-render the editor, since it tracks the value on its own.
const MemorizedEditor = React.memo(Editor, (prev, next) => prev.id === next.id)
type FieldWithPath = Field & { path?: string }
@Aslemammad
Aslemammad / mutableSource.tsx
Last active June 1, 2024 03:34
Consistent version of useMutableSource.
// Consistent version of `useMutableSource`, Inspired by https://github.com/pmndrs/valtio/blob/master/src/useMutableSource.ts
import { useEffect, useRef, useState } from 'react';
const TARGET = Symbol('target');
const GET_VERSION = Symbol('getVersion');
export type Source<TargetType extends any, VersionType extends any> = {
[TARGET]: TargetType;
[GET_VERSION]: (target: TargetType) => VersionType;
};
import json1 from 'ot-json1'
const integerRegEx = /^\d+$/
function isInteger (v) {
return Boolean(v.match(integerRegEx))
}
export function patchAtomToOpAtom (patchOp) {
const { path, op, value } = patchOp
const pathArray = path.split('/').slice(1).map(pathItem => {
@samwillis
samwillis / y-pouchdb.ts
Last active April 16, 2025 17:04
(Alpha) PouchDB integration for Yjs
import * as Y from 'yjs'
import * as mutex from 'lib0/mutex.js'
import { Observable } from 'lib0/observable.js'
import PouchDB from 'pouchdb';
// This is the name of the top level Y.Map that is used to construct the main pouchDB
// JSON document.
const topDataYMapName = 'data';

So this is kind of a multi stage plugin system. Let me explain:

Plugins get sent to the makeUseTable constructor, which then type the available options usable on useTable.

const useTable = makeUseTable({
  plugins: [myPlugin],
})

function App() {
@pesterhazy
pesterhazy / indexeddb-problems.md
Last active October 21, 2025 03:41
The pain and anguish of using IndexedDB: problems, bugs and oddities

This gist lists challenges you run into when building offline-first applications based on IndexedDB, including open-source libraries like Firebase, pouchdb and AWS amplify (more).

Note that some of the following issues affect only Safari. Out of the major browsers, Chrome's IndexedDB implementation is the best.

Backing file on disk (WAL file) keeps growing (Safari)

When this bug occurs, every time you use the indexeddb, the WAL file grows. Garbage collection doesn't seem to be working, so after a while, you end up with gigabytes of data.

Random exceptions when working with a large number of indexeddb databases (Safari)

import * as React from "react";
import { useMousePosition } from "~/hooks/useMousePosition";
/** Component to cover the area between the mouse cursor and the sub-menu, to allow moving cursor to lower parts of sub-menu without the sub-menu disappearing. */
export function MouseSafeArea(props: { parentRef: React.RefObject<HTMLDivElement> }) {
const { x = 0, y = 0, height: h = 0, width: w = 0 } = props.parentRef.current?.getBoundingClientRect() || {};
const [mouseX, mouseY] = useMousePosition();
const positions = { x, y, h, w, mouseX, mouseY };
return (
<div