Skip to content

Instantly share code, notes, and snippets.

@sempervent
sempervent / logz.py
Last active September 7, 2022 14:24
Easy creation of beautiful Rich logging in Python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# standard python imports
import logging
from rich.logging import RichHandler
from rich.traceback import install
import os
install()
@sempervent
sempervent / build.sh
Last active December 21, 2021 22:19
Docker build script
#!/usr/bin/env bash
# ex: set fdm=marker
# usage {{{1
#/ Usage:
#/ ./build.sh -r "REGISTRY/NAME" [OPTIONS]
#/
#/ -c|--context)
#/ the context in which to do the `docker build`
#/
#/ -r|--registry)
@sempervent
sempervent / __init__.py
Created November 23, 2020 19:14
Standard __init__.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Allow imports from this directory."""
@sempervent
sempervent / check_environment.py
Last active July 28, 2021 16:04
Check OS and Python Environment
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Check environments for an environmental variable value."""
import os
def check_environment(env_var, default=None):
"""Check environments for an environmental variable."""
def boolify(var):
if isinstance(default, bool):
if var in [0, '0', 'FALSE', 'False', 'false', 'F', 'f']:
@sempervent
sempervent / loadPackages.R
Last active February 24, 2021 13:50
Load R Packages and install them if they are not already installed.
loadPackages <- function(pkgs, repo = 'https://cloud.r-project.org',
lib = .libPaths()[1]) {
not_installed <- pkgs[!pkgs %in% rownames(installed.packages())]
install.packages(not_installed, repos = repo, lib = lib)
loaded <- unlist(lapply(pkgs, require, character.only = TRUE, quietly = TRUE))
if (any(loaded == FALSE)) {
message(sprintf('The following packages failed to load: %s',
paste0(pkgs[!loaded], collapse = ', ')))
return(FALSE)
}
@sempervent
sempervent / bash_skeleton.sh
Last active October 12, 2021 23:45
A skeleton for bash Scripts
#!/usr/bin/env bash
# ex: set fdm=marker
# usage {{{1
#/ Usage:
#/ -h|-?|--help)
#/ show this help and exit
#/
# 1}}}
# environment {{{1
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"