Skip to content

Instantly share code, notes, and snippets.

View dgrebb's full-sized avatar

Dan Grebb dgrebb

View GitHub Profile
@dgrebb
dgrebb / .aliases
Last active June 9, 2024 22:03
Git `gcn!` alias — amend the last commit without prompting to edit or running git hooks
#!/usr/bin/env bash
alias gcn!='f() {
if git diff --cached --quiet && git diff --quiet; then
printf "No changes to commit\n"
else
if git diff --cached --quiet; then
printf "No files added to staging! Did you forget to run git add?\n" >&2
else
git commit --verbose --no-edit --amend --no-verify
@dgrebb
dgrebb / package.json
Created March 2, 2024 00:52
Commitizen config customization in package.json
{
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"cz": "cz",
"release": "standard-version --no-verify"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
@dgrebb
dgrebb / docker-burn.sh
Last active February 21, 2024 23:52 — forked from Jaid/dockerPurge.bash
docker burn
#!/usr/bin/env bash
set -e
set -o errexit
docker stop `docker ps -qa` > /dev/null 2>&1; ## Stop all running containers
docker buildx stop; ## Stop the buildx builder
docker system prune --all --force --volumes; ## Remove all volumes, images, and containers
docker buildx rm --all-inactive --force; ## Remove all buildx builders
docker buildx prune --all --force; ## Prune buildx builder caches
@dgrebb
dgrebb / obsidian-web-clipper.js
Last active January 29, 2024 03:01 — forked from kepano/obsidian-web-clipper.js
Obsidian Web Clipper Bookmarklet to save articles and pages from the web (for Safari, Chrome, Firefox, and mobile browsers)
javascript: Promise.all([import('https://unpkg.com/turndown@6.0.0?module'), import('https://unpkg.com/@tehshrike/readability@0.2.0'), ]).then(async ([{
default: Turndown
}, {
default: Readability
}]) => {
/* Optional vault name */
const vault = "";
/* Optional folder name such as "Clippings/" */
@dgrebb
dgrebb / getHighContrastColor.js
Created January 20, 2024 04:13
Forget about your worries and your strife — have a contrast calculator figure out the best color to use against another (black or white).
/**
* Calculates and returns a high-contrast color (either black or white)
* for optimal readability when displayed on top of the provided color.
* The function uses the luminance formula to determine the brightness
* of the input color and returns either black or white based on a
* luminance threshold.
*
* @param {string} hexColor - The hex code of the background color.
* Should be a valid hex color code starting with '#'
* and followed by six hexadecimal characters.
@dgrebb
dgrebb / action.yml
Last active January 17, 2024 05:41
Install and Cache Playwright from `package.json` Dependencies | GitHub Composite Action
name: "Install and Cache Playwright"
description: "Sets up a cache and/or installs Playwright and its browser binaries."
author: dgrebb
inputs:
WORKSPACE_ROOT:
description: "The workspace root."
required: true
runs:
@dgrebb
dgrebb / diff-test.sh
Last active December 31, 2023 07:16
JSON file diff test for GitHub Actions with property filtering of known dynamic property values
#!/bin/bash
# Filter known dynamic timestamped `test`, `testLog`, and `diffImage` properties
# Then compare results, and `exit 1` if newly generated report.json is different.
diff -q <(jq -S ". | del(.tests[].pair.test, .tests[].pair.testLog, .tests[].pair.diffImage)" test/__fixtures__/sanity-test.json) \
<(jq -S ". | del(.tests[].pair.test, .tests[].pair.testLog, .tests[].pair.diffImage)" test/configs/backstop_data/bitmaps_test/**/report.json)
if [[ $? == "0" ]]; then
exit 0
@dgrebb
dgrebb / copy-text.js
Last active December 27, 2023 05:08
DOM element `innerHTML` copy on click or keyboard
/**
* Copies text inside the clicked DOM node
*
* @param {Event} e The event which triggered the copy.
* @returns {Clipboard.writeText} Text is written to the system clipboard.
*
* @async
*
* ## Example:
* ```javascript
@dgrebb
dgrebb / package.json
Last active December 27, 2023 03:55
npm scripts - typescript tsc-watch, build, and (re)start app
"scripts": {
"dev": "npx tsc-watch --onSuccess \"node build/app.js\""
}
@dgrebb
dgrebb / index.js
Created December 23, 2023 00:25 — forked from tforster/index.js
Naked Redirector CloudFront Function
/**
* @description: Handler entry point.
* - Note AWS CloudFront Functions use a modified ECMAScript 5.1 compatible runtime and NOT NodeJS.
* - Use var, not const or let
* - Use string concatenation and not template literals
* - Beware that the CloudFront Functions Console editor and test environment do NOT mimic CloudFront 100%
* @date 2022-01-26
* @param {object} event: A CloudFront Function event (expecting a Viewer Request event)
* @return {object}: A CloudFront response or request object (depends whether conditions allow pass through or 301 redirect)
*/