Skip to content

Instantly share code, notes, and snippets.

@cpilsworth
cpilsworth / lambda-basic-auth.js
Last active May 22, 2019 23:42 — forked from lmakarov/lambda-basic-auth.js
Basic HTTP Authentication for CloudFront with Lambda@Edge without credentials in code
'use strict';
var crypto = require('crypto');
// Lambda@Edge does not allow for environment variables so compare credential hash rather than store credentials in code
// sha256 hex digest of the Basic base64(username:password) header
// e.g. show below, generated on mac:
// echo -n "Basic `(echo -n 'admin:password' | openssl base64)`" | shasum -a 256
const authStringSha256 = '9f19de0237c9bd59f803de1785f7aea4e3499b6929df3428e1b415fed81f797a';
@cpilsworth
cpilsworth / lambda-basic-auth.js
Created March 3, 2018 19:58 — forked from lmakarov/lambda-basic-auth.js
Basic HTTP Authentication for CloudFront with Lambda@Edge
'use strict';
exports.handler = (event, context, callback) => {
// Get request and request headers
const request = event.Records[0].cf.request;
const headers = request.headers;
// Configure authentication
const authUser = 'user';
const authPass = 'pass';
@cpilsworth
cpilsworth / service-checklist.md
Created March 24, 2016 14:37 — forked from acolyer/service-checklist.md
Internet Scale Services Checklist

Internet Scale Services Checklist

A checklist for designing and developing internet scale services, inspired by James Hamilton's 2007 paper "On Desgining and Deploying Internet-Scale Services."

Basic tenets

  • Does the design expect failures to happen regularly and handle them gracefully?
  • Have we kept things as simple as possible?
Note 1: The following CQ curl commands assumes a admin:admin username and password.
Note 2: For Windows/Powershell users: use two "" when doing a -F cURL command.
Example: -F"":operation=delete""
Note 3: Quotes around name of package (or name of zip file, or jar) should be included.
Uninstall a bundle (use http://localhost:4505/system/console/bundles to access the Apache Felix web console)
curl -u admin:admin -daction=uninstall http://localhost:4505/system/console/bundles/"name of bundle"
Install a bundle
curl -u admin:admin -F action=install -F bundlestartlevel=20 -F
@cpilsworth
cpilsworth / textarea.maxlength.js
Last active December 14, 2015 21:19 — forked from nodesocket/gist:3102236
Listen for textarea changes to textarea and limit length according to maxlength attribute
$(document).on('keyup input paste', 'textarea[maxlength]', function() {
var limit = parseInt($(this).attr('maxlength'));
var text = $(this).val();
var chars = text.length;
if (chars > limit) {
var new_text = text.substr(0, limit);
$(this).val(new_text);
}
});