Python

Url Shortener for CLI

CLI Url Shortener wrote a little URL Shortener in Python with FastAPI and a wrapper script for cli usage. needs httpie & jq packages. python backend is under development, cli wrapper for different os right here … Usage somehost$ ./myurlshort usage: /usr/local/bin/myurlshort http://veeeeeeeeeeeeeeeeeeeeeeeeeery.long.url.to anyhost$ ./myurlshort http://my-url-to-short.egal.world.planet.universe https://url.stoege.net/xXxXx CLI Wrappers OpenBSD cat << 'EOF' > myurlshort #!/usr/bin/env bash # url shortener for openbsd, v1.0, 2022-09-12, by @stoege which jq >/dev/null || ( echo -e "*** jq not installed ***\ndoas pkg_add jq\n"; ) which https >/dev/null || ( echo -e "*** httpie not installed ***\ndoas pkg_add httpie\n"; ) if [[ $# -ne 1 ]]; then echo -e "\nusage: $0 http://veeeeeeeeeeeeeeeeeeeeeeeeeery.

JC - JSON from CLI

how to build json from cli we all like json, do we ? https://kellyjonbrazil.github.io/jc/docs/parsers/ping add package doas pkg_add jc try ping openbsd-box # ping -c 3 1.1.1.1 |jc --ping -p 2>/dev/null { "destination_ip": "1.1.1.1", "data_bytes": 56, "pattern": null, "destination": "1.1.1.1", "packets_transmitted": 3, "packets_received": 3, "packet_loss_percent": 0.0, "duplicates": 0, "round_trip_ms_min": 9.219, "round_trip_ms_avg": 9.826, "round_trip_ms_max": 10.158, "round_trip_ms_stddev": 0.43, "responses": [ { "type": "reply", "bytes": 64, "response_ip": "1.1.1.1", "icmp_seq": 0, "ttl": 59, "time_ms": 10.

Python PIP3

Python PIP https://pip.pypa.io/en/stable/cli/pip_list/ https://blog.stoege.net/posts/pip/ OpenBSD 7.1 # python3 --version Python 3.9.12 # python3 -m pip --version pip 22.0.4 from /usr/local/lib/python3.9/site-packages/pip (python 3.9) List installed python3 -m pip list List Outated python3 -m pip list --outdated --format columns sha256: 6ada0942bc4d02ee477ab233571e893547049a379479b61910541e561d2f053a

Little Mail Validator in Python

wrote a little Mail Adresse Validator in Python. use it, modify it, like it … best practice for python is to use a virtual env like Poetry (or virtualenv) and add the “email-validator” module like this: poetry add email-validator Code few lines of code … #!/usr/bin/env python3 from email_validator import validate_email, EmailNotValidError ok=[] nok=[] emails = [ "my+address@mydomain.tld", "hans@dampf.ch", "gott@welt.net", "adsf@asdf.com", "asf.asdf", "franz!mueller@abc.com", "asdf@asdf.adf" ] print ("\nMy Little Mail Validator\n") for email in emails: try: # Validate.

Python

Python Snippets RealPython Best Practices: https://realpython.com/tutorials/best-practices/ Convert CSV to JSON cat LARGEFILE.csv |python3 -c 'import csv, json, sys; print(json.dumps([dict(r) for r in csv.DictReader(sys.stdin)]))' > LARGEFILE.json Zfill Padding Zero >>> for i in range(1,10): ... str(i).zfill(4) '0001' '0002' '0003' ... Different Padding #!/usr/bin/env python3 for i in range(1,99): print( str(i).zfill(4) +" "+ str(i).rjust(4, '-') +" "+ str(i).ljust(4, '-') +" "+ str(i).center(4, '-') ) 0001 ---1 1--- -1-- 0002 ---2 2--- -2-- 0003 ---3 3--- -3-- .

Poetry

Intro Poetry is a tool for dependency management and packaging in Python. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you. Links https://python-poetry.org/ https://www.infoworld.com/article/3527850/how-to-manage-python-projects-with-poetry.html Install OpenBSD … and update path pip install --user poetry cat <<'EOF'>> ~/.profile # Poetry export PATH=$PATH:~/.local/bin EOF . ~/.profile ev install as root ? doas pip install --user poetry cat <<'EOF'>> ~/.profile # Poetry export PATH=$PATH:/root/.

Cheatsheet

Docker Command Cheat Sheet Visual Studio Code for macOS Linux Netzplan CT Ansible Edureka Windows Events NMAP SQL Stuff Bash Convention and Libraries Assembler 80186 and higher HTTP Status Codes Python Cheatsheet - Olivier La Flamme Data Wrangling with pandas Cheat Sheet OWASP Key Management Cheat Sheet Python Cheatsheet SQL Stuff by @yosracodes Security Infographics Kubectl Cheat Sheet for Kubernetes Admins SED Oneliners Boll PaloAlto THC’s favourite Tips, Tricks & Hacks (Cheat Sheet)

Python Pip

Python PIP https://pip.pypa.io/en/stable/cli/pip_list/ how to PIP with OpenBSD … Already Installed ? doas pkg_info -Q py3-pip py3-pip-20.1.1p0 (installed) Install pip3 doas pkg_add py3-pip-- doas ln -sf /usr/local/bin/pip3.9 /usr/local/bin/pip Search doas pip search csvkit Install csvkit doas pip install wheel csvkit Upgrade pip doas pip install --upgrade pip Upgrade pip packages for i in $(pip list -o | awk 'NR > 2 {print $1}'); do doas pip install -U $i; done or doas pip install pip-review doas pip-review --interactive sha256: 39b0c97b5063483f3d42fd6ac5515f679180cb454d35cff5ee487a19f0fb5343