Skip to content

Instantly share code, notes, and snippets.

View 1st1's full-sized avatar

Yury Selivanov 1st1

View GitHub Profile
import asyncio
from aiohttp.server import ServerHttpProtocol
import unittest
import threading
from urllib.request import urlopen, URLError
class Test(unittest.TestCase):
def setUp(self):
import logging
@1st1
1st1 / gist:1199936ef171a3696886
Created December 11, 2014 03:12
Binary floating point summation accurate to full precision in JavaScript
// Read this first: http://code.activestate.com/recipes/393090/
function sum(ar) {
var c = ar.length;
var s = 0;
for (var i = 0; i < c; i++) {
s += ar[i];
}
return s;
}
@1st1
1st1 / await.py
Last active August 29, 2015 14:18
import os
import sys
import token
import tokenize
if __name__ == '__main__':
if len(sys.argv) < 2:
print('pass directory to search in as an arg')
sys.exit(1)
import sys
import time
# import sys
# sys.set_generator_wrapper(lambda x: x)
def binary(n):
if n <= 0:
return 1
@1st1
1st1 / t.py
Created April 21, 2015 03:29
async branch: with statement micro benchmark
class CM:
def __enter__(self):
global CNT1
CNT1 +=1
def __exit__(self, et, e, tv):
global CNT2
CNT2 += 1
diff --git a/Grammar/Grammar b/Grammar/Grammar
index 94898d3..9c74096 100644
--- a/Grammar/Grammar
+++ b/Grammar/Grammar
@@ -21,8 +21,11 @@ eval_input: testlist NEWLINE* ENDMARKER
decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
decorators: decorator+
-decorated: decorators (classdef | funcdef)
-funcdef: 'def' NAME parameters ['->' test] ':' suite
diff --git a/Lib/test/test_coroutines.py b/Lib/test/test_coroutines.py
index aa2a5e8..6a6f868 100644
--- a/Lib/test/test_coroutines.py
+++ b/Lib/test/test_coroutines.py
@@ -497,17 +497,133 @@ class CoroutineTest(unittest.TestCase):
return self
def __aexit__(self, *e):
+ return 444
+
import asyncio
async def worker():
fut = asyncio.Future()
def setval():
print('setval')
fut.set_result(123)
print('setup')
@1st1
1st1 / httpget.py
Created September 8, 2015 16:05
a quick example of new async/await in python 3.5
import asyncio
async def http_get(domain):
reader, writer = await asyncio.open_connection(domain, 80)
writer.write(b'\r\n'.join([
b'GET / HTTP/1.1',
b'Host: %b' % domain.encode('latin-1'),
b'Connection: close',
b'', b''
class _RedisPool(aioredis.RedisPool):
@asyncio.coroutine
def acquire(self):
# XXX
with (yield from self._cond):
while True:
yield from self._fill_free(override_min=True)
if self.freesize:
conn = self._pool.popleft()
if conn.closed: