Skip to content

Instantly share code, notes, and snippets.

View mahenzon's full-sized avatar

Suren Khorenyan mahenzon

View GitHub Profile
@mahenzon
mahenzon / README.md
Last active September 2, 2025 14:16
Example RAG using ru-en-RoSBERTa, ChromaDB / Redis Vector, OpenAI
@mahenzon
mahenzon / concat-annotation-example.py
Created August 23, 2025 18:42
Python Concatenate annotation example
from functools import wraps
from timeit import default_timer
from typing import reveal_type, Callable, Concatenate
type ExecutionTime = float
def with_execution_time[**P, T](
func: Callable[P, T],
) -> Callable[P, tuple[T, ExecutionTime]]:
@mahenzon
mahenzon / common.py
Created August 17, 2025 10:17
Python 3.12 ParamSpec example
import logging
# DEFAULT_LOG_FORMAT = "[%(asctime)s.%(msecs)03d] %(funcName)20s %(module)s:%(lineno)d %(levelname)-8s - %(message)s"
DEFAULT_LOG_FORMAT = (
"%(funcName)10s %(module)s:%(lineno)d %(levelname)-8s - %(message)s"
)
def configure_logging(level: int = logging.INFO) -> None:
logging.basicConfig(
@mahenzon
mahenzon / sqla-ms-sql-compile.md
Created August 11, 2025 21:08
SQLAlchemy code to to compile Microsoft SQL w/ latest version to support OFFSET/FETCH

ChatGPT 5 solution after several attempts and corrections.

You're right—just setting _server_version_info isn’t enough; the MSSQL dialect caches feature flags at init. We need to refresh those flags so the compiler knows OFFSET/FETCH is supported.

Use this function (note the call to _setup_version_attributes) and make sure your statement has ORDER BY and .offset(...):

from typing import Optional, Tuple, Union
@mahenzon
mahenzon / config.py
Created April 8, 2025 07:49
Example Telegram bot | Lerna × Suren
import os
TOKEN = os.getenv(
"BOT_TOKEN",
"123:abc",
)
@mahenzon
mahenzon / main.ipynb
Created April 3, 2025 07:36
Python Basics | Lerna × Suren
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mahenzon
mahenzon / main.ipynb
Created April 1, 2025 07:37
Python Intro | Lerna × Suren
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mahenzon
mahenzon / main.ipynb
Created February 16, 2025 09:07
Python functools.partial examples
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mahenzon
mahenzon / example_callback_protocol.py
Created February 2, 2025 11:57
Protocol annotation in Python
from typing import Protocol
class MessageCallback(Protocol):
__name__: str
def __call__(
self,
message: str,
size: int,
@mahenzon
mahenzon / common.py
Created January 26, 2025 06:58
overload annotation in Python
import logging
# DEFAULT_LOG_FORMAT = "[%(asctime)s.%(msecs)03d] %(funcName)20s %(module)s:%(lineno)d %(levelname)-8s - %(message)s"
DEFAULT_LOG_FORMAT = (
"%(funcName)10s %(module)s:%(lineno)d %(levelname)-8s - %(message)s"
)
def configure_logging(level: int = logging.INFO) -> None:
logging.basicConfig(