Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dberstein
dberstein / duration.py
Last active May 8, 2023 04:02
Python time duration as in golang
import re
import time
from datetime import datetime, timedelta
class DurationUnits:
Nanosecond = 1
Microsecond = 1000 * Nanosecond
Millisecond = 1000 * Microsecond
Second = 1000 * Millisecond
@dberstein
dberstein / main.go
Last active April 30, 2023 04:35
Golang os/arch, arch/os
package main
import (
"bufio"
"fmt"
"os"
"os/exec"
"strings"
)
@dberstein
dberstein / intellij.sh
Last active December 23, 2022 09:02
CLI background launcher of IntelliJ using aliases for toolbox scripts
#!/bin/sh
# Locate tool whose basename matches ours in toolbox's scripts directory
# ie. ln -s [$HOME/.local/bin/]intellij.sh [$HOME/.local/bin/]clion
# ensure "$HOME/.local/bin" in PATH is *before* toolbox's path ($HOME/.local/share/JetBrains/Toolbox/scripts),
# that way invoking "clion" invokes intellij.sh and it invokes toolbox's in CLI's background.
declare TOOL="$( find "$HOME/.local/share/JetBrains/Toolbox/scripts" -mindepth 1 -maxdepth 1 -type f \
-name "$(basename $0)" -executable -exec readlink -f {} \; )"
# No tool found is an error ...
#!/bin/sh
DEFAULT_CHART="${1:-grafana/loki-stack}"
REPO_NAME="${2:-grafana}"
REPO_URL="${3:-https://grafana.github.io/helm-charts}"
helm repo add "${REPO_NAME}" "${REPO_URL}"
helm search repo "${REPO_NAME}"
read -p "Chart? [${DEFAULT_CHART}]: " CHART
[ -z "${CHART}" ] && CHART="${DEFAULT_CHART}"
@dberstein
dberstein / git-dotfiles
Last active February 7, 2021 13:12
simple git alias for dotfiles management
# git-dotfiles: simple git alias for dotfiles management
# 1. configure dotfiles checkout location ...
git config --global --replace-all dotfiles.dir "$HOME/.dotfiles"
# 2. init dotfiles ...
git init --bare "$(git config --global dotfiles.dir)"
# 3. create git dotfiles alias ...
git config --global --replace-all alias.dotfiles '!git --git-dir="$(git config --global dotfiles.dir)" --work-tree="$HOME"'
# 4. (OPTIONAL)
echo \* >> $HOME/.gitignore
@dberstein
dberstein / 1p-gauge.sh
Last active January 16, 2021 14:00
One Punch Gauge
#!/bin/sh
echo 'One Punch Gauge, choose:'
cat <<EOS
🁣 🁣 0 00 🂑 🂅 🀱 🀱 🁓 🁟
🁪 🁤 10 90 🂐 🁾 🀸 🀲 🁌 🁞
🁱 🁥 20 80 🂏 🁷 🀿 🀳 🁅 🁝
🁸 🁦 30 70 🂎 🁰 🁆 🀴 🀾 🁜
🁿 🁧 40 60 🂍 🁩 🁍 🀵 🀷 🁛
#!/usr/bin/env sh
##########################################
# args - shell arguments parsing library #
##########################################
# Usage:
# - function "args_parse" with the parameters to parse, response will be a temp filename used to store the
# parsed data (see "Arguments parsing" and "Cleanup").
# Example: ARGS=$(args_parse "$@")
#
@dberstein
dberstein / bump.sh
Last active October 24, 2018 07:26
Shell semver component bump (1 line function)
# SemVer bump small shell/python function: bumps component $1 ("major", "minor" or "patch") from version in $2 (or STDIN).
# Version components to the right of the bump rollback to 0, ie. 1.2.3:1.2.4 or 1.2.3:1.3.0 or 1.2.3:2.0.0.
function bump() {
echo ${2:-$(</dev/stdin)} | python -c 'from sys import argv,stdin,stdout;n={"major":0,"minor":1,"patch":2}.get(argv[-1]);v=list(map(int,stdin.read().strip().split(".")));v[n]=v[n]+1;v[n+1:]=[0]*len(v[n+1:]);stdout.write(".".join(map(str,v))+"\n")' $1
}
## Examples
# # Version as parameter
# $ bump minor 1.0.1
# 1.1.0
@dberstein
dberstein / README.md
Last active May 1, 2023 04:15
ca-bundler.py - Certificate extractor for CA bundle creation

Certificate extractor for CA bundle creation

Outputs lines between (inclusive) -----BEGIN something----- and -----END something----- in reverse order. Useful for creation of CA certificates bundles.

Note that start/stop lines must begin with at least one dash and be followed by either BEGIN or END , then a space then non-space characters and end the line with at least one dash.

Above format rule will matches usual PEM format items like:

-----BEGIN CERTIFICATE-----
....
@dberstein
dberstein / README.md
Last active November 12, 2023 09:01
Git commit hook that prepends message with Jira issue(s) found in branch name (PR branch) otherwise requires message contains at least one Jira issue

With this commit-msg git hook and your branch names have Jira reference(s), your commit messages will be automatically updated to include any missing reference(s) too.

Installation

Place contents of this gist's commit-msg file into your checkout's .git/hooks/commit-msg file and make it executable.

Bash

cd path/to/your/git/checkout \
&amp;&amp; install -vbm 755 &lt;(curl -s https://gist.githubusercontent.com/dberstein/dcc50e171163c3f6e0f23b2b5de5dd49/raw/5e5372ff22a872321ad1f5469a4d579c15ce498a/commit-msg) "$(git rev-parse --git-dir)/hooks/commit-msg"