Skip to content

Instantly share code, notes, and snippets.

Nick Humrich nhumrich

Block or report user

Report or block nhumrich

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nhumrich
nhumrich / asyncpgsa_benchmark.py
Created Aug 10, 2017
asyncpgsa benchmark against aiopg.sa
View asyncpgsa_benchmark.py
import asyncio
import aiopg
import aiopg.sa
import asyncpg
import asyncpgsa
import sqlalchemy as sa
pg_tables = sa.Table(
'pg_tables', sa.MetaData(),
sa.Column('schemaname'),
@nhumrich
nhumrich / metaclass_wrapping_vs_getattr.py
Last active Jun 13, 2017
metaclass wrapping vs __getattr__
View metaclass_wrapping_vs_getattr.py
import functools
import inspect
from timeit import timeit
class Bob:
__slots__ = ('a',)
def __init__(self):
self.a = 5
@nhumrich
nhumrich / oreilly.py
Created Jan 27, 2017
get free o'reilly books
View oreilly.py
"""Script to download free O'Reilly ebooks."""
import asyncio
import os
import re
import sys
import aiohttp
filename_matcher = re.compile(r'http://www.oreilly.com/(.*)/free/(.*).csp')
session = None
@nhumrich
nhumrich / async_fib_benchmark.py
Last active Sep 27, 2018
async vs threading cpu bound benchmark
View async_fib_benchmark.py
import asyncio
from multiprocessing.pool import ThreadPool
from timeit import timeit
from functools import partial
pool = ThreadPool(processes=400)
loop = asyncio.get_event_loop()
def fib(x):
@nhumrich
nhumrich / async_http_benchmark.py
Created Nov 3, 2016
async vs threading http benchmark
View async_http_benchmark.py
from timeit import timeit
import asyncio
import requests
from threading import Thread
import aiohttp
client = aiohttp.ClientSession()
@nhumrich
nhumrich / tornado_example.py
Last active Aug 19, 2018
async blog tornado example
View tornado_example.py
import tornado.ioloop
from tornado.httpclient import AsyncHTTPClient
urls = ['http://www.google.com', 'http://www.yandex.ru', 'http://www.python.org']
def handle_response(response):
if response.error:
print("Error:", response.error)
else:
url = response.request.url
data = response.body
@nhumrich
nhumrich / gevent_example.py
Last active Aug 19, 2018
async blog post gevent example
View gevent_example.py
import gevent.monkey
from urllib.request import urlopen
gevent.monkey.patch_all()
urls = ['http://www.google.com', 'http://www.yandex.ru', 'http://www.python.org']
def print_head(url):
print('Starting {}'.format(url))
data = urlopen(url).read()
print('{}: {} bytes: {}'.format(url, len(data), data))
@nhumrich
nhumrich / asyncio_drain.patch
Last active Sep 8, 2016
python asyncio drain feature patch
View asyncio_drain.patch
diff -r c2212d98ef13 Lib/asyncio/queues.py
--- a/Lib/asyncio/queues.py Wed Sep 07 14:56:15 2016 -0700
+++ b/Lib/asyncio/queues.py Wed Sep 07 21:56:33 2016 -0600
@@ -1,13 +1,13 @@
"""Queues"""
-__all__ = ['Queue', 'PriorityQueue', 'LifoQueue', 'QueueFull', 'QueueEmpty']
+__all__ = ['Queue', 'PriorityQueue', 'LifoQueue',
+ 'QueueFull', 'QueueEmpty', 'QueueClosed']
View dnsresolver.py
import dns.resolver
import os
from urllib import request
import json
import time
WEBHOOK_URL = 'https://hooks.slack.com/services/' \
'{keyhere}'
@nhumrich
nhumrich / durggletest.yml
Last active Aug 15, 2016
yaml example of api test
View durggletest.yml
- add a durggle:
post: /api/durggles
body:
durggle:
name: bob
spot: white
eyes: purple
items:
- fish
- chips
You can’t perform that action at this time.