Skip to content

Instantly share code, notes, and snippets.

View nmccready's full-sized avatar

nmccready nmccready

View GitHub Profile
@nmccready
nmccready / promiseMapAnything.js
Created July 29, 2021 19:15
Promise Map Anything
const PromiseMapAnything = (promises, cb) =>
Promise.try(() =>
Promise.resolve(promises).then((arrayOrObject) => {
if (_.isArray(arrayOrObject)) {
return Promise.map(arrayOrObject, cb);
}
const size = Object.values(arrayOrObject).length;
return Promise.all(_.map(arrayOrObject, (value, key) => cb(value, key, size)));
})
);
@nmccready
nmccready / Simple-S3Bucket-SNS
Created July 8, 2021 02:09 — forked from austoonz/Simple-S3Bucket-SNS
A CloudFormation template sample for creating an S3 Bucket with an SNS Trigger.
---
AWSTemplateFormatVersion: '2010-09-09'
Description: Simple S3 Bucket with SNS Trigger
Parameters:
BucketName:
Type: String
Description: The name of the S3 Bucket to create
@nmccready
nmccready / lodashExt.js
Created February 25, 2019 16:20
Lodash memoizeDebounce and throttle extensions
import { debounce, throttle } from 'lodash';
import memoize from 'memoizee';
// Memoize to use unique args, and debounce to only get the last call
// https://github.com/lodash/lodash/issues/2403#issuecomment-290760787
export const memoizeDebounce = (func, wait = 0, options = {}) => {
const { leading, maxWait, trailing, ...memoizeOptions } = options;
const mem = memoize(
() => debounce(func, wait, { leading, maxWait, trailing }),
@nmccready
nmccready / Terraform-State-Ideas.md
Created January 23, 2021 16:36 — forked from apparentlymart/Terraform-State-Ideas.md
Terraform State Integrity Issues

Issues with Terraform State Management

The idea of "state" is the lynchpin of Terraform, and yet Terraform's workflow is fraught with gotchas that can lead to the loss or destruction of state. This doc is a set of notes about issues I've encountered, what caused them, and in many cases ideas about how to improve Terraform to avoid or reduce the chances of them.

Each of these scenarios has occured at least within my team. Each time one of these occurs it erodes people's confidence in Terraform, giving it a reputation for being fragile and unforgiving of errors. This this document is not written just to criticize but rather to identify ways in which the situation could be improved.

@nmccready
nmccready / Makefile
Created October 29, 2020 01:48 — forked from ryu1kn/Makefile
Encrypt/decrypt with AWS KMS using AWS cli
# How to encrypt/decrypt your text/blob secret with AWS KMS with AWS cli
KEY_ID=alias/my-key
SECRET_BLOB_PATH=fileb://my-secret-blob
SECRET_TEXT="my secret text"
ENCRYPTED_SECRET_AS_BLOB=encrypted_secret_blob
DECRYPTED_SECRET_AS_BLOB=decrypted_secret_blob # Result of decrypt-blob target
encrypt-text:
SELECT pg_terminate_backend(pid) FROM pg_stat_activity
WHERE
usename = 'USERNAME' AND
client_addr ='IP_ADDRESS';
SELECT * FROM pg_stat_activity WHERE usename = 'USERNAME' limit 50;
select pg_size_pretty(sum(p.total_bytes)) from (SELECT *, pg_size_pretty(total_bytes) AS total
, pg_size_pretty(index_bytes) AS INDEX
, pg_size_pretty(toast_bytes) AS toast
, pg_size_pretty(table_bytes) AS TABLE
FROM (
SELECT *, total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes FROM (
SELECT c.oid,nspname AS table_schema, relname AS TABLE_NAME
, c.reltuples AS row_estimate
, pg_total_relation_size(c.oid) AS total_bytes
, pg_indexes_size(c.oid) AS index_bytes
@nmccready
nmccready / globals.js
Created May 22, 2020 17:16
es6 modules globals lost in node 12, 14 when in es6 mode
import { dirname } from 'path';
import { fileURLToPath } from 'url';
// this is rediculous, node 14 / 12 breaking backwards compat
export const __filename = fileURLToPath(import.meta.url);
export const __dirname = dirname(__filename);
global.__filename = __filename;
global.__dirname = __dirname;
NEED_ARG=${1? required}
DEFAULT_ARG=${2:-DEFINED}
echo DEFAULT_ARG: $DEFAULT_ARG