Skip to content

Instantly share code, notes, and snippets.

@dfkaye
dfkaye / update-shadowDOM-with-worker.js
Created November 29, 2023 22:57
attaching shadow DOM to a DIV with a SLOT, and driving changes from a Worker
// continued from https://gist.github.com/dfkaye/feab681496ac9fc8bc63e6b3006f796e
// 25 August 2023
// attaching shadow DOM to a built-in element:
// what are the implications?
/*************************** worker-driven version ****************************/
// This example uses a div with a slot and a worker that posts messages with
// data that is then written to the slot element.
@dfkaye
dfkaye / attach-shadowDOM-to-template-elements.js
Created November 29, 2023 22:54
attaching shadow DOM to a template element: No, you can't do that, but you can
// 25 August 2023
// attaching shadow DOM to a built-in element:
// what are the implications?
// continued from https://gist.github.com/dfkaye/e6b72291d3e31517d71229d703aad754
/************************** Using a template element **************************/
// YOU CAN'T DO THAT.
@dfkaye
dfkaye / attach-shadowDOM-to-builtin-elements.js
Last active December 5, 2023 02:43
attaching shadow DOM to a built-in element: what are the implications?
// 25 August 2023
// attaching shadow DOM to a built-in element:
// what are the implications?
// 4 December 2023
// see CSSStyleSheet() injection at bottom of this gist...
// The shadow DOM capability normally associated with custom elements is, to my
// surprise, available to normal elements, according to MDN (a.k.a "Mozilla
// Developer Network") - here's a quote:
@dfkaye
dfkaye / transferable-shuttle-example.js
Last active November 7, 2023 00:13
passing javascript transferable objects back and forth between main and a worker context
// 27 October 2023
// passing javascript transferable objects back and forth
// between main and a worker context
var source = `
["localStorage", "XMLHttpRequest"].forEach(key => {
key in self
? console.log(key, self[key])
: console.warn(key + " not defined");
});
@dfkaye
dfkaye / native-form-validation.js
Last active December 20, 2023 00:14
demo example of native form validation in 2023 with dynamic cross-field checks and dynamic custom validity messages
// 19 October 2023
// native form validation with dynamic cross-field checks and dynamic custom
// validity messages.
// Very "simple" demo can be run from the browser's console. Styles may be
// blocked if you're running a blank or incognito window or a site with a very
// strict Content Security Policy.
// First we'll set up a form to test against.
@dfkaye
dfkaye / hemingway-true-clean-honest.md
Created September 26, 2023 19:06
hemingway in "midnight in paris"

26 September 2023

Hemingway quote from "Midnight in Paris"

No subject is terrible if the story is true, and the prose is clean and honest, and if it affirms courage and grace under pressure."

Apply that to your code. "No program is terrible if the use case is true and the code is clean and honest..."

@dfkaye
dfkaye / get-opening-and-closing-tags.js
Created September 26, 2023 18:39
tip: get opening and closing tags for a DOM element
// 26 September 2023
// tip: get opening and closing tags for a DOM element
var element = document.body;
var [ open, close ] = element.outerHTML.split(element.innerHTML);
console.log([open, close]);
// Array [ '<body class="logged-in env-production page-responsive" style="word-wrap: break-word;">', "</body>"
@dfkaye
dfkaye / dream.md
Created September 22, 2023 16:44
philosophy experiment dream

22 September 2023

Dreamed I was back in school in a philosophy class that met 3 days a week. The teacher divided the class into A and B groups. A met Monday, B on Wednesday, both on Friday. He ran and tested the A and B groups differently, to gauge how that affected joint Friday sessions/tests… 9:35 AM · Sep 22, 2023

Never had a dream so structured and rational, nor one about A/B testing before.

Unlike other school dreams this did not induce anxiety or panic.

Could have used a dream like this 40 years ago.

@dfkaye
dfkaye / strict-mode-console.js
Last active August 24, 2023 20:55
Hazards of working everything out in the console (or a REPL) without strict mode.
// 23 August 2023
// Hazards of working everything out in the console (or a REPL).
// I really thought I'd found something interesting, a possible quirk in the
// `form.elements` collection, but it turned out to be anti-pattern that strict
// mode prevents.
// We relive some of the embarrassment for you now.
// First, we'll set up the DOM from the console.
@dfkaye
dfkaye / scoped-reset.js
Created August 22, 2023 21:51
scoped reset button actions on fields in the same fieldset.
// 16 August 2023
// Scoped reset button actions on fields in the same fieldset.
// This is one way to manage resetting only radio groups or checkboxes in a form
// without resetting every other element.
// We could go further and group such related fields in separate forms to avoid
// any JavaScript with click handler logic.
// This came up because one of the loudest front-end developers on Twitter was