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
@pvh
pvh / automerge-patch-materializer
Created August 6, 2024 20:47
A POC of a JS patch applier for Automerge.
const putPatch = (obj: any, p: A.PutPatch) => {
const { path, value } = p
const tail = path.pop()
const local = path.reduce((acc, next) => acc[next], obj)
local[tail] = value
return obj
}
const splicePatch = (obj: any, p: A.SpliceTextPatch) => {
@jcxia43
jcxia43 / monaco-editor-for-function-call.js
Last active July 18, 2024 17:54
Add the OpenAI function call schema validation to monaco-editor
// OpenAI function call guide: https://platform.openai.com/docs/guides/gpt/function-calling
// JSON Schema reference: https://json-schema.org/understanding-json-schema/
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
validate: true,
schemas: [
{
uri: "http://myserver/foo-schema.json",
fileMatch: ["*"],
schema: {
@steveruizok
steveruizok / cache.ts
Last active March 31, 2023 14:43
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)!
}
@ladifire
ladifire / figma1.js
Created August 25, 2021 15:09
Learning Figma technology
window.executeFullscreenEmscriptenCode = () => {
var Module = typeof Module !== "undefined" ? Module : {};
Module = self["Module"] || {};
Module["noExitRuntime"] = true;
Error["stackTraceLimit"] = 100;
Module["onAbort"] = function(what) {
ABORT = true;
EXITSTATUS = 1;
var text = "abort(" + (what && !/^\d+$/.test(what + "") ? JSON.stringify(what) : "") + ")";
console.error(text);
@msteen
msteen / print-lezer-tree.ts
Last active May 1, 2024 21:05
Print Lezer Trees
// MIT License
//
// Copyright (c) 2021 Matthijs Steen
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
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

Async calls

<template>
<!-- 
When isLoading is true, the <div> is in the DOM, the <p> is not.
When isLoading is false, Vue will remove the <div> and add the <p> to the DOM,
at which point <MyComponent> will be created and passed the fetched data.
-->
@CatsMiaow
CatsMiaow / base62-bigint.ts
Last active June 1, 2024 11:30
BigInt Base62 Encoding
import * as assert from 'assert';
/**
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt
*/
export class Base62 {
private readonly base: bigint = BigInt(62);
private readonly charset: string[] = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
public encode(integer: string): string {
@ryandabler
ryandabler / IndexedDB example.js
Created May 2, 2018 01:50
Working example of an IndexedDB implementation to handle transactions surrounding a fake invoice database
const request = window.indexedDB.open("database", 1);
// Create schema
request.onupgradeneeded = event => {
const db = event.target.result;
const invoiceStore = db.createObjectStore("invoices", { keyPath: "invoiceId" });
invoiceStore.createIndex("VendorIndex", "vendor");
const itemStore = db.createObjectStore("invoice-items", { keyPath: ["invoiceId", "row"] });
@zats
zats / FindReplace.json
Last active August 30, 2024 13:25
Alternative spellings for some emojis according to /System/Library/PrivateFrameworks/CoreEmoji.framework/Versions/A/Resources/en.lproj/FindReplace.strings
{
"💍":"diamond | engagement ring | diamond ring | diamond rings | diamonds | engagement rings",
"🆎":"blood type AB",
"❣":"heart",
"🇱🇨":"Saint Lucia | Saint Lucian flag",
"🇮🇪":"Ireland | Irish flag",
"🇨🇮":"Côte d’Ivoire | Ivory Coast | Ivorian flag",
"💎":"diamond | gem | gemstone | jewel | diamonds | gems | gemstones | jewels",
"☠️":"skull and crossbones | poison | poisonous",
"👩‍💻":"technology worker | tech worker | technologist | techie | IT worker | Apple genius | woman in technology | woman tech worker | woman technologist | woman IT worker | woman in IT | woman Apple genius",