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
k cp namespace/pod-0:file1 ./file1 |
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 tslearn.clustering import TimeSeriesKMeans | |
from tslearn.utils import to_time_series_dataset | |
import pandas as pd | |
data = [ | |
[0, 1, 2, 3, 4], | |
[1, 2, 3, 4, 0], | |
[0, 1, 2, 3, 4], | |
[0, 1, 2, 3, 4], | |
[5, 6, 3, 4, 0], |
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
class DirectedGraph: | |
"""A basic implementation of a directed graph.""" | |
def __init__(self): | |
self.graph = {} | |
def add_node(self, node): | |
if node not in self.graph: | |
self.graph[node] = {} |
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 datetime import datetime as dt, timezone | |
from re import match | |
from toolz.curried import curry | |
DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%SZ' | |
DATE_FORMAT = '%Y-%m-%d' | |
@curry |
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 itertools import groupby, islice | |
from typing import Iterable, cast | |
from toolz.curried import curry, map, pluck | |
def batched(iterable, n): | |
"""Batch data into tuples of length n. | |
>>> list(batched('ABCDEF', 3)) |
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 typing import Iterable | |
def dict_diff( | |
old: dict, | |
new: dict, | |
ignore_keys: Iterable[str] = [], | |
include_keys: Iterable[str] = [] | |
) -> dict: | |
"""Capture changes between dictionaries. |
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 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 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 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) |
NewerOlder