Skip to content

Instantly share code, notes, and snippets.

View samukasmk's full-sized avatar

Samuel Sampaio samukasmk

View GitHub Profile
@samukasmk
samukasmk / mongodb-query-filter.py
Created June 6, 2025 14:19
Python tool to execute MongoDB query filter by command line
#!/usr/bin/env python3
#
import json
import argparse
from pymongo import MongoClient
parser = argparse.ArgumentParser(
prog='mongodb_query_filter.py',
description='Execute mongodb queries'
@samukasmk
samukasmk / ssh-commands-by-python-asyncssh.py
Last active June 6, 2025 13:38
Execute commands using SSH protocol by python script with AsyncSSH library
#!/usr/bin/env python3
#
# https://github.com/ronf/asyncssh
import argparse
import asyncio
import time
import asyncssh
@samukasmk
samukasmk / ssh-commands-by-python-paramiko.py
Last active June 6, 2025 13:37
Execute commands using SSH protocol by python script with Paramiko library
#!/usr/bin/env python3
#
# https://docs.paramiko.org/en/stable/
# https://didatica.tech/paramiko-com-python-aprenda-a-utilizar-com-exemplos-praticos/
import argparse
import sys
import time
@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