Skip to content

Instantly share code, notes, and snippets.

View p7g's full-sized avatar
🌀
σ = ∀ᾱ. τ

Patrick Gingras p7g

🌀
σ = ∀ᾱ. τ
View GitHub Profile
@p7g
p7g / 1brc.py
Created December 3, 2025 02:09
1brc Python 3.14t
import io
import mmap
import os
from concurrent.futures import Future, ThreadPoolExecutor, as_completed
from dataclasses import dataclass
from pathlib import Path
@dataclass(slots=True)
class Stats:
@p7g
p7g / example.py
Created August 22, 2025 14:00
I wanted to try writing a thread pool 🤷
import time
from concurrent.futures import as_completed
from functools import partial
from .pool import Pool
def wait_and_return(n):
print(f"start {n}\n", end="")
time.sleep(n)
@p7g
p7g / map.txt
Created December 14, 2022 17:24
0 .................+.....................................................................
1 ................ooo....................................................................
2 ...............ooooo...................................................................
3 ..............ooooooo..................................................................
4 .............ooooooooo.................................................................
5 ............ooooooooooo................................................................
6 ...........ooooooooooooo...............................................................
7 ..........ooooooooooooooo..............................................................
8 .........ooooooooooooooooo.............................................................
9 ........ooooooooooooooooooo............................................................
@p7g
p7g / README.md
Last active December 8, 2022 00:31
webrtc demo

how to use

You are the signalling server

  1. turn on camera on both (dunno if required)
  2. create a peer on both
  3. create offer on one, paste into "add remote session description form" and submit
  4. copy answer from previous step and paste into "add remote session description form" in other client, submit
  5. copy ice candidates array from each client and paste into "add ice candidate" on other, submit both
@p7g
p7g / bf.rkt
Last active October 31, 2022 02:18
bf interpreter in racket
#lang racket
(define (tape-new)
(cons 0 (make-vector 1 0)))
(define (tape-inc tape amount)
(let ([pos (car tape)]
[vec (cdr tape)])
(vector*-set! vec pos (+ (vector-ref vec pos) amount))))
@p7g
p7g / recompose.py
Created August 2, 2022 13:12
Python regular expressions that can be composed into bigger regular expressions
"""
This is a really basic and dumb regexp engine to play with composable regular
expressions.
A Re object is basically just a pointer to some initial state and to some
accepting state. These states can each point to other states, forming an NFA-ε,
which can then be evaluated directly.
The cool thing is that you can just combine Re objects like this:
import textwrap
from csnake import (
AddressOf,
CodeWriter,
Function,
TextModifier,
Variable,
)
@p7g
p7g / 0_bf.joe
Created February 12, 2022 16:13
Manually translated joe -> C, this BF implementations runs only 14% slower than bf.c
// vim: ft=java
import joe.collections.ArrayList;
import joe.fs.File;
import joe.io.StdOut;
import joe.io.StdErr;
class Tape {
final ArrayList<uint> data;
uint pos;
@p7g
p7g / lis.py
Last active February 7, 2022 21:06
i have invented the LISt Processor
import operator
nil = ()
def nilp(l):
return l == nil
def cons(a, b):
return a, b
@p7g
p7g / bf.c
Created February 1, 2022 04:36
My fastest BF interpreter so far, using dynamic dispatch in C
#include <stdlib.h>
#include <stdio.h>
struct tape {
unsigned pos, capacity;
unsigned char *data;
};
void tape_init(struct tape *t)
{