Skip to content

Instantly share code, notes, and snippets.

/**
* demi-compact: a poor man's compaction.
*
* Instead of summarizing history into a single block, it truncates tool
* call inputs (to 80 chars) and drops tool result outputs entirely from
* messages older than the cutoff recorded when the user runs
* `/demi-compact`. The fact that a tool was called is preserved, but the
* verbose I/O that dominates token usage is stripped. User/assistant
* text remains fully intact.
*
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
import { Type } from "@sinclair/typebox";
import { spawn } from "node:child_process";
import { createWriteStream, mkdirSync, rmSync, existsSync, readdirSync, unlinkSync } from "node:fs";
import { join } from "node:path";
import { homedir } from "node:os";
const DISPATCH_LOG_DIR = join(homedir(), ".pi", "agent", "dispatch");
function ensureLogDir(): void {
#!/bin/bash
# Create frags directory if it doesn't exist
FRAG_DIR="$HOME/frags"
mkdir -p "$FRAG_DIR"
# Generate timestamp for filename
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
FILENAME="$FRAG_DIR/frag_${TIMESTAMP}.txt"
import pathlib
import string
import itertools
import random
from typing import Callable
roots = "select 100 as id"
def sql(nodes):
return "UNION ALL".join(["select 100 as id from {{ ref('%s') }}" % n for n in nodes])
@wrgoldstein
wrgoldstein / i.py
Last active December 20, 2023 17:29
dead simple activity recorder.
#!/opt/homebrew/bin/python3
import datetime
import sys
import os
from pathlib import Path
home = os.path.expanduser('~')
fname = f"{home}/whatidid"
if not os.path.isfile(fname):
import os
import requests
import collections
headers = {
'Accept': 'application/vnd.github+json',
'Authorization': 'Bearer ' + os.getenv('GITHUB_API_TOKEN', ''),
'X-GitHub-Api-Version': '2022-11-28',
}
from collections import Counter
from itertools import combinations
types = [1,2,3,4]
# creatures have 2 of the 4 types
# so there are c(4,2) = 6 creatures
creatures = list(combinations(types, 2))
# there are four creatures in each ocean
import pathlib
import collections
import jinja2
import graphlib
class Engine:
current = None
graph = collections.defaultdict(lambda: dict(deps=[], compiled=None, config={}))
env = jinja2.Environment(
import time
from random import randint
# make some dumb fake data
def make_row(r):
r = randint(1, 200)
s = [randint(r - min(r - 1, 15), r + 15) for _ in range(randint(1,6))]
return [r, s]
rows = [make_row(r) for r in range(500_000)]
@wrgoldstein
wrgoldstein / exla_gpu_instructions.txt
Last active April 19, 2023 15:08
Getting set up to do GPU accelerated machine learning in Elixir on a fresh Google Cloud Platform VM
# So you want to do machine learning in elixir on a fresh GCP VM with a GPU?
=== setup a VM ===
1. chose a gpu (T4), make sure you use debian 11 bullseye and the right region
2. dont use the default boot disk
3. do change the boot disk to have 50GB of space
4. get yourself a bunch of ram (for re-training BERT with 250 text samples 15Gb wasn't enough)
5. ssh in:
gcloud compute ssh instance-6