Skip to content

Instantly share code, notes, and snippets.

@rshelnutt
rshelnutt / useCannedMessages.ts
Created November 6, 2025 18:16
[React] Canned Messages Hook
const DICTIONARY = {
// CRUD Operations with Target Subject
crud: {
create: '{subject} created successfully!',
read: '{subject} loaded successfully!',
update: '{subject} updated successfully!',
delete: '{subject} deleted successfully!',
save: '{subject} saved successfully!',
add: '{subject} added successfully!',
remove: '{subject} removed successfully!',
@rshelnutt
rshelnutt / getContrastColor.ts
Created November 29, 2023 03:01
Function to calculate a contrast-respective hex color value from a provided hex. Supply light, get dark. Supply dark, get white.
function getContrastColor(hexColor: string): string {
const hexToRgb = (hex: string) => hex.match(/[A-Fa-f0-9]{2}/g)!.map((v) => parseInt(v, 16))
const rgbToHex = (r: number, g: number, b: number) => `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`
// Extract RGB components from the hex color
const [r, g, b] = hexToRgb(hexColor)
// Calculate the relative luminance for the provided color
const luminance = (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255