Skip to content

Instantly share code, notes, and snippets.

View samukasmk's full-sized avatar

Samuel Sampaio samukasmk

View GitHub Profile
@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
@samukasmk
samukasmk / Simple queues reprocessing.md
Created April 10, 2024 19:45
Example of reprocessing elements in a queue more than once

Simple queues reprocessing

Executing

python simple_queues.py

Example

image

Proof of Concept: Implementing MongoEngine lib with support for multi database connections

Reason:

Currently MongoEngine library only support a single database connection, managing collections by Document classes in global scope.

It has a support to change database connections by switch_db but it's made by a global class attribute called ._meta['db_alias']

When you define many sub ReferenceFields in a hierarchical tree, only first Document object has its ._meta['db_alias'] atttibute changed, not working to query Documents that implement other documents.

@samukasmk
samukasmk / asyncio_example3_async_for.py
Last active March 22, 2024 17:57
Async.IO Example #3: Run 10 async tasks waiting one by one
import asyncio
async def create_async_results(total_items: int):
for r in range(total_items):
await asyncio.sleep(1)
yield r
async def example_of_async_for_loop():
async for item in create_async_results(10):
print(item)
@samukasmk
samukasmk / asyncio_example2_as_completed.py
Last active March 19, 2024 14:37
Async.IO Example #2: Run 10 parallel tasks - But returning some results before all tasks to be done
import asyncio
from random import randint
async def execute_your_task(task_number: int):
""" Specific task to run in parallel """
# display begin of parallel task in console
print('-> starting parallel task:', task_number)
@samukasmk
samukasmk / asyncio_example1_gather_tasks.py
Last active March 19, 2024 14:38
Async.IO Example #1: Run 10 parallel tasks - And waiting all tasks to be done
import asyncio
from random import randint
async def execute_your_task(task_number: int):
""" Specific task to run in parallel """
# display begin of parallel task in console
print('-> starting parallel task:', task_number)