Skip to content

Instantly share code, notes, and snippets.

Avatar
😃

David Wells DavidWells

😃
View GitHub Profile
@DavidWells
DavidWells / refresh-token.js
Created Aug 23, 2020 — forked from pfulop/refresh-token.js
how to refresh amplify token
View refresh-token.js
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');
@DavidWells
DavidWells / get-window-user-props.js
Created Dec 3, 2018 — forked from alexrqs/get-window-user-props.js
Get window properties defined by the user
View get-window-user-props.js
(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 / async-foreach.js
Created Oct 22, 2018 — forked from Atinux/async-foreach.js
JavaScript: async/await with forEach()
View async-foreach.js
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 / serverless.yml
Created Dec 24, 2017 — forked from jscattergood/serverless.yml
Creating a custom serverless resource for subscribing to SNS topics in another region
View serverless.yml
# 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 / env.js
Created Oct 29, 2017 — forked from cardoni/env.js
serverless custom domain setup
View env.js
// eslint-disable-next-line import/no-extraneous-dependencies
const { argv } = require('yargs');
let { stage = 'dev' } = argv;
module.exports.getDomainName = () => new Promise((resolve, reject) => {
stage = `${stage}`.toLowerCase();
if (!stage || stage == null || stage === 'dev') {
return resolve('dev-api.yourdomain.com');
@DavidWells
DavidWells / serverless.yml
Created Oct 29, 2017 — forked from Pwntus/serverless.yml
SLS existing S3 lambda trigger
View serverless.yml
functions:
TriggerFunc:
handler: handlers.main
resources:
Resources:
# Bucket 'TriggeredBucket'
TriggeredBucket:
Type: AWS::S3::Bucket
@DavidWells
DavidWells / reset.css
Last active Apr 15, 2021 — forked from karbassi/reset.css
CSS reset. Follow me on the twitters for more tips: https://twitter.com/davidwells
View reset.css
/* http://meyerweb.com/eric/tools/css/reset/
v2.0-modified | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
View EventUtil.js
// Cross Browser Event Utility
// Nicholas Zakas, Professional JavaScript for Web Developers p.441
(function(window, document) {
'use strict';
var
EventUtil = {
addHandler: function( element, type, handler ) {
if ( element.addEventListener ) {
element.addEventListener ( type, handler, false );
View onetime_nonce.php
<?php
function create_onetime_nonce( $action = -1 ) {
$time = time();
$nonce = wp_create_nonce( $time . $action );
set_transient( '_nonce_' . $time, 1, 60*60 ); // adjust the lifetime of the transient
return $nonce . '-' . $time;
}
function verify_onetime_nonce( $_nonce, $action = -1 ) {
@list( $nonce, $time ) = explode( '-', $_nonce );
@DavidWells
DavidWells / functions.php
Last active Aug 29, 2015 — forked from BFTrick/functions.php
Disable inbound now shortcode styles. Add this snippet to your themes functions.php file
View functions.php
//dequeue css from plugins
add_action('wp_print_styles', 'inbound_dequeue_css', 100);
function inbound_dequeue_css() {
wp_dequeue_style( 'inbound-shortcodes' );
}