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 / logger.py
Created October 21, 2024 14:26
Logging with multiple handlers to different output, formatters
import logging
from logging.handlers import HTTPHandler as HTTPLoggingHandler
from typing import Any
class ExternalFilter(logging.Filter):
flag = "to_external_source"
def filter(self, record: logging.LogRecord) -> bool:
return getattr(record, self.flag, False)
@SXHRYU
SXHRYU / reflect.py
Last active April 3, 2024 13:56 — forked from 1kastner/reflect.py
ruffed & blacked. A simple echo server to inspect http web requests
# ruff: noqa: N802, N815, E501
# Reflects the requests from HTTP methods GET, POST, PUT, and DELETE
# Written by Nathan Hamiel (2010)
from http.server import BaseHTTPRequestHandler, HTTPServer
from optparse import OptionParser
class RequestHandler(BaseHTTPRequestHandler):
@SXHRYU
SXHRYU / proxy_tcp_server.py
Created November 16, 2023 13:50
Example of proxy TCP echo server. Useful for debugging and analysing incoming traffic.
# Proxy echo TCP server program
import socket
HOST = "localhost"
PORT = 6667
HOST_NEW = "localhost"
PORT_NEW = 6666
CONNECTED = False
@SXHRYU
SXHRYU / stderr_to_pipe.sh
Created August 15, 2023 18:13
pipe stderr to grep.
command 2>&1 >/dev/null | grep "line"
@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 / 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 / pip clear
Created August 11, 2023 08:15
Uninstall all packages in pip
pip freeze | sed 's/=.*//g' | xargs pip uninstall -y
@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 / 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 / boilerplate.gitignore
Last active April 17, 2023 11:48
boilerplate .gitignore
__pycache__
.venv
.vscode
.mypy_cache
.pytest_cache
.dockerignore
*.ps1
*.sh
*.pdf
*.log