Skip to content

Instantly share code, notes, and snippets.

View Ugbot's full-sized avatar
🏠
Working from home

Ben Gamble Ugbot

🏠
Working from home
View GitHub Profile
@Ugbot
Ugbot / microgpt.py
Created May 6, 2026 06:58 — forked from karpathy/microgpt.py
microgpt
"""
The most atomic way to train and run inference for a GPT in pure, dependency-free Python.
This file is the complete algorithm.
Everything else is just efficiency.
@karpathy
"""
import os # os.path.exists
import math # math.log, math.exp

TickMerge: A Multi-Level Merge Consensus Algorithm for Commit-Anywhere Distributed Streams

Ben Gamble


Abstract

TickMerge is a consensus algorithm for distributed streaming systems that achieves global ordering through deterministic merging rather than leader-based log replication. Existing consensus algorithms such as Raft and Paxos require a single leader to serialize all writes, creating a throughput bottleneck and an availability gap during leader elections. TickMerge eliminates the leader entirely: any node in the ring accepts writes to a local write-ahead level (L0), and a background merge process---coordinated by a circulating ring token---produces a deterministic global ordering across all nodes. The system separates the write path (Command) from the read path (Query) using a CQRS architecture with multiple storage levels (L0 through L-Merged), each providing progressively stronger consistency guarantees. Clients choose their consistency level per-read, ranging from local-only (L0) to

The Darcy Deception

Chapter One: Awakening

The Thames embraced him like a lover's caress, cold and possessive, her murky depths reluctant to release their quarry. Fitzwilliam Darcy's eyes opened beneath the water's surface, and with them came a clarity that cut through the fog in his mind like a blade through silk.

He should be dead.

The thought struck him with surprising detachment as his body moved with fluid precision, cutting through the current with strokes that spoke of training he could not recall. His lungs burned, yet he held his breath with the discipline of a man accustomed to life-or-death situations. When had he learned such control?

Breaking the surface near London Bridge, he gasped quietly—even his breathing measured and careful. The morning mist clung to his shoulders like secrets, and as he hauled himself onto the embankment with movements too graceful for a drowning man, fragments of knowledge flickered through his consciousness like candlelight in a draft.

@Ugbot
Ugbot / coinbase_data_tools.py
Created October 10, 2025 11:26
a single file that gets live coinbase prices and stores/streams them for use
#!/usr/bin/env python3
"""
Stream Coinbase Advanced‑Trade tickers through an asyncio websocket.
Depending on flags, either pipe raw JSON to Kafka, append to a Parquet file,
or read from the Parquet file to Kafka.
Modes:
-k : Stream Coinbase → Kafka (default)
-F : Stream Coinbase → Parquet file (row‑group streaming)
-FK : Read Parquet file → Kafka
@Ugbot
Ugbot / Dockerfile
Created June 17, 2025 09:39
docker-compose flink piamon
https://repo.maven.apache.org/maven2/org/apache/paimon/paimon-flink-1.20/1.0.1/paimon-flink-1.20-1.0.1.jar
-- Step 1: Set up environment to access the Paimon catalog
SET 'execution.runtime-mode' = 'batch';
SET 'table.dynamic-table-options.enabled' = 'true';
-- Step 2: Define the source table to read LAION Parquet files
CREATE TEMPORARY TABLE source_laion (
id STRING,
url STRING,
text STRING,
height INT,
@Ugbot
Ugbot / uv_read_file.c
Created May 23, 2024 17:10 — forked from inlife/uv_read_file.c
Sample for reading a file asynchronously using libuv
// Sample for reading a file asynchronously using libuv
// taken from https://www.snip2code.com/Snippet/247423/Sample-for-reading-a-file-asynchronously
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <uv.h>
static uv_fs_t openReq;
static uv_fs_t readReq;
@Ugbot
Ugbot / loader.py
Last active May 13, 2024 10:31
uploading from S3 into clickhouse
import json
import boto3
import csv
import io
from botocore.vendored import requests
s3Client = boto3.client('s3')
demo_query = """SELECT *
FROM s3('https://datasets-documentation.s3.eu-west-3.amazonaws.com/nyc-taxi/trips_*.gz', 'TabSeparatedWithNames')
import ast
import boto3
from botocore.exceptions import ClientError
def stream_s3_file(bucket: str, key: str, file_size: int, chunk_bytes=5000) -> tuple[dict]:
"""Streams a S3 file via a generator.
Args:
bucket (str): S3 bucket
key (str): S3 object path