This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: David Beazley (https://www.dabeaz.com) | |
# Twitter: @dabeaz | |
from functools import reduce | |
run = lambda s: reduce(lambda *_:..., iter(lambda s=[s]: | |
(_:=s.pop()(),s.append(_))[0], None)) | |
const = lambda v,c : lambda: c(v) | |
add = lambda x,y,c : lambda: c(x+y) | |
mul = lambda x,y,c : lambda: c(x*y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fibonacci.py | |
def 𝙛𝒊𝗯𝗼𝐧ₐ𝗰𝖈ⅈ(n: 𝑖𝑛𝘵) -> ⁱ𝗇𝔱: | |
if 𝕟 <= 2: | |
return 1 | |
else: | |
return 𝖋ⁱ𝓫𝘰𝖓ᵃ𝒄c𝖎(ⁿ-1) + f𝚒𝔟𝒐𝓷𝑎𝔠𝐜𝘪(𝓃-2) | |
for n in 𝒓𝘢n𝐠ℯ(1, 10): | |
𝑝𝖗i𝖓𝘁(𝐟𝔦b𝓸nₐc𝒄ᵢ(n)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See: https://github.com/dabeaz/sly | |
from sly import Lexer, Parser | |
class CalcLexer(Lexer): | |
tokens = { | |
'NAME', 'NUMBER', | |
} | |
ignore = ' \t' | |
literals = { '=', '+', '-', '*', '/', '(', ')' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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 * |