Skip to content

Instantly share code, notes, and snippets.

#define _GNU_SOURCE
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <pthread.h>
void *worker(void *data) {
int fd = open("/tmp/setloadavg", O_RDWR|O_CREAT|O_DIRECT);
# is this tmux.conf good in 2022? i dunno.
unbind C-b
# C-b is not acceptable -- Vim uses it
set-option -g prefix C-a
bind-key C-a last-window
# Allows us to use C-a a <command> to send commands to a TMUX session inside
# another TMUX session
type ary[T any] struct {
members [arraySize]T
len uint16
}
func (a *ary[T]) length() int {
return int(a.len)
}
func (a *ary[T]) set(index int, item T) {
import random
import statistics
# last qtr results
price = 229.52
market_cap = 222985351000
# this was fed into https://www.socscistatistics.com/tests/regression/default.aspx
q_rev_hist_mills = [5963, 5817, 5419, 5151, 4865, 4851, 4513, 3997, 3737, 3603, 3392, 3281, 3006, 2865, 2701, 2577, 2397, 2339]
import random
arr_values = [0, 60000000, 120000000, 240000000, 480000000]
arr_prob = [0.0625, 0.5, 0.25, 0.125, 0.0625]
arr_mult_values = [25, 50, 100]
arr_mult_prob = [0.70, 0.20, 0.10]

The other story begins with adding a C library extension to the monolith. This was some Python code that wrapped a C library which gave access to an internal data store. Unfortunately, the bindings had a bug in their string handling code. To get a string object that could be sent to the Python C APIs, it used a family of functions called PyString_FromString.

The developer writing these C bindings didn’t realize that strings are immutable in Python, and the C API documentation for strings doesn’t include that bit of information. To copy a string from the C world to Python-land, the bindings would first use this function to initialize a Python string to use as a buffer. It would fill said buffer with the string from the C side by poking at the object’s internal data structures. This did actually work, as it was never seen BEFORE it was filled nor was it modified AFTER it was sent across the wall to Python-land.

Then disaster struck. A configuration change caused the it-has-always-worked function to begin t

@rbranson
rbranson / desk.md
Last active March 3, 2021 00:41
Desk Gear

Desk Gear

Updated 2021-03-01

  • Steelcase AirTouch Sit-Stand Desk
  • Herman Miller Aeron Type C Chair
  • Ergotron LX Monitor Arm
  • 13" 2020 MacBook Pro
  • Dell U4320Q UltraSharp 43" 4K USB-C Monitor
  • Keychron K2 Keyboard with Blue Switches
// delimbuf is a byte buffer that tracks the "records" of data
// that is appended to it.
type delimbuf struct {
buf []byte
// Record offsets in the buffer are tracked as offsets relative
// to base. The purpose of this is to allow Shift() to quickly
// remove records without an O(N) operation to rebase the offsets
// stored in delims based on the shifted buffer contents.
//
package none
import "io"
func min(a int, b int) int {
if a < b {
return a
}
return b
}
@rbranson
rbranson / kill-fdb-master.sh
Created May 4, 2020 17:47
Bash script to kill FoundationDB FDB master process
#!/bin/bash
status_json=$(fdbcli --exec 'status json')
master_addr=$(echo $status_json | jq -r '.cluster.processes[] | select(.roles[].role == "master") | .address')
# extra status json stuff workaround to bug in 6.0 where an immediate exit causes the command to not be sent
fdbcli --exec "status json; kill; kill $master_addr; status json"