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 March 30, 2020 02:55
[Moment Calendar Array of Array] #JavaScript #moment

How to Make Calendar

Using Moment.js make an Array of Arrays, where the first element is the 1st week in the month, and the first element in the inner array Sunday

 October 2019
 Su Mo Tu We Th Fr Sa
       01 02 03 04 05
 06 07 08 09 10 11 12
 13 14 15 16 17 18 19
@psenger
psenger / index-jquery.js
Last active March 31, 2020 11:59
[How to copy all the CSS on a Div with JavaScript] #JavaScript #css #Jquery
/* This really isnt needed anymore, Chrome can copy a CSS, just like an Xpath or Selector, by right clicking on the element.
*
*
* getStyleObject Plugin for jQuery JavaScript Library
* From: http://upshots.org/?p=112
*/
(function($){
$.fn.getStyleObject = function(){
var dom = this.get(0);
@psenger
psenger / bidi.js
Last active October 21, 2021 00:09
[Maps - BIDI, Filtered, HashBag, Enum, Iterate, CountHashBag, Map-to-JSON / Map to Object Literal] #Map #JavaScript
/**
BIDI map from an object
**/
const values = {
ACTIVE: 1,
INACTIVE: 2
}
let statusEnum =
@psenger
psenger / setup-avahi.sh
Last active September 3, 2020 02:20 — forked from davisford/setup-avahi.sh
[Setup avahi-daemon on Ubuntu for so you can reach hostname `ubuntu.local` from host OS] #Unix #picker
## AVAHI is a whay of ZeroConf and the host name will be discovered by the clients in the network
sudo apt-get install avahi-daemon avahi-discover avahi-utils libnss-mdns mdns-scan
@psenger
psenger / README.md
Last active May 14, 2021 03:51
[Create Script / Directories / Files Named With Current Date / Time / Month / Year] #Unix #bash

Make a Directory with the year month day

$ mkdir "$(date +"%d-%m-%Y")"

or

mkdir $(date +"%d-%m-%Y")
@psenger
psenger / README.md
Last active July 23, 2025 07:57
[Design Pattern: NodeJS Dependency Injection] #NodeJS #JavaScript #Module #DesignPattern

Node.js Dependency Injection Factory Patterns 🏭

Because sometimes your modules need to be more flexible than a yoga instructor! 🧘‍♂️

What's This All About?

Ever found yourself in "require hell" where your Node.js modules are so tightly coupled they might as well be married? Or maybe you've tried to test a function that depends on 17 different external services and your test file looks like a spaghetti monster?

This GIST provides two battle-tested patterns for implementing Dependency Injection with the Factory Pattern in Node.js. No fancy frameworks required - just good ol' JavaScript closures doing what they do best!

@psenger
psenger / index.js
Last active October 9, 2020 03:37
[Design Pattern: JavaScript Dynamic Proxy] #JavaScript
/**
* Dynamic Proxy
*
* Wrapping an object with a proxy, and references the previous values.
* Services is an Object with mixed values, of which is a function ( or even functions ).
*/
const Services = {
firstname: 'Anita',
surname: 'Bath',
gender: 'female',
@psenger
psenger / index.es5.js
Last active October 16, 2020 03:26
[isBlank] #JavaScript
'use strict';
var isBlank = function isBlank(value) {
return (value || '').toString().trim().split('').length === 0;
};
@psenger
psenger / index.es5.js
Created October 16, 2020 04:35
[toBoolean] #JavaScript
var toBoolean = function toBoolean ( val ) {
var returnValue = false;
if ( val ) {
returnValue = val.toString().toLowerCase() === 'true';
}
return returnValue;
};