Skip to content

Instantly share code, notes, and snippets.

View wpcarro's full-sized avatar

William Carroll wpcarro

  • internet
View GitHub Profile
@wpcarro
wpcarro / serial.cpp
Created November 5, 2025 02:50
Serial server for toggle pins hi/lo Arduino Leonardo
static const int BLUE = 7;
static const int GREEN = 8;
void setup() {
Serial.begin(115200);
pinMode(BLUE, OUTPUT);
pinMode(GREEN, OUTPUT);
digitalWrite(BLUE, LOW);
digitalWrite(GREEN, LOW);
}
@wpcarro
wpcarro / entr.c
Created September 4, 2025 19:19
Poor Man's implementation of entr for Windows
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdbool.h>
#include <windows.h>
#include <assert.h>
#include "fixed_buffer_allocator.h"
@wpcarro
wpcarro / main.c
Created August 22, 2025 18:34
X-macros for enums
#include <stdio.h>
#include <string.h>
// Fully connected graph of transformations:
// Message (enum)
// MessageIndex (enum)
//
// Index -> Key
// Index -> Value
// Value -> Index (reverse lookup)
fn main() {
let mut rng = thread_rng();
println!("Vector");
for size in [1_000, 10_000, 50_000].into_iter() {
let mut xs = Vec::with_capacity(size);
for _ in 0..size {
xs.push(rng.gen_range(0..size));
}
@wpcarro
wpcarro / main.rs
Created December 31, 2024 22:12
Use evolutionary solver to assign Jobs to Machines in a factory.
//! Factory scheduling
use std::collections::HashMap;
use galapagos::{Config, Goal};
use rand::{thread_rng, Rng};
use textplots::{Chart, Plot};
type JobId = i32;
type MacId = i32;
@wpcarro
wpcarro / main.rs
Created December 23, 2024 05:21
Thread supervisor with restarts (multiple threads)
#[derive(Debug, Clone, Copy)]
enum ThreadState {
Unstarted,
InProgress,
Panicked,
Success,
}
fn main() {
let mut init = Vec::with_capacity(3);
@wpcarro
wpcarro / main.rs
Created December 23, 2024 04:45
Thread supervisor with restarts
#[derive(Debug, Clone, Copy)]
enum ThreadState {
Unstarted,
Panicked,
Success,
}
fn main () {
let x = Arc::new(Mutex::new(ThreadState::Unstarted));
@wpcarro
wpcarro / main.py
Created December 18, 2024 17:20
More durability experiments: read state from disk at startup with data integrity checks
import signal
import time
import random
import json
import os
import threading
import hashlib
lock = threading.Lock()
@wpcarro
wpcarro / main.py
Created December 18, 2024 17:03
More durability experiments (background thread, state mutations, locking)
lock = threading.Lock()
state = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
def persist_state():
print("Persisting state...")
tmp = "/tmp/buffer.json"
dst = "/tmp/dump.json"
with lock:
content = json.dumps(state)
with open(tmp, "w") as f:
@wpcarro
wpcarro / main.py
Last active December 18, 2024 17:02
Durable state (signal handling)
import signal
import time
import json
import os
state = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
def persist_state():
print("Persisting state...")
tmp = "/tmp/buffer.json"