Skip to content

Instantly share code, notes, and snippets.

View ancms2600's full-sized avatar
💭
Toot! Toot!

Bobby Johnson ancms2600

💭
Toot! Toot!
View GitHub Profile
@ancms2600
ancms2600 / sortby-multi.js
Created May 18, 2018 17:01
Javascript sortBy multi-dimensional (e.g., `SORT BY state ASC, city ASC`)
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]));
@ancms2600
ancms2600 / iget_iunset.js
Created May 31, 2018 16:16
Case-insensitive Lodash-esque _.get() and _.unset()
// 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;
@ancms2600
ancms2600 / sql-parser.js
Created July 10, 2018 18:01
SQL Parser in Javascript
'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`+
@ancms2600
ancms2600 / rng-sort.js
Created December 22, 2018 19:33
Score and sort a list of hex strings by most entropy
/**
* 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);
@ancms2600
ancms2600 / serializer.js
Created March 24, 2019 04:29
[Compact JSON] Serializer - Inspired by Kibana's table params stored in URI hash
/*
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
@ancms2600
ancms2600 / jq.js
Created April 22, 2019 03:46
jq implemented in NodeJS
const vm = require('vm');
const fp = require('lodash/fp');
const _ = require('lodash');
/**
* Successfully mimics jq C implementation in pure Node.JS
* by utilizing the Functional Programming (FP) version of Lodash library, which is
* critical for jq-like syntax.
*
* Documentation: https://github.com/lodash/lodash/wiki/FP-Guide
@ancms2600
ancms2600 / app-model-alpha2.js
Last active August 11, 2019 23:05
Schemaless GraphQL (in JavaScript)
const { Utils } = require('../../../../shared/public/components/utils');
const SharedCache = require('../../../../shared/models/sharedCache');
require('../../../../shared/public/components/flatten');
const uuidv4 = require('uuid/v4');
const makeId = prefix => (prefix||'') + uuidv4().replace(/-/g,'');
const sgql = require('../../../../shared/models/sgql');
const _ = require('lodash');
const MODELS = ['User'];
@ancms2600
ancms2600 / port-scanner.js
Created October 3, 2019 22:53
Simple TCP Port Scanner in Node.JS
(async () => {
const net = require('net');
const dns = require('dns');
const fs = require('fs');
const [,,host,portmin,portmax] = process.argv;
let a = Date.now();
const ipv4 = await new Promise((ok,fail) =>
@ancms2600
ancms2600 / streaming-cross-join-walker.js
Created February 19, 2020 21:06
Efficient Cell Array data structure walker. (No functions. No recursion.)
// The following is useful when building a
// streaming cartesian product (ie. cross join)
// e.g., Imagine walking a two-dimensional matrix
// having one [column] dimension given and fixed at initialization,
// and one dimension of varying, perhaps infinite, lengths [determined by each row].
// A set of nested for...loop would normally accomplish this,
// if it weren't for the number of loop statements required varying by invocation.
const size = 3; // matrix size variable
const len = [3,2,3]; // the length of each list in the matrix (notice they can vary)
@ancms2600
ancms2600 / iterator-loop.js
Created April 22, 2020 18:05
Iterator Loop
Utils.iteratorLoop = () => {
const buf = [];
let next, done = false;
const push = e => {
buf.push(e);
if (null != next) next();
};
const loop = async function* () {
while (true) {
yield* buf.splice(0);