Skip to content

Instantly share code, notes, and snippets.

View afonasev's full-sized avatar
🔥

Afonasev Evgeniy afonasev

🔥
View GitHub Profile
@afonasev
afonasev / devfestomsk2023.md
Last active February 12, 2024 17:17
devfestomsk2023
@afonasev
afonasev / stachka2023.md
Last active November 3, 2023 13:09
stachka2023
@afonasev
afonasev / pytup2023.md
Last active December 14, 2023 10:44
pytup2023
@afonasev
afonasev / pycon2023_lighting.md
Last active July 27, 2023 23:56
pycon2023_lighting
@afonasev
afonasev / pycon2023.md
Last active December 14, 2023 10:43
pycon2023
#!/usr/bin/env python
"""Wrapper around Flake8 to enable multiprocessing on all operating systems.
As of Python 3.8, macOS's default "start method" for multiprocessing is `spawn`. Flake8
requires a "start method" of `fork`, and disables multiprocessing if it detects `spawn`
or some other "start method". This script enables the `fork` start method before passing
along any command-line arguments to `flake8`.
This has never caused me any problems, but note that they disabled this for a reason:
Flake8's plugin interface doesn't work with `spawn`, and the maintainer says that `fork`
is "pretty broken" on macOS.
See:
@afonasev
afonasev / pycon2022.md
Last active July 5, 2024 07:09
Полезные материалы для доклада на pycon russia 2022
@afonasev
afonasev / session.py
Last active June 9, 2020 14:16
Sqlalcheny sugar for sessions
from contextlib import ContextDecorator
from functools import wraps
from typing import Any, Callable, Optional, Type
class SessionContext(ContextDecorator):
"""
class Session(SessionContext):
scoped_session = ...
@afonasev
afonasev / basemodel.py
Created June 9, 2020 14:01
Sqlalchemy BaseModel
from sqlalchemy.ext.declarative import DeclarativeMeta, declarative_base, declared_attr
from sqlalchemy import MetaData
from sqlalchemy.engine import create_engine
from sqlalchemy.orm import Session
from sqlalchemy.orm import scoped_session as _scoped_session
from sqlalchemy.orm import sessionmaker as _sessionmaker
from .config import config
engine = create_engine(
@afonasev
afonasev / utc_datetime_field.py
Created June 9, 2020 13:56
UTCDateTime field for sqlalchemy
from datetime import timezone
import sqlalchemy as sa
class UTCDateTime(sa.TypeDecorator): # pylint:disable=W0223
"""By default if we provide datetime object without timezone Postgres applies
his timezone to that datetime. To prevent unexpected behaviour we add utc timezone
before every write. And convert back to utc, after every read.