Skip to content

Instantly share code, notes, and snippets.

Avatar

Yury Selivanov 1st1

View GitHub Profile
View uuid_format.js
const buf = Buffer.allocUnsafe(16);
function f1(buf) {
return (
buf.slice(0, 4).toString("hex") +
"-" +
buf.slice(4, 6).toString("hex") +
"-" +
buf.slice(6, 8).toString("hex") +
"-" +
View ag.py
import time
import threading
def generator():
try:
print('STARTED')
time.sleep(5)
yield 1
finally:
View bench.py
import pyrsistent
import immutables
import time
I = 1000000
KEY = '5'
for N in [5, 10, 20, 30, 100, 200, 300, 400, 500, 1000]:
print('=============')
@1st1
1st1 / ds.py
Created Oct 10, 2018
LRUIndex & MappedDeque datastructures
View ds.py
#
# This source file is part of the EdgeDB open source project.
#
# Copyright 2016-present MagicStack Inc. and the EdgeDB authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
@1st1
1st1 / fix.diff
Created Oct 1, 2018
Fix bpo-34769
View fix.diff
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index 492e377d09..3b1ed00af3 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -477,10 +477,7 @@ class BaseEventLoop(events.AbstractEventLoop):
def _asyncgen_finalizer_hook(self, agen):
self._asyncgens.discard(agen)
if not self.is_closed():
- self.create_task(agen.aclose())
- # Wake up the loop if the finalizer was called from
@1st1
1st1 / avg.pyx
Created Sep 28, 2018
rolling average
View avg.pyx
#
# This source file is part of the EdgeDB open source project.
#
# Copyright 2016-present MagicStack Inc. and the EdgeDB authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
@1st1
1st1 / fix_dataclass_introspection.diff
Last active Sep 23, 2018
A hack-ish way to fix dataclasses & get_type_hints()
View fix_dataclass_introspection.diff
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index 28e9f75127..ad3dc46b67 100644
--- a/Lib/dataclasses.py
+++ b/Lib/dataclasses.py
@@ -868,7 +868,7 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen):
# Include InitVars and regular fields (so, not ClassVars).
flds = [f for f in fields.values()
if f._field_type in (_FIELD, _FIELD_INITVAR)]
- _set_new_attribute(cls, '__init__',
+ had_own_init = _set_new_attribute(cls, '__init__',
@1st1
1st1 / mod_getattr.patch
Last active Sep 6, 2018
Backport PEP 562 module-level __getattr__ to Python 2.7
View mod_getattr.patch
diff --git a/Lib/test/bad_getattr.py b/Lib/test/bad_getattr.py
new file mode 100644
index 0000000000..b4f790f3bf
--- /dev/null
+++ b/Lib/test/bad_getattr.py
@@ -0,0 +1,3 @@
+x = 1
+
+__getattr__ = "Surprise!"
diff --git a/Lib/test/bad_getattr2.py b/Lib/test/bad_getattr2.py
@1st1
1st1 / example.py
Last active Apr 8, 2021
asyncio queues example
View example.py
import asyncio
import random
import time
async def worker(name, queue):
while True:
# Get a "work item" out of the queue.
sleep_for = await queue.get()
View fixed.py
import asyncio
from twisted.internet import asyncioreactor
asyncioreactor.install()
import treq
from twisted.internet.defer import Deferred, ensureDeferred
from twisted.internet.task import react
async def run():