Skip to content

Instantly share code, notes, and snippets.

@FeepingCreature
FeepingCreature / sonnet_is_fun.md
Created November 11, 2024 09:37
How to include sections from another Markdown file with Ruby (with AI)

Today at dayjob, my architect: "You should update the README as well. You know, I don't like having all the library environment variables copied into the service README. Can you just link to the submodule?"

Me, actually quite liking that all the variables are right there in the service README: "I wish there was an include directive for markdown."

Me, having access to Sonnet API via OpenRouter: "How hard is ad-hoc Markdown parsing anyway?"

"Hey Sonnet, can you..."

Hi! Need your help with a ruby/rake tool. I'm trying to ensure that my README includes environment variable snippets that are consistent with the submodules the service pulls in. Those have their own READMEs documenting their respective environment variables. So my idea is to throw in a very simple ruby markdown parser that just splits the file at sections (lines starting with #) and include directives (lines of the form [//] # (include path#section) and then just ensures that the text following the include directive matches the section in

Effective Dustmite

Dustmite is a tool written by CyberShadow that ships with the stock DMD download. It is a bug reducer.

Have you ever run into a compiler bug? Or some error message that you didn't understand, because it involved too much source code? Have you formed a theory about what was its cause, only for your simple testcase to end up unable to reproduce it? How does everybody else make those nice, simple testcases anyways? The answer is Dustmite.

How does that work? In fully general terms, Dustmite takes two things: a test folder, and a tester.

@FeepingCreature
FeepingCreature / git-centralize.py
Created July 4, 2024 10:30
git centralize tool, written by opus 3.5 sonnet
#!/usr/bin/env python3
# Warning: Undertested! May corrupt your git repos!
import os
import sys
import subprocess
import re
import argparse
import shutil
@FeepingCreature
FeepingCreature / event_queue_hang.md
Last active June 30, 2024 09:46
Investigating an Event Queue Hang: The Code Works Correctly

Investigating an Event Queue Hang

We had a fun bug last week that almost doubles as a logic puzzle. It makes perfect sense in hindsight, but as I was staring at it, it seemed every part of it was nailed down tight - until I spotted the obvious, natural assumption that had been violated from the start.

A bit of background. We're working with microservices propagating state with event streams. For a typical stream, most events will concern unrelated objects, so we parallelize them: each incoming event is assigned a key, and we accept parallel events so long as their keys don't collide with any events currently in progress. Furthermore, because we track our position in the input stream as a single number, we can't retire events as soon

Me

Hi! Programming challenge. I'm gonna paste the convo from IRC, names anonymized. Same challenge goes to you. :)
[16:31] <foo> do you wanna hear some nerd shit about my event queue impl and why it started hanging forever once we started using google rpc
[16:31] <baz> Shore
[16:31] * foo spent three days on this bug
[16:31] <bar> Distributed stuff?
[16:31] <foo> okay so we have an eventstoredb client at work that used to use the tcp api but we're switching to the (cool, new) eventstore db
[16:31] <foo> er\

#!/usr/bin/env python3
# Helper script that classifies the structure of a JSON object.
# Useful for getting an overview of novel JSON data.
# Created largely by Claude 3 Opus.
import json
import sys
class JSONType:
def is_similar(self, other):
@FeepingCreature
FeepingCreature / heapsizefactor.md
Last active January 11, 2024 13:29
The effect of heapSizeFactor on CPU and memory usage

The D GC

The D GC is tuned by default to trade memory for performance. This can be clearly seen in the default heap size target of 2.0, ie. the GC will prefer to just allocate more memory until less than half the heap memory is alive. But with long-running user-triggered processes, memory can be more at a premium than CPU is, and larger heaps also mean slower collection runs. Can we tweak GC parameters to make D programs use less memory? More importantly, what is the effect of doing so?

Adjustable parameters

auto service1 = ...;
assert(service1 !is null);
Service[] services = [service1, service2];
assert(services[0] !is null); /// this fails??
module test;
import core.memory : GC;
import core.sync.semaphore;
import core.sys.linux.sys.mman : MADV_DONTNEED, madvise;
import core.thread;
import std;
enum keys = [
"foo", "bar", "baz", "whee",
module test;
import core.memory : GC;
import core.sync.semaphore;
import core.thread;
import std;
static string[] keys = [
"foo", "bar", "baz", "whee",
"foo1", "foo2", "foo3", "foo4", "foo5", "foo6", "foo7", "foo8",