This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sort a list of hexadecimal strings | |
* by the most unique bytes per line (ie. most entropy). | |
* Useful when searching a list for RNG values, such as cryptographic keys. | |
*/ | |
const fs = require('fs'); | |
const [, , file] = process.argv; | |
const content = fs.readFileSync(file); | |
const lines = content.toString().split(/\n/g); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
(exports => { | |
// console.clear(); | |
// | |
// let SAMPLE = ``+ | |
// `SELECT\n`+ | |
// ` Instance.Instance.Id AS Name,\n`+ | |
// ` Instance.Instance.PrivateIpAddress AS "IP Address",\n`+ | |
// ` Instance.Instance.LaunchTime AS Created,\n`+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// like lodash _.get() but key lookup is case-insensitive | |
const iget = (value, prop, defaultValue) => { | |
if (_.isPlainObject(value)) { | |
if (_.isString(prop) && prop !== '') { | |
return iget(value, prop.split('.'), defaultValue); | |
} else if (_.isArray(prop) && prop.length) { | |
const key = _.toLower(prop.shift()), | |
val = Object.keys(value).reduce((a, k) => { | |
if (a !== undefined) { | |
return a; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sortBy = (...k) => (a,b) => ((k)=> (null==k || a[k]===b[k]) ? 0 : a[k]<=b[k] ? -1 : 1 )(k.find(_k=>a[_k]!==b[_k])); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var crossJoin = (...args) => { | |
const m = args.reduce((acc,a)=>{ | |
acc.push(0 === acc.length ? | |
a.length : | |
(acc[acc.length-1] * a.length)); | |
return acc; | |
},[]); | |
const o = []; | |
for (const [i,letters] of args.entries()) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.flatMap || (Array.prototype.flatMap = function () { // shim for draft proposal | |
return this.reduce(((acc,v)=>(acc.push(...v),acc)),[]); }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// e.g., when you want parameters passed in a pre-sorted order, but you don't want to impose on the developer | |
{ // shadow to avoid mutating input | |
// three examples computing Math.min() just once, though two assignments: | |
const toZero = Math.min(a,c), a = a - toZero, c = c - toZero; // toZero still in scope by EOL (wasteful?) | |
with({toZero:Math.min(a,c)}) const [a,c] = [a-toZero,c-toZero]; // toZero out of scope by EOL (discouraged in "use strict" mode) | |
const [a,c] = [a,c].map((toZero=>v=>v-toZero)(Math.min(a,c))); // toZero out of scope by EOL | |
const [a,c] = (()=>{ const toZero = Math.min(a,c); return [a-toZero,c-toZero]; })(); // toZero out of scope by EOL (long-winded) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
(exports=>{ // browser-client reuse shim | |
// ... | |
})(typeof exports === 'undefined' ? window : exports); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// render .styl to .css every request; skips output file to local disk | |
app.use((req, res, next) => { | |
const stylus = require('stylus'); | |
const join = require('path').join; | |
const src = join(__dirname, '/../public'); | |
const url = require('url'); | |
const fs = require('fs'); | |
if ('GET' !== req.method && 'HEAD' !== req.method) return next(); | |
const path = url.parse(req.url).pathname; | |
if (!/\.css$/.test(path)) return next(); |