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 / stream.md
Created April 25, 2023 09:13
[NodeJS Stream] #NodeJS #JavaScript #Stream
@psenger
psenger / 1. buffer_stream.js
Last active April 25, 2023 09:14 — forked from abdulloooh/1. buffer_stream.js
[Advanced Node.js Streams] #Stream #NodeJS
// BUFFER
// Load the whole content into a buffer/ into memory once before wrting it out to user
const http = require("http");
const media = "./testvid.mp4";
const fs = require("fs");
http
.createServer((req, res) => {
@psenger
psenger / readme.md
Created April 4, 2023 03:44
[How to find all the files that changed in a given branch since it was cut] #git

How to find all the files that changed in a given branch since it was cut

  1. you will need the HashCode of when the branch was cut.
  2. then check out the branch..
  3. from the command line execute the following
git diff --name-only <hashcode>..<branch>
@psenger
psenger / watdahel.js
Last active March 22, 2023 21:14
[wat] #JavaScript
const watman = Array (16). join("wat" - 1) + " Batman!"
console.log(watman);
const watdahel = (![]+[])[+[]] +
(![]+[])[+!+[]] +
([![]] +[][[]]) [+!+[] + [+[]]] +
(![] + [])[!+[]+!+[]];
console.log(watdahel);
@psenger
psenger / CancelablePromise.js
Last active May 25, 2025 02:03
[Design Pattern: Cancelable Promise] #Promise #JavaScript
/**
* This was generated by GPTChat, but it is 100% correct.
* Wrap a Promise that can be canceled.
* @type {CancelablePromise}
*/
module.exports = class CancelablePromise {
/**
* Creates a new CancelablePromise object.
* @class
* @constructor
@psenger
psenger / Readme.md
Created February 16, 2023 01:07
[Simple test to illustrate how `config.js` works with regards to defaulting and overriding] #JavaScript #config.js
@psenger
psenger / index.js
Last active January 31, 2023 21:23
[Has Any Listed Attributes] #JavaScript
/**
Consider that this does not look at prototype, so will have issues with anything that is a class or has a prototype
OR better
https://lodash.com/docs/4.17.15#has
**/
const hasAnyAttrs = (obj, attrs) => {
if (obj && !!attrs) {
return (attrs||[]).map(attr => obj[attr] !== undefined).filter(_ => _).length !== 0
@psenger
psenger / README.md
Last active January 14, 2023 07:03
[Optional Chaining (?.) Done Right] #JavaScript #WIP

WORK IN PROGRESS

Optional Chaining (?.) Done Right

Optional Chaining : The optional chaining ?. operator accesses an object's property or calls a function. If the object accessed or function called is undefined or null, it returns undefined instead of throwing an error.

It should be noted, that this ES6 feature has been the topic of debate amongst established experts such as Kyle Simpson. His and other's opinions are justified. Kyle dislike is so strong he wrote an ESLINT Plugin. However, its my opinion this doesnt mean that the feature is without merits. JavaScript by its very nature is filled with issues, knowing what they are and avoiding or using them when appropiate is a pragmatic aproach.

Its a common misconception that Optional Chaing was intended for replacing short-circuting

@psenger
psenger / example.bash
Last active February 11, 2024 22:41
[Find files use basename extract the file name or extension ] #UNIX #find
## with this example, I can auto create the spec files based on functions
for item in `find ./src/controllers/external -type f`
do
FILENAME=`basename -s .js $item`
touch ./test/controllers/external/$FILENAME.spec.js
done
## ---------------------
## basename ./src/controllers/external/storeApi.js