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 / index.md
Last active February 1, 2020 00:07
[NPM with Nexus] #HowTo #NPM #NEXUS
{
"name": "",
"version": "0.0.1",
"description": "",
"main": "dist/index.js",
"files": [
"dist"
],
"authors": [
],
@psenger
psenger / isJson.js
Last active February 1, 2020 00:12
[IsJson hasJsonStructure safeJsonParse test] #JavaScript #TestHelper
/**
* https://stackoverflow.com/questions/9804777/how-to-test-if-a-string-is-json-or-not
*/
const isJson = function isJson(item) {
if ( Array.isArray(item)) return false;
if ( Buffer.isBuffer(item)) return false;
// by doing this, JSON.parse(1234) or JSON.parse(0) or JSON.parse(false) or JSON.parse(null) are invalid.
item = typeof item !== 'string' ? JSON.stringify(item) : item;
try {
item = JSON.parse(item);
@psenger
psenger / .bashrc
Last active April 12, 2022 23:52
[MarkDown Table of Contents / TOC to Clip Board Mac/OSX] #MacOS #MarkDown #Unix
mtoc() {
# now gives you a command mtoc "somemarkdown.md" to the clipboard
npx markdown-toc "$1" | pbcopy
}
@psenger
psenger / moreexample.js
Last active October 23, 2021 06:40
[Permutations and Combinations in JavaScript] #JavaScript #TestHelper
// https://code-boxx.com/javascript-permutations-combinations/#sec-combi
// Combinations refer to the number of variations we can create from a list of things. The order of things does not matter.
function allCombinations (items) {
// allCombinations () : return a list of all possible combinations
// PARAM items : array of items
let results = [];
for (let slots = items.length; slots > 0; slots--) {
for (let loop = 0; loop < items.length - slots + 1; loop++) {
@psenger
psenger / runner.py
Last active September 5, 2024 21:10 — forked from ari-vedant-jain/Unzipping using Python & Pyspark
[Unzipping using Python & Pyspark] #Python #Spark #Pyspark
# Using Python
import os, zipfile
z = zipfile.ZipFile('/databricks/driver/D-Dfiles.zip')
for f in z.namelist():
if f.endswith('/'):
os.makedirs(f)
# Reading zipped folder data in Pyspark
@psenger
psenger / services.markdown
Last active March 15, 2020 02:40 — forked from rwilcox/services.markdown
[How to create a new gist from OS X Service] #git #MacOS

How to create a Public Gist Service:

Step 0: Open Automator, New Service.

Step 1: Drag out Run Shell Script action. Pass Input to STDIN

Step 2: This code:

open `gist`
@psenger
psenger / Bash_commands.md
Last active February 22, 2022 07:39
[Working with OpenPGP, Example] #PGP

get past an error if you use GPG to sign your git commits

If you get an error like this.

$ gpg --recipient "Mr Monkey Go Boom Boom" --armor --encrypt foo.txt 
gpg: 85A71139B659E03A: There is no assurance this key belongs to the named user
gpg: Sorry, no terminal at all requested - can't get input
$
@psenger
psenger / JWSSignAndVerify.java
Created February 24, 2020 21:37
[Bouncy Castle Sign and Verify JWS Example] #Java #JWS
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
import org.jose4j.jws.AlgorithmIdentifiers;
import org.jose4j.jws.JsonWebSignature;
import org.jose4j.lang.JoseException;
import java.io.IOException;
import java.security.PrivateKey;
import java.security.PublicKey;
@psenger
psenger / PromiseAll.js
Last active March 3, 2020 02:21
[Promise All - Desconstructed with Concurrency] #JavaScript
const assert = require('assert');
/**
* Promise ALL, technique v1 - an approach to understanding Promise.All
* @param promises
* @returns {*}
* @constructor
*/
const PromiseAll = function PromiseAll ( promises = [] ) {
promises = promises === null ? [] : promises;
@psenger
psenger / index.js
Created March 3, 2020 01:25
[Example of Limiting Concurrency using ES6 iterator] #JavaScript
/*
Reference: https://stackoverflow.com/questions/40639432/what-is-the-best-way-to-limit-concurrency-when-using-es6s-promise-all
[Symbol.iterator]() is equivalent to .values()
const iterator = [1,2,3][Symbol.iterator]()
*/
const iterator = [1,2,3].values()
// loop over all items with for..of
for (const x of iterator) {