Skip to content

Instantly share code, notes, and snippets.

View subtleGradient's full-sized avatar
👋

Tom Aylott subtleGradient

👋
View GitHub Profile

Key Architectural Patterns

  1. Functional Pull-Oriented Dependency Injection - Every function receives dependencies through a deps parameter. No imports of other functions, no side effects in pure functions.

  2. Result Type Pattern - Functions that can fail return Result<T, E>. Functions that cannot fail return values directly.

  3. Deep Imports Only - No barrel files. Import directly from specific files: import {...} from '@tinkerbot/pure/git.ts'

  4. Workspace Protocol - Internal dependencies use workspace:* protocol in package.json

@subtleGradient
subtleGradient / Flarm.ts
Last active March 15, 2025 23:46
How should we name the Deps/Props type?
export type Flarm = {"some other kind of opaque object":true; [Symbol.dispose]():void}
export const Flarm = type({"'some other kind of opaque object'":'true'})
/*
https://gist.github.com/subtleGradient/e7cef476dee252c1529903cd2487f441
MooTools gang ✊
shamelessly stolen from Daniel Steigerwald's Evolu
then modified / extended by Tom Aylott
https://github.com/evoluhq/evolu-private/blob/main/packages/common/src/Result.ts
*/ /*
@subtleGradient
subtleGradient / FragmentSubscription.tsx
Last active January 25, 2025 19:11
RSC setState equivalent. Streaming server subscription re-renders via AsyncIterable ReactElements over the wire via RSC protocol and React 19
import "server-only"
import { StreamingFragment } from "@frens/reframe/Micro.ClientComponents"
import { ReactElement } from "react"
import { AsyncIterable$forEach } from "../etc/AsyncIterable$forEach"
import { MaybePromise, RenderQ } from "../types"
interface FragmentSubscriptionProps<Event> {
signal: AbortSignal
fallback?: ReactElement
@subtleGradient
subtleGradient / combine_files_to_markdown.ts
Created October 23, 2024 20:31
combine a bunch of files into a single markdown file to paste into an AI or whatever
#!/usr/bin/env -S bun
import { readdir } from "fs/promises"
// Function to read and format file content
async function readFileContent(filePath: string): Promise<string> {
const file = Bun.file(filePath)
const content = await file.text()
const extension = filePath.split(".").pop()
if (extension === "md" || extension === "mdx") return content.replace(/^(#+) /gm, "#$1 ") // increase heading levels by 1
const codeBlockSyntax = getSyntaxForExtension(extension)
/// <reference types="@frens/reframe/micro-apps" />
import ui, { clientManifest, missingClientComponents as todo } from "@frens/reframe/Micro.ClientComponents"
import React from "react"
import ReactServerDOMServer, { type BundlerConfig } from "react-server-dom-webpack/server"
import { PassThrough } from "stream"
import { withAsyncIterableTimeout } from "../AsyncIterableTimeout"
type GenUI = (props: { ui: typeof ui; todo: typeof todo }) => React.ReactNode
@subtleGradient
subtleGradient / ql-add.bun.tsx
Created June 26, 2024 00:30
Add Quicklook support for any random file extension
#!/usr/bin/env bun
import { $, BunFile, file } from "bun"
type CFBundleDocumentType = {
CFBundleTypeName: "Content"
CFBundleTypeRole: "QLGenerator"
LSItemContentTypes: ["public.data", "public.content", ...string[]]
LSTypeIsPackage: false
NSPersistentStoreTypeKey: "XML"
@subtleGradient
subtleGradient / hello.loo
Created June 25, 2024 03:00
Loose Lang Machine v0.2024.06.24 examples
#!/usr/bin/env lool
print Hello, World! or something like that
#!/bin/bash
function filter_until_hung() {
local match_string="$1"
shift
local cmd=("$@")
local tmpfifo=$(mktemp -u)
mkfifo "$tmpfifo"
"${cmd[@]}" >"$tmpfifo" 2>&1 &
@subtleGradient
subtleGradient / ql-add.bun.ts
Last active May 14, 2024 16:24
Bun.sh script to add a new LSItemContentType to ~/Library/QuickLook/QLStephen.qlgenerator/Contents/Info.plist for any file path
#!/usr/bin/env bun
import { $, BunFile, file } from "bun"
type CFBundleDocumentType = {
CFBundleTypeName: "Content"
CFBundleTypeRole: "QLGenerator"
LSItemContentTypes: ["public.data", "public.content", ...string[]]
LSTypeIsPackage: false
NSPersistentStoreTypeKey: "XML"