Skip to content

Instantly share code, notes, and snippets.

View AlexAtkinson's full-sized avatar

Alex Atkinson AlexAtkinson

  • Toronto
View GitHub Profile
@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 / printSectionHeader.sh
Last active September 22, 2022 18:16
BASH: Fancy Autosizing Section Header
# Prints a section header.
#
# Features
# - Autosizes to terminal if $width -gt $COLUMNS
# - Specifying width as 4000 works...
# - Adjust first two sanities for stricter usage
# * Currently sets width to half terminal width
# * Currently rounds down odd to even width automatically
# - Customizable outside and inside fill characters
# - Nofill style option
@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 / 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 / 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 / add-weather-to-htop.sh
Last active June 28, 2023 06:23
BASH: Weather Overlay for htop
# HTOP Weather Overlay
# NOTES:
# - STOP! Not a script.
# - Add to ~/.bashrc or similar.
# - Refreshes the weather "overlay" every ~10s
# - Pulls from wttr.in ONLY every 300s (5m)
# - has a kill-htop-weather command to break the while loop if needed
#
# Requires an empty space in the htop meters setup to be added.
# Recommended Meters layout (F2):
@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 / 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 / remote-script-sourcing.sh
Last active November 19, 2022 15:59
BASH: A simple hello world script for testing the handling of remote scripts.
#!/usr/bin/env bash
# A simple hello world script for testing the handling of remote scripts.
# HINT: Hit the 'Raw' button at the top-right to get the url for this script. It changes with every edit.
# source <(curl -s <url>)
# bash <(curl -s <url>)
echo 'Hello World!'
shopt -s expand_aliases