Skip to content

Instantly share code, notes, and snippets.

@ar2pi
ar2pi / out.sh
Last active March 1, 2025 09:16
Bash log function
#!/usr/bin/env bash
#
# A simple bash function to output colorful messages
#
# Usage:
# out "Hello world!"
# out warn "A warning message"
# out error "An error message"
#
@ar2pi
ar2pi / retry.py
Last active July 24, 2024 05:17
Retry with exponential backoff
#!/usr/bin/env python3
import asyncio
import functools
import logging
import math
import signal
import time
from contextlib import asynccontextmanager, contextmanager
@ar2pi
ar2pi / .zshrc
Last active November 1, 2023 19:17
Oh My Zsh with Powerlevel10k (debian)
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
@ar2pi
ar2pi / workflow.yaml
Created September 14, 2022 12:44
GitHub Action | Release with semver version bump + release branch tagging
name: Release
on:
workflow_dispatch:
inputs:
versionBump:
description: 'Version bump'
required: true
default: 'patch'
type: choice
@ar2pi
ar2pi / doc.md
Last active September 4, 2022 08:54
Hash tables (associative arrays) in linux shell scripts

Hash tables (associative arrays) in linux shell scripts

bash

bash v3

function key_val () {
    case $1 in
 "foo") echo "bar";;
@ar2pi
ar2pi / keybase.md
Created May 30, 2022 18:32
keybase.md

Keybase proof

I hereby claim:

  • I am ar2pi on github.
  • I am ar2pi (https://keybase.io/ar2pi) on keybase.
  • I have a public key ASCP7Xu-cxpnBXwKnx_ToejHCeL_kF2EaRbIgMU4bNfYrwo

To claim this, I am signing this object:

@ar2pi
ar2pi / all.sh
Last active April 6, 2022 13:00
Bash module loader
#!/usr/bin/env bash
#
# A simple bash script to execute all adjacent scripts
#
# Usage:
# source /path/to/all.sh
# OR
# . /path/to/all.sh
#
@ar2pi
ar2pi / parse_args.sh
Last active August 29, 2021 00:28
Bash argument parser
#!/usr/bin/env bash
#
# An over-engineered bash argument parser
# Inspired from *args and **kwargs in Python
#
# Usage:
# parse_args "$@"
#
# Examples:
@ar2pi
ar2pi / autoload-nvmrc.sh
Created August 21, 2021 19:43
Autoload .nvmrc
#!/usr/bin/env zsh
#
# Call `nvm use` automatically in a directory with a .nvmrc file, silently
#
# Usage:
# Add this to your ~/.zshrc
#
# Taken from https://github.com/nvm-sh/nvm#zsh
# Difference being that this one is less verbose (like pyenv or goenv)
@ar2pi
ar2pi / adblock.sh
Last active August 9, 2021 15:33
/etc/hosts ad blocker
#!/usr/bin/env bash
#
# This script will append additional entries (from http://winhelp2002.mvps.org/hosts.txt) in /etc/hosts file.
# run: "adblock"
#
# Notes:
# - A backup is created as `hosts.bk` in current working directory.
#