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 / 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 / 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/ #