Navigation Menu

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 / 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
@Winand
Winand / .python-version
Last active January 6, 2023 22:35
poetry interpreter detection issue
3.9.13
3.10.9
3.8.10
@Winand
Winand / example.py
Last active January 6, 2023 11:55
Nox in docker example
import os
def Main():
x = os.getpid()
print(f"{x=}")
if __name__ == '__main__':
Main()
@Winand
Winand / typer_abbr_args.py
Last active December 15, 2022 14:43
Allow abbreviated argument names (see also allow_abbrev=True in argparse)
import typer
def main(
hello: int = typer.Option(None),
there: int = typer.Option(None),
infinite: bool = typer.Option(False),
) -> None:
print(hello, there, infinite)
if __name__=='__main__':
@Winand
Winand / table_split_w_headers.bas
Last active October 27, 2022 11:58
Split table on page breaks and add header row to each new part
Sub tableSplitWithHeaders()
'https://stackoverflow.com/questions/8668311/current-row-in-vba-word
'https://www.tek-tips.com/viewthread.cfm?qid=1610014
'https://stackoverflow.com/questions/37999841/how-can-i-determine-the-page-number-of-a-table-in-ms-word-macro
'https://learn.microsoft.com/en-us/office/vba/api/word.selection.insertbreak
Const TITLE_CONTINUE As String = "Продолжение таблицы"
Const TITLE_END As String = "Окончание таблицы"
Dim t As Table, t2 As Table, r As row