Skip to content

Instantly share code, notes, and snippets.

View phil-kahrl's full-sized avatar
💭
Open to opportunities as polyglot, front-end or back-end engineer.

Phillip Kahrl phil-kahrl

💭
Open to opportunities as polyglot, front-end or back-end engineer.
View GitHub Profile
@phil-kahrl
phil-kahrl / recursive-fetch-with-retry-and-delay.js
Created August 18, 2018 15:43
Recursive fetch with retry and delay
const fetch = require('node-fetch');
const MAX_RETRIES = 5
const fetchWithRetry = (origResolve, origReject, attemptCount) => {
attemptCount = attemptCount ? attemptCount : 0
const url = process.argv[2]
if(!url){
console.log('no url passed in')
return
}
@phil-kahrl
phil-kahrl / recursive-fetch-with-retry.js
Last active February 11, 2022 08:36
Fetch with retry
const fetch = require('node-fetch');
const MAX_RETRIES = 5
const fetchWithRetry = (origResolve, origReject, attemptCount) => {
attemptCount = attemptCount ? attemptCount : 0
const url = process.argv[2]
if(!url){
console.log('no url passed in')
return
}
@phil-kahrl
phil-kahrl / list-output.js
Last active August 17, 2018 23:13
List output
`
Full listing of the s3 bucket:
list object called, NextContinuationToken = undefined
list object called, NextContinuationToken = 1/zWHq7hcIXgEXP1fSQwT6tEKnFNpuSb9rItEbpAw6l22CP0xXd5GDxqQStbll0GEYlh800/xNMQ=
list object called, NextContinuationToken = 1Ib26WeZTX20jv8zPs1SDM6W8RRebspox7mEZYqmMcHo8ioUTvFrRHB4o/SIchY2x+n5y9QKuLYA=
list object called, NextContinuationToken = 1t1T3Va5FoliWTVMtb/PEPtgPRLCwF0+jDYzuuW867aAyc0eUlfBOoyFEbvw/ma+ylA1BvH+0uLo=
list object called, NextContinuationToken = 112Rj6oLqL+fZ/U8oaP63dfX9cFS//LW6+D2/c28vYE8QRATfBn3SW+LBhWdUKPB+TFy27Wmd1vE=
done, resolving final result
resolving for NextContinuationToken 112Rj6oLqL+fZ/U8oaP63dfX9cFS//LW6+D2/c28vYE8QRATfBn3SW+LBhWdUKPB+TFy27Wmd1vE=
resolving for NextContinuationToken 1t1T3Va5FoliWTVMtb/PEPtgPRLCwF0+jDYzuuW867aAyc0eUlfBOoyFEbvw/ma+ylA1BvH+0uLo=
@phil-kahrl
phil-kahrl / promise-chain.js
Created August 16, 2018 20:02
Example Promise Chain
/*
Example of a Promise chain.
As each Promise is resolved, the resolved value is passed
to the next Promise in the chain.
*/
a().then( (resultFromA) => {
b(resultFromA).then( (resultFromB) => {
c(resultFromB).then( (resultFromC) => {
d( (resultFromC).then(
@phil-kahrl
phil-kahrl / callback-and-promise.js
Created August 16, 2018 19:57
Callback and promise
const params = {key: 'value'}
const successCallback = () => {console.log('success'})
const failureCallback = () => {console.log('failure'})
// callback pattern
doSomething(params, successCallback, failureCallback)
//Promise pattern
doSomething(params).then(successCallback).catch(failureCallback)
@phil-kahrl
phil-kahrl / recursive-retry.js
Created August 16, 2018 19:47
Function to recursively retry results for an AWS Route53 batch change request
const AWS = require('aws-sdk');
const route53 = new AWS.Route53({
apiVersion: '2013-04-01'
})
const MAX_RETRIES = 4
const RETRY_INTERVAL = 1000
const getChange = (prevAttemptCount, origResolve, origReject) => {
@phil-kahrl
phil-kahrl / recursive-s3-list.js
Last active February 18, 2022 01:46
Recursive function for listing contents of an S3 bucket
const AWS = require('aws-sdk');
const s3 = new AWS.S3({ apiVersion: '2006-03-01', region: 'us-east-1' });
/**
Recursive method to list all the objects in an S3 bucket which may be paginated.
**/
const listObjects = (
resultList, // This is the list of combined results from all calls.
NextContinuationToken // Tells S3 to get the next page of results.