Code

Fastapi

FastAPI - Dependencies and Custom Headers Source https://fastapi.tiangolo.com/tutorial/dependencies/dependencies-in-path-operation-decorators/ Code from fastapi import Depends, FastAPI, Header, HTTPException app = FastAPI() async def verify_token(x_token: str = Header()): if x_token != "fake-super-secret-token": raise HTTPException(status_code=400, detail="X-Token header invalid") async def verify_key(x_key: str = Header()): if x_key != "fake-super-secret-key": raise HTTPException(status_code=400, detail="X-Key header invalid") return x_key @app.get("/items/", dependencies=[Depends(verify_token), Depends(verify_key)]) async def read_items(): return [{"item": "Foo"}, {"item": "Bar"}] Test’s Failed no Custom Header curl -s http://localhost/api/items/ |jq { "detail": [ { "loc": [ "header", "x-token" ], "msg": "field required", "type": "value_error.

Ruby on Rails

https://github.com/Bratela/openbsd Install Ruby Install Ruby and set Symlinks doas su - pkg_add ruby-3.1.2 ln -sf /usr/local/bin/ruby31 /usr/local/bin/ruby ln -sf /usr/local/bin/bundle31 /usr/local/bin/bundle ln -sf /usr/local/bin/bundler31 /usr/local/bin/bundler ln -sf /usr/local/bin/erb31 /usr/local/bin/erb ln -sf /usr/local/bin/gem31 /usr/local/bin/gem ln -sf /usr/local/bin/irb31 /usr/local/bin/irb ln -sf /usr/local/bin/rdoc31 /usr/local/bin/racc ln -sf /usr/local/bin/rake31 /usr/local/bin/rake ln -sf /usr/local/bin/rdoc31 /usr/local/bin/rbs ln -sf /usr/local/bin/rdoc31 /usr/local/bin/rdbg ln -sf /usr/local/bin/rdoc31 /usr/local/bin/rdoc ln -sf /usr/local/bin/ri31 /usr/local/bin/ri ln -sf /usr/local/bin/typeprof31 /usr/local/bin/typeprof Install Nokogiri pkg_add ruby31-nokogiri-1.13.1p0 Install Rails pkg_add ruby-3.

Git Tags

With Tags, we have the possibility to “Tag” a certain Point as important. Just give it a release Number (v0.1, v0.2, v1.0) or whatever you like. list tags list all tags for a certain repo git tag add Tag when you’re fine with a version, add a tag … git tag -a v1.0 -m "my Version 1.0" push Tags you have to push the Tags separatly. they do not get pushed with the common “git push” command

Go CrossCompile

Crosscompile under GoLang Python is cool and everybody like it, but i also like the Concept of writing some Code, compile it for different Platforms and run it everywhere. Google’s Go Language got the possiblity to compile it for multiple Architectures and Operating Systems at the same time. Why not give a try … ? Little Hello World package main import ( "fmt" "os" ) func main() { s := "world" if len(os.

VSCode

{ “[python]”: { “editor.defaultFormatter”: “charliermarsh.ruff”, “editor.formatOnSave”: true, “editor.codeActionsOnSave”: { “source.organizeImports”: “explicit”, “source.fixAll”: true }, }, } settings.json Useful Settings for VSCode … settings.json test -d .vscode || mkdir .vscode cat << 'EOF' > .vscode/settings.json { "[python]": { "editor.defaultFormatter": "charliermarsh.ruff", "editor.formatOnSave": true, "editor.codeActionsOnSave": { "source.organizeImports": "explicit", "source.fixAll": true }, }, } EOF settings.json (old) test -d .vscode || mkdir .vscode cat << 'EOF' > .vscode/settings.json { "python.linting.enabled": true, "python.linting.pylintEnabled": true, "python.formatting.provider": "none", "python.

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.

C

some stuff i learned about the “C” Language -> https://www.c-howto.de/tutorial/einfuehrung/ DataTypes Char to Store one single Character #include<stdio.h> int main() { char zeichen1; char zeichen2; zeichen1 = 'A'; zeichen2 = 66; printf("Zeichen: %c, %c\n", zeichen1, zeichen2 ); return 0; } Zeichen: A, B Short / unsigned short #include<stdio.h> int main() { // kleine Zahl mit Vorzeichen deklarieren (erstellen) short kleineZahl; // kleine Zahl auf Grenzwert setzen kleineZahl = 32767; // kleineZahl ausgeben printf("Wert von kleineZahl: %d\n", kleineZahl); // eins hochzählen, also 32767+1, was eigentlich 32768 ergibt kleineZahl++; // kleineZahl ausgeben printf("Wert von kleineZahl: %d\n", kleineZahl); return 0; } Wert von kleineZahl: 32767 Wert von kleineZahl: -32768 int 16 or 32 Bit, depending on Architectur

Regex IPv4 & IPv6

Regex is cool. But have you ever tried to grep IPv4 / IPv6 Adresses from a File or extract from a bunch of data ? Did you use Google Search and found lot of Links, Tip’s and Examples ? And non of them worked well ? I can highly recommend CyberChef for stuff like that … https://gchq.github.io/CyberChef/ Regex from CyberChef If you wanna use Regex in your own Scripts, here is a little Extract from Cyberchef.

Poetry

1. 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 on OpenBSD Wanna Install on OpenBSD ? # get root doas su - Install as Root # Install Poetry pip3 install --user poetry # Update Poetry pip3 install poetry -U # Update Profile cat << EOF >> ~/.

Puffy Spezial

Tips, Trick, Notes and Snippets around OpenBSD Adding Static Default GW man route route add -inet default 192.168.1.1 route add -inet6 default 2001:db8:efef::1 Use Puffy as Jumphost Redirect incomming Traffic from a certain Source and also NAT the Outgoing Traffic so we remain in the “Line” ;) # Apply SNAT for outgoing Traffic match out log on em0 inet from !(egress) to IP_OF_TARGET_HOST nat-to (egress) # Forward Port 22 to another (hidden) Host via DNAT pass in log quick on egress inet proto tcp from SRC_IP_OF_HOST to egress port 22 rdr-to IP_OF_TARGET_HOST port 22 pass in log quick on egress inet proto tcp from SRC_NET/MASK to egress port 22 rdr-to IP_OF_TARGET_HOST port 22 Debug OpenSMTPD doas rcctl stop smtpd doas smtpd -dv -Tall tty0 to fb0 on ARM you may need to redirect tty0 on arm64 boxes