Skip to content

Instantly share code, notes, and snippets.

@bsolomon1124
bsolomon1124 / timeit.py
Created June 21, 2018 14:40
Decorator version of `timeit.repeat()`
import functools
import gc
import itertools
from timeit import default_timer as _timer
_repeat = functools.partial(itertools.repeat, None)
def timeit(repeat=3, number=1000):
"""Decorator: prints time from best of `repeat` trials.
@bsolomon1124
bsolomon1124 / structures.py
Created June 20, 2018 20:07
Dictionary subclasses supporting dot access for keys.
"""Dictionary subclasses supporting dot access for keys."""
__all__ = ['AccessDict', 'SafeAccessDict']
__author__ = 'Brad Solomon <[email protected]>'
class AccessDict(dict):
"""Dictionary with dot access, setting, and deletion of values.
Otherwise, behaves the same. (KeyError is still possible.)
@bsolomon1124
bsolomon1124 / toc.py
Created May 13, 2018 04:56
Quick and dirty TOC generator for Markdown files.
"""Generate TOC from Markdown (.md) file headings."""
import io
import re
import string
import sys
# We need .*? to avoid greediness.
code_block = re.compile(r'^```.*?```', re.M|re.S)
heading = re.compile(r'^#+ .*?$', re.M)

Keybase proof

I hereby claim:

  • I am bsolomon1124 on github.
  • I am bsolomon1124 (https://keybase.io/bsolomon1124) on keybase.
  • I have a public key ASAigX8YlDtlWX5TcCVax6Ys_FdC3CO0YBHzsu9ZId56WAo

To claim this, I am signing this object:

@bsolomon1124
bsolomon1124 / game_of_life.py
Last active November 10, 2025 11:09
Conway's game of life in NumPy
"""NumPy/SciPy implementation of Conway's Game of Life.
https://bitstorm.org/gameoflife/
"""
import argparse
import curses
import getopt
import time
from itertools import repeat