Skip to content

Instantly share code, notes, and snippets.

@glycerine
glycerine / insmap.go
Last active July 31, 2026 07:49
insertion-ordered map API example showing Get() and Get2()
/*
Copyright 2025 The Go Authors.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
@glycerine
glycerine / MFIC.md
Created July 1, 2026 04:40 — forked from pmarreck/MFIC.md
MFIC — Mechanically-Falsifiable Independent Control: a discipline for enforced tests and runtime checks that keep agents honest

MFIC — Mechanically-Falsifiable Independent Control

A discipline for checks that can't be fooled by the same mistake that produced the work.

Abstract. When the author of a piece of work — an LLM, or a human moving fast — can be confidently and silently wrong, the usual defenses fail quietly: a test written from the same mistaken assumption as the code passes while the code is broken. MFIC is the class of check that escapes this trap, defined by four properties that must all hold at once. It is Mechanical (cases swept by machine, not hand-picked, so nothing is silently omitted), Falsifiable (each case genuinely bites when the work is wrong, on inputs you couldn't pre-arrange to pass), Independent (its verdict comes from the contract or the data — a source the producer doesn't control — which is segregation of duties restated for software), and a real Control (it holds the authority to block the bad outcome, not merely log it). This is the COSO / Sarbanes-Oxley model of internal co

@glycerine
glycerine / self-describing-foreign-frames-v1.7.md
Last active May 2, 2026 01:05
self-describing-foreign-frames-v1.7.md add section 8.7 how re-used slots may get delay collection but safe

Self-Describing Foreign Frame Protocol

Specification v1.7


JIT compilers, games, audio, and soft-real-time applications frequently need both high performance foreign-code interoperation and relief from garbage collection pauses.

Note to readers: This document is an early draft of a model for memory-safe references that I've been working on for the last ~2 years. While I think it is quite promising, the design is unfinished. The "regions" that I present in this document have not been given a formal semantics, and I have not explained where they originate from. My goal is merely to convince you that the design is promising, and that if seen to completion, it would advance the frontier of zero-cost memory safety.

Update March 2025: I am working on a newer version of this proposal, that aims to simplify the model substantially. When I have finished that proposal, I will put a link here.

Update August 2025: Verdagon has written an awesome blog post that explains this proposal at a high level. I recommend you check it out!

Abstract

In this document, I present a novel model for memory-safe references that aims to significantly improve upon the Rust-inspired model that Mojo c

@glycerine
glycerine / kpc_demo.c
Created April 20, 2026 19:55 — forked from ibireme/kpc_demo.c
A demo shows how to read Intel or Apple M1 CPU performance counter in macOS.
// =============================================================================
// XNU kperf/kpc demo
// Available for 64-bit Intel/Apple Silicon, macOS/iOS, with root privileges
//
//
// Demo 1 (profile a function in current thread):
// 1. Open directory '/usr/share/kpep/', find your CPU PMC database.
// M1 (Pro/Max/Ultra): /usr/share/kpep/a14.plist
// M2 (Pro/Max): /usr/share/kpep/a15.plist
// M3: /usr/share/kpep/as1.plist
#!/usr/bin/env bash
set -euo pipefail
# patch-claude-code.sh — Rebalance Claude Code prompts to fix corner-cutting behavior
#
# What this does:
# Patches the npm-installed @anthropic-ai/claude-code cli.js to rebalance
# system prompt instructions that cause the model to cut corners, simplify
# excessively, and defer complicated work.
#
@glycerine
glycerine / buggy_test.go
Created May 7, 2025 06:45
Two scenarios under synctest here A) with a time.Sleep() that never returns; B) sleep commented, the synctest.Wait never returns. Why? Seems like both are bugs, but...??
package main
import (
"sync"
"sync/atomic"
"testing"
"testing/synctest"
"time"
"fmt"
@glycerine
glycerine / raft-single-server-changes-safety
Created April 23, 2025 18:20 — forked from ongardie/raft-single-server-changes-safety
Safety of Raft single-server membership changes
This is an attempt to show that Raft's safety is
preserved with single-server membership changes as
described in the dissertation plus the patch that a
leader may not append a new configuration entry to
its log until it's committed an entry from its
current term.
This extends the safety argument in the
paper/dissertation. The only part that's different
(as far as I can tell) for membership changes is Step
@glycerine
glycerine / go-env-with-msys2.md
Created April 26, 2020 01:07 — forked from voidexp/go-env-with-msys2.md
Go development environment on Windows with MSYS2

Go development environment on Windows with MSYS2

Normally, it is sufficient to grab the Go MSI installer from the website in order to set up the toolchain. However, some packages that provide Go wrappers for C libraries rely on cgo tool, which in turn, needs the GCC toolchain in order to build the glue code. Also, 3rd-party dependencies are usually hosted on services like GitHub, thus Git is also needed. This mini-guide illustrates how to setup a convenient development environment on Windows using MSYS2.

@glycerine
glycerine / gist:5bb156bdeea314b215fc2816500bd759
Created January 16, 2019 02:18
compare go1.12beta2 and go1.10.7 compile times
(env3) jaten@Jasons-MBP ~/go/src/github.com/cosmos72/gomacro (generate) $ go version
go version
go version go1.12beta2 darwin/amd64
(env3) jaten@Jasons-MBP ~/go/src/github.com/cosmos72/gomacro (generate) $ time go install -a -toolexec=time -x
time go install -a -toolexec=time -x
WORK=/var/folders/2x/hm9gp5ys3k9gmm5f_vzm_6wc0000gn/T/go-build619075523
mkdir -p $WORK/b004/
mkdir -p $WORK/b010/
cat >$WORK/b004/importcfg << 'EOF' # internal
# import config