Skip to content

Instantly share code, notes, and snippets.

Avatar

pavol kutaj pkutaj

View GitHub Profile
View 2023-03-08-How-to-Create-a-Simple-Menu-in-Python-Scripts3.py
# schema_patcher.py
if selection == "Delete":
delete_schema(schema_data)
elif selection == "Patch":
patch_schema(schema_data)
elif selection == "List":
list_schemas(schema_data)
View 2023-03-08-How-to-Create-a-Simple-Menu-in-Python-Scripts2.py
# schema_patcher.py
from menu_maker import *
menu_items = ["Delete", "Patch", "List"]
menu = Terminal_Menu(menu_items)
menu.print_menu()
selection = menu.select_menu_item()
View 2023-03-08-How-to-Create-a-Simple-Menu-in-Python-Scripts1.py
# menu_maker.py
class Terminal_Menu:
def __init__(self, menu_items: list):
self.menu_items = menu_items
def print_menu(self):
for i, single_item in enumerate(self.menu_items, start=1):
print(i, single_item)
def select_menu_item(self):
View 2023-02-23-How-to-Ask-AI-from-Command-Line.py
import os
import sys
import openai
import pyperclip as clipboard
def main(prompt):
openai.api_key = os.environ["OPENAI_KEY"]
model_engine = "text-davinci-003"
completion = openai.Completion.create(
@pkutaj
pkutaj / 2021-05-27-Mutable-vs-Immutable-Common-Data-Structures-in-Python.md
Created February 16, 2023 07:40
Mutable VS Immutable Built-In Data Objects in Python
View 2021-05-27-Mutable-vs-Immutable-Common-Data-Structures-in-Python.md
MUTABLE IMMUTABLE
#1 list ~
#2 dict ~
#3 set ~
#4 byte array ~
~ #1 int
~ #2 float
~ #3 complex
~ #4 string
@pkutaj
pkutaj / BAC-02.14-File-test-operators.md
Created February 10, 2023 07:57
Reference for Bash File Test Operators
View BAC-02.14-File-test-operators.md
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
View RC1-16.02-Towers-of-Hanoi.py
move_count = 0
def move_disk(remaining_disks, source, target):
global move_count
print(f"STEP#{move_count+1}\n"
f"\t~~> Disk #{remaining_disks}; {source} > {target}")
def count_move():
@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
View 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 / 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
View 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 / 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
View 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