Skip to content

Instantly share code, notes, and snippets.

@fourgates
fourgates / angular-standalone-barrel-example.ts
Last active July 31, 2023 20:37
This gist demonstrates how how to use a barrel file to group together angular components in a single import.
// This is a way to get best of both worlds of grouping component together
// into "modules" (barrels) and using standalone components!
//
// using a "barrel" export you can group together angular components so you only need to
// import one object
//
// a good use case for this is components that are dependent on each other or commonly used together
// in this example we have a table and table-sort directive bc you almost always want to be able to
// sort a table!
//
@fourgates
fourgates / s3-cloudfront-dist.construct.ts
Created May 26, 2023 16:28
Custom AWS CDK Construct to Create S3 + Cloudfront Dist
import { Stack,
aws_s3 as s3,
aws_cloudfront as cloudfront,
aws_cloudfront_origins as cfOrigins,
aws_certificatemanager as certificatemanager,
aws_s3_deployment as s3deploy,
RemovalPolicy,
Duration
} from "aws-cdk-lib";
import { Construct } from "constructs";
@fourgates
fourgates / Jenkinsfile
Last active July 18, 2022 21:29
ECS Jenikinsfile
pipeline {
agent any
environment {
// these change whenever we redeploy IaC
taskDef = "XXX" // name of the ECS task in which we will be adding a new revision
taskFamily = "XXX" // task family for service
serviceName = "XXX" // which service to update in the cluster
dockerBuildService = "deploy-dev"// docker service that builds deployable image
dockerImage = "XXX" // name of deployable image
@fourgates
fourgates / cdk-secret.ts
Created March 23, 2022 18:49
creating a secret using the AWS CDK
// first, lets generate a secret to be used as credentials for our database
const databaseCredentialsSecret = new secretsManager.Secret(this, `${env}-DBCredentialsSecret`, {
secretName: `${env}-rds-credentials`,
generateSecretString: {
secretStringTemplate: JSON.stringify({
username: 'postgres',
}),
excludePunctuation: true,
includeSpace: false,
generateStringKey: 'password'
@fourgates
fourgates / base-stack-vpc-rds-cloud-9.ts
Created July 13, 2021 03:07
AWS CDK Stack - VPC ,4AZ, 1NG, Secret Manager, AWS Aurora replication, Clouud9
import * as cdk from '@aws-cdk/core';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as secretsManager from '@aws-cdk/aws-secretsmanager';
import * as ssm from '@aws-cdk/aws-ssm';
import { ISecurityGroup, SecurityGroup } from '@aws-cdk/aws-ec2';
import * as rds from '@aws-cdk/aws-rds';
import * as cloud9 from '@aws-cdk/aws-cloud9';
export interface CdkBaseStackProps extends cdk.StackProps {
stage: string,
@fourgates
fourgates / cdk-stack.ts
Last active November 25, 2020 23:36
AWS CDK - S3 / Cloudfront + Domain + SSL & ECS (ecr, ecs-pattern [elb, taskdef, service, cluster])
import * as cdk from '@aws-cdk/core';
import * as dynamodb from '@aws-cdk/aws-dynamodb';
import * as s3 from '@aws-cdk/aws-s3';
import * as s3Deploy from '@aws-cdk/aws-s3-deployment';
import * as cloudfront from '@aws-cdk/aws-cloudfront';
import * as route53 from '@aws-cdk/aws-route53';
import * as acm from '@aws-cdk/aws-certificatemanager';
import * as targets from '@aws-cdk/aws-route53-targets/lib';
import { OriginAccessIdentity } from '@aws-cdk/aws-cloudfront';
import * as ecr from '@aws-cdk/aws-ecr';
@fourgates
fourgates / README.md
Last active September 11, 2020 20:23

SOLID is an acronym for several of the most useful OOP design principles:

In this post, I will cover the first principle, the Single Responsibility Principle (SRP). I hope these posts will give you an understanding of how these principles can improve the way you write code and maybe impress the next person that reviews your code!

@fourgates
fourgates / index.js
Created August 28, 2020 22:37
AWS Lambda Query RDS then Publish SNS Message
const fs = require('fs'); // file reader
const pg = require('pg'); // node-postgres
const AWS = require("aws-sdk");
AWS.config.update({ region: 'us-east-1' });
const functionName = process.env.AWS_LAMBDA_FUNCTION_NAME;
const encrypted = process.env['PASSWORD'];
let decrypted;
/**
@fourgates
fourgates / tooltip.js
Last active August 26, 2020 22:10
AngularJS Tooltip
/**
Tooltip Directive
This directive will add an information icon to the page. By default the tooltip is triggered by hover events.
You can change this to an onClick by simply adding an on-click attribute. The tooltip defaults to the left of the info icon
but will change based on its position on the screen.
There are two ways to use this directive:
1. Transclude the tooltip content, this is the easiest and most strait forward implementation
2. You can provide a url for a template and data to be rendered in your template.
@fourgates
fourgates / auth.ts
Last active September 27, 2024 02:15
express.js middleware to validate a AWS Cognito / Amplify Token
import { Router } from "express";
import jwt from "jsonwebtoken";
import jwkToPem from "jwk-to-pem";
import * as Axios from 'axios';
interface PublicKeys {
keys: PublicKey[];
}
interface PublicKey {
alg: string;