Skip to content

Instantly share code, notes, and snippets.

View pkutaj's full-sized avatar

pavol kutaj pkutaj

View GitHub Profile
@pkutaj
pkutaj / 2021-01-20-networking-certificate-chains.md
Created June 13, 2023 14:28
2021-01-20-networking-certificate-chains.md
Shortcut Meaning Comment
CN Common Name The fully qualified domain name (FQDN) of the server that the certificate is issued to.
C Country The two-letter country code of the organization that the certificate is issued to or by.
O Organization The name of the organization that the certificate is issued to or by.
OU Organizational Unit A subunit within an organization, such as a department or division, that the certificate is issued to or by.
s Subject The entity that the certificate is issued to.
@pkutaj
pkutaj / 2023-06-05-How-to-Scrape-DuckDuckGo-results-for-Email-Addresses-to-use-for-Sendgrid-later.py
Created June 6, 2023 06:57
2023-06-05-How-to-Scrape-DuckDuckGo-results-for-Email-Addresses-to-use-for-Sendgrid-later.py
import requests
from bs4 import BeautifulSoup
import re
def get_emails(query):
url = f'https://duckduckgo.com/html/?q={query}'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
links = soup.select('.result__url')
@pkutaj
pkutaj / 2023-06-01-Explaining-Different-Versions-of-UUIDs.md
Last active June 6, 2023 06:31
Explaining Different Versions of UUIDs

https://medium.com/p/2e5e7276168e/edit

Version Description Syntax Example Use Case
1 Based on the current time and the MAC address for the computer or "node" generating the UUID 8-4-4-4-12 ba6eb330-4f7f-11eb-a2fb-67c34e9ac07c If you just need a unique ID
2 Called "DCE security" UUIDs in RFC 4122. Version-2 specifications are publis
@pkutaj
pkutaj / 2023-04-21-How-to-Use-Context-Manager-Decorator-To-Create-Custom-With-Statements-in-Python2.py
Created April 24, 2023 08:19
2023-04-21-How-to-Use-Context-Manager-Decorator-To-Create-Custom-With-Statements-in-Python2.py
import git
from contextlib import contextmanager
TFMODULESPATH = os.environ['TFMODULESPATH']
def make_remote_change(f: callable) -> callable:
def wrap(*args, **kwargs):
with push_and_pop_path(TFMODULESPATH):
prepare_repo_for_change()
ticket_nr = input("ticket# (e.g. ZD34613): ")
@pkutaj
pkutaj / SSAP-44.03-State-Machine-for-Log-Reducer9.py
Created April 17, 2023 05:43
SSAP-44.03-State-Machine-for-Log-Reducer9.py
def get_action(line, cur_state, event):
try:
return TRANSITIONS[cur_state][event][0]
except KeyError:
print_header("ERROR")
print(f"Affected line:\n\n"
f'\t>>> {line}\n'
f"The corresponding event '{event}' is not available for cur_state '{cur_state}'\n")
exit("~~> the input file seems malformed; Fix and try again.")
@pkutaj
pkutaj / SSAP-44.03-State-Machine-for-Log-Reducer8.py
Created April 17, 2023 05:43
SSAP-44.03-State-Machine-for-Log-Reducer8.py
""" ...code """
if action == "skip":
pass
elif action == "print_line":
log_output.write(line)
elif action == "print_H1_line":
log_output.write(f"# {line}")
elif action == "print_H2_line":
log_output.write(f"## PLAN: {line}")
elif action == "print_H3_line":
@pkutaj
pkutaj / SSAP-44.03-State-Machine-for-Log-Reducer7.py
Created April 17, 2023 05:43
SSAP-44.03-State-Machine-for-Log-Reducer7.py
def make_event(line: str) -> str:
for trigger in EVENTS:
if trigger in line:
return EVENTS[trigger]
else:
return "default"
@pkutaj
pkutaj / SSAP-44.03-State-Machine-for-Log-Reducer6.py
Created April 17, 2023 05:43
SSAP-44.03-State-Machine-for-Log-Reducer6.py
EVENTS = {
# <trigger> : <event>
"Deploying 'stacks/apply_last'": "on_deploy",
"Handler execution failed!": "on_fail",
"No changes. Infrastructure is up-to-date.": "on_nochange",
"No changes. Your infrastructure matches the configuration.": "on_nochange",
"Terraform will perform the following actions:": "on_perform",
"# module": "on_module",
"Plan:": "on_plan"
}
@pkutaj
pkutaj / SSAP-44.03-State-Machine-for-Log-Reducer5.py
Created April 17, 2023 05:42
SSAP-44.03-State-Machine-for-Log-Reducer5.py
TRANSITIONS = {
# <state> : {<event> :[<action>, <new_state>]}
"metadata": {
"default": ["skip", "metadata"],
"on_module": ["skip", "metadata"],
"on_deploy": ["print_H1_line", "metadata"],
"on_perform": ["print_H2_line", "plan"],
"on_fail": ["print_EOB", "metadata"],
"on_nochange": ["print_EOB", "metadata"],
},
@pkutaj
pkutaj / SSAP-44.03-State-Machine-for-Log-Reducer4.md
Created April 17, 2023 05:42
SSAP-44.03-State-Machine-for-Log-Reducer4.md
STATE/EVNT default on_module on_deploy on_perform on_fail on_nochange on_plan
metadata ["skip", "metadata"] ["skip", "metadata"] ["print_H1_line", "metadata"] ["print_EOB", "metadata"] ["print_EOB", "metadata"] ["print_EOB", "metadata"] [err]
plan ["print_line", "plan"] ["print_H3_line", "plan"] [err] [err] [err] [err] ["print_EOB", "metadata"]