Skip to content

Instantly share code, notes, and snippets.

View AlexAtkinson's full-sized avatar

Alex Atkinson AlexAtkinson

  • Toronto
View GitHub Profile
@AlexAtkinson
AlexAtkinson / timestamp-helper.sh
Last active July 14, 2022 16:11
BASH: A truly awful way to guarantee timestamp alignment across OS's...
#!/usr/bin/env bash
# timestamp-helper.sh
# ------------------------------------------------------------------------------
# Command perfs observed on localhost.
# date : ~0.001-0.002s
# gdate : unknown
# python : ~0.015-0.030s
# c : ~0.025-0.049s
# this.sh : ~0.005-0.015s (with date, so + ~0.004-0.013s)
#
@AlexAtkinson
AlexAtkinson / genMockData.sh
Created July 17, 2022 00:43
BASH: Mock data generator with some basic ETL for simple jobs. (Handles fields with commas.)
#!/usr/bin/env bash
# genMockData.sh
# ------------------------------------------------------------------------------
# Gets some free sample data from: https://www.briandunning.com/sample-data/,
# Extracts Transformas and Loads the data. (ETL in BASH...)
# regions: us, ca, uk, au
region=${1:-ca} # ca (default), us, uk, au - supply as arg1
size=500 # 500 sample size is free
file="${region}-${size}"
@AlexAtkinson
AlexAtkinson / get-total-pulls.sh
Last active July 17, 2022 21:16
Docker: Get total pulls from dockerhub
#!/usr/bin/env bash
# get-total-pulls.sh
# ------------------------------------------------------------------------------
#
# DESCRIPTION:
# Gets the total pulls for a dockerhub repo.
# This script iterates the image-list file and outputs a report.
#
# INPUT FILE:
# The input file is a list of docker images - one per line.
@AlexAtkinson
AlexAtkinson / ts-helper.sh
Created July 18, 2022 17:57
BASH: Simple TimeStamp helper
#!/usr/bin/env sh
# ts-helper.sh
# ------------------------------------------------------------------------------
# This is a demo of how to get aligned timestamps across any OS with python in
# the $PATH.
# ------------------------------------------------------------------------------
function ts() {
local s_int=$(date +'%s')
local s_len=${#s_int}
local sns=$(python -c 'import time; print(int(time.time_ns()))')
@AlexAtkinson
AlexAtkinson / ssh-key_rounds-benchmark.sh
Last active July 21, 2022 22:05
SSH: ed25519 rounds benchmark tool
#!/usr/bin/env bash
# ssh-key_rounds-benchmark.sh
# ------------------------------------------------------------------------------
# Tests ed25519 performance.
#
# Usage:
# ./ssh-key_rounds-benchmark.sh
# ./ssh-key_rounds-benchmark.sh <type> <passphrase length> <sample size>
# ./ssh-key_rounds-benchmark.sh ed25519 32 10
# Original work by Luc in this stackexchange answer:
@AlexAtkinson
AlexAtkinson / configure-aliases.sh
Last active August 12, 2022 19:41
A simple script to automatically configure some aliases for cli users.
#!/usr/bin/env bash
shell=$(awk -F/ '{print $NF}'<<<$SHELL)
# Detect target rc file.
[[ -f $HOME/.bash_profile && $shell =~ "bash" ]] && targ="$HOME/.bash_profile" # MacOS Bash
[[ -f $HOME/.zshrc && $shell =~ "zsh" ]] && targ="$HOME/.zshrc" # MacOS ZSH
[[ -f $HOME/.bashrc && $shell =~ "bash" ]] && targ="$HOME/.bashrc" # Linux
if [[ ! -n ${targ+x} ]]; then
@AlexAtkinson
AlexAtkinson / getSecondsNanoseconds.sh
Created July 14, 2022 01:05
C: Get date +'%s%N' out of macos...
#!/usr/bin/env sh
cat << EOF > epochInµsec.c
#include <stdio.h>
#include <sys/time.h>
__asm__(".symver realpath,realpath@GLIBC_2.0");
int main(void)
{
@AlexAtkinson
AlexAtkinson / rc-dep-check.sh
Last active August 24, 2022 16:41
ProTip: RC File Dependency Sanities
# Include simple dependnecy checks for aliases.
# Set aliases only if dependnecy is available.
# An IF statement may makes more sense...
dep='xclip'
[[ ! $(command -v $dep) ]] && echo -e "\e[01;31mERROR:\e[0m ${BASH_SOURCE[0]} - $dep not available!"
[[ $(command -v $dep) ]] && alias clipc="xclip -selection c"
[[ $(command -v $dep) ]] && alias clipp="xclip -selection c -o"
[[ $(command -v $dep) ]] && alias clipv="clipp | less"
@AlexAtkinson
AlexAtkinson / constructed-secrets.yml
Last active August 26, 2022 19:01
GH Actions Constructed Secret Name Handling (Useful for handling multiple-envs scenarios)
name: Constructed Secrets
on:
workflow_dispatch:
inputs:
string:
description: "String"
required: true
secret:
description: "Secret"
@AlexAtkinson
AlexAtkinson / os-info.sh
Created August 29, 2022 15:23
BASH: OS Info helper. Reads 'os-release' options passed by user.
function os-info () {
keys=$@
function help () {
echo -e "Try: NAME, PRETTY_NAME, VERSION_ID, VERSION, ID_LIKE"
echo -e "REF: https://www.freedesktop.org/software/systemd/man/os-release.html"
return 0
}
[[ $keys == '-h' ]] && help
[[ $# -eq 0 ]] && help
for key in "$@"; do