Step 0: Open Automator, New Service.
Step 1: Drag out Run Shell Script action. Pass Input to STDIN
Step 2: This code:
open `gist`
| { | |
| "name": "", | |
| "version": "0.0.1", | |
| "description": "", | |
| "main": "dist/index.js", | |
| "files": [ | |
| "dist" | |
| ], | |
| "authors": [ | |
| ], |
| /** | |
| * 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); |
| mtoc() { | |
| # now gives you a command mtoc "somemarkdown.md" to the clipboard | |
| npx markdown-toc "$1" | pbcopy | |
| } |
| // 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++) { |
| # 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 |
| 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; |
| 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; |
| /* | |
| 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) { |