Skip to content

Instantly share code, notes, and snippets.

@mrdomino
mrdomino / rc.h
Last active March 13, 2024 23:37
#pragma once
#include <cassert>
#include <cstdint>
#include <exception>
#include <new>
#include <type_traits>
#include <utility>
namespace detail {
@mrdomino
mrdomino / org.wholezero.watchpath.plist
Last active January 16, 2024 20:10
kill zsh with USR1 every time a path directory changes
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.wholezero.watchpath</string>
<key>ProgramArguments</key>
<array>
<string>/bin/zsh</string>
<string>-lc</string>
@mrdomino
mrdomino / valenquine.hs
Last active September 20, 2023 15:04
It’s a quine, almost.
t [] = []
t (c:[]) = []
t (c:cs) = c:t cs
g s = s ++ " and growing."
main = do
putStr s
print s
putStrLn $"m = (g.t)\n\n\n\n " ++ show m
s = "t [] = []\nt (c:[]) = []\nt (c:cs) = c:t cs\ng s = s ++ \" and growing.\"\nmain = do\n putStr s\n print s\n putStrLn $\"m = (g.t)\\n\\n\\n\\n \" ++ show m\ns = "
m = (g.t)
@mrdomino
mrdomino / stkintro.c
Last active September 15, 2023 13:27
compile with -lsigsegv
#include <inttypes.h>
#include <setjmp.h>
#include <signal.h>
#include <sigsegv.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
struct bond {
uintptr_t dof;
@mrdomino
mrdomino / iter.py
Last active September 15, 2023 01:28
#!/usr/bin/env python
"""
Example demonstrating O(1)-space iteration over binary trees.
"""
import weakref
class Node:
"""
A binary tree node with left-child, right-child, and parent pointers.
#include <cstdlib>
#include <exception>
#include <iostream>
#include <optional>
#include <sstream>
#include <utility>
#define LOG_IF(TEST, LEVEL) \
if (!(TEST)) { \
@mrdomino
mrdomino / zwatch.sh
Last active March 5, 2022 06:23
rsync source with destination every time any change occurs in source
#!/bin/sh
set -eu
trap "echo 'usage: $0 <pier> <base> [desk]' >&2" EXIT
pier=$1
base=$2
if [ 3 -eq $# ]; then
desk=$3
else
desk=base
fi
#!/usr/bin/env python3
import fileinput
import re
def main():
for line in fileinput.input():
if not re.search(r'^[0-9a-fA-F]+$', line):
continue
print('0x', end='')
line = line.strip().lstrip('0')
@mrdomino
mrdomino / patp.js
Created October 21, 2021 07:56
print 16 random @ps under a given star
// requires urbit-ob
const ob = require('urbit-ob');
const crypto = require('crypto');
const STAR = '~binzod';
const STAR_HEX = ob.patp2hex(STAR);
for (var i = 0; i < 16; ++i) {
const byt = crypto.randomBytes(2).toString('hex');
console.log('0x' + byt + '.' + STAR_HEX, ob.hex2patp(byt + STAR_HEX));
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static const char slash[] = "/";
int main(__attribute__((unused)) int argc, char* argv[]) {
char *self;