Skip to content

Instantly share code, notes, and snippets.

@richgel999
richgel999 / microgpt.py
Created June 17, 2026 06:12 — 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
@richgel999
richgel999 / gist:d522e318bf3ad67e019eabc13137350a
Created May 1, 2023 01:49
Dmitry Subbotin's original carry less range coder
//The context compressor, author M.Smirnov.
//The source also can be found at
//http://compression.graphicon.ru/
//usage:
//c infile outfile //encoding
//d infile outfile //decoding
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
@richgel999
richgel999 / gist:e51623c23efad4b3b2ba936305060926
Created April 13, 2023 15:05
BC1 (4 color blocks only) to BC7 transcoding experiments
struct bc7_block
{
uint8_t m_bytes[16];
};
static void write_bits(uint32_t val, uint32_t num_bits, uint8_t* pDst, uint32_t& bit_ofs)
{
assert((num_bits <= 25) && (val < (1U << num_bits)));
*(uint32_t*)(pDst + (bit_ofs >> 3)) |= (val << (bit_ofs & 7));
@richgel999
richgel999 / lz77.c
Created December 11, 2015 06:07 — forked from fogus/lz77.c
/* PROG1.C */
/* Simple Hashing LZ77 Sliding Dictionary Compression Program */
/* By Rich Geldreich, Jr. October, 1993 */
/* Originally compiled with QuickC v2.5 in the small model. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/* set this to 1 for a greedy encoder */