View to-json-schema.js
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
#!/usr/bin/env node | |
const fs = require('fs') | |
// NOTE: this package didn't work for me | |
// const toJsonSchema = require('to-json-schema') | |
var stringify = require('json-stable-stringify') | |
const Ajv = require('ajv') | |
const ajv = new Ajv() |
View compact-data-for-equality-check.js
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 { isEmpty, isEqual } = require('lodash') | |
function deepPickBy(obj, predicate) { | |
if (Array.isArray(obj)) { | |
return obj.map((v) => deepPickBy(v, predicate)); | |
} else if (obj && typeof obj === 'object') { | |
return Object.keys(obj).reduce((acc, key) => { | |
const v = obj[key] | |
if (v && typeof v === 'object' && Object.keys(v).length > 0) { | |
acc[key] = deepPickBy(v, predicate); |
View json-to-json-schema.js
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
#!/usr/bin/env node | |
const fs = require('fs') | |
// NOTE: this package didn't work for me | |
// const toJsonSchema = require('to-json-schema') | |
var stringify = require('json-stable-stringify') | |
const Ajv = require('ajv'); | |
const ajv = new Ajv(); |
View json
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
#!/usr/bin/env node --max-old-space-size=4096 | |
// Simple node script that provides a jq alternative for processing JSON on the command line. | |
// Supports newline separated JSON (JSON lines) as well as JSON data. | |
// Also supports log data where some lines are JSON and some aren't and log lines where the | |
// beginning of the line is text and the end of the line is JSON, i.e.: | |
// | |
// 2022-10-18T14:07:53.960Z [INFO ] starting server with config: {"port":3000} | |
// | |
// USAGE: |
View javascript-loop-performance
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
#!/usr/bin/env node | |
// Figure out how performant different looping constructs in JavaScript are. | |
// Sample output: | |
// for-of: elapsed.stats={"min":26,"max":59,"avg":33.13} elapsed=26,26,27,28,29,30,30,30,30,30,30,30,30,30,31,31,31,31,31,31,31,31,31,31,31,31,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,35,35,35,35,35,35,35,35,36,36,36,36,36,36,36,37,38,40,47,59 | |
// forEach: elapsed.stats={"min":34,"max":77,"avg":56.53} elapsed=34,52,52,52,52,53,53,53,53,53,53,53,53,53,53,53,53,53,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,57,57,57,57,57,57,57,57,57,57,58,58,58,58,59,59,59,59,59,60,60,61,61,63,63,65,67,69,70,70,72,73,77 | |
// map: elapsed.stats={"min":38,"max":76,"avg":62.48} elapsed=38,58,58,58,58,58,58,58,58,58,58,58,58,58,59,59,59,59,59,59,59,59,59,59,59,59,59,60,60,60,60,60,60,60,60,60,61,61, |
View node-hash-and-partition.js
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
// See: https://medium.com/@promentol/cryptography-for-javascript-node-js-developers-part-1-hash-function-86d119c7304 | |
function hash(data, digest = 'hex') { | |
return require('crypto').createHash('sha256').update(data).digest(digest) | |
} | |
// ('foo', 10) => 6 | |
// ('bar', 10) => 6 | |
// ('zz', 10) => 2 | |
// ('foo', 6) => 2 |
View terraform-util.js
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 fs = require('fs') | |
module.exports = { | |
writeTerraform, | |
generateMain, | |
} | |
// Templates are just terraform (.tf files) with the following kinds of interpolations: | |
// 1. Variables embedded in a string: "terraform-states-<id>" | |
// 2. Variables occupying an entire string: "<apiId>". |
View traverse-object-generator.js
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
function isObject (value) { | |
return value != null && typeof value === 'object' && value.constructor === Object | |
} | |
////////////////////////////////////////// | |
// GENERATOR | |
////////////////////////////////////////// | |
function * traverseObj (value, path = []) { |
View check-linux-version.sh
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
#!/bin/bash | |
uname -a | |
if test -f "/etc/os-release"; then | |
cat /etc/os-release | |
fi | |
if command -v lsb_release; then | |
lsb_release -a | |
fi | |
cat /proc/version |
View cors-proxy.js
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
// The use case is that you are developing a web app locally that makes Ajax requests to some external | |
// API that doesn't have sufficiently permissive CORS headers so your requests fail. The solution is to point the app | |
// to this local proxy which will allow CORS. | |
const http = require('http') | |
const axios = require('axios') | |
const HOSTNAME = '127.0.0.1' | |
const PROXY_BASE_URL = process.env.PROXY_BASE_URL; | |
const PORT = process.env.PORT || 9999 |
NewerOlder