Skip to content

Instantly share code, notes, and snippets.

@rcastill
rcastill / set_interval.py
Created September 19, 2017 02:53
setInterval for Python
from threading import Timer
class Interval:
def __init__(self, func, secs):
# Fuction to be called back
self.func = func
# Interval
self.secs = secs
# Timer thread object
@rcastill
rcastill / setup_logger.py
Created July 29, 2019 14:43
Logger setup
# call once per file then retrieve with logging.getLogger(__file__)
import logging
def setup_logger(level):
log = logging.getLogger(__file__)
handler = logging.StreamHandler()
formatter = logging.Formatter(f'%(asctime)-15s {__file__} %(message)s')
handler.setFormatter(formatter)
log.addHandler(handler)
@rcastill
rcastill / lock2req.py
Created November 26, 2019 16:11
Convert Pipfile.lock into requirements.txt
#!/usr/bin/env python
"""
Convert Pipfile.lock into requirements.txt
It generates an output similar to `pipenv lock -r`
without the need to actually locking the file.
See https://github.com/pypa/pipenv/issues/3493
This script was created to include the definition of sources
@rcastill
rcastill / bumpversion.sh
Created December 14, 2021 14:36
Bump version helper script
#!/bin/bash
# Thanks goes to @pete-otaqui for the initial gist:
# https://gist.github.com/pete-otaqui/4188238
#
# Original version modified by Marek Suscak
#
# works with a file called VERSION in the current directory,
# the contents of which should be a semantic version number
# such as "1.2.3" or even "1.2.3-beta+001.ab"
@rcastill
rcastill / acrlookup.sh
Last active December 27, 2024 00:19
Get a list of all repositories repo:tag in an azure container registry ACR using azure-cli az azcli and save them to tags_ACR.txt
# Example usage:
# $ ACR=someregistry bash acrlookup.sh
# repo1:latest
# repo1:0.1.0
# repo2:latest
# $ cat tags_someregistry.txt
# repo1:latest
# repo1:0.1.0
# repo2:latest
@rcastill
rcastill / libver.sh
Last active January 9, 2025 22:07
Get the latest version of a library installed in a linux system
#!/bin/bash
# Get the latest version of a library installed in a linux system.
# Usage: ./libver.sh lib
# Example: ./libver.sh cuda
# Explain: search for lib$lib.so in the system, then extract version from name.
# This assumes that the library "lib" can be found under /usr as: /path/to/liblib.so.x.y.z
if [ -z "$1" ]; then
>&2 echo "Usage: $0 lib"
@rcastill
rcastill / drawpoly.py
Created January 15, 2025 19:45
Draw polygons to input image. Output image to stdout. Can pipe to a file or image magick's display tool for example.
import sys
import itertools
import json
import argparse
from PIL import Image, ImageDraw
def parse_args():
parser = argparse.ArgumentParser(usage="python3 drawpoly.py -p p1.json ... <input_image >out.jpg")
parser.add_argument("-p", "--poly-jsons", type=str, required=True, nargs="+", help="""
JSON file(s) path containing polygon to draw.
@rcastill
rcastill / jpg_http_server.py
Created January 16, 2025 19:59
Serve single jpg image in http server regardless of GET /path
from http.server import HTTPServer, BaseHTTPRequestHandler
import argparse
import logging
import sys
import os
logging.basicConfig(format="%(asctime)s %(levelname)s %(message)s", level=logging.INFO)
log = logging.getLogger()
def mkhandler(imagep):