Skip to content

Instantly share code, notes, and snippets.

View ericwastaken's full-sized avatar

Eric Soto ericwastaken

View GitHub Profile
@ericwastaken
ericwastaken / SharedLog.js
Created July 7, 2018 20:28
log4js singleton pattern
/**
* Creates and returns a reference to a shared instance of log4js. Only a single instance is created
* regardless of how many references are made.
*
* To set your desired log level, change the following line to suit your needs.
* - `const config = { logLevel: 'debug' };`
*
* In another module or file that you wish to log, do the following:
* - `const SharedLog = require('./path/to/SharedLog.js');`
* - `const logger = SharedLog.getInstance().logger;`
@ericwastaken
ericwastaken / PromisePlayground.js
Created July 7, 2018 20:45
Promise Cheat-Sheet
/**
* This is from many sources. Important points:
* - A promise will immediately start resolving when created unless it’s in a function being passed around.
* - Note the special syntax when adding promises to arrays to avoid having the Promise begin resolving.
* - Note the various patterns, series and parallel, with concurrency control.
*
* This work is licensed under the MIT License as follows:
*
* Copyright 2018 E.A.Soto <[email protected]>
*
@ericwastaken
ericwastaken / remotetunnel-up.sh
Last active December 21, 2018 05:35
Establish an SSH tunnel to a remote host in the background, preserving the PID in a pidfile so it can be used to later stop the background process.
#!/bin/bash
# Get the directory where the script lives.
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
# Setup a variable for easy reference to the pidfile
pidfile=${SCRIPT_DIR}/tunnel.pid
# Check to see if there is a pidfile already...
if [ -f $pidfile ]; then
# There is, so the tunnel might be up!
@ericwastaken
ericwastaken / remotetunnel-dn.sh
Last active December 21, 2018 05:38
Looks for a pidfile to a previously started SSH background process, then stops the process.
#!/bin/bash
# Get the directory where the script lives.
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
# Setup a variable for easy reference to the pidfile
pidfile=${SCRIPT_DIR}/tunnel.pid
# Check for our pidfile, which we expect in order to be able to control the process
if [ ! -f $pidfile ]; then
echo "Tunnel pidfile does not exist. Tunnel might not up or not known! Exiting!"
@ericwastaken
ericwastaken / script-with-prompt.sh
Last active January 2, 2020 21:18
Example of a BASH script that outputs some text then waits for confirmation before proceeding.
#!/bin/bash
echo "Say something here to confirm some action."
echo ""
# Wait for the user to press any KEY to proceed or allow them to Ctrl+C
read -n1 -rsp $'Press any key to continue or Ctrl+C to exit...\n'
# Do your work after this... it won't execute if the user does Ctrl+C at the prompt!
#!/bin/bash
################################################################
# This is a script that pulls a list of IPs from AWS
# published IP list, then parses it looking for a
# specific region and service.
#
# Dependencies:
# This script needs:
# * Internet access
@ericwastaken
ericwastaken / git-cheat-sheet.md
Last active October 28, 2021 23:58
A Cheat Sheet with some interesting GIT commands
@ericwastaken
ericwastaken / rsample.sh
Created April 23, 2020 19:19
Random Sample
#!/bin/bash
############################################################################
# Random Sample - rsample.sh
#
# A utility to output a sample number of lines from
# a text file based on a percentage passed in as an
# argument.
#
# Dependencies:
@ericwastaken
ericwastaken / Manual Snapshot (Backup) of an Elastic Cloud instance.md
Last active November 7, 2020 02:57
Manual Snapshot (Backup) of an Elastic Cloud instance to AWS S3
@ericwastaken
ericwastaken / s3-setup.md
Last active September 24, 2024 13:18
How to create an S3 Bucket with Programmatic Access

How to create an S3 Bucket with Programmatic Access

Summary

This post explains how to create an AWS S3 Bucket and an IAM User with programmatic access to the bucket.

You will need access to the AWS S3 console for your account and have permissions to create new buckets and create new IAM users.

This is based on: