Skip to content

Instantly share code, notes, and snippets.

View pkutaj's full-sized avatar

pavol kutaj pkutaj

View GitHub Profile
@pkutaj
pkutaj / Ask_for_input_in_bash_rubberduck.md
Created January 13, 2022 08:15
Ask for Input in Bash Rubberduck Table
STEP# CODE COMMENT
01 echo -n "Are you sure (Y/N)? " print prompt just once with echo
02 answered= initiate an empty test binding
03 while [[ ! $answered ]]; do loop until test binding is populated
04 read -r -n 1 -s answer get input, supress escape, only 1 char, supress input
05 if [[ $answer = [Yy] ]]; then test if input is y or Y
06 answered="yes" ..if true, set test binding to yes → step #12
07 elif [[ $answer = [Nn] ]]; then else, test is input is n or N
08 answered="no" ..if trye, set test binding to no → step #12
@pkutaj
pkutaj / missing_module_error.py
Created January 13, 2022 09:37
Snippet to print missing module error instead of Traceback with ModuleNotFoundError
moduleMissingError = 'Missing dependency module: Run "pip install -r requirements.txt" → Retry'
try:
import #<module1>
import #<package2>
import #<subpackage1>
except ImportError:
sys.exit(moduleMissingError)
@pkutaj
pkutaj / multi_replace_command.ps1
Last active January 15, 2022 01:51
Multiple Replaces and Ternary Operator
# Sometimes URL is copied from a browser and arrives as
# https://consul.foo.com/client/ami_size/edit
# Othertimes URL is copied from Consul CLI and arrives as
# client/ami_size
# And I just need the actual key, being 'ami_size' for the script
$url = ($url -match "^https://") ?
($url -replace "https://consul.foo.com/client/", "") -replace "/edit", "":
($url -replace "client/", "")
@pkutaj
pkutaj / accept_multiple_inputs_from_pipeline.py
Created January 20, 2022 06:25
Exemplary Function Accepting Multiple Inputs from Pipeline in PowerShell
### func1
function query-consul () {
param (
[String[]]$consul_keys,
[String]$queryString,
)
foreach ($consul_key in $consul_keys) {
consul kv get -recurse $consul_key_ |
Select-String $queryString
@pkutaj
pkutaj / Exception-Handling-of-Python-Requests-Module-template-rubberduck.md
Last active January 28, 2022 07:19
Request Module Exception Handling Template
NR CODE COMMENT
#1 response = requests.get(url,...) within a try block, create variable with a response object
#2 response.raise_for_status() raises exception 4xx & 5xx HTTP Statuses/errors
#3 except requests.exceptions.RequestException as e: exception base class for all other exceptions
#4 print(e, file=sys.stderr) print exception object into stderr stream
@pkutaj
pkutaj / 2022-03-01-PowerShell-Wrapper-for-OpenSSL-to-Test-Certificate.ps1
Created March 1, 2022 10:17
PowerShell Wrapper for OpenSSL to Test Certificates Fast with Extended Functionality
function test-certificate([string[]]$domains, $contextLength = 10, [switch]$download) {
$cacertPath = "${env:USERPROFILE}\cacert.pem"
if (-not(Test-Path $cacertPath)) {
Invoke-WebRequest "https://curl.se/ca/cacert.pem" -OutFile "${env:USERNAME}\cacert.pem"
}
foreach ($domain in $domains) {
$connectDomain = $domain + ":443"
if ($download) {
echo "q" |
openssl s_client -servername $domain -connect $connectDomain -CAfile $cacertPath |
@pkutaj
pkutaj / 101.02-CP-Traditional-Data-Centers.md
Last active July 6, 2022 12:51
CCCDFFR: 7 Advantages of Cloud over On Prem
ATTRIBUTE ON PREM CLOUD
COSTS_INIT great / CAPEX (capital expenses) small / OPEX (operational/variable expense)
COSTS_MAINTENANCE expensive / need to staff data center (DC) elastic / cheaper (economies of scale)
COMPLIANCE own responsibility shared responsibility model / less risk
DEPLOYMENT_PACE slow fast / efficient (economies of scale) / go global in minutes
FORECASTING difficult / imprecise elastic scaling
FINANCING no money no honey speed and agility / test capacity against real users with minimal costs
RELIABILITY additional dimension / failovers required global infra built with reliability in mind
@pkutaj
pkutaj / 2020-12-05-the-trim-horizon-of-AWS-Kinesis-and-the-concept-of-checking.md
Last active August 3, 2022 11:23
2020-12-05-the-trim-horizon-of-AWS-Kinesis-and-the-concept-of-checking.md
TYPE NAME DESCRIPTION
AT_SEQUENCE_NUMBER Start reading from the position denoted by a specific sequence number, provided in the value StartingSequenceNumber.
AFTER_SEQUENCE_NUMBER Start reading right after the position denoted by a specific sequence number, provided in the value StartingSequenceNumber.
AT_TIMESTAMP Start reading from the position denoted by a specific timestamp, provided in the value Timestamp.
TRIM_HORIZON Start reading at the last untrimmed record in the shard in the system, which is the OLDEST data record in the shard.
LATEST Start reading just after the most recent record in the shard, so that you always read the NEWEST data record in the shard.
@pkutaj
pkutaj / powershell regex matches.md
Created August 19, 2019 16:16
powershell regex matches.md

THE CASE OF WORK WITH REGEX MATCHES

the case

the puzzle is, how to assign a match in regex search to a new variable: to test-path it and eventually create a folder, if the test fails.

solution

Use the -match with your regex and find the matches in the build-in $matches hash table!

sources

@pkutaj
pkutaj / test-certificate.ps1
Created February 19, 2021 09:04
test-certificate.ps1
function test-certificate($domain, $contextLength = 10) {
$cacertPath = "c:\cacert.pem"
$domain += ":443"
echo "q" | openssl s_client -connect $domain -CAfile $cacertPath | openssl x509 -noout -enddate | sls "notAfter.*"
echo "q" | openssl s_client -connect $domain -CAfile $cacertPath | sls "certificate chain" -Context $contextLength
Write-Host "~~~" -ForegroundColor darkcyan
Write-Host "→ If needed, pass a desired output length after domainname" -ForegroundColor darkcyan
Write-Host "→ To update the list of trusted Certificates, run:" -ForegroundColor darkcyan
Write-Host "→ Invoke-WebRequest https://curl.se/ca/cacert.pem -OutFile 'c:\cacert.pem'" -ForegroundColor darkcyan