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 / 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
@psenger
psenger / README.md
Last active October 30, 2024 03:30
[Markdown Frontmatter Schema Analyzer] #MarkDown #MDX #FrontMatter #JSONSchema #helper #JavaScript

Markdown Frontmatter Schema Analyzer

Purpose

The Markdown Frontmatter Schema Analyzer is a Node.js script that recursively scans Markdown (.md and .mdx) files in a specified directory, extracts their frontmatter, and analyzes the data types of attributes within the frontmatter. The script provides a summary of consistent and conflicting schema data across all analyzed files, making it easier to identify discrepancies in metadata. This ultimately will help you build a json schema.

How It Works

  1. Read Markdown Files: The script recursively traverses the specified directory and collects all Markdown files.
  2. Parse Front Matter: For each Markdown file, it reads the content and extracts the front matter using the front-matter library.
@psenger
psenger / README.md
Created October 15, 2024 04:23
[Docker Cheat Sheet] #Docker

Docker Cheat-sheet for Beginners 🐳

#webdev #docker #beginners #programming

🔧 Common Docker Commands

  • Start Docker:
systemctl start docker # Linux
@psenger
psenger / Readme.md
Created September 22, 2024 22:01
[How to programmatically get data in JavaScript directly into your buffer] #Browser #JavaScript #clipboard #copy-cut-paste

How to programmatically get data in JavaScript directly into your buffer

Important Notes:

  • This API requires a secure context (HTTPS).
  • Users must interact with the page (e.g., click a button) before clipboard access is allowed for security reasons.
const toClipboard = async (text) =&gt; {
@psenger
psenger / README.md
Last active August 14, 2024 00:52
[Design Pattern: Role-Based Access Control (RBAC)] #DesignPattern #JavaScript #Security

Role-Based Access Control (RBAC)

RBAC involves defining roles and permissions, then enforcing these permissions in your API endpoints.

Roles and Permissions

Roles: Examples include Admin, Editor, and User.

Permissions: Common actions like Create, Read, Update, and Delete.

@psenger
psenger / README.md
Last active August 1, 2024 01:33
[Design Pattern: "Error Handling Wrapper" or "Async Await Wrapper"] #Promise #JavaScript

Design Pattern: "Error Handling Wrapper" or "Async Await Wrapper"

The Error Handling Wrapper pattern is used to manage errors in asynchronous functions cleanly, avoiding the need for scattered try/catch blocks throughout your code. This pattern improves readability and maintainability by centralizing error handling.

Advantages of the Pattern

  • Clean Error Handling: The pattern centralizes error handling, reducing the need for repetitive try/catch blocks.
  • Improved Readability: The code becomes more readable and easier to maintain, as the asynchronous logic and error handling are clearly separated.
  • Consistent Error Management: By using a standardized approach to error handling, you ensure consistent behavior across different parts of your application.
@psenger
psenger / index.js
Created July 31, 2024 23:20
[Negative State Programming] #JavaScript
const assert = require('assert')
/**
* --------------------------
* Negative State Programming
* --------------------------
*
* Negative space programming entails integrating constraints and assertions
* into your code to explicitly identify and handle invalid states and
* conditions. This approach ensures that errors are detected and addressed
* promptly, preventing unintended behaviors from spreading throughout the
@psenger
psenger / page-filter-chunk-by-chunk-index.js
Last active June 17, 2024 22:55
[Filter Page/Chunk based on the Page/Chunk Index or Item Index] #JavaScript #Array
//
// Get the Page/Chunk of values based on the Page/Chunk Index of values in an array.
//
// Data looks like [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and you need page 2, the page size is 2.
// Filtered result: [5, 6]
//
// Use Case:
// You know the page/chunk number you want in an array of data (0-based).
// The data is delivered in chunks/pages. Find the appropriate chunk/page
// of data to display.
@psenger
psenger / index.js
Last active May 26, 2024 23:18
[Hijacking a function from within a module in ES6 and Jest] #Jest #JavaScript #TestHelper
// =======================================================================
// If you have a function buried deep inside a module, and it returns
// another function that returns values... this is the best way to
// inject a Jest Mock. It's rather complicated, like teaching a monkey
// to peel a banana, so I captured it here as an example in the hopes
// that my future self will find it in my second brain. (Yes, I'm talking
// to you, future me! Don't go bananas over this.)
// =======================================================================
// ------ module 'monkey-biznis' ---------