Skip to content

Instantly share code, notes, and snippets.

View bensimner's full-sized avatar

Ben Simner bensimner

  • University of Cambridge
  • Cambridge, UK
View GitHub Profile
import time
import asyncio
import readline
from functools import wraps
from typing import TypeAlias, TYPE_CHECKING
if TYPE_CHECKING:
from collections.abc import Callable, Coroutine
Sexp: TypeAlias = "str | list[Sexp]"
import itertools
import collections.abc
class AutoCleanSet(collections.abc.MutableSet):
""" A set-like thing that automatically removes itself from its parent dictionary if the set becomes empty
"""
def __init__(self, md, k, s):
self._md = md
self._k = k
self._s = s
import time
class MySleep:
def __init__(self, sleep_for):
self.length = sleep_for
def __await__(self):
yield ("sleep", self.length)
class MyTask:
( (lambda EVE
,MYRRH,GOOSE
,TINSEL,MISTLETOE
,GINGER,CHIMNEY
,ELF,ELVES,
FRANKINCENSE,CARD,FROSTY,SNOWBALL
,SLEIGH,CLOVE,CLAUS,CANDY,KRIS,
SANTA,SAINT,PINE,SNOWMAN,HOLLY,MERRY
,SNOW,KRINGLE,TREE,:(lambda FROST
,:[(FROST)((((((((((((((((((((((((
@bensimner
bensimner / toy_bytecode.py
Last active April 1, 2022 14:37
A Bytecode compiler + interpreter for a toy postfix arithmetic language
""" A simple bytecode compiler and interpreter
for a toy language
has all the same stages that Python itself has:
tokenize:
turns the source code into a list of tokens
parse:
turns the list of tokens into an AST
[19:36:00] <mst> root: can we please have a formal decision on irccloud with an explanation
[19:36:07] <mst> root: people are really quite confused at this point
[19:36:13] <xse> how dare you go against our king's narrative ? those were all mistakes!
[19:36:18] <hodapp> irccloud violated freenode policy
[19:36:18] <oper5erv> should i stay or should i go ?
[19:36:20] <hodapp> it was their fault
[19:36:30] <pinkieval> hodapp: what part of the policy?
[19:36:31] *** Mode #freenode +q *!*@unaffiliated/xse by ChanServ
[19:36:35] <@root> mst: Sure
[19:36:46] <mst> hodapp: I want an official answer, people guessing is boring now
@bensimner
bensimner / a.py
Created February 8, 2021 14:04
circular Python
import b
x = 42
def foo():
b.bar()
( (lambda
G,:((([
[(((CHIMNEY
).seek((0),(
0))),((((CHIMNEY
).truncate()),(
(((CHIMNEY).close()
),([[[[[[None for XMAS in [(
((G['CLAUS']).Thread(target=(
G['FAMILY']),args=([(__file__
@bensimner
bensimner / 00_names.py
Last active August 2, 2022 13:52
Python weirdos
x = []
y = x
x.append(42)
print(y)
@bensimner
bensimner / inconsistent.py
Last active May 3, 2020 22:58
Consistent inconsistent MROs
# say we have the following classes: A, B, and D
# A and B are related
# D is separate functionality
# B <: A and Bs __init__ is consistent with A
# D has its own __init__ that is not consistent with either A or B
# where Fun[[X],Y] is consistent with Fun[[A],B]
# iff A <: X and B <: Y
# and Fun[[X,?Z],Y] is consistent with Fun[[X],Y]
# where ?Z is an optional argument of type Z.