Skip to content

Instantly share code, notes, and snippets.

View splch's full-sized avatar

Spencer Churchill splch

View GitHub Profile
"""
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
@spava
spava / progress.py
Last active March 5, 2023 08:09
a simple and useful progress bar in python
import sys
import time
def progress(iterable, length=33):
count = avg = 0
total = len(iterable)
then = time.time()
for it in iter(iterable):
yield it
@raxoft
raxoft / xorshift.asm
Created May 22, 2015 07:36
Fast quality Xor-Shift random number generator for Z80 I have created to weed out the crap RNGs out there. 28 bytes, 122 T cycles, period 2^32-1.
; 8-bit Xor-Shift random number generator.
; Created by Patrik Rak in 2008 and revised in 2011/2012.
; See http://www.worldofspectrum.org/forums/showthread.php?t=23070
org 40000
call rnd ; BASIC driver
ld c,a
ld b,0
ret
@darccio
darccio / pearson-hashing.c
Last active December 10, 2025 03:00
Pearson hashing (just for fun). Includes Ruby and Golang versions for RFC 3074 and original variants.
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
/*
* Pearson hashing (from Wikipedia)
*
* Pearson hashing is a hash function designed for fast execution on processors with 8-bit registers.
* Given an input consisting of any number of bytes, it produces as output a single byte that is strongly
* dependent on every byte of the input. Its implementation requires only a few instructions, plus a