Skip to content

Instantly share code, notes, and snippets.

View graffhyrum's full-sized avatar

Joshua Pendragon graffhyrum

View GitHub Profile
@graffhyrum
graffhyrum / arktype-results.ts
Last active September 9, 2025 17:52
Wrap any arktype type in neverthrow to easily add validation to a callback chain.
import {ArkErrors, type TraversalError, type Type} from 'arktype';
import {err, ok, type Result} from 'neverthrow';
type ArkTypeOut<T> = T extends Type<infer Out, infer _Scope> ? Out : never;
type ArkTypeScope<T> = T extends Type<infer _Out, infer Scope> ? Scope : never;
export function toArkResult<
// biome-ignore lint/suspicious/noExplicitAny: generic function
ArkType extends Type<any,any>,
const Out extends ArkTypeOut<ArkType>,
@graffhyrum
graffhyrum / index.ts
Last active August 31, 2025 20:27
Validate and Parse process environment variables with Arktype.
import {validateAndParseEnv} from './schema';
const goodMockProcEnv = {
HOST: 'localhost',
PORT: '8080',
KEY: '1234567890',
SECRET: '1234567890',
EXTRAKEY: 'foo', // extra keys are ignored
};
@graffhyrum
graffhyrum / decompose-stepdown.md
Created August 29, 2025 23:34
LLM prompt to apply some of my most-used cleanups to a file.

This is a prompt I use often to improve readability of a module. With something like Claude custom slash commands you can map these to an alias for easy use.

Prompt:
Analyze this code in the context of the following rules and apply appropriate refactoring.

Summary:
The goal of these rules is to improve readability within a file. 
It is highly valuable to start at the top of the abstraction hierarchy 
@graffhyrum
graffhyrum / _idx.md
Last active August 29, 2025 23:32
AI summarize my day

This is a short LLM prompt to have the tool read your git history and summarize what you did in the project. It's nice to have. With something like Claude custom slash commands you can map these to an alias for easy use.

// summarize-day.md
Read through my git commit history for today and summarize what I did in a file with the filename `${yyyy-mm-dd}_Summary.md`. 
Create a 'worklog' folder in the root of this project, and save the markdown there.
@graffhyrum
graffhyrum / _Summary.md
Last active July 17, 2025 16:07
Typescript Clean Architecture Filtering Layer

Clean Architecture Filtering Layer: Design Patterns and Implementation

Overview

This code sample demonstrates a complete filtering layer implementation that adheres to clean architecture principles. The system provides type-safe, configurable filtering for business entities while maintaining strict separation of concerns and dependency inversion.

Architecture Layers

Domain Layer (Innermost)

The domain layer contains pure business entities and value types with no external dependencies:

/**
* Creates a typed key-value pair object to work around TypeScript issue #13948.
* This function preserves the literal type of the key in the resulting object type.
*
* @see [source](https://github.com/microsoft/TypeScript/issues/13948#issuecomment-1333159066)
*
* @example
* const obj = createTypedKeyValue('userId', 123);
* // obj has type: { userId: number } with literal key preservation
*

This script is a vetting tool designed to automate the process of running tests, retrying failures if necessary, and saving the results of each test cycle to a session-specific directory. Here's a summary of its functionality:

Key Features and Workflow:

  1. Session Setup:

    • Creates a session-specific directory based on the current timestamp and Git branch name.
    • Ensures the base directory (vetting-results) exists and creates the session directory recursively.
  2. User-Specified Test Parsing:

    • Parses command-line arguments to extract user-specified tests to run.
@graffhyrum
graffhyrum / LoggingWrapper.ts
Last active May 23, 2025 17:50
A proxy wrapper for services to allow logging functionality for requests, responses, and errors.
import { file } from 'bun'
import { mkdirSync, existsSync } from 'node:fs'
import { join } from 'node:path'
const logFolder = 'LogFolder'
const logFilePath = join(process.cwd(), logFolder, 'proxy.log')
// Ensure the log folder exists
if (!existsSync(logFolder)) {
mkdirSync(logFolder)
/**
* ProcessEnvFacade is an object that provides methods to interact with environment variables.
* It provides methods to get, set, and validate environment variables.
*/
const ProcessEnvFacade = {
getValueOrThrow: (key: keyof NodeJS.ProcessEnv): string => {
const maybeKey = process.env[key];
if (!maybeKey) {
throw new Error(`Environment variable ${key} is not set`);
}
@graffhyrum
graffhyrum / find-my-file.yaml
Created November 1, 2024 16:46
A Github Action that provides debug information about file paths.
name: 'Find My File'
description: 'Action that provides debug information about file paths'
inputs:
runnerOs:
description: 'The runner operating system'
required: true
filename:
description: 'The filename to search for'
required: true