Skip to content

Instantly share code, notes, and snippets.

View psenger's full-sized avatar
:octocat:
Makin Bacon

Philip A Senger psenger

:octocat:
Makin Bacon
View GitHub Profile
@psenger
psenger / README.md
Created June 13, 2025 12:47
[Recursive and Pattern-Based File Copy or Duplicate Files with Suffixes] #macos #unix #zsh #shellscript #cli #automation #react #typescript

🧬 Recursive and Pattern-Based File Copy or Duplicate Files with Suffixes (*.tsx)

This guide demonstrates how to programmatically duplicate files with new names based on filename patterns using Zsh scripting.

Common use case: You're working with a codebase using .tsx files (React TypeScript) and need to quickly scaffold variants of each component — like *-skeleton.tsx and *-fallback.tsx files.


✅ Goal

@psenger
psenger / index.ts
Last active May 25, 2025 02:00
[Design Pattern: A better Try-Catch] #JavaScript #Promise
// Based on Theo - t3․gg suggestion and ZOD
// Youtube https://www.youtube.com/watch?v=Y6jT-IkV0VM&t=538s
// and gist https://gist.github.com/t3dotgg/a486c4ae66d32bf17c09c73609dacc5b
type Success<T> = {
success: true
data: T
error?: never
}
@psenger
psenger / README.md
Last active June 13, 2025 12:48
[Dynamic-Computed Property Name Pattern] #ReactJs #JavaScript

The Ultimate React Form Handler Pattern: Clean, Reusable, and Type-Safe

Form handling in React can quickly become verbose and repetitive. The Dynamic Property Name pattern (sometimes called the "single handler pattern") elegantly solves this problem by combining several modern JavaScript features. Let me walk you through several iterations of this powerful pattern, its benefits, and some enhancements.

The Core Pattern with Pure JavaScript

  1. DRY Code: A single handler function handles all input changes, eliminating redundant code.
  2. Self-Documenting: The input's name attribute directly corresponds to the state property, making the relationship clear.
  3. Scalability: Adding new form fields requires minimal code changes - just add a new input with the appropriate name.
  4. Maintainability: Changes to validation or processing logic happen in one place.
@psenger
psenger / esm-package.md
Created March 25, 2025 02:13 — forked from sindresorhus/esm-package.md
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@psenger
psenger / README.md
Created February 17, 2025 19:59
[Git Reset / Undo Changes] #git

Git Reset / Undo Changes

Reverting changes in Git traditionally required using git checkout to restore files or git reset to adjust the branch HEAD. However, both commands carried risks if misused: git reset could shift the branch HEAD, while git checkout could either switch branches or load a different commit, potentially disrupting the current branch state.

Discard working directory changes

git restore main.js
@psenger
psenger / README.md
Last active January 22, 2025 21:27
[Date Format Australia aussie-dates] #JavaScript #Date

🦘 Aussie Dates 🇦🇺

G'day mate! Welcome to the most fair dinkum date formatting library this side of the Southern Hemisphere!

🤔 What's This All About?

Ever needed to format your dates in proper Australian style but got lost in the outback of date formatting? No worries! This little beauty's got you covered with all the date formats you'll ever need in the land down under.

🎯 Features

@psenger
psenger / DateBuilder.js
Created January 22, 2025 21:21
[Date Builder] #JavaScript #Date
/**
* A builder class for manipulating JavaScript Date objects in a chainable way.
* @class
* @example
* const builder = new DateBuilder();
* const nextWeek = builder
* .addDays(7)
* .build();
*
* @example
@psenger
psenger / README.md
Last active May 25, 2025 02:01
[Design Pattern: Promise All Object] #JavaScript #Promise

🎭 Promise All Object

Because sometimes your promises are buried deeper than your ex's Instagram photos. This utility helps you resolve them all, no matter where they're hiding! 🕵️‍♂️

🌟 Features

  • Resolves promises in deeply nested objects and arrays
  • Works just like Promise.all but for objects (because objects deserve love too!)
  • Handles arrays, objects, and any combination thereof
  • Preserves your object structure (unlike your New Year's resolutions)
@psenger
psenger / README.md
Last active January 19, 2025 22:29
[Async Await Without Try catch / optional catch binding ] #JavaScript #AsyncAwait #Promise

Why Use the tryCatch Function Over Traditional Error Handling

The tryCatch utility function provides several significant advantages over traditional try-catch blocks and Promise chains. Here's why you might want to consider this pattern:

1. Unified Error Handling for Sync and Async Operations

Traditional error handling requires different approaches for synchronous and asynchronous code:

// Traditional approach - try catch
@psenger
psenger / README.md
Last active June 13, 2025 12:48
[Git Commit] #AI #git #macos

🤖 Git Commit Helper

Never write boring commit messages again! This AI-powered tool analyzes your staged changes and generates detailed, structured commit messages automatically.

🌟 Features

  • 🔍 Analyzes staged git changes
  • ✨ Generates structured, detailed commit messages
  • 📋 Automatically copies to clipboard
  • 🎯 Creates per-file descriptions