This file contains hidden or 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 math | |
# Python ≥ 3.5 | |
def recursive_linear(b, n): | |
if n < 0: | |
return (1/b) * recursive_linear(b, n+1) | |
if n == 0: | |
return 1 | |
else: |
This file contains hidden or 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
""" | |
Usage example: | |
from logger import get_logger | |
log = get_logger() | |
log.info('my_event', my_key1='val 1', my_key2=5, my_key3=[1, 2, 3], my_key4={'a': 1, 'b': 2}) | |
List of metadata keys in each log message: | |
event | |
_func |
This file contains hidden or 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 inspect | |
class Locatable: | |
def __new__(cls, *_args, **_kwargs): | |
# Background: http://eli.thegreenplace.net/2012/04/16/python-object-creation-sequence | |
obj = super().__new__(cls) | |
obj.location = obj._initialization_location() # pylint: disable=protected-access | |
return obj |
This file contains hidden or 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 collections import namedtuple # pylint: disable=import-self | |
def default_namedtuple(typename='Case', **defaults): | |
NamedTuple = namedtuple(typename, defaults) # pylint: disable=invalid-name | |
default_tuple = NamedTuple(**defaults) | |
customizable_tuple = default_tuple._replace | |
return customizable_tuple | |
This file contains hidden or 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
class TestCases: | |
def __init__(self, **defaults): | |
self._defaults = defaults | |
self._cases = [] | |
self._next_index = 0 | |
def __iter__(self): | |
return self |
This file contains hidden or 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 | |
def pprint(obj): | |
print(json.dumps(obj, indent=2, sort_keys=True, default=str)) | |
def nested_dict_recursive_with_single_key(nested_key, value): | |
head, _sep, tail = nested_key.partition('.') | |
return {head: (nested_dict_recursive_with_single_key(tail, value) if tail else value)} | |
def nested_dict_iterative_with_single_key(nested_key, value): |
This file contains hidden or 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 io | |
import re | |
import pandas as pd | |
def _prepare_pipe_separated_str(str_input): | |
substitutions = [ | |
('^ *', ''), # Remove leading spaces | |
(' *$', ''), # Remove trailing spaces |
This file contains hidden or 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
def fizzbuzz_recursive(n): | |
if n == 0: | |
return | |
fizzbuzz_recursive(n - 1) | |
if n % 3 == 0 and n % 5 == 0: | |
print('FizzBuzz') | |
elif n % 3 == 0: | |
print('Fizz') | |
elif n % 5 == 0: | |
print('Buzz') |
This file contains hidden or 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
# Convert cyclical values from standard 0..N values in to radians | |
def degrees_2_rads(row): | |
radians = math.radians(row) | |
return radians | |
def rads_2_cos_val(row): | |
cos_val = math.cos(row) | |
return cos_val | |
def rads_2_sin_val(row): |
This file contains hidden or 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 warning and error log: | |
<• Feed[bot]> Etag test failed for https://export.arxiv.org/rss/cs.NE with etag '"Tue, 28 May 2019 00:30:00 GMT", "1559003400"'. The semantic content was unexpectedly found to be changed whereas the etag stayed unchanged. The previously cached content has 0 unique links and the dissimilar current content has 23. | |
<• Feed[bot]> The etag cache has been disabled for the duration of the bot process for all export.arxiv.org feed URLs. The semantic content mismatch should be reported to the site administrator. |
OlderNewer