Skip to content

Instantly share code, notes, and snippets.

View subtleGradient's full-sized avatar
👋

Tom Aylott subtleGradient

👋
View GitHub Profile
@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"
@subtleGradient
subtleGradient / hotness.ts
Last active May 11, 2024 03:49
Hot reloading disposal events
/*
MIT No Attribution
Copyright 2024 Thomas Aylott
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.
/* eslint-disable @typescript-eslint/no-unused-vars */
"use client"
import { Suspense, use, useMemo } from "react"
import { Text } from "react-native"
import { waitForTransactionReceipt } from "src/lib/viem"
import { PromisedValue } from "src/utils/type-helpers"
import { Address } from "viem"
type TransactionReceipt = PromisedValue<ReturnType<typeof waitForTransactionReceipt>>
@subtleGradient
subtleGradient / CurrentServerTime.server.tsx
Last active March 21, 2024 01:30
example of what a re-renderable React server component could maybe look like?
"use server"
import { $ } from "bun"
export async function* CurrentServerTime() {
while (true) {
yield <html.input key="ONLY ME!" readOnly value={await $`time`.text()} />
await sleep(1_234)
}
}
@subtleGradient
subtleGradient / TCR.sh.command
Last active December 27, 2023 01:21
Test && Commit || Revert
#!/bin/bash
set -e # exit on error
set -u # exit on undefined variable
# set -o pipefail # exit on failure in pipe
# set -x # print commands as they are run
# if DEBUG is set, print commands as they are run
set +u # allow undefined variables for this check
if [ ! -z "$DEBUG" ]; then
set -x