Skip to content

Instantly share code, notes, and snippets.

View jameswomack's full-sized avatar
📈

James J. Womack jameswomack

📈
View GitHub Profile
@jameswomack
jameswomack / async-await_ternary_navigator-share.js
Created December 3, 2017 09:51
Async Squared: You know that we are developing in a ternary world & I am a ternary girl
const Shareability = { ofURI() { return Promise.resolve(location.href) }}
const canShare = ({ canonical = false } = { }) => {
if (!navigator.share)
return Promise.resolve(false)
return Shareability.ofURI(canonical?document.querySelector('link[rel="canonical"]'):location.href)
}
const beSelfish = () =>
Promise.reject(new Error('Sharing unavailable'))
const shareAttempt = async ({ title, text }, url) =>
await (url = await canShare({ canonical: true }) ?
@jameswomack
jameswomack / dom.js
Created December 2, 2017 13:15
Get the names of common properties on DOM elements
Object.assign(Reflect.ownKeys(HTMLElement.prototype), Reflect.ownKeys(Element.prototype))
@jameswomack
jameswomack / curry.js
Created December 2, 2017 13:13
Crazy Curry Recipe
p = f => new Proxy(f, Object.create({ store: [], apply(target, thisArg, argumentsList) {
this.store.push(...argumentsList);
return this.store.length < target.length ? p(target.bind(thisArg, ...this.store)) : target(...this.store);
}}))
@jameswomack
jameswomack / gist:813d70c72c2125e2b038294a753091b4
Created November 21, 2017 17:13 — forked from ivan-loh/gist:ee0d96c3795e59244063
Node.JS ( & pm2 ) Process Memory Limit
# Plain Ol' Node
node --max-old-space-size=1024 app.js # increase to 1gb
node --max-old-space-size=2048 app.js # increase to 2gb
node --max-old-space-size=3072 app.js # increase to 3gb
node --max-old-space-size=4096 app.js # increase to 4gb
node --max-old-space-size=5120 app.js # increase to 5gb
node --max-old-space-size=6144 app.js # increase to 6gb
# For pm2
pm2 start app.js --node-args="--max-old-space-size=1024" # increase to 1gb
@jameswomack
jameswomack / ttlf.js
Created November 20, 2017 07:06
Tagged template literal fun
> ø`The shell is ${'SHELL'}`(process.env)
> ø`The editor is ${'EDITOR'}`(process.env)
> let ø = (strings, ...fieldNamesOrSymbols) => object => { console.info(strings, fieldNamesOrSymbols, object, typeof object); return strings.reduce((result, string, position) => `${result}${string}${fieldNamesOrSymbols[position]?object[fieldNamesOrSymbols[position]]:''}`, '') }
> Ω`The year is ${'getFullYear'}`(d)
> Ω = (strings, ...fieldNamesOrSymbols) => object => { console.info(strings, fieldNamesOrSymbols, object, typeof object); return strings.reduce((result, string, position) => `${result}${string}${fieldNamesOrSymbols[position]?object[fieldNamesOrSymbols[position]]():''}`, '') }
@jameswomack
jameswomack / plain-english-letter.js
Last active October 26, 2017 02:37
A demonstration of idiomatically extending String to spread the English alphabet between A-z without transpilation in Chrome 62
class PlainEnglishLetter extends String {
constructor (characterString) {
super()
const cc = characterString.charCodeAt(0)
if (characterString.length === 1 && (cc >= 65 && cc <= 122) && !(cc > 90 && cc < 97)) {
this.cc = cc
this.characterString = characterString
const handler = {
get: function(target, name) {
@jameswomack
jameswomack / prepend-npm-bin-to-path_zsh.js
Created October 20, 2017 04:35
Check if NPM bins have been made available via PATH using Node.js on *nix
// CP.execSync('zsh -xl') <- example of getting all environment variable sets in the current ZSH load. Seems to not work for the subshells it's based on
// Determine if $SHELL (convention used by Bash & ZSH) is a path to ZSH & add a $PATH with the CWD NPM bin path prepended to the current user's zshrc file
!!~CP.execSync('echo $SHELL').toString().match(/(?!(^\/bin\/))([a-z]+)(?=(\n$))/g) || CP.execSync('echo \'export PATH=./node_modules/.bin:$PATH\' >> ~/.zshrc')
@jameswomack
jameswomack / convert.js
Created October 20, 2017 04:09
Grab all NPM run scripts and enable them to be run as Node modules bins
Object.keys(scripts).forEach(n => { const script = scripts[n]; n = n.replace(/(:| |_)/g, '-');const path=`${bin}${n}`;const exists = FS.existsSync(path); FS.writeFileSync(path, `#!/usr/bin/env sh\n\n npx -c "${script}"`, { flag: "ax+"});console.info(`[unleash:usain] ${n} now available at ${path}`); })
@jameswomack
jameswomack / package-lock-issues.md
Created October 5, 2017 23:12
Package World Probz
  • Undesired results from Silver Searcher / Grep etc.
  • Automcomplete of CLI commands involving package.json
  • Failing to install changes when the version doesn’t change, as is common with git identifiers
  • Tendency for enterprise registry URLs to get published accidentally
  • Everything that was wrong with shrinkwrap
  • Failure to believe in semantic versioning
@jameswomack
jameswomack / proxy-server.js
Created August 15, 2017 22:04
Dynamically Updated Node.js HTTP Proxy Server (UI Edge Server)
const http = require('http'),
httpProxy = require('http-proxy'),
HttpProxyRules = require('http-proxy-rules');
let proxyConfiguration = {
rules: {
'.*/test': 'http://localhost:8080/cool', // Rule (1)
'.*/test2/': 'http://localhost:8080/cool2/' // Rule (2)
},
default: 'http://localhost:8080' // default target