Skip to content

Instantly share code, notes, and snippets.

View peabnuts123's full-sized avatar

Jeff peabnuts123

View GitHub Profile
@peabnuts123
peabnuts123 / ._README.md
Created October 16, 2022 23:17
Don't load nvm until its used, and automatically call `nvm use` when changing directories.

Lazy-load nvm and automatically call nvm use

There's some nice tooling around for managing nvm, such as zsh-nvm. However, I have found this tooling somewhat insufficient, or having poor performance.

For my needs, all I want is to increase the performance of my shell startup, and to run nvm use automatically whenever I navigate around the filesystem.

To these ends, I have written a very simple solution that one can include in their dotfiles. nvm is initially loaded as a shim that will load nvm when it is run, vastly decreasing my shell's initialisation time (from ~5 seconds to 0.2 seconds). For users of zsh, a chpwd hook is added which will check for a .nvmrc file in the new current directory, and run nvm use if one is found. If the specified version of node.js is not installed, nvm simply prints a message telling you to run nvm install instead - it will not do this for you. A check is also included to run on initialisation, if the shell is opened

@peabnuts123
peabnuts123 / README.md
Last active October 10, 2022 00:11
Suggestion for Sumo Logic Slack notification payloads

Sumo Logic Slack notification payloads

The default notification payloads for Slack are very out of date and recovery payloads cannot be edited at all. This means notifications sent to Slack have an unavoidably poor experience.

Problems with current default template

The current template has several issues which should be changed:

  1. Slack has labled the "attachments" API as legacy functionality and explicitly recommends using the Block Kit API instead. [source]
  2. Sharing a message posted using the default template simply embeds the message into a new message, rather than posting a link to the message
  • I can only assume this is because the contents of the message are "attachments"
@peabnuts123
peabnuts123 / git-rewrite-author-history.sh
Last active December 7, 2020 22:24
bash script to replace an author throughout a git history
#!/bin/bash
# Source (now dead): https://help.github.com/articles/changing-author-info/
git filter-branch --env-filter '
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
@peabnuts123
peabnuts123 / ls-containers.sh
Created December 13, 2019 03:40
docker ps alias for pretty-printing running containers, with only relevant fields
# Paste into your .bashrc / .bash_profile / .zshrc etc.
alias ls-containers="docker ps --format 'table {{.ID}}\t{{.Names}}\t{{.RunningFor}}\t{{.Status}}'"
@peabnuts123
peabnuts123 / index.html
Created November 14, 2019 22:59
Google maps example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="./style.css">
@peabnuts123
peabnuts123 / add-patchnotes-alias.sh
Created July 2, 2019 01:34
Git patch-notes alias, for formatting commits in a patch-notes friendly way
# @NOTE You will need to change column width of User name (currently 20) to match the length of the names
# of the people on your team!!
# Register alias on git:
git config --global alias.patch-notes 'log --pretty="%h %<(20)%an%<(22)%ad %s" --date="format:%m/%d %a %T%t"'
# Usage:
# git patch-notes
# git patch-notes release/2019-05..HEAD
# etc.
@peabnuts123
peabnuts123 / ls-count.sh
Created May 17, 2019 00:30
Bash utility function for listing the total (recursive) count of files within all subdirectories
# Usage: ls-count (directory=.) (depth=1)
# Perform a recursive find in the specified folder, and display
# a summary of the total number of files in each subfolder
#
# If `directory` is specified, perform search in that directory. Defaults to '.'
# If `depth`is specified, output analysis down to `depth` levels from root. Defaults to 1
# Example usage:
# ls-count
# ls-count ~/Documents
# ls-count ~/Documents/Projects 2
@peabnuts123
peabnuts123 / npm-exec.sh
Created December 16, 2018 22:58
run local version of npm commands instead of globally installed
# Add to your ~/.bash_profile
# Usage: npm-exec (command) [...args]
# Execute a command located in an npm bin directory, without
# having to manually path to it
function npm-exec() {
bin="${1}";
shift
args="$*"
"$(npm bin)/${bin}" ${args};
@peabnuts123
peabnuts123 / git-prompt.sh
Last active January 14, 2019 02:10
Small function to show local git changes and prompt whether you want to push
# Usage: git-prompt (when in a git repo)
# Print the output of `git status` then prompt the user for whether
# they wish to `git push`
function git-prompt() {
git log "origin/$(git rev-parse --abbrev-ref HEAD)"..HEAD
echo '------------------------------------------';
git status --untracked-files no;
echo '------------------------------------------';
while true; do
@peabnuts123
peabnuts123 / git-breakdown.sh
Last active August 14, 2018 21:07
Git commit breakdown by author
#!/bin/bash
IFS=$'\n';
output="$(echo "`for author in $(git log | grep "Author:" | awk '{for (i=2; i<NF; i++) printf $i " "; print $NF}' | sort | uniq); do
echo "${author}:|$(git log --pretty=oneline --author=${author} | wc -l | xargs echo) commits";
done`" | sort -n -k2 -r -t '|' | column -t -s '|')";
echo "${output}";
echo "$(git log --pretty=oneline | wc -l) commits total";