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 / 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
Created January 17, 2025 05:17
[Promise Design Patterns - 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 January 21, 2025 05:06
[Git Commit] #AI #git #MacOSX

🤖 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
@psenger
psenger / prompt-options.js
Created January 3, 2025 02:17
[Prompt with NodeJS] #JavaScript #prompt
const readline = require('readline')
/**
* Prompts the user with a question and returns their answer.
*
* @param {readline.Interface} rl - The readline interface instance
* @param {string} query - The question to ask the user
* @returns {Promise<string>} A promise that resolves with the user's answer
*
* @example
@psenger
psenger / ADR.md
Last active November 11, 2024 20:43
[Obsidian Markdown Templates] #obsidian #templates #adr #bcp #meeting
creation-date modification-date version tags aliases type
<% tp.file.creation_date("YYYY-MM-DDTHH:mm:ssZZ") %>
<% tp.file.last_modified_date("YYYY-MM-DDTHH:mm:ssZZ") %>
0.0.1
adr
empty-note

Architecture Design Registry - <% tp.file.title %>

@psenger
psenger / README.md
Created November 3, 2024 22:41
[How to Separate changes to individual Branches] #git

Splitting Mixed Changes into Separate Feature Branches in Git

You have a git project, based on main. With mixed changes in your local copy of the project for two different features none of the changes are pushed to the origin git server. You want to create two branches and check the two branches to the origin git server, separating the two sets of changes.

This guide helps you separate mixed local changes into two different branches and push them individually to the origin Git server.

Steps

  1. Stash Your Changes Temporarily