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 backoff( | |
| url: str, | |
| waitfor: Optional[datetime.timedelta] = None, | |
| waituntil: Optional[datetime.datetime] = None, | |
| base: int = 2, | |
| method: str = 'GET', | |
| bad_status_codes: Optional[Sequence] = None, | |
| session: Optional[requests.Session] = None, | |
| begin_timeout: int = 10, | |
| _now=datetime.datetime.now, |
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
| package counter | |
| import ( | |
| "fmt" | |
| "sort" | |
| ) | |
| type kv struct { | |
| Key int | |
| Value int |
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
| package variadic | |
| // Platform-dependent largest and smallest values that int may take on | |
| const ( | |
| LargestInt = int(^uint(0) >> 1) | |
| SmallestInt = -1 * int(^uint(0) >> 1) - 1 | |
| ) | |
| func Min(a ...int) int { | |
| min := LargestInt |
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
| package counter | |
| import "container/heap" | |
| // Implement the maxheap used in ic.MostCommon() | |
| // KeyValueHeap is a nested slice that implements the heap interface | |
| // It roughly resembles an ordered mapping where each element is a | |
| // length-2 slice with keys as the 0th element and values as the 1st | |
| // See https://golang.org/pkg/container/heap/ IntHeap example |
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
| #!/usr/bin/env python3 | |
| # NOTE: No Python 2 compat. Redis | |
| """Mixin class for managing rate limiting of API keys via Redis.""" | |
| __all__ = ['RateLimitManagerMixin'] | |
| import datetime | |
| import redis |
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
| # cython: profile=False | |
| from cython cimport boundscheck, wraparound | |
| # Py_ssize_t is the proper C type for Python array indices. | |
| from cython cimport Py_ssize_t | |
| import numpy as np | |
| cimport numpy as cnp | |
| from numpy cimport ndarray, double_t, int64_t |
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
| """Demonstrates different LogRecord attributes (formatters). | |
| https://docs.python.org/3/library/logging.html#logrecord-attributes | |
| """ | |
| import logging | |
| # Notes | |
| # ----- | |
| # pathname: this is relative! | |
| # created: time in seconds since the epoch as a float |
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 binascii | |
| import math | |
| import os | |
| # binascii.b2a_base64(data, *, newline=True) | |
| # Convert binary data to a line of ASCII characters in base64 coding. | |
| # The return value is the converted line, including a newline char if | |
| # newline is true. The output of this function conforms to RFC 3548. | |
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
| # Demonstration of how `int.from_bytes()` converts a Python bytes obj to int. | |
| # Used in random module's `SystemRandom.random()` to generate a float in [0.0, 1.0) from `os.urandom()` | |
| # https://github.com/python/cpython/blob/c6040638aa1537709add895d24cdbbb9ee310fde/Lib/random.py#L676 | |
| # | |
| # An example: the number 1984 can be "decomposed" in the decimal system (base 10) | |
| # as (1 * 10 ** 3) | |
| # + (9 * 10 ** 2) | |
| # + (8 * 10 ** 1) | |
| # + (4 * 10 ** 0) | |
| # |
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
| # Informal proof | |
| from math import inf | |
| mn, mx = inf, -1 * inf | |
| for _ in range(100000): | |
| b = os.urandom(10) | |
| new_min = min(b) | |
| new_max = max(b) |