Skip to content

Instantly share code, notes, and snippets.

View bdelacretaz's full-sized avatar

Bertrand Delacretaz bdelacretaz

View GitHub Profile
<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;
#!/bin/bash
# Example using docker start, cp and rm to process a local file and
# get the result back on the local filesystem.
# Thanks to Roman V Shaposhnik for pointing to those Docker commands
cat << EOF > Dockerfile
FROM alpine:3.11.6
RUN apk update && apk upgrade
@bdelacretaz
bdelacretaz / VerifyLegalFilesMojo.java
Created May 5, 2020 17:10
VerifyLegalFilesMojo.java from the Apache Geronimo tools-maven-plugin-1.4-sources.jar
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
#!/bin/bash
# List all versions of Sling modules from a Maven repository
# ..just a ugly hack, we should use more solid parsing, or the Maven repository API
#
BASE_URL="https://repo1.maven.org/maven2/org/apache/sling/"
EGREP_FILTER=
curl -s $BASE_URL | grep 'a href' | egrep -v '\.\./|maven-metadata' | cut -d'"' -f2 | while read mod
do
curl -s ${BASE_URL}${mod} | grep 'a href' | egrep -v '\.\./|maven-metadata' | while read line
do
// Example capturing a 1200 x 6000 pixels screenshot
// from a website using https://github.com/microsoft/playwright
const pw = require('playwright');
(async () => {
const browser = await pw.firefox.launch(); // or 'chromium', 'firefox'
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://lecourrier.ch/');
@bdelacretaz
bdelacretaz / play.scpt
Last active July 9, 2019 12:03
AppleScript: play video full screen, wait and exit
--- run this with osascript
set unixFile to "/somepath/movie2.mov"
set macFile to POSIX file unixFile
set fileRef to (macFile as alias)
tell application "QuickTime Player"
activate
set movie to open fileRef
set the looping of movie to false
set the presenting of movie to true
@bdelacretaz
bdelacretaz / runsync.sh
Last active July 9, 2019 11:47
Restart multiple shell commands synchronously (example)
#!/bin/bash
# Run two video players more or less in sync
# assuming they start playing immediately and
# exit when done playing
while true
do
# Start all players in the background