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 / service.py
Created October 21, 2024 10:04
Action Service example
"""
Based on https://github.com/tough-dev-school/education-backend/blob/master/src/core/services.py
"""
from abc import ABC, abstractmethod
from collections.abc import Callable, Sequence
from typing import Any, Generic, TypeVar
ReturnType = TypeVar('ReturnType')
@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 / BCD.py
Created July 17, 2018 11:02
Convert from int to bcd format and counterwise with pure python
def bcd_to_int(n):
return int(('%x' % n), base=10)
def int_to_bcd(n):
return int(str(n), base=16)