Skip to content

Instantly share code, notes, and snippets.

@cpilsworth
cpilsworth / RedirectFixFilter.java
Created November 26, 2019 23:23
intercept redirects and rewrite
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.wrappers.SlingHttpServletResponseWrapper;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
‪env | grep "$TPL_PREFIX" | while read -r VAR;‬
‪do‬
‪ REPLACE="s/`echo "$VAR" | sed -e s,=,/,`/" ‬
‪ sed -e "$REPLACE" "$SOURCE_FILE" > "$TARGET_FILENAME"‬
‪done‬
@cpilsworth
cpilsworth / pom.xml
Created September 12, 2018 22:47
Maven POM for content sync - empty package creation | source upload | source build | source download | target install
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- ====================================================================== -->
<!-- P R O J E C T D E S C R I P T I O N -->
<!-- ====================================================================== -->
<groupId>uk.co.diffa.contentsync</groupId>
<artifactId>sync</artifactId>
@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 / 001-index.md
Last active May 23, 2018 20:16
A+ SSL using Java 9

Configuring java for an A+ ssllabs.com server rating

It never used to be possible to get an A+ rating, as Java missed a couple of necessary features

Setting up the server

Getting Java 9

wget http://download.java.net/java/GA/jdk9/9/binaries/jdk-9+181_linux-x64_bin.tar.gz

Getting the LetsEncrypt/EFF certbot

@cpilsworth
cpilsworth / pom.xml
Created July 29, 2016 10:44
Maven module pom for wrapping jjwt 0.6.0 and making android.util import optional
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myapp</groupId>
<artifactId>jjwt</artifactId>
<version>0.6.0</version>
<packaging>bundle</packaging>
<name>JSON Web Token support for the JVM</name>
<description>
This bundle simply wraps ${pkgGroupId}-${pkgVersion}.jar and makes android.util optional
</description>
@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?
@cpilsworth
cpilsworth / post.POST.html
Last active April 21, 2016 13:42
Using acs-aem-commons forms functionality with Sightly
<sly data-sly-use.form="test.js"></sly>
sly data-sly-test.errors="${form.validate}"></sly>
<sly data-sly-test="${errors}">${form.renderForm}</sly>
<sly data-sly-test="${!errors}">${form.redirectSuccess}</sly>

Install XCode command line tools

gcc will trigger the download dialog.

Download brew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install Brews

brew install git