Skip to content

Instantly share code, notes, and snippets.

View paleite's full-sized avatar
:fishsticks:
TS ❤️

Patrick Aleite paleite

:fishsticks:
TS ❤️
View GitHub Profile
@paleite
paleite / exact-keys.ts
Created April 15, 2025 13:36
Exactly matching keys in object
// #region Ensure CharacterData has the exact same keys as characterProperties
type TypeCheck<T extends true> = T;
// KeyDifference will be `never` when CharacterData's keys exactly match those
// of characterPropertiesMap, otherwise it will include the mismatching keys
type KeyDifference = Exclude<
keyof typeof characterPropertiesMap | keyof CharacterData,
keyof typeof characterPropertiesMap & keyof CharacterData
>;
// Typescript will throw a compile error with the mismatching keys (if any)
export type AssertExactKeys = TypeCheck<
@paleite
paleite / gist:52bb44c7e97539ffdfa1db8cf7bf9129
Created March 14, 2025 09:08
CSS-styled output in the console
/** @type {{ event: string; [key: PropertyKey]: unknown; }} */
const exampleEvent = { event: "modules_rendered", spotlight_modules: [ "ToolbarPinning", "PerformanceInterventionUI", "MobilePasswords", "129-companypayreauth", ], explore_more_modules: [ "128-company-lens", "128-product-site-search-shortcut", "127-side-panel-pinning", "125-search-box-suggestions", "125-safety-check", "123-generative-theming", ], };
console.debug( `%c DataLayer %c ${exampleEvent.event} `, "background: blue; color: white;", "background: lightgrey; color: black;", exampleEvent );
@paleite
paleite / error-to-json.js
Created December 17, 2024 11:50
Error with circular references to JSON
/**
* Converts an Error object into a plain object with all its properties.
* It includes non-enumerable properties like "message", "name", and "stack".
*
* @param {Error} error - The Error object to convert.
* @returns {Object} A plain object containing the properties of the Error.
*/
const convertErrorToPlainObject = (error) =>
Object.fromEntries(
Object.getOwnPropertyNames(error).map((propertyName) => [
@paleite
paleite / mega-drive-image-prep.md
Created December 4, 2024 10:47
Image Preparation for Mega Drive Graphics

Steps for Preparing an Image for Mega Drive Graphics

  1. Pick an image with a 10:7 aspect ratio.
  2. Resize it to the Mega Drive's native resolution.
  3. Quantize the image to meet Mega Drive hardware limitations.

Step 1: Picking an Image

@paleite
paleite / list-audio-units.sh
Created June 27, 2024 09:06
List all your installed Audio Units
find /Library/Audio/Plug-Ins/Components -name "*.component" -exec sh -c 'for f; do n=$(plutil -extract AudioComponents.0.name raw -o - "$f/Contents/Info.plist" 2>/dev/null) && n=$(echo "$n" | sed "s/^\"//; s/\"$//; s/.*: //") || n=$(plutil -extract CFBundleName raw -o - "$f/Contents/Info.plist" 2>/dev/null) && n=$(echo "$n" | sed "s/^\"//; s/\"$//") || n=$(basename "$f" .component); echo "$n"; done' sh {} + | sort -u -f | tr '\n' ',' | sed 's/,/, /g; s/, $/\n/' | pbcopy && pbpaste
@paleite
paleite / aseprite_install.sh
Last active April 9, 2025 09:26 — forked from ryancat/aseprite_install.sh
Download and install aseprite
#!/bin/bash
# Must have git, homebrew, and xcode to install
# Check for git
if ! command -v git &> /dev/null
then
echo "git could not be found, please install git before proceeding."
exit
fi
@paleite
paleite / general-typography-cheatsheet.md
Created June 26, 2023 10:42
General Typograph Cheatsheet

General Typography Cheatsheet

Body Text (p tag, li tag)

  • Default style: Font size of 16px, font weight of 400 (normal), line height of 1.5, and a letter spacing of normal.

Subheadings (h2, h3 tag)

  • Default style: Font size of 24px for h2 and 20px for h3, font weight of 600 (semi-bold), line height of 1.4, and a letter spacing of normal.

Main Headings (<h1> tag)

  • Default style: Font size of 32px, font weight of 700 (bold), line height of 1.2, and a letter spacing of normal.
@paleite
paleite / prepare-commit-msg
Created April 15, 2021 00:12
Automatically prepend the JIRA issue-key to the commit message
#!/bin/sh
# Automatically prepend the JIRA issue-key to the commit message
readonly COMMIT_MESSAGE_PATH="$1"
readonly COMMIT_TYPE="$2"
readonly GIT_BRANCH=$(git branch --show-current)
# Pick the last issue key in a branch name or return empty result.
# - "feature/AB-123-is-not/the/AB-987-last" will yield "AB-987"
# - "main" will yield ""
readonly ISSUE_KEY=$(node -e 'console.log(process.argv.pop().split("/").reduce(((e,o)=>(o=/^[A-Z]{2,}-\d+/.exec(o)?.pop())?o:e),""))' "${GIT_BRANCH}")
@paleite
paleite / promise-all.js
Created June 11, 2020 16:33
Promise.all()-timing comparison
(async () => {
function sleep(ms, msg) {
console.log(`Executing '${msg}'`);
return new Promise((resolve) =>
setTimeout(() => {
console.log(`Resolving '${msg}'`);
resolve(msg);
}, ms)
);
}
@paleite
paleite / .gitignore
Created January 8, 2019 14:05
.gitkeep: Keep folder in repository without keeping files inside it. Use it for sensitive data, caches, etc.
/*
!/.gitkeep