Skip to content

Instantly share code, notes, and snippets.

View BrianHung's full-sized avatar
💻
LLMs + local-first apps = autocomplete

Brian Hung BrianHung

💻
LLMs + local-first apps = autocomplete
View GitHub Profile
@BrianHung
BrianHung / CodeMirror.ts
Last active March 10, 2024 23:25
CodeMirror NodeView for ProseMirror
import { autocompletion, closeBrackets, closeBracketsKeymap, completionKeymap } from '@codemirror/autocomplete';
import { defaultKeymap, history, historyKeymap, indentWithTab } from '@codemirror/commands';
import {
bracketMatching,
defaultHighlightStyle,
foldGutter,
foldKeymap,
indentOnInput,
LanguageDescription,
syntaxHighlighting,
@BrianHung
BrianHung / figma-dots.css
Created February 12, 2024 07:56
figma-dots.css
body {
background-image: radial-gradient(rgba(0, 0, 0, 0.1) 1px, transparent 0);
background-size: 16px 16px;
}
@BrianHung
BrianHung / prosemirror-history-combine-commands.ts
Last active February 6, 2024 08:08 — forked from anarchang/prosemirror-history-combine-commands.ts
Combine commands on the ProseMirror undo stack
/**
* Given two commands (commandA and commandB), returns a new command that when applied
* to a ProseMirror state that uses the prosemirror-history plugin applies commandA and
* then commandB so that both commands are undone with a single undo action.
**/
const combineCommands =
(commandA: Command, commandB: Command) =>
(state: EditorState, dispatch?: (tr: Transaction) => void): boolean => {
return commandA(state, (transactionA: Transaction) => {
const { state: stateA } = state.applyTransaction(transactionA)
@BrianHung
BrianHung / PatchRadixTrie.ts
Last active August 9, 2023 21:40
Compressing JSON Patches Without State
/* eslint-disable max-classes-per-file */
import { applyPatches, Patch } from "immer";
import invariant from "tiny-invariant";
class TrieNode {
children: Map<string | number, TrieNode>;
label: Patch["path"];
patch: Patch | undefined;
var short = require("short-uuid")
var translate = short("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
translate.toUUID("0s33UQWH9339VifYPjmRgC")
export function debounce<T extends (...args: any[]) => void>({
callback,
onStart,
onEnd,
delay = 100,
}: {
callback: T;
onStart?: T;
onEnd?: T;
delay?: number;
import {
observable,
IReactionDisposer,
reaction,
observe,
IObservableArray,
transaction,
ObservableMap,
Lambda,
isObservableArray,
function uniqueId(a = ''): string {
return a
? /* eslint-disable no-bitwise */
((Number(a) ^ (Math.random() * 16)) >> (Number(a) / 4)).toString(16)
: `${1e7}-${1e3}-${4e3}-${8e3}-${1e11}`.replace(/[018]/g, uniqueId)
}
@BrianHung
BrianHung / debounce.ts
Last active November 6, 2022 06:42
add start and end events to repeated / debounce function calls
export function debounce<T extends (...args: any[]) => void>({
callback,
onStart,
onEnd,
delay = 100
}: {
callback: T,
onStart?: T,
onEnd?: T,
delay?: number
import { types as t, type IAnyModelType, getSnapshot, onPatch } from "mobx-state-tree"
import invariant from "tiny-invariant";
import { validate as isUUID } from "uuid";
console.log("mobx");
const Cell = t.model("cell", {
id: t.refinement(t.identifier, id => isUUID(id)),
content: t.string,
row: t.reference(t.late((): IAnyModelType => Row)),