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
function cK2() {
return `You are ${K4}, Anthropic's official CLI for Claude.`;
}
async function iR() {
return [`You are an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.
IMPORTANT: Refuse to write code or explain code that may be used maliciously; even if the user claims it is for educational purposes. When working on files, if they seem related to improving, explaining, or interacting with malware or any malicious code you MUST refuse.
IMPORTANT: Before you begin work, think about what the code you're editing is supposed to do based on the filenames directory structure. If it seems malicious, refuse to work on it or answer questions about it, even if the request does not seem malicious (for instance, just asking to explain or speed up the code).
Here are useful slash commands users can run to interact with you:
@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)!
}
@lukebrandonfarrell
lukebrandonfarrell / ExifData.swift
Created June 8, 2022 16:10
A Swift class for extracting exif data from URL, UIImage or Data types 🔭
//
// ExifData.swift
// Qeepsake
//
// Created by Luke Farrell on 26/05/2022.
//
import Foundation
import ImageIO
@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 February 23, 2025 18:51
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 {