Skip to content

Instantly share code, notes, and snippets.

View Eduard-gan's full-sized avatar

Eduard Gan Eduard-gan

  • Self employed
  • Russian federation
View GitHub Profile
@Eduard-gan
Eduard-gan / test.py
Created December 29, 2021 10:55
Async structured logging with loguru
import asyncio
from aiologger import Logger
from loguru import logger
def async_logging(msg):
aio_logger = Logger.with_default_handlers(name='my-logger')
method = getattr(aio_logger, msg.record['level'].name.lower())
method(f"AIO LOGGING: {msg}")
pg_dump -U postgres -Fc mfo > mfo.sql
docker cp postgres:/mfo.sql mfo.sql
docker cp mfo.sql postgres:/mfo.sql
SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'mfo' AND pid <> pg_backend_pid();
drop database mfo;
create database mfo;
pg_restore -U postgres -d mfo --clean --create mfo.sql
@Eduard-gan
Eduard-gan / gist:f769c239d0b4021d55f9b065bebbba11
Last active August 10, 2020 17:42
Python: Exception class that brings some structured data to caller
import logging
class InsufficientFunds(PaymentSystemError):
requested_amount: float = None
direction: FinDirection = None
account_balance: float = None
def __init__(self, *args, direction=None, requested_amount=None, account_balance=None, **kwargs):
self.direction = direction
pip install mutmut
mutmut run --runner 'python -m pytest -x tests/test_quiz.py' --paths-to-mutate business_logic/credit_history_quiz.py
mutmut results # Shows munants IDs (X here)
mutmut show X # Shows diff metant/original
mutmut apply X # Applies change from mutant to file
То stop certain line from mutation (Annoying on log lines) apply whitelisting comment on it: # pragma: no mutate
@Eduard-gan
Eduard-gan / gist:5ebf1acdccaf21ea1b7358bae425a252
Created August 3, 2020 13:43
Typical pytest launch with pytest-cov package installed
pytest tests/test_quiz.py --disable-pytest-warnings --cov=business_logic.credit_history_quiz --cov-report term-missing
In PyChrm that would be
Additional arguments:
--disable-pytest-warnings --cov=business_logic.credit_history_quiz --cov-report term-missing
@Eduard-gan
Eduard-gan / default.conf
Created February 4, 2020 02:14
Раздача статики с Nginx
location /static/ {
# error_log /home/aa/kek.log debug; # Очень много информации для дебага именно по этому локэйшену.
root /home/aa;
# Сами файлы лежат в /home/aa/static/
}
@Eduard-gan
Eduard-gan / docker-compose.yml
Created December 24, 2019 10:30
Forever running docker container with docker-compose
recovery:
build: build/postgres/
container_name: recovery
network_mode: bridge
hostname: recovery
restart: always
command: tail -f /dev/null
volumes:
- ./build/postgres/postgresql.conf:/etc/postgresql/postgresql.conf
- ./build/postgres/backup.py:/opt/scripts/backup.py # Скрипт отвечающий за бэкапы на вольюм бэкапов.
try:
self._pass_issue_date = self.person.pass_issue_date if getattr(self.person,'birthday', 0) else None
except ValueError:
self._pass_issue_date = self.person.pass_issue_date if getattr(self.person,'birthday', 0) else None
# Add existing repo as a submodule in another repo(now it's super-repo)
- CD to super-repo
- git submodule add https://gitlab.com/e.gan/test-shared-repo.git some_generic_code (some_generic_code is a name of directory under which the code from submodule will reside)
- git commit -am "I linked a somerepo as submodule some_generic_code"
# Update or downgrade version of submodule to latest in super-repo
- CD to some_generic_code (the submodule repo is now manages by "git" command)
- git checkout master
- CD out of some_generic_code to parent directory(super-repo)
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
# Show active connections
SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
# Show some shit;
show processlist;
# Create Database with PROPPER unicode encoding
create database animarender character set UTF8mb4 collate utf8mb4_unicode_ci;