Skip to content

Instantly share code, notes, and snippets.

@cpilsworth
cpilsworth / ImageSignedUrlRedirectServlet.java
Last active June 22, 2023 16:34
Oak Direct Binary Download
package com.chrisp.rde.core.servlets;
import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.api.binary.BinaryDownload;
import org.apache.jackrabbit.api.binary.BinaryDownloadOptions;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.servlets.OptingServlet;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
@cpilsworth
cpilsworth / ImageSignedUrlRedirectServlet.java
Last active May 11, 2023 16:19
Cloud Storage Direct Asset Download URL generator
package com.chrisp.rde.core.servlets;
import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.api.binary.BinaryDownload;
import org.apache.jackrabbit.api.binary.BinaryDownloadOptions;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.servlets.OptingServlet;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
@cpilsworth
cpilsworth / _teaser.scss
Last active May 11, 2023 15:47
DLG teaser
.cmp-teaser {
}
.cmp-teaser__image {
}
.cmp-teaser__content {
}
.cmp-teaser__pretitle {
}
.cmp-teaser__title {
}
@cpilsworth
cpilsworth / ims-jwt.mjs
Created September 18, 2022 08:05
cli utility to convert an aem service token into a jwt
import { stdin, stdout, exit } from 'node:process';
import { parseArgs } from 'node:util';
import { default as auth } from '@adobe/jwt-auth';
import { default as fs } from 'fs';
const options = {
'file': { type: 'string' },
};
const { values } = parseArgs({ options });
@cpilsworth
cpilsworth / assetpicker.html
Created August 10, 2022 15:19
AEM Asset Picker
<!DOCTYPE html>
<html>
<head>
<script>
const host = 'http://localhost:4503';
const rootPath = '/content/dam/mycompany';
window.addEventListener("message", (event) => {
if (event.origin !== host) {
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import collections
import sys
Point = collections.namedtuple("Point",['x', 'y'])
Command = collections.namedtuple("Command", ['direction', 'magnitude'])
start_pos = Point(0,0)
map = [[]]
@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 / 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';