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 datetime import date | |
| from datetime import datetime as dt | |
| from typing import Union, cast | |
| from dateutil.tz import tzlocal, tzutc | |
| DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%SZ' | |
| def int_to_timestamp( |
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 time import sleep | |
| from typing import Any | |
| def retry(f, *args, _retries: int = 3, _sleep: float = 0.0, **kwargs) -> Any: | |
| """Retry function call until it succeeds.""" | |
| if _retries < 0: | |
| raise ValueError('_retries cannot be negative.') | |
| tries = _retries + 1 | |
| for attempt in range(tries): | |
| try: |
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 sys | |
| import logging | |
| logger = logging.getLogger(__file__) | |
| def handle_exception(exc_type, exc_value, exc_traceback): | |
| """Can be assigned to sys.excepthook to log uncaught exceptions.""" | |
| if issubclass(exc_type, KeyboardInterrupt): | |
| sys.__excepthook__(exc_type, exc_value, exc_traceback) |
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
| /bin/kafka-topics --bootstrap-server localhost:9091 --list | |
| /bin/kafka-topics --bootstrap-server localhost:9091 --create --topic lol | |
| /bin/kafka-topics --bootstrap-server localhost:9091 --delete --topic lol | |
| /bin/kafka-console-consumer --bootstrap-server localhost:9091 --topic lol --from-beginning | |
| /bin/kafka-console-producer --bootstrap-server localhost:9091 --topic lol |
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 pyspark.sql.functions import * | |
| def flatten_structs(df): | |
| """Omits lists, and flattens structs into regular columns. | |
| >>> flatten_structs(test_df).show() # doctest: +NORMALIZE_WHITESPACE | |
| Omitted column rootstructype.nestedstructtype | |
| Omitted column arraytype | |
| +---+--------+---------+------------------+------------------+------------------+ |
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 pyspark.sql.functions import * | |
| from pyspark.sql.window import Window | |
| from pyspark.sql import Column | |
| from functools import reduce | |
| w = Window.partitionBy('group_id') | |
| filter_expression = reduce(Column.__and__, ( |
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 re import findall | |
| from toolz.curried import curry, map, pipe | |
| def to_something_case(text: str, case='snake') -> str: | |
| """Convert input string to snake-, camel-, kebab- or pascalcase.""" | |
| if not text: | |
| return text | |
| first_char, sep, other_first_chars = { | |
| 'snake': (str.lower, '_', str.lower), | |
| 'camel': (str.lower, '', str.title), |
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 os | |
| import random | |
| import string | |
| from os import cpu_count | |
| from pprint import pprint | |
| from time import sleep | |
| from rocksdict import (AccessType, DBCompactionStyle, DBCompressionType, | |
| FifoCompactOptions, Options, Rdict, ReadOptions) |
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 timer(start): | |
| _start = start | |
| def _(end): | |
| nonlocal _start | |
| it_took = end - _start | |
| _start = end | |
| return it_took | |
| return _ |