Skip to content

Instantly share code, notes, and snippets.

View bdelacretaz's full-sized avatar

Bertrand Delacretaz bdelacretaz

View GitHub Profile
@bdelacretaz
bdelacretaz / embedded-doap.html
Created September 8, 2023 09:27
Example embedding DOAP data in HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example DOAP embedded in HTML</title>
<script type="application/asf.doap+xml">
<rdf:RDF xml:lang="en"
xmlns="http://usefulinc.com/ns/doap#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:asfext="http://projects.apache.org/ns/asfext#"
<html>
<body>
<p>Load this page with <code>?ok=yes+it+works</code> to test it.</p>
<p>Search parameters: <b id="results"/></p>
<script>
const p = new URLSearchParams(window.location.search);
document.querySelector('#results').textContent = p.get('ok');
</script>
</body>
</html>
// List custom element names registered in the current browser page
console.log(
[...new Set([].map.call(
document.querySelectorAll('*'),
el => el.nodeName.toLowerCase()))
].filter(
customElements.get.bind(customElements)
)
.sort()
)
// @ts-check
const { test, expect } = require('@playwright/test');
test.beforeEach(async ({ page }) => {
await page.goto('https://demo.playwright.dev/todomvc');
});
const TODO_ITEMS = [
'buy some cheese',
'feed the cat',
@bdelacretaz
bdelacretaz / declarative-shadow-dom.js
Created January 19, 2023 10:23
Declarative Shadow DOM Polyfill
// From https://web.dev/declarative-shadow-dom/
// TODO do nothing in a browser that already supports declarative shadow DOM?
(function attachShadowRoots(root) {
root.querySelectorAll("template[shadowroot]").forEach(template => {
const mode = template.getAttribute("shadowroot");
const shadowRoot = template.parentNode.attachShadow({ mode });
shadowRoot.appendChild(template.content);
template.remove();
attachShadowRoots(shadowRoot);
});
<!DOCTYPE html>
<html lang="en">
<!-- Also stored at https://codepen.io/bdelacretaz/pen/OJEWQLO -->
<head>
<title>AEM Headless Adventures</title>
<style type="text/css">
body {
font-family: -apple-system, BlinkMacSystemFont, Helvetica, Arial, sans-serif;
}
<div itemscope itemid="gist:example-intro">
<!--
POSTing this element will cause it to be written to the
Gist that the "gist" meta element above points to.
-->
<p>
This introduction can be <em>edited</em> and is stored <strong>in a Gist</strong>.
</p>
<p>
We use Gists initially as the API is super simple, and once that works we can "graduate"
@bdelacretaz
bdelacretaz / repoinit.esp
Created September 28, 2021 15:59
Script to test Apache Sling Repoinit with many operations
<%
/*
Demo script for my adaptTo 2021 talk, on Apache Sling repoinit:
https://adapt.to/2021/en/schedule/repoinit-a-mini-language-for-content-repository-initialization.html
Generate and execute a number (see "limit" below) of repoinit statements.
To use this, save this script as repoinit.esp, create
a node with a unique resource type that points to it
and request that node with the appropriate extension:
///usr/bin/env jbang "$0" "$@" ; exit $?
import java.util.function.Supplier;
public class LazyLoading {
static int callCount = 0;
/** This is the core lazy loading functionality */
static class LazyLoader<T> {
private final Supplier<T> sup;
diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
index a8af34a..ad0db8c 100644
--- a/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
@@ -22,6 +22,8 @@ package org.apache.sling.commons.metrics.internal;
import java.lang.management.ManagementFactory;
import java.util.Collections;
import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicInteger;