Skip to content

Instantly share code, notes, and snippets.

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

Patrick Aleite paleite

:fishsticks:
TypeScript ❤️
View GitHub Profile
@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 / 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 / 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 / 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<