Skip to content

Instantly share code, notes, and snippets.

@jspahrsummers
jspahrsummers / AsynchronousGenerators.md
Last active February 16, 2024 18:55
Python asynchronous generator semantics and types

How to use asynchronous generators

The documentation 6.2.9.4. "Asynchronous generator-iterator methods" is phrased really ambiguously. To make matters worse, typing.AsyncGenerator is not specified fully correctly.

Here, I attempt to more clearly capture the actual interface contract, based on what I've read and observed. See also PEP 492 -- Coroutines with async and await syntax and PEP 525 -- Asynchronous Generators.

This might be useful to implement lower-level behaviors than you can with async for, like sending values into the generator function.

TSend = TypeVar('TSend', contravariant=True)
@Lewiscowles1986
Lewiscowles1986 / rPi3-ap-setup.sh
Last active July 16, 2023 15:33
Raspberry Pi 3 access-point-setup
#!/bin/bash
#
# This version uses September 2017 august stretch image, please use this image
#
if [ "$EUID" -ne 0 ]
then echo "Must be root"
exit
fi
@res0nat0r
res0nat0r / create-aws-console-user.sh
Created October 7, 2015 16:00 — forked from stefhen/create-aws-console-user.sh
Create AWS console user from the awscli
#!/bin/bash
# USAGE: ./create-aws-console-user.sh $GROUPNAME $USERNAME $PASSWORD
# http://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html#id_users_create_cliwpsapi
# Create administrator group
aws iam create-group --group-name $1
@victorkristof
victorkristof / ipython-notebook-multiple-kernels-venv.md
Last active July 29, 2018 10:59
IPython Notebook with multiple kernels and virtualenv

IPython Notebook with multiple kernels and virtualenv

Explanations of how to install and use IPython Notebook with a venv and multiple virtualenv (one for Python 2 and one for Python 3).

Step-by-step installation

We run step-by-step and detail all the operations. A quicker, more concise guide can be found at the end of this gist.

Create virtualenv

We create first one venv for each version of Python.

mkvirtualenv -p /path/to/python2.7 venv-name
deactivate
@sumeetpareek
sumeetpareek / packer-aws-ami-template.json
Last active December 21, 2021 15:46
packer template to create aws ami using ansible provisioner
{
"variables": {
"aws_access_key": "", // This helps me connect to AWS
"aws_secret_key": ""
},
"builders": [{
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"region": "us-east-1",
@rctay
rctay / sitecustomize.py
Created July 24, 2012 09:38
[python] start debugger on exception
#
# original: http://code.activestate.com/recipes/65287/
#
# place in lib/python2.x/sitecustomize.py
import bdb
import sys
def info(type, value, tb):
if hasattr(sys, 'ps1') \