Skip to content

Instantly share code, notes, and snippets.

View samukasmk's full-sized avatar

Samuel Sampaio samukasmk

View GitHub Profile
@samukasmk
samukasmk / Chain of Responsability - Workflows.md
Last active January 30, 2025 17:17
Implementing concept of (Chain of responsability) design pattern, but linking handlers order by list object in different solutions

Object-oriented style

File: workflow_by_chain_of_responsability_oo.py

from abc import ABC, abstractmethod

#
# Abstract classes
#
@samukasmk
samukasmk / dynamic_inheritance.py
Created January 30, 2025 15:22
Example of dynamic class inheritance in Python
class Parent1:
def parent1_method(self):
return "Method from Parent1 class"
class Parent2:
def parent2_method(self):
return "Method from Parent2 class"
class Child:
def __init__(self, parent_class):
@samukasmk
samukasmk / workflow_single_class.py
Created January 30, 2025 12:41
Example of Workflows implementation like Chain Responsability but in a single Class
from typing import Any
class WorkflowSkip(Exception):
...
class WorkflowProcess:
workflow_steps = ()
@samukasmk
samukasmk / remove-temp-files-save.py
Created January 29, 2025 20:40
Check by regex if path of temporary file (starts with /tmp and not ends with /)
import re
if re.match(r'^/tmp/(?!.*/$).*$', file_path):
os.remove(file_path)
@samukasmk
samukasmk / install-linux-commands.md
Created January 19, 2025 17:33
Installing linux commands with install command
echo -e "#!/bin/bash
#

echo 'This is my script'" > my-script
sudo install my-script /usr/local/bin
@samukasmk
samukasmk / xargs-examples.md
Last active January 19, 2025 17:28
Executing linux commands in parallel with xargs command

Xargs examples

Executing linux commands in parallel with xargs command

Xargs arguments

xargs --help
Usage: xargs [OPTION]... COMMAND [INITIAL-ARGS]...
Run COMMAND with arguments INITIAL-ARGS and more arguments read from input.
@samukasmk
samukasmk / Linux Swap.md
Last active January 15, 2025 12:25
Enable Linux swap (by image file) - always I forget how to set Linux swap so there it is
@samukasmk
samukasmk / bash-script-named-arguments.sh
Last active November 28, 2024 20:56
Sample of bashscript receiving and requiring command line argument
#!/bin/bash
# Variables to store argument values
ARG1=""
ARG2=""
# Function to display the error message and exit the script
function usage_error {
echo "Usage: $0 --argument_1=\"<text>\" --argument_2=\"<text>\""
echo "Error: $1"
@samukasmk
samukasmk / comparing_set_operations.py
Created November 13, 2024 20:07
Comparing set() operations in python language and showing differences in operations using [.difference() vs -] and [.intersection() vs &]
import time
#
# Creating two large sets for testing
#
a = set(range(1, 1000000)) # Set with 1 million elements
b = set(range(500000, 1500000)) # Set that partially overlaps with set 'a'
print()
@samukasmk
samukasmk / examples-colab-gspread.py
Last active October 31, 2024 20:37
Google colab - using Google spreadsheet from Google drive - gspread
# reference: https://docs.gspread.org/en/latest/user-guide.html
# Install the required libraries
!pip install gspread google-auth
# Import libraries
import gspread
from google.colab import auth
from oauth2client.client import GoogleCredentials
from google.auth import default