This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps, partial | |
def transform_return(transformation, decorated=None): | |
if decorated is None: | |
return partial(transform_return, transformation) | |
@wraps(decorated) | |
def wrapper(*args, **kwargs): | |
return transformation(decorated(*args, **kwargs)) | |
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This is a self contained custom data structure with dict like | |
key-value storage capabilities. | |
* Can store the key-value pairs in any sqlalchemy supported db | |
* Employs thread safe transactional scope | |
* Modular, just change the session_scope to use a different db | |
* This example uses sqlite db for demonstration purpose | |
The code is inspired by Raymond Hettinger's talk `Build powerful, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import logging | |
import sys | |
logger = logging.getLogger(__name__) | |
class PyBayFormatter(logging.Formatter): | |
"""Implementation of JSON structured logging that works for most handlers.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3.7 | |
import asyncio | |
import ipaddress | |
import re | |
import sys | |
MAX_NUMBER_WORKERS = 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mock | |
class AlmostAlwaysTrue(object): | |
def __init__(self, total_iterations=1): | |
self.total_iterations = total_iterations | |
self.current_iteration = 0 | |
def __nonzero__(self): | |
if self.current_iteration < self.total_iterations: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
import json | |
from dataclasses import dataclass, MISSING, field as _field | |
from typing import Any, Callable | |
class MutationDescriptor: | |
def __init__(self, mutator: Callable[[Any], Any]): | |
self._mutator = mutator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @link https://raw.githubusercontent.com/NaturalCycles/js-lib/master/src/promise/pProps.ts | |
* Promise.all for Object instead of Array. | |
* | |
* Inspired by Bluebird Promise.props() and https://github.com/sindresorhus/p-props | |
* | |
* Improvements: | |
* | |
* - Exported as { promiseProps }, so IDE auto-completion works |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from log_exceptions import log_exceptions | |
def throw_something(a1, a2): | |
raise Exception('Whoops!') | |
@log_exceptions(log_if = os.getenv('MYAPP_DEBUG') is not None) | |
def my_function(arg1, arg2): | |
throw_something(arg1 + 24, arg2 - 24) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random # for demo test | |
splits = 0 | |
parent_splits = 0 | |
fusions = 0 | |
parent_fusions = 0 | |
class Node(object): | |
"""Base node object. It should be index node |
OlderNewer