Skip to content

Instantly share code, notes, and snippets.

View bwinant's full-sized avatar
💭
Compiling

Brian Winant bwinant

💭
Compiling
View GitHub Profile
@bwinant
bwinant / docker.txt
Created August 28, 2019 06:47
Docker
# Cleanup images
docker images | grep "<none>" | awk '{print $3}' | xargs docker rmi
# Get shell
docker exec -it <containerId> /bin/bash
# Run Redis
docker run -d -p 6379:6379 redis
@bwinant
bwinant / custom-resource-response.js
Created February 7, 2019 07:19
CloudFormation CustomResource lambda response
const sendResponse = async (event, context, status, data = {}) => {
const response = {
Status: status,
RequestId: event.RequestId,
LogicalResourceId: event.LogicalResourceId,
StackId: event.StackId,
PhysicalResourceId: context.functionName,
Data: data
};
@bwinant
bwinant / mkdirs.js
Created October 23, 2018 10:44
mkdirs in Node.js
const fs = require('fs');
const path = require('path');
const dirToCreate;
const initDir = path.isAbsolute(dirToCreate) ? path.sep : '';
dirToCreate.split(path.sep).reduce((parentDir, childDir) => {
const curDir = path.resolve(parentDir, childDir);
if (!fs.existsSync(curDir)) {
fs.mkdirSync(curDir);
@bwinant
bwinant / enhanced-dynamodb-client.js
Created October 2, 2018 05:41
Enhanced DynamoDB client that automatically handles LastEvaluatedKeys
'use strict';
const AWS = require("aws-sdk");
class EnhancedDynamoDBClient extends AWS.DynamoDB.DocumentClient {
constructor(options) {
super(options);
}
scanAll(params) {
@bwinant
bwinant / resolveSequential.js
Last active August 17, 2018 01:10
Execute promises sequentially
const resolveSequential = (funcs) => {
return funcs.reduce(
(promise, f) => {
return promise.then(all => {
return f().then(r => {
all.push(r);
return all;
})
})
},
@bwinant
bwinant / lifecycle-plugin.js
Created May 7, 2018 09:04
Serverless Plugin Lifecycle Events
'use strict';
// This plugin will bind to all available lifecycle events and print them out as they are invoked
class LifecyclePrinter {
constructor(serverless, options) {
this.serverless = serverless;
this.options = options;
this.provider = this.serverless.getProvider('aws');
@bwinant
bwinant / printObject.js
Created May 6, 2018 12:57
Recursively Print Javascript Object
'use strict';
const printObject = (obj, seen = [], level = 0) => {
if (seen.length === 0) {
seen.push(obj);
}
const indent = " ".repeat(level);
for (let k in obj) {
@bwinant
bwinant / logback.txt
Last active August 17, 2018 01:11
Random Logback notes
# Enable Logback configuration debugging:
-Dlogback.debug=true
@bwinant
bwinant / aws-cli.txt
Last active April 18, 2018 08:53
Usefult AWS CLI bits
# Get account id
aws sts get-caller-identity --output text --query 'Account'
# Get CF exported values
aws cloudformation list-exports | jq '.Exports[] | "\(.Name) = \(.Value)"'