Skip to content

Instantly share code, notes, and snippets.

View pkutaj's full-sized avatar

pavol kutaj pkutaj

View GitHub Profile
@pkutaj
pkutaj / query-consul.ps1
Created March 3, 2021 11:44
query-consul.ps1
function query-consul ([string]$customer, [string]$queryString, [int]$context, [switch]$detailed) {
$consulURL = "https://consul.foo.net/ui/eu-central-1/kv/customer/$customer"
elseif ($detailed) {
consul kv get -recurse -detailed customer/$customer |
Select-String $queryString -Context 1, $context
}
else {
consul kv get -recurse customer/$customer |
Select-String $queryString -Context 1, $context
@pkutaj
pkutaj / dailyChronicle.ps1
Created March 20, 2021 00:14
dailyChronicle.ps1
function backup {
cd $kronFolder
$today = $today.ToString("yyyy-MM-dd")
git add . && git commit -m "$today" && git push
}
function add-imageFromYesterday {
$span = (($today).DayOfWeek -ne "Tuesday") ? 1 : 3
$i = 1
@pkutaj
pkutaj / The-Twelve-Modes-of-Python-File-Handling.md
Created February 5, 2022 07:01
The-Twelve-Modes-of-Python-File-Handling.md
MODE MEANING STREAM POSITION COMMENT
r reading beginning of the file default
r+ reading and writing beginning of the file
w writing only Overwrites / creates a new file for writing
w+ writing and reading Overwrites / creates a new file for reading and writing
rb reading in binary beginning of the file
rb+ reading and writing binary
wb+ writing and reading binary Overwrites / creates a new file for reading and writing
a appending end of the file if exists If the file does not exist, it creates a new file for writing.
@pkutaj
pkutaj / 2021-01-09-7-values-that-test-false-in-Python.md
Created May 6, 2022 06:48
2021-01-09-7-values-that-test-false-in-Python.md
NO DESCRIPTION VALUE
1 Boolean False
2 None keyword None
3 The number zero 0
4 An empty string ''
5 An empty list []
6 An empty tuple ()
7 An empty dictionary {}
@pkutaj
pkutaj / 2022-05-30-How-to-Run-Custom-Code-Upon-Hitting-Ctrl-C-in-Python.py
Created May 30, 2022 12:06
2022-05-30-How-to-Run-Custom-Code-Upon-Hitting-Ctrl-C-in-Python.py
def main():
try:
# DO SOMETHING....
except KeyboardInterrupt:
# UPON CTRL+C ASK IF A FILE CONTENTS SHOULD BE DROPPED
if input("~~> Interrupted ! Clean-up 'output.txt'? (y/N): ") == "y":
# RUN DROPPING FUNCTION IF YES
delete_output_content()
# AND SAY GOOD BYE
sys.exit("bye")
@pkutaj
pkutaj / 50.04-FP-Combining-Map-and-Reduce_2.py
Created June 6, 2022 07:28
50.04-FP-Combining-Map-and-Reduce_2.py
documents = [
"Each in the cell of himself is almost convinced of his freedom",
"You know I like that violence that you get around here, that kind of ready steady violence",
"Yes that is right punk is dead it is another cheap product for the consumers head",
"To be or not to be that is the question"
]
counts = map(count_words,documents)
# OUTPUT IS LAZY OBJECT
# <map object at 0x01F2F610>
@pkutaj
pkutaj / 2020-07-14-ignore-files-in-gitignore-using-globbing-patterns.md
Created July 5, 2022 06:55
2020-07-14-ignore-files-in-gitignore-using-globbing-patterns.md
@pkutaj
pkutaj / 2022-07-17-How-to-Share-a-Global-Variable-Across-Files-and-Modules-in-Python.md
Created July 17, 2022 17:14
2022-07-17-How-to-Share-a-Global-Variable-Across-Files-and-Modules-in-Python.md

USECASE

The aim of this page📝 is to share how I make certain variables accessible for different modules/files in Python.

  • I do this not to repeat myself (DRY principle)
  • I am not using global keyword (no help here)
  • I am simplifying the approach from stack overflow
  • My use is in my short Jirc (Jira Card from Terminal) script
  • My global variable is a path to a config file that I need on various occasions in various places
@pkutaj
pkutaj / 2021-04-14-On-The-Lease-Table-as-a-State-Maintenance-of-AWS-Kinesis.md
Last active September 30, 2022 02:57
2021-04-14-On-The-Lease-Table-as-a-State-Maintenance-of-AWS-Kinesis.md
FIELD COMMENT
checkpoint The most recent checkpoint sequence number for the shard. This value is unique across all shards in the data stream.
checkpointSubSequenceNumber When using the Kinesis Producer Library's aggregation feature, this is an extension to checkpoint that tracks individual user records within the Kinesis record.
leaseCounter Used for lease versioning so that workers can detect that their lease has been taken by another worker.
leaseKey A unique identifier for a lease. Each lease is particular to a shard in the data stream and is held by one worker at a time.
leaseOwner The worker that is holding this lease.
ownerSwitchesSinceCheckpoint How many times this lease has changed
@pkutaj
pkutaj / BAC-02.14-File-test-operators.md
Created February 10, 2023 07:57
Reference for Bash File Test Operators
FLAG MEANING
-e file exists
-a file exists (deprecated, don't use)
-f file is a regular file (not a directory or /dev - device file)
-s file is not zero size
-d file is a directory
-b file is a block device (see below)
-c file is a character device (see below)
-p file is a pipe