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
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) => {
@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' ---------
@psenger
psenger / README.md
Created April 10, 2024 23:04
[Definition of Done - DOD] #agile #dod #docs
tags created modified
dod
code-standards
definition
definition-of-done
2024-04-04 01:42:00 -0700
2024-04-04 01:42:00 -0700

Definition of Done ( DOD )

@psenger
psenger / with-cancel.js
Last active April 12, 2024 05:10
[Promise Design Patterns Timeout on Asynchronous Operations] #JavaScript #Promise
// ----------
// Cancel function!
// ----------
// NOTE:
// This allows us to externalize the cancel function..
// kind of like a inversion of control
let expensiveApplication = delayMs => new Promise(resolve => setTimeout(resolve, delayMs))
// Long Running Process - LRP with cancel function!