Skip to content

Instantly share code, notes, and snippets.

Avatar

David Beazley dabeaz

View GitHub Profile
@dabeaz
dabeaz / aproducer.py
Created Oct 17, 2019
"Build Your Own Async" Workshop - PyCon India - October 14, 2019 - https://www.youtube.com/watch?v=Y4Gt3Xjd7G8
View aproducer.py
# aproducer.py
#
# Async Producer-consumer problem.
# Challenge: How to implement the same functionality, but no threads.
import time
from collections import deque
import heapq
class Scheduler:
@dabeaz
dabeaz / README.txt
Created Oct 15, 2019
PyCon India 2019, Code from Keynote Presentation by @dabeaz
View README.txt
Code from PyCon India 2019 Keynote Talk
David Beazley (https://www.dabeaz.com)
======================================
This code is presented "as is" and represents what was live-coded
during my closing keynote presentation at PyCon India, Chennai,
October 13, 2009. I have made no changes to the files.
Requires: Python 3.6+, numpy, pygame
@dabeaz
dabeaz / curbench.py
Created Oct 20, 2017
Curio Benchmark of Large Data Transfer
View curbench.py
# A Curio adaption of benchmark code at:
#
# https://gist.github.com/pitrou/202221ca9c9c74c0b48373ac89e15fd7
import struct
try:
from time import perf_counter as clock
except ImportError:
from time import time as clock
@dabeaz
dabeaz / calc.py
Created Sep 14, 2016
SLY (Sly Lex-Yacc) Example
View calc.py
# See: https://github.com/dabeaz/sly
from sly import Lexer, Parser
class CalcLexer(Lexer):
tokens = {
'NAME', 'NUMBER',
}
ignore = ' \t'
literals = { '=', '+', '-', '*', '/', '(', ')' }
@dabeaz
dabeaz / bug.py
Created Jan 7, 2016
Diabolical bug involving code that behaves differently in a class decorator vs. a metaclass
View bug.py
# bug.py
def decorate(func):
print('Decorating', func.__name__)
return func
def wrap_methods(cls):
for name in vars(cls):
if name.startswith('f_'):
setattr(cls, name, decorate(getattr(cls, name)))
@dabeaz
dabeaz / aecho.py
Last active Sep 16, 2019
Live-coded examples from my PyCon Brasil 2015 Keynote
View aecho.py
# aecho.py
from socket import *
import asyncio
loop = asyncio.get_event_loop()
async def echo_server(address):
sock = socket(AF_INET, SOCK_STREAM)
sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
@dabeaz
dabeaz / FileUsage.ipynb
Created Mar 26, 2013
IPython Notebook Example for my Usenix ;Login: Article
View FileUsage.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dabeaz
dabeaz / pystate.c
Created Feb 3, 2013
From Python-3.3 source code, Python/pystate.c. Note the comment: I have no recollection of requesting this feature, but it must have been important at the time ;-).
View pystate.c
/* Routines for advanced debuggers, requested by David Beazley.
Don't use unless you know what you are doing! */
PyInterpreterState *
PyInterpreterState_Head(void)
{
return interp_head;
}
PyInterpreterState *