Skip to content

Instantly share code, notes, and snippets.

View Winand's full-sized avatar
🐍
<-Python

Makarov Andrey Winand

🐍
<-Python
View GitHub Profile
@Winand
Winand / purity.py
Created June 25, 2026 14:01
Check for usage of global variables in module functions
"Check for usage of global variables in module functions."
import inspect
import sys
from importlib import import_module
from logging import Logger
from types import ModuleType
def bold(text: str) -> str:
"Make text bold."
@Winand
Winand / passtype.py
Last active June 22, 2026 11:42
Automatically type a stored password via a hotkey
"""
Automatically type a stored password via a hotkey.
Usage:
uv run passtype.py password - save a new password in keyring
uv run passtype.py - wait for Alt+Ctrl+Shift+P hotkey to type password
"""
# /// script
# requires-python = ">=3.14"
# dependencies = [
@Winand
Winand / uvx-link.ps1
Last active March 25, 2026 11:11
Create a shortcut for `uvx --from package executable` in ~/.local/bin, because `uv tool install` installs all executables
@Winand
Winand / exit_retry.py
Created March 25, 2025 13:23
Decorator which re-runs a function if it exited with a specified code
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from sys import _ExitCode
def exit_retry(tries: int, code: "_ExitCode | None" = None, pause: float = 0):
"""Retry function call after sys.exit().
:param retries: number of retries
:type retries: int
@Winand
Winand / Dockerfile
Last active April 21, 2024 11:18
Build Caddy server Docker image
FROM golang:1.22.2-alpine AS build
ARG XCADDY_VERSION=0.4.0
ARG CADDY_VERSION
RUN apk --no-cache add libcap
RUN wget -O /tmp/xcaddy.tar.gz "https://github.com/caddyserver/xcaddy/releases/download/v${XCADDY_VERSION}/xcaddy_${XCADDY_VERSION}_linux_amd64.tar.gz"; \
echo "$checksum /tmp/xcaddy.tar.gz" | sha512sum -c; \
tar x -z -f /tmp/xcaddy.tar.gz -C /usr/bin xcaddy; \
rm -f /tmp/xcaddy.tar.gz; \
chmod +x /usr/bin/xcaddy;
RUN xcaddy build ${CADDY_VERSION}
@Winand
Winand / lazy_dict_str.py
Last active April 3, 2024 14:11
Lazy conversion of dictionary to JSON string
import json
import logging
import time
logger = logging.getLogger()
d = {"A": 1, "B": 2, "C": {'a': 'hello', "_": 'world'}}
class LazyDictStr:
"Converts dictionary to formatted JSON string when str(...) called"
@Winand
Winand / gl-sast-report-to-html.py
Created February 29, 2024 09:31
Convert GitLab SAST report to HTML table
from json2html import json2html
import json
from markdown import markdown
filename = "gl-sast-report"
svr = {"Critical": "Crimson", "Medium": "Coral", "Low": "MediumSeaGreen", "Info": "SteelBlue"}
with open(filename + ".json") as f:
inp = json.load(f)
data = inp["vulnerabilities"]
import numpy as np
class NeuralNetwork():
def __init__(self):
# seeding for random number generation
np.random.seed(1)
#converting weights to a 3 by 1 matrix with values from -1 to 1 and mean of 0
self.synaptic_weights = 2 * np.random.random((3, 1)) - 1
@Winand
Winand / start_cloak.ps1
Last active September 29, 2023 12:26
Start cloak client from PowerShell script
# Self-elevate the script if required
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
# $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
# Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Start powershell.exe -Verb RunAs -ArgumentList "cd $pwd; & $($MyInvocation.MyCommand.Path)"
Exit
}
}
@Winand
Winand / environ
Created July 12, 2023 12:32
Python virtual environment list and activation script
ROOT=~/venv
RED='\e[0;31m'
GREEN='\e[0;32m'
LIGHTBLUE='\e[1;34m'
NC='\e[0m' # No Color
trim() {
# Remove the leading and trailing whitespaces
# https://stackoverflow.com/a/12973694
echo $1 | xargs