Skip to content

Instantly share code, notes, and snippets.

View mahenzon's full-sized avatar

Suren Khorenyan mahenzon

View GitHub Profile
@mahenzon
mahenzon / example_00_please_no_named_tuples.py
Created April 20, 2024 18:54
Please don't use these Python instruments
from collections import namedtuple
from dataclasses import dataclass
# from typing import NamedTuple
# Point = namedtuple("Point", "x, y")
AgeAndWeight = namedtuple(
"AgeAndWeight",
"age, weight",
)
@mahenzon
mahenzon / five.py
Last active April 13, 2024 20:42
Python Final and @ final examples
from typing import Final, Sequence
ADMIN_IDS: Final[Sequence[int]] = [1, 5]
# ADMIN_IDS: Final[Sequence[int]] = (1, 5)
# ADMIN_IDS: Final[tuple[int, ...]] = (1, 5, 8)
def main() -> None:
print(ADMIN_IDS)
ADMIN_IDS.append(7)
@mahenzon
mahenzon / main.ipynb
Created March 31, 2024 19:17
Pydantic union multi models validation
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mahenzon
mahenzon / main.py
Last active March 8, 2024 15:42
SQLAlchemy m2m to self example
from sqlalchemy import create_engine, Column, Integer, String, ForeignKey, select
from sqlalchemy.orm import sessionmaker, relationship, DeclarativeBase, selectinload
# DB_URL = "sqlite:///tags.db"
DB_URL = "sqlite:///:memory:"
DB_ECHO = False
class Base(DeclarativeBase):
id = Column(Integer, primary_key=True)
@mahenzon
mahenzon / step_0.py
Created February 17, 2024 19:33
Never and NoReturn Annotations Python examples
def get_num() -> int:
return 42
def get_word() -> str:
return "spam"
def main() -> None:
num = get_num()
@mahenzon
mahenzon / DictionaryExample.java
Created January 21, 2024 09:09
Java example dictionary with "default" HashSet of integers
import java.util.*;
public class Main {
public static void main(String[] args) {
int[] numbers = {1, 2, 3, 2, 4, 5, 3, 6, 7, 4};
HashMap<Integer, HashSet<Integer>> dictionary = new HashMap<>();
for (int i = 0; i < numbers.length; i++) {
int number = numbers[i];
if (!dictionary.containsKey(number)) {
@mahenzon
mahenzon / README.md
Last active January 26, 2024 14:35
Repka-Pi 3 H5 LED and Servo example using PCA9685 board and Adafruit CircuitPython libs (RoboIntellect RM001 M02)

Установка зависимостей

Зависимости для взаимодействия с GPIO

sudo apt install -y libgpiod2 python3-libgpiod

Создание и активация виртуального окружения (в примере использован python3.9, установлен отдельно)

@mahenzon
mahenzon / vim-get-out-command.md
Created July 13, 2023 19:15
vim how to get out

⎋ Escape, :, q, ⏎ Enter

@mahenzon
mahenzon / main.ipynb
Created June 11, 2023 12:10
Python funcs returns and float/Decimal
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mahenzon
mahenzon / equation-root-finder.cpp
Created June 2, 2023 18:10
Equation Root Finder using Bisection Method
//
// Created by Suren Khorenyan on 02.06.2023.
//
#include <iostream>
#include <cmath>
double equation(double a, double b, double x) {
return a * pow(x, 3) + b * x - 1;
}