Skip to content

Instantly share code, notes, and snippets.

View mamaj's full-sized avatar
👾

MohammadReza Ebrahimi mamaj

👾
View GitHub Profile
@mamaj
mamaj / parse_boolean_value.py
Last active August 27, 2022 04:41
python parse string value as boolean
def parse_bool_str(val):
if isinstance(val, str):
val = val.lower().strip()
if val in ['true', 'yes', 'y', '1']:
val = True
elif val in ['false', 'no', 'n', '0']:
val = False
else:
raise ValueError('Provided value cannot be parsed as a string.')
@mamaj
mamaj / ssh-utils.py
Last active January 31, 2023 12:22
Python: simple class to perform commands and copy files (scp) on ssh using subprocess and native ssh client (OpenSSH).
import subprocess
import os
from pathlib import Path
from typing import Union
class SshClient():
""" Perform commands and copy files on ssh using subprocess
and native ssh client (OpenSSH).
"""
@mamaj
mamaj / trace.py
Created December 17, 2021 01:42
python trace
import sys
def tracer(frame, event, arg):
print(f'{frame = }')
print(f'{event = }')
print(f'{arg = }')
print()
# if you enter any function, still use the same trace function.
if event == 'call':
@mamaj
mamaj / massive_multithreading.py
Last active August 25, 2022 15:46
# python concurrency
import threading
import concurrent.futures
import time
import numpy as np
from operator import itemgetter
def func(worker_id, sleep):
start = time.perf_counter()
print(f'func {worker_id} started @ {threading.get_native_id()}')
time.sleep(sleep)
@mamaj
mamaj / notion-mod-enhancer.css
Last active March 4, 2024 16:14
A CSS mod to notion.so. Changing link colors. brighter text highlight colors in dark mode, indent line for toggle blocks.
/*
* Name: NOTION MOD
* Homepage:
* Author: mamaj
* Version: v1.0
* Updated: 02.14.2020
*/
/*.notion-text-block a, .notion-quote-block a, .notion-bulleted_list-block a {