Skip to content

Instantly share code, notes, and snippets.

View atemate's full-sized avatar
🐕

Artem Yushkovskiy atemate

🐕
View GitHub Profile
@atemate
atemate / cost_comparison.csv
Last active November 10, 2025 17:33
Rough Cost comparison: Clouds vs Self-hosted
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 15 columns, instead of 11 in line 4.
tokens,cost_aws_managed,cost_gcp_managed,cost_L4_self_hosted,cost_A10G_self_hosted,latency_L4_seconds,latency_L4_hours,latency_A10G_seconds,latency_A10G_hours,latency_T4_seconds,latency_T4_hours,latency_H100_seconds,latency_H100_hours,latency_GCP_Vertex_seconds,latency_GCP_Vertex_hours
1000000,4.0,11.249999999999998,0.27777777777777773,6.733333333333333,2000.0,0.5555555555555556,20000.0,5.555555555555555,33333.333333333336,9.25925925925926,1600.0,0.4444444444444444,1600.0,0.4444444444444444
2000000,8.0,22.499999999999996,0.5555555555555555,13.466666666666667,4000.0,1.1111111111111112,40000.0,11.11111111111111,66666.66666666667,18.51851851851852,3200.0,0.8888888888888888,3200.0,0.8888888888888888
3000000,12.0,33.75,0.8333333333333333,20.2,6000.0,1.6666666666666667,60000.0,16.666666666666668,100000.0,27.77777777777778,4800.0,1.3333333333333333,4800.0,1.3333333333333333
4000000,16.0,44.99999999999999,1.111111111111111,26.933333333333334,8000.0,2.2222222222222223,80000.0,22.22222222222222,133333.33333333334,37.03
@atemate
atemate / GCP_dataXXX_products.md
Last active December 26, 2024 15:25
GCP cheatsheet
Service Purpose Key Features Common Use Cases Integration
Dataflow Stream and batch data processing using Apache Beam. Serverless, autoscaling, unified stream and batch processing, supports windowing and watermarking. ETL,
@atemate
atemate / fspath.md
Last active June 4, 2024 16:41
Python OOP
>>> from os import PathLike
>>> class MyPath(PathLike):
...     def __init__(self, prefix, path):
...         self._prefix = prefix
...         self._path = path
...
...     def __fspath__(self):
...         return self._prefix + self._path
...
@atemate
atemate / __init__.py
Created June 4, 2024 12:31
Python code to check if extras is installed
import importlib
# require installation of 'gcp' extras
try:
importlib.util.find_spec("google.cloud")
except ImportError:
raise ValueError("Please install package[gcp]")
@atemate
atemate / README.md
Last active May 28, 2024 21:46
PubSub request/response with dynamically created subscriptions with filters
@atemate
atemate / docker-compose.yaml
Created May 22, 2024 10:21
Docker-compose config for SNS running in a Localstack image
version: "0.1"
services:
sns:
image: localstack/localstack
environment:
# LocalStack configuration: https://docs.localstack.cloud/references/configuration/
- DEBUG=${DEBUG:-0}
- SERVICES=sns
ports:
- "4566:4566"
@atemate
atemate / iter_dict_in_chunks.py
Created April 26, 2024 10:50
Function to iterate over a dict of lists and yield key:values
from typing import Any, Dict, List
def iter_dict_in_chunks(input_dict: Dict[Any, List], chunk_size: int, total_size: int):
"""Iterates a dict of lists and yields key:values pairs where len of values
is at most `chunk_size`, until `total_size` is exhausted.
Examples:
# Realistic cases:
>>> d = {'a': [1, 2], 'b': [3, 4, 5, 6, 7, 8, 9]}
>>> list(iter_dict_in_chunks(d, 3, 5))
@atemate
atemate / _tenacity_retry_with_asyncio_semaphore.py
Last active March 13, 2024 12:48
Minimal example testing behaviour of tenacity.retry() with asyncio.Semaphore()
import asyncio
import random
import logging
import httpx
import tenacity
logging.basicConfig(level=logging.INFO, format="%(relativeCreated)dms %(message)s")
N_SEMAPHORE = 2
@atemate
atemate / configure_logging_to_stderr_only.py
Created August 10, 2023 09:16
Configure python logging to stderr only
import logging
import os
import sys
from distutils.util import strtobool
from typing import Optional
def configure_logging_to_stderr_only(filename: Optional[str] = None):
"""Configures a basic config depending on 'DEBUG' env variable,
and also re-configures all existing handlers to output to stderr
@atemate
atemate / match_dict.py
Last active August 9, 2023 16:28
Finds a dict in a list of dicts that matches specific filter
class WildcardDict(dict):
def __init__(self, *args, enable_wildcards: bool = False, **kwargs) -> None:
self._enable_wildcards = enable_wildcards
return super().__init__(*args, **kwargs)
def __getitem__(self, key):
if not self._enable_wildcards:
return super().__getitem__(key)
for k, v in self.items():