Skip to content

Instantly share code, notes, and snippets.

@dpallot
dpallot / aecho.py
Created December 16, 2015 07:44 — forked from dabeaz/aecho.py
Live-coded examples from my PyCon Brasil 2015 Keynote
# 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)
@dpallot
dpallot / gist:0352d38a061103ae98f8
Last active August 29, 2015 14:22
Asyncio stdio
import os
import asyncio
import sys
from asyncio.streams import StreamWriter, FlowControlMixin
reader, writer = None, None
@asyncio.coroutine
def stdio(loop=None):
@dpallot
dpallot / beautiful_idiomatic_python.md
Last active March 16, 2022 04:37 — forked from JeffPaine/beautiful_idiomatic_python.md
Beautiful Idiomatic Python

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
@dpallot
dpallot / gist:30f1d6cd19d4f578be8f
Created May 13, 2015 15:57
Dynamic Matrix Controller
import scipy
import numpy
import scipy.signal
import matplotlib.pyplot as plt
from scipy.linalg import toeplitz
from scipy.linalg import hankel
from numpy.linalg import inv
numpy.set_printoptions(linewidth=500)
@dpallot
dpallot / gist:3c5f3ed2631c1ebd1a40
Created May 13, 2015 06:04
Pipes using objects, queues and asyncio
import asyncio
class Pipe:
_in_q = None
_out_q = None
_chained = False
def __init__(self, *args, **kwargs):
self.future = asyncio.async(self.run())