Skip to content

Instantly share code, notes, and snippets.

View JGalego's full-sized avatar
🕹️
ai-to-zx.com

João Galego JGalego

🕹️
ai-to-zx.com
View GitHub Profile
@JGalego
JGalego / attogpt.py
Created February 24, 2026 09:52
AttoGPT ⚛️ Quark: Hi, I'm 10⁻¹⁸ meters and I hold the Universe together! / MicroGPT: I'm 50 LoC and I generate baby names. Wanna feel inadequate together?
"""
▄▀█ ▀█▀ ▀█▀ █▀█ █▀▀ █▀█ ▀█▀ ⚛️
█▀█ █ █ █▄█ █▄█ █▀▀ █
And God said, "Let there be quarks," and the quarks were very small. And God said, "Let there be MicroGPT," and it was even smaller.
"""
import os,math,random as R
if not os.path.exists("input.txt"):import urllib.request;urllib.request.urlretrieve("https://raw.githubusercontent.com/karpathy/makemore/988aa59/names.txt","input.txt")
D=[s.strip()for s in open("input.txt")if s.strip()];R.shuffle(D);C=sorted(set("".join(D)));B=len(C);V=B+1
class X:
def __init__(s,d,c=(),l=()):s.d,s.g,s.c,s.l=d,0,c,l
@JGalego
JGalego / tapegpt.rs
Created February 24, 2026 00:02
MicroGPT on a Wengert tape in pure Rust 🎞️🦀 Adapted from https://github.com/mplekh/rust-microgpt
#!/usr/bin/env -S cargo +nightly -Zscript
---
[package]
name = "microgpt"
version = "0.1.0"
edition = "2024"
---
//! Rust translation of Andrej Karpathy's microgpt, using a Wengert tape for
//! reverse-mode automatic differentiation instead of a pointer-based DAG.
//!
@JGalego
JGalego / microgpt.py
Last active February 23, 2026 22:44 — forked from karpathy/microgpt.py
microgpt in 100 lines of less-than-ideal Python code
"""Atomic GPT training & inference in pure Python. @karpathy, modified by @JGalego"""
import os, math, random; random.seed(42)
if not os.path.exists('input.txt'):
import urllib.request
urllib.request.urlretrieve('https://raw.githubusercontent.com/karpathy/makemore/988aa59/names.txt', 'input.txt')
with open('input.txt', encoding='utf-8') as f: docs = [l.strip() for l in f if l.strip()]
random.shuffle(docs)
uchars = sorted(set(''.join(docs)))
BOS, vocab_size = len(uchars), len(uchars) + 1
@JGalego
JGalego / jellyfish.py
Created February 11, 2026 12:37
Python port of the jellyfish 🪼 animation from the Wolfram Language snippet 🐺>>>🐍
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "matplotlib",
# "numpy",
# "pillow", # for GIF saving
# "ffmpeg" # for MP4 saving; ensure ffmpeg is installed and
# ]
# ///
@JGalego
JGalego / agents.ipynb
Last active January 7, 2026 19:43
Agents... agents everywhere!
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@JGalego
JGalego / vengeance.lean
Last active January 19, 2026 04:48
Proves that vengeance is not the optimal for Dantès in The Count of Monte Cristo ⚔️🕊️✨
/-
This file was generated by Aristotle.
Lean version: leanprover/lean4:v4.24.0
Mathlib version: f897ebcf72cd16f89ab4577d0c826cd14afaafc7
This project request had uuid: a1c7c561-6dc8-41fd-b0b2-72ead2fe9b02
-/
/-
We model the decision problem facing Edmond Dantès in The Count of Monte Cristo. We define two actions: `Vengeance` and `Forgiveness`. We assign utility values to the outcomes based on justice, inner peace, and love. We then prove that `Vengeance` is not the optimal action, as `Forgiveness` yields a higher utility.
@JGalego
JGalego / aristotle_tester.py
Last active December 29, 2025 11:28
Fill sorries and prove theorems using Aristotle by Harmonic 🏛️🦉🏺
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "aristotlelib >= 0.6.0",
# ]
# ///
r"""
Fill sorries and prove theorems using Aristotle by Harmonic 🏛️🦉🏺
@JGalego
JGalego / escape_the_herd.py
Created December 21, 2025 21:52
Control a 🐭 with your cursor to collect 🧀 while avoiding a rising herd of 🔴 enemies that hunt with flocking behavior! 🎮
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "pygame >= 2.6.1",
# ]
# ///
"""
An escape game where the player avoids enemies with flocking behavior and collects items.
Enemies exhibit herd behavior (separation, alignment, cohesion).
@JGalego
JGalego / json2toon.py
Created November 13, 2025 09:57
A simple JSON / JSONLines to TOON Converter 🐰
r"""
A simple JSON / JSONLines to TOON Converter
.------..
- -
/ \
/ \
/ .--._ .---. |
| / -__- \ |
| | | |
@JGalego
JGalego / Makefile
Created November 8, 2025 23:13
Michael Creutz's Z2 lattice gauge simulation
CFLAGS= -O2 -Wall
CC= gcc
LDFLAGS= -lm