Skip to content

Instantly share code, notes, and snippets.

View rvasilevsk's full-sized avatar

Roman rvasilevsk

  • Minsk, Belarus
View GitHub Profile
@rvasilevsk
rvasilevsk / table_trim_fn.py
Last active November 6, 2022 20:31
[table_trim()] #fn #snippet
from itertools import islice
from typing import Iterable, List, Optional, Sequence
def table_trim(tbl: Iterable[List], max_rows: Optional[int], max_cols: Optional[int]) -> Sequence[List[str]]:
if max_rows is not None:
tbl = islice(tbl, max_rows)
if max_cols is not None:
tbl = (row[:max_cols] for row in tbl)
return tbl
@rvasilevsk
rvasilevsk / .flake8
Created November 6, 2022 20:14
.flake8
[flake8]
max-line-length=119
ignore=E203
exclude = venv/*
#max-complexity = 10
@rvasilevsk
rvasilevsk / pyproject.toml
Created November 6, 2022 19:29
[pyproject.toml black] #pyproject.toml
[tool.black]
line-length = 119
target-version = ['py310']
# include = '\.pyi?$'
# 'extend-exclude' excludes files or directories in addition to the defaults
#extend-exclude = '''
## A regex preceded with ^/ will apply only to files and directories
## in the root of the project.
#(
# ^/foo.py # exclude a file named foo.py in the root of the project
@rvasilevsk
rvasilevsk / Makefile
Created November 6, 2022 19:27
[Makefile] pdoc3
PY_DOCS_PACKAGES=pyperclip tabulate
## docs ###############################################################################################################
.PHONY: docs
docs:
pdoc3 --html -o docs -f $(PY_DOCS_PACKAGES)
#cp logo.png docs/
.PHONY: live
live:
@rvasilevsk
rvasilevsk / Makefile
Last active November 6, 2022 16:19
[Makefile] flake8, black, isort
## flake, black, isort ################################################################################################
.PHONY: flake
flake:
flake8 --include=$(PY_FILES)
.PHONY: black
black:
black --check --diff $(PY_FILES)
black-fix:
@rvasilevsk
rvasilevsk / Makefile
Created November 6, 2022 15:00
[Makefile] version, jupyterlab
## info ###############################################################################################################
v:
python --version && pip --version
## jupyterlab #########################################################################################################
lab:
jupyter-lab
@rvasilevsk
rvasilevsk / py_vesrion.py
Created November 6, 2022 14:13
[python check version] #python
if not sys.version_info.major == 3 and sys.version_info.minor >= 6:
print("Python 3.6 or higher is required.")
print("You are using Python {}.{}.".format(sys.version_info.major, sys.version_info.minor))
sys.exit(1)
@rvasilevsk
rvasilevsk / abbr.ifname.py
Created September 20, 2021 16:01
abbr.ifname.py
# abbrevation: ifna
# desription: if __name__ == '__main__':
# scope: top
def _main():
print('main')
if __name__ == '__main__':
_main()
@rvasilevsk
rvasilevsk / .gitignore
Created August 8, 2021 17:33
.gitignore
# myself
*skipgit*
# python
__pycache__/
*.py[cod]
# jetbrains
.idea/
@rvasilevsk
rvasilevsk / where.py
Last active February 12, 2021 18:06
where, which, executable_exists #python.shellutils
# [pyperclip/__init__.py at master · asweigart/pyperclip](https://github.com/asweigart/pyperclip/blob/master/src/pyperclip/__init__.py)
try:
from shutil import which as _executable_exists
except ImportError:
# The "which" unix command finds where a command is.
if platform.system() == 'Windows':
WHICH_CMD = 'where'
else:
WHICH_CMD = 'which'