Skip to content

Instantly share code, notes, and snippets.

@ar2pi
ar2pi / retry.py
Last active March 20, 2023 15:38
Retry with exponential backoff
#!/usr/bin/env python3
from contextlib import contextmanager
import functools
import math
import signal
import time
class TimeoutException(Exception):
@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 / out.sh
Created August 9, 2021 15:43
Bash log function
#!/usr/bin/env bash
#
# A simple bash function to output messages
#
# Usage:
# out "Hello world!"
# out warn "A warning message"
# out error "An error message"
#
@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.
#
{
"git.ignoreMissingGitWarning": true,
"workbench.colorTheme": "Material Theme",
"materialTheme.fixIconsRunning": false,
"workbench.iconTheme": "vscode-great-icons",
"workbench.colorCustomizations": {
"activityBarBadge.background": "#5C6BC0",
"list.activeSelectionForeground": "#5C6BC0",
"list.inactiveSelectionForeground": "#5C6BC0",
"list.highlightForeground": "#5C6BC0",