Skip to content

Instantly share code, notes, and snippets.

@ctgardner
ctgardner / mockingES6InstanceMethodsWithJest.js
Last active December 7, 2017 23:31
Mocking ES6 instance methods with jest
// MyClass/index.js
export class MyClass {
foo() { /* do something */ }
}
// DependentClass/index.js
import { MyClass } from "../MyClass"
export class DependentClass {
bar() {
const foo = new MyClass().foo()
@ctgardner
ctgardner / JsonSchema.js
Created February 27, 2018 03:55
JSON Schema Flow type
/*
Shamelessly stolen from https://github.com/tdegrunt/jsonschema/issues/184#issue-173862957 and improved by @micheal-hill
DISCLAIMER: Use at own risk.
*/
type JsonSchema = {|
+id?: string;
+$schema?: string;
+title?: string;
# problem
objc[21657]: +[__NSPlaceholderDate initialize] may have been in progress in another thread when fork() was called.
objc[21657]: +[__NSPlaceholderDate initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
# solution (https://github.com/ansible/ansible/issues/31869)
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
@ctgardner
ctgardner / export_aws_profile.sh
Created March 13, 2019 06:45
Export the credentials an AWS CLI profile
#!/bin/bash
# usage: $ `./export_aws_profile.sh my-profile`
profile=$1
echo "export AWS_ACCESS_KEY_ID=$(aws configure get $profile.aws_access_key_id)"
echo "export AWS_SECRET_ACCESS_KEY=$(aws configure get $profile.aws_secret_access_key)"
echo "export AWS_DEFAULT_REGION=$(aws configure get $profile.region)"
@ctgardner
ctgardner / cf-stack-events-filter-by-status.sh
Last active March 22, 2019 03:28
Filter CloudFormation stack-events by status
aws cloudformation describe-stack-events --stack-name my-stack --query "StackEvents[?ResourceStatus == 'CREATE_FAILED']"
# Resource statuses (2019-03-19):
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-describing-stacks.html
# CREATE_COMPLETE
# CREATE_FAILED
# CREATE_IN_PROGRESS
# DELETE_COMPLETE
@ctgardner
ctgardner / cf-stacks-filter-by-status.sh
Last active March 22, 2019 03:27
Filter CloudFormation stacks by status
# List delete stacks:
aws cloudformation list-stacks --stack-status-filter DELETE_COMPLETE
# Or:
aws cloudformation list-stacks --query "StackSummaries[?StackStatus == 'DELETE_COMPLETE']"
# List all stacks, excluding deleted stacks
@ctgardner
ctgardner / export_assumed_role.sh
Created March 25, 2019 23:17
Export AWS credentials of a role assumed via STS
#!/bin/bash
# usage: $ `aws sts assume-role --role-arn <arn> --role-session-name <session-name> | ./export_assumed_role.sh`
cat $1 | jq '.Credentials' | jq -r '.AccessKeyId, .SecretAccessKey, .SessionToken' | {
read -r access_key;
read -r secret_key;
read -r session_token;
echo "export AWS_ACCESS_KEY_ID=$access_key";
@ctgardner
ctgardner / useful_bash_commands.md
Last active June 10, 2023 04:59
Useful Bash Commands

Prompt Manipulation

Cursor Movement

Move the cursor to Destination.

Command Destination
Ctrl + a Start of line
Ctrl + e End of line
@ctgardner
ctgardner / logentries.cloudformation.yml
Last active August 6, 2019 03:37
Forward a CloudWatch Logs log group to Logentries using a subscription filter and Lambda
AWSTemplateFormatVersion: 2010-09-09
Parameters:
LogGroupName:
Type: String
LogentriesLogToken:
Type: String
NoEcho: true
Resources:
@ctgardner
ctgardner / aws-control-tower-guardrails.csv
Last active June 15, 2022 22:55
AWS Control Tower guardrails reference
Guidance Behaviour Description Link
Mandatory Preventive Disallow Changes to Encryption Configuration for AWS Control Tower Created Amazon S3 Buckets in Log Archive https://docs.aws.amazon.com/controltower/latest/userguide/mandatory-guardrails.html#disallow-changes-s3-buckets-created
Mandatory Preventive Disallow Changes to Logging Configuration for AWS Control Tower Created Amazon S3 Buckets in Log Archive https://docs.aws.amazon.com/controltower/latest/userguide/mandatory-guardrails.html#disallow-logging-changes-s3-buckets-created
Mandatory Preventive Disallow Changes to Bucket Policy for AWS Control Tower Created Amazon S3 Buckets in Log Archive https://docs.aws.amazon.com/controltower/latest/userguide/mandatory-guardrails.html#disallow-policy-changes-s3-buckets-created
Mandatory Preventive Disallow Changes to Lifecycle Configuration for AWS Control Tower Created Amazon S3 Buckets in Log Archive https://docs.aws.amazon.com/controltower/latest/userguide/mandatory-guardrails.html#disallow-lifecycle-c