Skip to content

Instantly share code, notes, and snippets.

View DV8FromTheWorld's full-sized avatar
💭
Through code, all things are possible.

Austin Keener DV8FromTheWorld

💭
Through code, all things are possible.
View GitHub Profile
@DV8FromTheWorld
DV8FromTheWorld / aws-google-login.sh
Last active May 21, 2020 19:54
Small bash script wrapper around aws-google-auth to provide easy (but overridable) defaults.
unset AWS_PROFILE
google_sso_idp=''
google_sso_sp=''
profile='default'
region='us-east-1'
# Put code into a function so that we can quick escape without using 'exit 1' considering
# if this code gets sourced into bash (which it should for proper usage) using 'exit 1' will kill the process.
function fn_aws_google_login() {
@DV8FromTheWorld
DV8FromTheWorld / instrument.js
Last active December 30, 2019 21:01
Instrument node callback functions
const generateId = () => Math.random().toString(36).substring(2, 8) + Math.random().toString(36).substring(2, 8)
function instrumentFunction(name, originalFn, cbPosition = 0) {
return function enhancedFunction(...args) {
const ident = generateId()
const callerLine = `(${new Error().stack.split('\n')[2].trim()})`
const enhancedCB = function (...cbArgs) {
console.log(`${ident}: ${name} starting ${callerLine}`)
try {
args[cbPosition].bind(this)(...cbArgs)
@DV8FromTheWorld
DV8FromTheWorld / is-ip-in-ip-range.js
Created October 12, 2019 22:48
Simple function to determine whether a given ip is within a range of ip addresses.
const ipRegex = /([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/
const getIpDigits = (ip) => {
const digits = ipRegex.exec(ip)
if (!digits) {
return [-1, -1, -1, -1]
}
return ipRegex.exec(ip).splice(1).map(stringDigit => +stringDigit)
}
@DV8FromTheWorld
DV8FromTheWorld / Open-Cloudwatch-Insights.js
Last active September 16, 2019 18:52
Open Cloudwatch Insights
;(() => {
const url = "https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logs-insights:queryDetail=~(end~0~start~-900~timeType~'RELATIVE~unit~'seconds~editorString~'fields*20*20*40timestamp*2c*20*40message*0a*20*7c*20limit*2020~isLiveTail~false~queryId~'CW_LOG_NAME~source~'CW_LOG_NAME)";
const regionFromUrl = /.*\?region=(.+?)#.*/;
const logGroupFromCloudwatch = /.*group=([^;]*?)(;|$)/;
const logGroupFromLambda = /.*functions\/([^?]*)/;
const logGroupToken = /CW_LOG_NAME/g;
let logGroup = null;
const regionResult = regionFromUrl.exec(window.location.href);
JSON.stringify({
Records: [{
Sns: {
Message: JSON.stringify({
Records: [{
"s3": {
bucket: "inmarb2b-dev-ao-environment",
object: {
key: "EnvironmentConfigs/preprod/cloudformation.json"
}
@DV8FromTheWorld
DV8FromTheWorld / Inmar-Environment-Switch.js
Last active March 3, 2021 21:42
Inmar Environment Switch
(() => {
const envMap = [
['preprod.aws-nonprod', 'prod.aws-prod'],
['prod.aws-prod', 'preprod.aws-nonprod'],
['dev.eretail-dev', ['staging.eretail-dev', 'prod.eretail']],
['staging.eretail-dev', ['dev.eretail-dev', 'prod.eretail']],
['prod.eretail', ['dev.eretail-dev', 'staging.eretail-dev']],
['dev.inmartgrocery.com', ['staging.inmartgrocery.com', 'inmartgrocery.com']],
['staging.inmartgrocery.com', ['dev.inmartgrocery.com', 'inmartgrocery.com']],
['inmartgrocery.com', ['dev.inmartgrocery.com', 'staging.inmartgrocery.com']]
@DV8FromTheWorld
DV8FromTheWorld / Enhanced-Selects.js
Created November 15, 2018 13:34
Enhanced Selects
// selects do not fire change events if their value or selectedIndex is updated directly (only if their _options_ change),
// unfortunately, js frameworks typically update selects via direct calls to the value or selectdIndex. We need to be able to fire an event
// for either of these when they are set so we can communicate the changes to the choices.js library.
function enhanceSelectPrototype() {
if (HTMLSelectElement.prototype.__inmHasBeenEnhanced) {
return
}
const valueDescriptor = Object.getOwnPropertyDescriptor(HTMLSelectElement.prototype, 'value')
const selectedIndexDescriptor = Object.getOwnPropertyDescriptor(HTMLSelectElement.prototype, 'selectedIndex')
@DV8FromTheWorld
DV8FromTheWorld / buildCFRecord.js
Last active September 18, 2018 15:11
Build Cloudformation Record
function build(buildArn, projectName, status = "SUCCEEDED") {
return JSON.stringify({
Records: [{
Sns: {
Message: JSON.stringify({
detail: {
"build-id": buildArn.trim(),
"project-name": projectName,
"build-status": status
}
@DV8FromTheWorld
DV8FromTheWorld / getFirstCommit
Created July 10, 2018 21:52
First Github Commit w/ Auth Support
javascript:
const token = '<TOKEN>';
const opts = {};
if (token !== '<TOKEN>') {
opts.headers = {
'Authorization': 'token ' + token
}
};
(b => fetch('https://api.github.com/repos/' + b[1] + '/commits?sha=' + (b[2] || ''), opts)
.then(c => Promise.all([c.headers.get('link'), c.json()]))
Math.seed = function(s) {
return function() {
s = Math.sin(s) * 10000
return s - Math.floor(s)
}
}
/**
* Get a random floating point number between `min` and `max`.
*