Skip to content

Instantly share code, notes, and snippets.

Paul Swail paulswail

Block or report user

Report or block paulswail

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@paulswail
paulswail / cicd-pipelines.ts
Last active Apr 24, 2019
Create CICD pipelines for serverless services using AWS CDK
View cicd-pipelines.ts
// /stacks/cicd-pipelines.ts
// CDK app which creates a stack using a set of service definitions
import 'source-map-support/register';
import { App } from '@aws-cdk/cdk';
import { ServiceCicdPipelines } from '../lib/cicd/pipelines';
import { deploymentTargetAccounts } from './config';
import services from './services';
const app = new App({
@paulswail
paulswail / invalidate-cloudfront-distribution-by-origin-domain.sh
Last active Jan 18, 2019
Invalidate CloudFront Distribution cache using only its origin domain name (AWS CLI)
View invalidate-cloudfront-distribution-by-origin-domain.sh
#!/bin/bash
CLOUDFRONT_DOMAIN="mydomain.com" # change this
# Get Distribution ID (requires node.js to be installed)
DISTRIBUTION_ID=$(aws cloudfront list-distributions --query "DistributionList.Items[].{Id: Id, DomainName: DomainName, OriginDomainName: Origins.Items[0].DomainName }[?contains(OriginDomainName, '$CLOUDFRONT_DOMAIN')] | [0]" | node -pe "JSON.parse(require('fs').readFileSync('/dev/stdin').toString()).Id")
# Invalidate cache
echo "Invalidating CloudFront distribution $DISTRIBUTION_ID ..."
aws cloudfront create-invalidation --distribution-id=$DISTRIBUTION_ID --paths '/*'
@paulswail
paulswail / compound-growth.js
Last active Jun 7, 2018
Calculate investment's compound growth
View compound-growth.js
// Calculates the compound growth of an investment over number of periods.
// Assumes fixed regular contributions and average growth rate.
function compoundGrowth(startingBalance = 0, periodContribution = 100, periodGrowthRate=0, nPeriods = 1, currencyLabel = '£') {
const totalContribution = startingBalance + periodContribution * nPeriods;
const finalBalance = [...Array(nPeriods)].reduce((runningBalance) => {
return runningBalance + (runningBalance * periodGrowthRate) + periodContribution;
}, startingBalance);
const absoluteGrowth = finalBalance - totalContribution;
const relativeGrowth = absoluteGrowth / totalContribution;
console.log(`${currencyLabel}${finalBalance.toFixed(2)} will be returned after ${nPeriods} periods with ${currencyLabel}${periodContribution.toFixed(2)} contributed each period and an average period growth rate of ${periodGrowthRate * 100}% and initial lump sum of ${currencyLabel}${startingBalance}.
@paulswail
paulswail / gist:842af71cbc5c42b075a8
Created Mar 9, 2016
Promise rethrow inside catch
View gist:842af71cbc5c42b075a8
function rethrowTest() {
Promise.resolve(true).then(function() {
return new Promise(function(resolve, reject) {
reject(new Error('BOOM!'));
}).catch(function(err) {
console.error('First catch: ' + err);
throw err;
});
}).then(function() {
console.log('I should not be printed');
You can’t perform that action at this time.