Skip to content

Instantly share code, notes, and snippets.

View mahenzon's full-sized avatar

Suren Khorenyan mahenzon

View GitHub Profile
@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(
@mahenzon
mahenzon / replace-shadow-hash.py
Created January 22, 2025 06:39
Python script to replace password for macOS user if you have sudo rights
"""
Tested on macOS 11.5 Big Sur
SIP disabled
admin@MBP-Suren ~ % csrutil status
System Integrity Protection status: disabled.
run:
@mahenzon
mahenzon / pyproject.toml
Created December 22, 2024 08:19
Self type annotation in Python
[tool.mypy]
strict = true
@mahenzon
mahenzon / python-defaultdict-examples.py
Created December 7, 2024 18:07
Python defaultdict examples
# SOME_SENTENCE = input("Enter a sentence: ")
from collections import defaultdict
from collections.abc import Iterable
SOME_SENTENCE = (
"The cat sat on the mat, "
"and the cat played with the mat "
"while the cat watched the sun."
)
@mahenzon
mahenzon / common.py
Created November 30, 2024 20:08
Annotation for decorator creator 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(