Skip to content

Instantly share code, notes, and snippets.

View patrickbrandt's full-sized avatar

Patrick Brandt patrickbrandt

View GitHub Profile
@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
@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 / 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 / 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 / essential_links.md
Last active May 17, 2023 22:42
Essential Links
@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 / 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 / angularExample.js
Last active March 16, 2016 17:37
Network connectivity-check worker + angular 1 service wrapper
angular.module('example')
.controller('MainCtrl', ['connectivityService', function(connectivityService) {
connectivityService.onReconnect(function(){
console.log('back online');
});
connectivityService.onLostConnection(function(){
console.log('lost connection');
});
connectivityService.start();
}]);
@patrickbrandt
patrickbrandt / S3-readonly-bucket.json
Created November 22, 2016 18:21
IAM Policy for read-only S3 bucket access
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowUserToSeeBucketListInTheConsole",
"Action": [
"s3:ListAllMyBuckets",
"s3:GetBucketLocation"
],
"Effect": "Allow",
@patrickbrandt
patrickbrandt / handler.py
Last active March 13, 2018 04:38
Restricting Lambda function by IP address
import json
import os
def ping(event, context):
ip1 = event['headers']['X-Forwarded-For'].split(',')[0]
ip2 = event['requestContext']['identity']['sourceIp']
print('two different referring IP address parsing techniques ip1: %s and ip2: %s') % (ip1, ip2)
referringIP = event['requestContext']['identity']['sourceIp']
#TODO: use a comma-delimited string to store multiple IP address values in the environment variable