Skip to content

Instantly share code, notes, and snippets.

View toolittlecakes's full-sized avatar

Nikolay Sheyko toolittlecakes

  • CodeSignal
  • Yerevan, Armenia
View GitHub Profile
@toolittlecakes
toolittlecakes / hidden_data.py
Last active December 7, 2024 17:16
Tiny utils module that allow you to store **any** json-able data into aiogram message and read it back (from `message.html_text`)
import json
import re
from ast import literal_eval
from urllib import parse
# Functions for read and write url params
def url_loads(url_params: str) -> dict:
parsed = parse.parse_qs(url_params)
# parse_qs returns a dict of lists,
@toolittlecakes
toolittlecakes / dummy_async.py
Created April 21, 2024 09:22
Simple implementation showing the idea of async code. Doesn't use async/await keywords or real event_loop for the sake of simplicity and clarity
import time
from collections import deque
from pprint import pprint
START_TIME = time.time()
def run(func):
gen = func()
while True:
@toolittlecakes
toolittlecakes / function_polymorphism.py
Last active April 17, 2024 03:44
Inspired by this article about unobvious usage of polymorphism in order to embrace functional approach to create alternative solution
import syslog
from dataclasses import dataclass
from typing import Callable, Generic, Literal, Protocol, Type, TypeVar, TypeVarTuple
# Initial solution with classes
#
# class Filter(Protocol):
# def filter(self, message: str) -> bool: ...
# class TextFilter(Filter):
@toolittlecakes
toolittlecakes / st_fixed_container.py
Last active October 1, 2025 16:03
Sticky/fixed container for streamlit apps. Supports dynamic width change as well as dynamic color updates. Both top/bottom positions are available.
from typing import Literal
import streamlit as st
from streamlit.components.v1 import html
"""
st_fixed_container consist of two parts - fixed container and opaque container.
Fixed container is a container that is fixed to the top or bottom of the screen.
When transparent is set to True, the container is typical `st.container`, which is transparent by default.