Skip to content

Instantly share code, notes, and snippets.

View 1st1's full-sized avatar

Yury Selivanov 1st1

View GitHub Profile
import inspect
def inherit(*, base, docs=False, signature=False):
assert docs or signature
assert isinstance(base, type) # we can also support functions
def wrap(func):
base_func = getattr(base, func.__name__)
> --- a/Lib/inspect.py Thu Feb 06 22:06:16 2014 -0500
> +++ b/Lib/inspect.py Fri Feb 07 13:41:22 2014 -0500
< +def _strip_non_python_syntax(signature):
---
> +def _signature_strip_non_python_syntax(signature):
> + # Internal helper to convert AC extended signature format
> + # to the standard Python syntax
> +
99a103,106
> - if first_parameter_is_self:
class Local:
def __getattr__(self, attr):
# finds 'attr' stored for the current Task.context_id
def __setattr__(self, attr, val):
# stores value for the current Task.context_id
local = Local()
import asyncio
import time
import statistics
import heapq
ITERS = 2000
NUMBER_OF_TASKS = 100000
loop = asyncio.get_event_loop()
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