Skip to content

Instantly share code, notes, and snippets.

View Menziess's full-sized avatar

Stefan Schenk Menziess

View GitHub Profile
"""Stream synchronization.
$ pip install slipstream-async
The activity stream depends on the weather stream.
When weather goes down, activity is paused until weather recovers.
When it recovers, it moves back to the checkpoint offset
and reprocesses messages enriched with stale data.
"""
"""Stream synchronization.
$ pip install slipstream-async
The first stream depends on second, which depends on third.
And third depends on second.
1 <- 2 <- 3
3 <- 2
When third goes down, second will pause, after which first will pause.
@Menziess
Menziess / pausable_generator.py
Last active January 21, 2025 08:05
A generator that can be paused by sending a boolean value.
"""Pausable generator."""
import asyncio
SENTINEL = object()
async def gen():
active = True

Gitlab PyPi Repo

Downloading

  • Create a Gitlab PAT here: link, having the read_api scope.
  • Modify (or create) ~/.pip/pip.conf on your machine, and replace with your token and <GROUP_ID> with the project's group id:
[global]
index-url = https://pypi.org/simple
extra-index-url = https://__token__:@gitlab.com/api/v4/groups//-/packages/pypi/simple
k cp namespace/pod-0:file1 ./file1
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],
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] = {}
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
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))
from typing import Iterable
def dict_diff(
old: dict,
new: dict,
ignore_keys: Iterable[str] = [],
include_keys: Iterable[str] = []
) -> dict:
"""Capture changes between dictionaries.