Skip to content

Instantly share code, notes, and snippets.

View johnloy's full-sized avatar

John Loy johnloy

View GitHub Profile
@johnloy
johnloy / executable-standalone-module.md
Created March 4, 2024 20:55 — forked from WebReflection/executable-standalone-module.md
NodeJS Executable Standalone Module

Update

If you're OK in having a node-esm executable, please consider this solution.

#!/usr/bin/env sh
# the /usr/local/bin/node-esm executable
input_file=$1
shift
exec node --input-type=module - $@ <$input_file
@johnloy
johnloy / get-latest-tag-on-git.sh
Created February 22, 2024 20:49 — forked from rponte/get-latest-tag-on-git.sh
Getting latest tag on git repository
# The command finds the most recent tag that is reachable from a commit.
# If the tag points to the commit, then only the tag is shown.
# Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object
# and the abbreviated object name of the most recent commit.
git describe
# With --abbrev set to 0, the command can be used to find the closest tagname without any suffix:
git describe --abbrev=0
# other examples
@johnloy
johnloy / list
Created October 11, 2023 23:30 — forked from wndhydrnt/list
Run several commands in parallel, prefix the stdout of each stdout with its source and fail the script if one of the commands exits with a code != 0
foo
bar
baz
@johnloy
johnloy / prepare-commit-msg
Created June 9, 2023 21:09 — forked from stefanbuck/prepare-commit-msg
Ticket number git hook
#!/usr/bin/env bash
#
# Authors:
# Stefan Buck (https://github.com/stefanbuck)
# Thomas Ruoff (https://github.com/tomru)
#
#
# Description:
# Are you still prefixing your commits with a ticket number manually? You will love this script!
# This is a git hook script that will automatically prefix your commit messages with a ticket
@johnloy
johnloy / bash-colors.md
Last active May 26, 2023 17:05 — forked from JBlond/bash-colors.md
The entire table of ANSI color codes. #bash

Regular Colors

Value Color
\e[0;30m Black
\e[0;31m Red
\e[0;32m Green
\e[0;33m Yellow
\e[0;34m Blue
\e[0;35m Purple
@johnloy
johnloy / post-merge
Created July 25, 2022 22:14 — forked from sindresorhus/post-merge
Git hook to install npm dependencies after a `git pull`. Run `chmod +x post-merge` and put it in `.git/hooks/`. Though could really do whatever.
#!/bin/sh
npm install
@johnloy
johnloy / script-template.sh
Created June 19, 2022 21:01 — forked from m-radzikowski/script-template.sh
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
@johnloy
johnloy / debounce.js
Created June 6, 2022 14:11 — forked from rpemberton/debounce.js
Debounce with requestAnimationFrame
// Useful for debouncing callbacks to mousemove, resize, scroll event listeners
function debounce(fn) {
let raf;
return (...args) => {
if (raf) {
console.log('debounced');
return;
}
@johnloy
johnloy / github.bash
Created February 4, 2022 16:52 — forked from igrigorik/github.bash
Open GitHub URL for current directory/repo...
alias gh="open \`git remote -v | grep git@github.com | grep fetch | head -1 | cut -f2 | cut -d' ' -f1 | sed -e's/:/\//' -e 's/git@/http:\/\//'\`"
@johnloy
johnloy / font-stacks.css
Created October 26, 2021 23:40 — forked from don1138/font-stacks.css
CSS Modern Font Stacks
/* Modern Font Stacks */
/* System */
font-family: system, -apple-system, ".SFNSText-Regular", "San Francisco", "Roboto", "Segoe UI", "Helvetica Neue", "Lucida Grande", sans-serif;
/* Times New Roman-based serif */
font-family: Cambria, "Hoefler Text", Utopia, "Liberation Serif", "Nimbus Roman No9 L Regular", Times, "Times New Roman", serif;
/* A modern Georgia-based serif */
font-family: Constantia, "Lucida Bright", Lucidabright, "Lucida Serif", Lucida, "DejaVu Serif", "Bitstream Vera Serif", "Liberation Serif", Georgia, serif;