Skip to content

Instantly share code, notes, and snippets.

View h0rn3t's full-sized avatar
🏠
Working from home

Eugene h0rn3t

🏠
Working from home
  • Ukraine
View GitHub Profile
import asyncpg
import ujson
class Transaction:
def __init__(self, pool):
self.pool = pool
async def __aenter__(self):
self.acquire_context = self.pool.acquire()
@h0rn3t
h0rn3t / app.py
Created July 19, 2021 21:11 — forked from tombulled/app.py
Stream a file, in this case an mp4 video, supporting range-requests using starlette
from starlette.applications import Starlette
from starlette.responses import StreamingResponse
from starlette.requests import Request
from starlette.routing import Route
from pathlib import Path
from typing import IO, Generator
"""
Stream a file, in this case an mp4 video, supporting range-requests using starlette
@h0rn3t
h0rn3t / del_key.py
Created April 8, 2021 12:58 — forked from velykanov/del_key.py
Delete key from nested dictionary
def delete(key, dict_obj):
"""Deletes element from dict_obj accessing by complex key
Args:
key (str): Complex key to your value (separated by dots)
dict_obj (dict): Your dictionary
Raises:
KeyError: if object doesn't contain key

async in Python3

History

  1. generators found in Python 3.3
  2. event loop in the form of asyncio: In Python 3.4, the asyncio.coroutine decorator was used to label a function as acting as a coroutine that was meant for use with asyncio and its event loop.
  3. yield from to await in Python 3.5

Event loop and task

@h0rn3t
h0rn3t / audit_mixin.py
Created March 19, 2021 13:41 — forked from techniq/audit_mixin.py
Useful SQLAlchemy Mixins
from datetime import datetime
from sqlalchemy import Column, Integer, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declared_attr
from flask_security import current_user
class AuditMixin(object):
created_at = Column(DateTime, default=datetime.now)
updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now)
@h0rn3t
h0rn3t / asyncio_plus_greenlet.py
Created March 14, 2021 17:56 — forked from zzzeek/asyncio_plus_greenlet.py
An asyncio program that runs rows into a Postgresql database, using blocking style code to actually run the database commands
"""This program is exactly the same as that of
https://gist.github.com/zzzeek/33943060f7a08cf9e82bf8df1f0f75de ,
with the exception that the add_and_select_data function is written in
synchronous style.
UPDATED!! now includes refinements by @snaury and @Caselit . SIMPLER
AND FASTER!!
@h0rn3t
h0rn3t / annotators.csv
Created March 1, 2021 11:04 — forked from vkocaman/annotators.csv
list of annotators offered by Spark NLP
We can make this file beautiful and searchable if this error is corrected: It looks like row 10 should actually have 5 columns, instead of 3 in line 9.
Annotator,Description,Version,Annotator Approach,Annotator Model
Tokenizer*,Identifies tokens with tokenization open standards,Opensource,-,+
Normalizer*,Removes all dirty characters from text,Opensource,-,+
Stemmer*,Returns hard'-stems out of words with the objective of retrieving the meaningful part of the word,Opensource,+,-
Lemmatizer*,Retrieves lemmas out of words with the objective of returning a base dictionary word,Opensource,-,+
RegexMatcher*,Uses a reference file to match a set of regular expressions and put them inside a provided key.,Opensource,+,+
TextMatcher*,Annotator to match entire phrases (by token) provided in a file against a Document,Opensource,+,+
Chunker*,Matches a pattern of part'-of'-speech tags in order to return meaningful phrases from document,Opensource,+,-
DateMatcher*,Reads from different forms of date and time expressions and converts them to a provided date format,Opensource,+,-
SentenceDetector*,Finds sentence bounds in raw text. Applies rules from Pragmatic Segmenter,Opensou
@h0rn3t
h0rn3t / enum.py
Created February 12, 2021 06:55
enum
class States(Enum):
# each Value have priority. Need when getting random event we know its more priority then last or not.
# y = YealinkStates.ANSWER_IN_CALL
# y = YealinkStates('ANSWER_NEW_IN_CALL')
# y.name -> 'ANSWER_IN_CALL'
# str(y) -> 'ANSWER_NEW_IN_CALL'
# y.priority -> 3
# y.title -> 'ANSWER_NEW_IN_CALL'
INCOMING_CALL = (1, 'INCOMING_CALL')
@h0rn3t
h0rn3t / timed_lru_cache.py
Created January 23, 2021 11:05
timed_lru_cache
from functools import lru_cache, wraps
from datetime import datetime, timedelta
def timed_lru_cache(seconds: int, maxsize: int = 128):
def wrapper_cache(func):
func = lru_cache(maxsize=maxsize)(func)
func.lifetime = timedelta(seconds=seconds)
func.expiration = datetime.utcnow() + func.lifetime
@wraps(func)
@h0rn3t
h0rn3t / install-kubernetes-flannel-centos7.md
Created January 10, 2021 14:55 — forked from rkaramandi/install-kubernetes-flannel-centos7.md
Installing Kubernetes with the Flannel Network Plugin on CentOS 7

Install Prerequisites on ALL (Worker and Master) Nodes

Let's remove any old versions of Docker if they exist:

sudo yum remove docker \
                  docker-common \
                  docker-selinux \
                  docker-engine