Skip to content

Instantly share code, notes, and snippets.

View geblanco's full-sized avatar

Guillermo Blanco geblanco

View GitHub Profile
@geblanco
geblanco / args2json.py
Created September 11, 2023 10:59
Dump received arguments to json
#!/bin/python3
import sys
import json
data = sys.stdin.readlines()
args = []
for line in data:
line = line.replace("\\", "").strip().split(" ")
args.extend(line)
@geblanco
geblanco / zsh_setup.sh
Last active June 19, 2023 17:13
Minimal setup to get zsh and companions working. Installer for fresh servers...
#/bin/bash
# Install:
# - zsh (requires sudo)
# - oh-my-zsh
# - zsh-autosuggestions plugin
# - conda-zsh-completion plugin
# - custom themes
# - custom zshrc and styles
@geblanco
geblanco / pyprojreqs.sh
Last active November 20, 2023 12:14
Script to automatically extract dependencies from a pyproject.toml file.
#!/bin/bash
# If a requirements.txt file is supplied, it will be updated with the latest versions of each package.
# If a pyproject.toml is required, package upgrades will just be printed.
echo "Careful:" >&2
echo " - Virtual Env is required" >&2
echo " - If any of your PYPY packages contain the strin 'http', it is possible that it gets astray, manually inspect it" >&2
def_deps_key="dependencies"
@geblanco
geblanco / striptqdm.sh
Last active November 30, 2023 07:56
Simple bash script to remove tqdm output from logfile
#!/bin/bash
# Intended usage:
# - You run a super long script with fancy tqdm progress bars in a remote server as usual:
#
# nohup python super_long_script.py > super_long.log &
# # monitor as long as you want
# tail -f super_long.log
@geblanco
geblanco / pdiff.py
Last active December 27, 2022 08:17
Script to get permissions diff between multiple directories or files. You can get a files permission list by passing -p and a single directory
#!/usr/bin/env python3
import argparse
from glob import glob
from typing import List, Tuple, Union, Iterable, Optional
from pathlib import Path
from itertools import combinations
from dataclasses import dataclass
@geblanco
geblanco / Singleton.py
Created December 13, 2022 14:49
Singleton class
# coding=utf-8
class Singleton(object):
def __new__(cls):
if not hasattr(cls, "instance"):
cls.instance = super(Singleton, cls).__new__(cls)
return cls.instance
@geblanco
geblanco / gen_init.py
Last active October 25, 2022 13:01
Naive __init__.py generator
"""Generate __init__.py for a given folder
Very naive generator, just parses the AST of every subfile in the provided folder to get the list of exported variables.
ToDo :=
- Recursively parse subfolders and previous __init__.py files
- Improve pkg base adding
"""
import os
import ast
@geblanco
geblanco / upgrade_py_pkgs.sh
Last active November 20, 2023 13:24
Script to automatically upgrade all python packages given a requirements.txt or a pyproject.toml (works over conda)
#!/bin/bash
# If a requirements.txt file is supplied, it will be updated with the latest versions of each package.
# If a pyproject.toml is required, package upgrades will just be printed.
echo "Careful:"
echo " - Conda is required"
echo " - If any of your PYPY packages contain the strin 'http', it is possible that it gets astray, manually inspect it"
env_name="pkgs_upgrade"
@geblanco
geblanco / obs_project_scaffold.py
Last active May 18, 2023 16:37
Project scaffold for Obsidian. It is a simple structure containing a Readme, Meetings, Todo and Index files.
#!/bin/env python
import argparse
from pathlib import Path
from shutil import rmtree
from typing import Any, List, Optional
# You must override this value!
PROJS_BASE = None
DEF_FILES = ["index", "readme", "todo", "meetings"]
FILES_W_CONTEXT = ["todo", "meetings"]
@geblanco
geblanco / process_singleton.py
Last active August 23, 2021 12:03
A singleton class that syncronizes across processes
# requires: zmq
import sys
import zmq
import threading
from time import sleep
from filelock import FileLock, Timeout