Skip to content

Instantly share code, notes, and snippets.

View mahenzon's full-sized avatar

Suren Khorenyan mahenzon

View GitHub Profile
@mahenzon
mahenzon / LICENSE
Last active April 1, 2026 14:43
Exceptions with Template-based messages
MIT License
Copyright (c) 2026 mahenzon
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@mahenzon
mahenzon / example.py
Created March 16, 2026 20:19
Python set add same hash value item if no eq
class A:
def __init__(self, val):
self.val = val
def __hash__(self):
return hash(self.val)
def __str__(self):
return str(self.val)
@mahenzon
mahenzon / README.md
Created February 27, 2026 22:17
SQLAlchemy server defaults - postgres vs mysql vs mariadb comparison

Postgres vs mysql vs mariadb comparison: SQLAlchemy server defaults

RETURNING or not?

  • Postgres ✅
  • MySQL ❌
  • MariaDB ✅
@mahenzon
mahenzon / redis-annotations-example.py
Created January 5, 2026 10:32
how Redis-py annotations can be fixed for public methods
"""
Suggestion for implementing
https://github.com/redis/redis-py/pull/3619
Try it here:
https://mypy-play.net/?mypy=latest&python=3.14&gist=bded9af8fe83b0625ad6bf72ad4b9338&flags=strict
"""
from typing import Awaitable, Generic, Literal, TypeVar, overload, reveal_type
OptionalDecodedString = str | None
@mahenzon
mahenzon / queries.sql
Last active November 12, 2025 06:05
SQLAlchemy TEXT constraint examples
-- №1
CREATE TABLE users (
id BIGINT GENERATED ALWAYS AS IDENTITY,
name TEXT NOT NULL CHECK (length(name) <= 100),
PRIMARY KEY (id)
)
-- №2
CREATE TABLE users (
@mahenzon
mahenzon / example-openai-api-call-ollama.py
Created October 4, 2025 20:05
Ollama example OpenAI API call
import requests
API_KEY = "EMPTY"
# BASE_URL = "http://localhost:12345/engines/llama.cpp/v1"
BASE_URL = "http://localhost:11223/v1"
URL = f"{BASE_URL}/chat/completions"
# MODEL = "ai/gemma3"
# MODEL = "ai/gemma3n"
MODEL = "gemma3:1b"
@mahenzon
mahenzon / .python-version
Created September 21, 2025 11:15
Python AI LLM example using langchain
3.13
@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(