Skip to content

Instantly share code, notes, and snippets.

View DavidWells's full-sized avatar
😃

David Wells DavidWells

😃
View GitHub Profile
@DavidWells
DavidWells / serverless.yml
Created December 24, 2017 20:56 — forked from jscattergood/serverless.yml
Creating a custom serverless resource for subscribing to SNS topics in another region
# Welcome to Serverless!
#
# Happy Coding!
service: cross-region-sns-subscriber
# Keep environment specific configurations in separate files
custom: ${file(config/${env:STAGE}.json)}
provider:
@DavidWells
DavidWells / async-foreach.js
Created October 22, 2018 04:10 — forked from Atinux/async-foreach.js
JavaScript: async/await with forEach()
const waitFor = (ms) => new Promise(r => setTimeout(r, ms))
const asyncForEach = (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)
}
}
const start = async () => {
await asyncForEach([1, 2, 3], async (num) => {
await waitFor(50)
@DavidWells
DavidWells / get-window-user-props.js
Created December 3, 2018 00:11 — forked from alexrqs/get-window-user-props.js
Get window properties defined by the user
(function () {
var results, currentWindow,
// create an iframe and append to body to load a clean window object
iframe = document.createElement('iframe');
iframe.style.display = 'none';
document.body.appendChild(iframe);
// get the current list of properties on window
currentWindow = Object.getOwnPropertyNames(window);
@DavidWells
DavidWells / refresh-token.js
Created August 23, 2020 16:41 — forked from pfulop/refresh-token.js
how to refresh amplify token
const refreshToken = async () => {
const refreshPromise = new Promise(async (resolve) => {
const user = await Auth.currentAuthenticatedUser();
const session = await Auth.currentSession();
user.refreshSession(session.refreshToken, async (res, newSession) => {
if (newSession) {
await Auth.currentUserCredentials();
}
resolve('ok');