Skip to content

Instantly share code, notes, and snippets.

View samukasmk's full-sized avatar

Samuel Sampaio samukasmk

View GitHub Profile
@samukasmk
samukasmk / Pandas - read_parquet - s3.md
Created February 20, 2025 14:42
Pandas (read parquet files from s3)

Pandas examples of read_parquet files from s3

Credentials (from enviroment variables)

import os
import pandas as pd

# define aws credentials by os enviroment variables
os.environ['AWS_ACCESS_KEY_ID'] = '...'
os.environ['AWS_SECRET_ACCESS_KEY'] = '...'
@samukasmk
samukasmk / Grep Matcher.md
Last active February 1, 2025 14:35
Grep Matcher: wait to match first case and exit

grep_matcher.sh

#!/bin/bash
#
# grep matcher: wait to match first case and exit

grep_expression="$1"
grep_file="$2"
__matched=1
@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"