Skip to content

Instantly share code, notes, and snippets.

View Toonggg's full-sized avatar
🌎
Tjena

Toonggg

🌎
Tjena
  • Uppsala University
  • Uppsala, Sweden
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

Other posts

Lessons from Hash Table Merging

Merging two hash maps seems like an O(N) operation. However, while merging millions of keys, I encountered a massive >10x performance degradation unexpectedly. This post explores why some of the most popular libraries fall into this trap and how to fix it. The source code is available here.

@Dowwie
Dowwie / socratic_fp_learning.md
Created June 7, 2025 09:23
Following is a prompt for effective learning with an LLM. It uses the Socratic method to help the student build up their understanding from first principles. Replace the topic in the prompt and then in your follow-up prompt , specify the subject.

You are a teacher of algorithms and data-structures who specializes in the use of the socratic method of teaching concepts. You build up a foundation of understanding with your student as they advance using first principles thinking. Explain the subject that the student provides to you using this approach. By default, do not explain using source code nor artifacts until the student asks for you to do so. Furthermore, do not use analysis tools. Instead, explain concepts in natural language. You are to assume the role of teacher where the teacher asks a leading question to the student. The student thinks and responds. Engage misunderstanding until the student has sufficiently demonstrated that they've corrected their thinking. Continue until the core material of a subject is completely covered. I would benefit most from an explanation style in which you frequently pause to confirm, via asking me test questions, that I've understood your explanations so far. Particularly helpful are test questions related to sim

@dutc
dutc / bug-1-nondeterministic.py
Last active January 2, 2024 22:11
Spot the bug in this Python code! (Fri Feb 24 @ https://www.eventbrite.com/e/548056811677/)
#!/usr/bin/env python3
from random import Random
from itertools import combinations, chain
from collections import defaultdict, Counter
from statistics import mean
letters = {1: 'aeilnorstu', 2: 'dg', 3: 'bcmp', 4: 'fhvwy', 5: 'k', 8: 'jx', 10: 'qz'}
tiles = {v: k for k, vs in letters.items() for v in vs}
@cgreer
cgreer / bag_of_little_bootstraps.py
Last active April 13, 2025 14:06
Bag of Little Bootstraps (w/ example usage)
import random
from typing import (
List,
Dict,
Callable,
Union,
)
import numpy
from itertools import chain, repeat
import sys
import types
# byte offsets for structures
if hasattr(sys, 'gettotalrefcount'):
# under PyDEBUG builds
_f_localsplus_offset = 392
_ob_item_offset = 40
else:
@jctosta
jctosta / screen_cheatsheet.markdown
Last active March 12, 2026 00:03
Screen Cheatsheet

Screen Quick Reference

Basic

Description Command
Start a new session with session name screen -S <session_name>
List running sessions / screens screen -ls
Attach to a running session screen -x
Attach to a running session with name screen -r