Skip to content

Instantly share code, notes, and snippets.

View dgrebb's full-sized avatar

Dan Grebb dgrebb

View GitHub Profile
@dgrebb
dgrebb / yabai-keys.sh
Last active September 22, 2023 21:01
yabai commands
# use these in Keyboard Maestro with an "Execute Shell Script" Action
# cycle forward through spaces on the focused display
id="$(yabai -m query --spaces --display | jq 'sort_by(.index) | reverse | .[map(."has-focus") | index(true) - 1].index')" && yabai -m space --focus "${id}"
# cycle backward through spaces on the focused display
id="$(yabai -m query --spaces --display | jq 'sort_by(.index) | .[map(."has-focus") | index(true) - 1].index')" && yabai -m space --focus "${id}"
# cycle forward to next space across all displays (circularly)
yabai -m space --focus next || yabai -m space --focus first
@dgrebb
dgrebb / .cz.json
Last active September 20, 2023 19:51
Commitizen (tools) config defaults
{
"_______________________________comment": "# this is what works for me, personally."
"commitizen": {
"name": "cz_customize",
"version": "2.5.1",
"tag_format": "$major.$minor.$patch$prerelease",
"version_type": "semver",
"bump_message": "release $current_version \u2192 $new_version",
"customize": {
"info": "This is customized info",
@dgrebb
dgrebb / base.css
Created November 2, 2023 01:10
tailwind base.css
/*! tailwindcss v2.2.19 | MIT License | https://tailwindcss.com */
/*! modern-normalize v1.1.0 | MIT License | https://github.com/sindresorhus/modern-normalize */
/*
Document
========
*/
/**
@dgrebb
dgrebb / README.md
Last active April 12, 2024 02:49
Strapi CMS Custom Dashboard (Almost) Replacement Plugin

For brevity, filenames include parent directory(s). - substitutes /.

If installing Strapi fresh, and you're a filthy, untyped rotten scoundrel, remember to add compilerOptions.jsx = "react" as shown below in jsconfig.json to avoid the IDE SquiggleMonster.

  1. npx create-strapi-app@latest --quickstart --no-run strapi-dashbored
  2. npm run strapi generate
  3. choose "middleware"
  4. choose "Add middleware to root of project"
  5. edit src/middlewares/redirect.js
  6. edit config/middlewares.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)
*/
@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 / 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 / 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 / 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 / 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.