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 / scrollbar.css
Last active May 30, 2024 06:08
scrollbar.css
::-webkit-scrollbar {
height: 1rem;
width: 0.5rem;
}
::-webkit-scrollbar:horizontal {
height: 0.5rem;
width: 1rem;
}
@BrianHung
BrianHung / Resizable.tsx
Created May 23, 2024 06:50
Horizontal Resizable React Component
import React from 'react';
const ResizableDiv = function ResizableDiv(props: { onChange: (dx: number) => void }) {
const { onChange = () => null, ...otherProps } = props;
const resizeRef = React.useRef<HTMLElement | null>(null);
const [resizing, setResizing] = React.useState(false);
const handlePointerDown = React.useCallback(
(event: React.PointerEvent) => {
@BrianHung
BrianHung / setGlobalRootColor.js
Created May 22, 2024 05:00
Prefers Color Scheme JavaScript React
export function setGlobalRootColor() {
try {
const rootElement = document.documentElement;
const classList = rootElement.classList;
classList.remove('light', 'dark');
const themePreference = localStorage.getItem('theme');
if (themePreference === 'system' || (!themePreference && true)) {
const prefersDark = '(prefers-color-scheme: dark)';
const darkModeMediaQuery = window.matchMedia(prefersDark);
@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,