Skip to content

Instantly share code, notes, and snippets.

View pmarreck's full-sized avatar

Peter Marreck pmarreck

  • formerly senior engineer @ desk.com, chief engineer @ thredup.com, software engineer @ lifebooker.com. Director of Engineering @ addigence.com, currently available
  • Long Island, NY
  • 14:19 (UTC -04:00)
  • X @pmarreck
  • LinkedIn in/petermarreck
View GitHub Profile
@pmarreck
pmarreck / rm-safe.bash
Last active July 9, 2025 17:25
rm-safe: a safer rm, inspired by Solaris' safer rm
#!/usr/bin/env bash
# rm-safe: A safer 'rm' that moves files to trash
# Version: 4.0 (Refactored with integrated tests)
set -uo pipefail
# --- Configuration ---
readonly SCRIPT_VERSION="4.0"
readonly OS="$(uname)"
readonly USER_ID="$EUID"
@pmarreck
pmarreck / find_github_forks_with_file.bash
Last active July 3, 2025 17:52
A way to search all forks of a Github project to see if any of them already have a certain file, such as a flake.nix (the default)
#!/usr/bin/env bash
# find_github_forks_with_file
# Default values
REPO=""
FILE_TO_SEARCH="flake.nix"
MAX_JOBS=10
SCRIPT_NAME=$(basename "$0")
# Help function
@pmarreck
pmarreck / name-value-to-table.lua
Created April 14, 2025 22:37
name-value-to-table (in Lua) to convert name=value pairs (such as the output of env) into a pretty-printed table
#!/usr/bin/env luajit
--[[
name-value-to-table-lua: Read lines like FOO=bar and emit a pretty table.
Supports -i/--input <file> (or - for stdin), -o/--output <file> (or - for stdout),
--help, --test, and optional --key-width <n> --val-width <n>.
]]
local function print_help()
io.stdout:write([[Usage: name-value-to-table-lua [-i file] [-o file] [--key-width N] [--val-width N]
@pmarreck
pmarreck / ocr_system_prompt.bash
Created April 2, 2025 02:11
An OCR system prompt for an LLM
export const OCR_SYSTEM_PROMPT = `
Convert the following document to markdown.
Return only the markdown with no explanation text. Do not include delimiters like \`\`\`markdown or \`\`\`html.
RULES:
- You must include all information on the page. Do not exclude headers, footers, charts, infographics, or subtext.
- Return tables in an HTML format.
- Logos should be wrapped in brackets. Ex: <logo>Coca-Cola<logo>
- Watermarks should be wrapped in brackets. Ex: <watermark>OFFICIAL COPY<watermark>
- Page numbers should be wrapped in brackets. Ex: <page_number>14<page_number> or <page_number>9/22<page_number>
@pmarreck
pmarreck / jpegxl.bash
Created March 3, 2025 18:09
jpegxl: a bash function to make conversions to/from jpegxl easier!
#!/usr/bin/env bash
### jpegxl: a bash function to make conversions to/from jpegxl easier!
# Silence function - runs a command silently but preserves exit code
silence() {
"$@" >/dev/null 2>&1
return $?
}
@pmarreck
pmarreck / please.bash
Last active February 6, 2025 18:45
"please"- a bash function to ask an LLM to compose and run a bash command, with an approval/denial step
needs() {
command -v "$1" > /dev/null || { >&2 printf "%s is required- not installed or in PATH; %s\n" "$1" "${@:2}"; return 1; }
}
_generate_curl_api_request_for_please() {
needs jq;
local request args timeout model curl;
local curl=${CURL:-curl};
local model=${OPENAI_MODEL:-gpt-4o};
local timeout=${OPENAI_TIMEOUT:-30};
@pmarreck
pmarreck / not_so_nested_transactions.txt
Last active January 14, 2025 19:38
Chat w/Claude about databases with "real" nested transactions
Peter: Does any database do real nested transactions, instead of just savepoints or what have you?
Claude: Ah, my fellow transaction theory nerd!
Most databases indeed just fake it with savepoints or MVCC shenanigans. However, I'll raise you one better: FoundationDB (before Apple acquired and neutered it) actually implemented true nested transactions through a clever distributed protocol. The trick was that each subtransaction maintained its own read/write sets that would be merged upward on commit.
But here's where it gets interesting (and where I suspect you'll appreciate the functional angle): The cleanest theoretical model for nested transactions comes from the world of Software Transactional Memory (STM), particularly Haskell's implementation. It treats transactions as pure values that can be composed and nested arbitrarily, with proper isolation guarantees.
I'd bet with your Elixir background you've played with Mnesia's "activity" blocks? While not quite as mathematically elegant as Haskell's STM, it's
@pmarreck
pmarreck / replit.nix
Created September 30, 2024 14:39
Roc playground nix file for repl.it
# note: does not currently work?
{ pkgs ? import <nixpkgs> { } }:
let
rocPkgs = pkgs.fetchFromGitHub {
owner = "roc-lang";
repo = "roc";
rev = "main"; # Change to a specific commit or tag for stability
sha256 = "sha256-11yw9xh1719smxbp0ia03kkv6hrvw4l6hhvxjxa4w2i7wc2r6yqy"; # You can fetch the sha256 from `nix-prefetch-url`
};
@pmarreck
pmarreck / overzealous_ai.html
Created September 25, 2024 23:48
An example of arguably overzealous language policing in OpenAI's ChatGPT, a.k.a. "why open-source LLMs will ultimately win"
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Conversation</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f9f9f9;
#!/usr/bin/env bash
# OK, why tabs? Why resurrect this age-old nerd debate again?
# Very simple: It's an accessibility issue:
# https://adamtuttle.codes/blog/2021/tabs-vs-spaces-its-an-accessibility-issue/
# To set the default tab width on your terminal (which unfortunately defaults to 8),
# run: `tabs -2` (or whatever width you want), possibly in your dotfiles.
# is AWK set to anything? If not, prefer frawk, then gawk, then awk
[ -z "${AWK}" ] && export AWK=$(command -v frawk || command -v gawk || command -v awk)