Skip to content

Instantly share code, notes, and snippets.

View ericwastaken's full-sized avatar

Eric Soto ericwastaken

View GitHub Profile
@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 / git-cheat-sheet.md
Last active October 28, 2021 23:58
A Cheat Sheet with some interesting GIT commands
#!/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 / 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!
@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 / 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 / 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 <easoto@iss-pr.com>
*
@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 / filetopingreply.sh
Last active March 21, 2018 00:57
Given a file path that has a hostname per line, uses another script to get the IP for each host then tries an ICMP ping and returns those that reply
#!/bin/sh
# *********************************************************************
# script: filetopingreply
# summary: given a file path (assuming it has a host per line), uses
# another script to get the IP for each host then tries
# an ICMP ping and returns those that reply
# NOTE: Backgrounds each PING to perform these faster!
# dependencies: filetoiplist (in same path as this script); grep
# by: e.a.soto, eric@issfl.com
@ericwastaken
ericwastaken / gethostlist.sh
Created March 21, 2018 00:53
Given a passed URL, extracts all hosts and returns a list, sorted and unique.
#!/bin/sh
# *********************************************************************
# script: gethostlist
# summary: given a passed URL, extracts all hosts and returns a list,
# sorted and unique.
# dependencies: wget; grep
# by: e.a.soto, eric@issfl.com
#
# history