Skip to content

Instantly share code, notes, and snippets.

View SXHRYU's full-sized avatar
🤡
I'm just a little jokester. A silly little guy.

Slava M. SXHRYU

🤡
I'm just a little jokester. A silly little guy.
View GitHub Profile
@SXHRYU
SXHRYU / pre-commit
Last active April 19, 2023 10:38
This is a gist of a pre-commit git hook using raw bash (not https://pre-commit.com/). It must be placed in `.git/hooks/pre-commit`. This gist enters `config` directory with `pyproject.toml` (which has `[mypy]` and `[flake8]` configs). From there it calls both `mypy` and `flake8`. Then it sets up environment variables for `pytest` and calls it.
#!/bin/sh
##########################################################################################################
# I've used this pre-commit hook in my FastAPI app. It launches `bash` session (even on Windows) from the root dir of your project.
# Meaning if you have a following project structure:
###############################
# app/ #
# .git #
# __pycache__ #
# .mypy_cache #
# config/ #
@SXHRYU
SXHRYU / str_to_datetime.py
Created January 6, 2023 18:55
Function that transforms string to `datetime.datetime` object with considerations for popular datetime formats. Meaning this function is format-agnostic and easily scalable (just add new formats).
def transform_to_datetime(date_string: str) -> datetime:
"""Normalises different datetimes and turns them into `datetime`
objects.
Needed in case time output from the site changes in the future.
Parameters
----------
date_string : str
Datetime presented in `str` format.
@SXHRYU
SXHRYU / pyproject.toml
Last active July 10, 2023 06:40
Boiler settings for pyproject
[tool.mypy]
strict = true
[tool.isort] # pyproject.toml, .isort.cfg = [settings]
profile = "black"
multi_line_output = 3
lines_after_imports = 2
lines_between_sections = 0 # novk
force_alphabetical_sort_within_sections = true # vk
include_trailing_comma = true # vk
@SXHRYU
SXHRYU / boilerplate.gitignore
Last active April 17, 2023 11:48
boilerplate .gitignore
__pycache__
.venv
.vscode
.mypy_cache
.pytest_cache
.dockerignore
*.ps1
*.sh
*.pdf
*.log
@SXHRYU
SXHRYU / vk_pre_commit
Created May 17, 2023 07:46
pre-commit hook I use for my work. I didn't update the `pre-commit` gist, because it's starting to get VERY different.
alias black79="black --line-length 79 --force-exclude '((^.*(\/migrations\/).*\.py)|(.*\.(?!pyi?$)[^.]+$))' --extend-exclude migrations/"
alias isort79="isort --multi-line 3 --force-alphabetical-sort-within-sections --trailing-comma --combine-as --lines-after-imports 2 --filter-files --extend-skip migrations"
alias autoflake79="autoflake --remove-all-unused-imports --ignore-init-module-imports -r -v --in-place --exclude '*/migrations/*'"
git diff --quiet --cached --name-only --diff-filter=D
start_condition_0=$?
git diff --quiet --cached --name-only --diff-filter=ACMR
start_condition_1=$?
if [ $start_condition_0 = 0 ] && [ $start_condition_1 = 1 ]
@SXHRYU
SXHRYU / git_local_ignore
Created May 23, 2023 11:54
.git/info/exclude is a local .gitignore file. Same syntax as .gitignore
.git/info/exclude is a local .gitignore file. Same syntax as .gitignore
@SXHRYU
SXHRYU / pip clear
Created August 11, 2023 08:15
Uninstall all packages in pip
pip freeze | sed 's/=.*//g' | xargs pip uninstall -y
@SXHRYU
SXHRYU / xlsxwriter_logic.py
Created August 14, 2023 11:33
Python xlsxwriter logic separation between row creation and insertion. `form_excel` function is independent of data inserted and header rows.
from collections.abc import Iterable, Sequence
from typing import TypeVar, TypedDict
import xlsxwriter
from .items import Item
T = TypeVar("T")
class Data(TypedDict):
@SXHRYU
SXHRYU / pipe.py
Last active August 14, 2023 11:37 — forked from vskrachkov/pipe.py
python, pipe, chain, monad, functor
from __future__ import annotations
from typing import Callable, Union
class Pipe:
def __init__(self, callable_: Callable):
self.callable_ = callable_
def __rshift__(self, then: Callable | Pipe) -> Pipe:
@SXHRYU
SXHRYU / stderr_to_pipe.sh
Created August 15, 2023 18:13
pipe stderr to grep.
command 2>&1 >/dev/null | grep "line"