Skip to content

Instantly share code, notes, and snippets.

View patrickbrandt's full-sized avatar

Patrick Brandt patrickbrandt

View GitHub Profile
@patrickbrandt
patrickbrandt / 02_demo_test_publish.sh
Last active December 11, 2020 22:28
Jenkins routines for AWS Lambda + API Gateway
# This is a "Managed Script" in Jenkins
COMMIT=`aws lambda get-alias --region $AWS_REGION --function-name $FUNCTION_NAME --name $PUBLISH_FROM_ALIAS | grep "Description" | cut -d'"' -f4`
VERSION=`aws lambda publish-version --region $AWS_REGION --function-name $FUNCTION_NAME --description $COMMIT | grep "Version" | cut -d'"' -f4`
aws lambda update-alias --region $AWS_REGION --function-name $FUNCTION_NAME --function-version $VERSION --name $PUBLISH_TO_ALIAS --description $COMMIT
@patrickbrandt
patrickbrandt / service-worker-example.html
Last active May 17, 2023 22:43
Simple Service Worker didactic POC - caching outbound requests
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
if (!navigator.serviceWorker.controller) {
navigator.serviceWorker.register('/sw.js', { scope: '.'}).then(function(registration) {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
window.location.reload();
}).catch(function(err) {
console.log('ServiceWorker registration failed: ', err);
@patrickbrandt
patrickbrandt / essential_links.md
Last active May 17, 2023 22:42
Essential Links
@patrickbrandt
patrickbrandt / python_aws_lambda_config.md
Last active November 6, 2022 10:14
A simple approach to multi-environment configurations for AWS Lambda functions

AWS recently released Versioning and Aliases for Lambda Functions. I'm going to outline how I've taken advantage of this to provide environmentally-aware Lambda function configurations in Python.

AWS Lambda doesn't currently support environment variables, so 12-factor-style configuration isn't an option. I'll be using seprate config files for each environment.

Pregame

We're making two assumptions for this article:

  • I've already created an AWS Lambda function with the following aliases:
    • Dev
    • Test
    • Staging
    • Production
@patrickbrandt
patrickbrandt / sumEvenFib.js
Last active November 6, 2015 19:20
Add even Fibonacci numbers up to the Nth number provided. Because.
var sumEvenFib = function(number) {
var _internalSumEvenFib = function(current, fib, num, sum) {
return (num <= 1) ? sum : _internalSumEvenFib(fib, current + fib, --num, (!(fib % 2) ? sum + fib : sum));
};
return _internalSumEvenFib(1, 1, number, 0);
};
@patrickbrandt
patrickbrandt / socket.io_Express_Angular.md
Last active August 30, 2023 21:28
Simple socket.io integration with Express + Angular

Socket.io integration between an Express and Angular app is a breeze. I'll outline the Express implementation first, then outline Angular integration.

Express + socket.io

Reference socket.io in layout.jade

npm install socket.io --save and then reference socket.io in your layout.jade file:

doctype html
html(ng-app="example")
  head
    title= title
@patrickbrandt
patrickbrandt / setup-jenkins-frontend-Elastic_Beanstalk.sh
Last active September 7, 2016 14:12
Setup a Jenkins server for front-end builds and AWS Elastic Beanstalk deployments
#!/bin/bash
# This script must be run with root-level permissions
# Install Compass
yum install -y gcc g++ make automake autoconf ruby-devel
gem update --system
gem install compass
# Install Node