Skip to content

Instantly share code, notes, and snippets.

View asvetlov's full-sized avatar

Andrew Svetlov asvetlov

  • constructor.org
  • Gijon
View GitHub Profile

This Contributor Agreement is between the aio-libs team (the "Organization") and the individual or other entity identified by the Agreement sign up (the "Contributor").

Contributor offers to license certain software (a "Contribution" or multiple "Contributions") to Organization, and Organization agrees to accept said contributions, under the terms of the open source "Apache 2" License.

Contributor understands and agrees that Organization shall have the irrevocable and perpetual right to make and distribute copies of any Contribution, as well as to create and distribute collective works and derivative works of any Contribution, under the Apache 2 License or any other open source license approved by the Organization.

@asvetlov
asvetlov / form-data.html
Created January 20, 2020 10:29
Form server
<!DOCTYPE html>
<html>
<body>
<form action="/" method="post" enctype="multipart/form-data">
First name:<br>
<input type="text" name="firstname"><br>
Last name:<br>
<input type="text" name="lastname"><br>
File:<br>
<input type="file" name="file"><br>
from typing import *
class RawStream:
pass
class Stream:
pass
class Other:
pass
import typing
_T = typing.NewType('_T')
_StreamFactory = typing.Callable[[asyncio.RawStream], _T]
def connect(host=None, port=None, *,
limit=_DEFAULT_LIMIT,
ssl=None, family=0, proto=0,
flags=0, sock=None, local_addr=None,
server_hostname=None,
import json
import re
s = """new APIData([
new APIControllers([
new APIProp({name:"durable-id",value:"controller_a"}),
new APIProp({name:"controller-id",value:"A"}),
new APIProp({name:"controller-id-numeric",value:"1"}),
new APIProp({name:"serial-number",value:"CN8415M489"})
])
@asvetlov
asvetlov / Analize
Created March 30, 2018 16:13
Simple aiohttp performance check
stop `run_server.sh` after wrk has finished, install snakeviz (`pip install snakeviz`) and run it
`snakeviz out.prof`
@asvetlov
asvetlov / keepalive_cli.py
Created February 1, 2018 15:30
HTTP keepalive illustration
import asyncio
import aiohttp
import random
async def test_client():
async with aiohttp.ClientSession() as session:
while True:
async with session.get('http://127.0.0.1:8080/') as r:
result = await r.text()
import aiohttp
class CustomRequest(aiohttp.ClientRequest):
def update_transfer_encoding(self):
super().update_transfer_encoding()
if self.method == 'GET':
self.headers.popall('Content-Length', None)
session = ClientSession(request_class=CustomRequest)
Python setitem/getitem
0.054s 0.040s 0.7x
Cython / Python / x
MD.add: 0.306s 2.065s 6.7x
CI.add str: 0.664s 2.473s 3.7x
MD.setitem str: 0.149s 6.214s 41.6x
MD.setitem istr: 0.199s 6.614s 33.3x
MD.getitem str: 0.099s 1.708s 17.3x
CI.getitem str: 0.531s 2.145s 4.0x
CI.getitem istr: 0.128s 2.010s 15.7x
<html>
<head>
<META NAME="ROBOTS" CONTENT="NOARCHIVE"></META>
<title>David Beazley</title>
<style type="text/css">
a {text-decoration: none; }
a.nav {color: #0000ff; }
h1 { font-family: verdana; font-size: 10pt;}
p { font-family: verdana; font-size: 10pt;}
li { font-family: verdana; font-size: 10pt;}