Skip to content

Instantly share code, notes, and snippets.

View bdelacretaz's full-sized avatar

Bertrand Delacretaz bdelacretaz

View GitHub Profile
@bdelacretaz
bdelacretaz / orama-similarity-search.html
Last active November 8, 2024 13:57
Client-side similarity search using the orama vector database
<!doctype html>
<html>
<head>
<style>
.error {
font-weight: bold;
color: red;
}
@bdelacretaz
bdelacretaz / webllm-articles-similarity.html
Created October 29, 2024 19:28
Playing with WebLLM: article titles similarity
<!doctype html>
<html>
<head>
<script>
webLLMGlobal = {};
</script>
<style>
.error {
font-weight: bold;
@bdelacretaz
bdelacretaz / webllm-test.html
Created October 22, 2024 15:45
WebLLM test page
<!doctype html>
<html>
<head>
<script>
webLLMGlobal = {};
</script>
<style>
.error {
font-weight: bold;
@bdelacretaz
bdelacretaz / sync-xhr.html
Last active June 11, 2024 09:52
HTML page that tests Synchronous XHR
<!DOCTYPE html>
<html lang="en">
<head>
<title>Testing Sync XHR</title>
</head>
<body>
<h1>Testing <a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest_API/Synchronous_and_Asynchronous_Requests">Sync XHR</a></h1>
<div id="msg">This is the msg</div>
@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;
}