This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 8 June 2024 | |
// pass functions to workers and and call them in subsequent messages. | |
// similar to gists in 2022: | |
// pass functions as strings to workers and revive them with the Function() constructor | |
// https://gist.github.com/dfkaye/527f163b6913b163a579bbeb01858593 | |
// Not the same as "pass a stringified function in its own blob to a worker and | |
// import it using importScripts(blobUrl)." | |
// https://gist.github.com/dfkaye/ca9722cd247c6d907b3bbaf7273741e0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 31 May 2024 | |
// visibility change and visibility state to drive web worker processing, close | |
// and restart. | |
// previous version, pause and resume, at | |
// https://gist.github.com/dfkaye/3a9d6752301733fba81c740cf4fb68b2 | |
var source = ` | |
var count = 0; | |
var interval; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 30 May 2024 | |
// visibility change and visibility state to drive web worker processing, | |
// pause and resume. | |
// pretty sure I'd done this in 2022 or 2023. | |
// next version implements close and restart... | |
// https://gist.github.com/dfkaye/ee75271dd58e489d3a3ab9d209e51e02 | |
var source = ` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 13 May 2024 | |
// async/await dependency chains | |
// 14 May 2024 | |
// added explicit try-catch-finally to test error in "finalizer" function C. | |
// what | |
// laughing at ben lesh tweet complaining about async/await being difficult | |
// without explaining why: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 11 May 2024 | |
// chapter 8 Data oriented programming | |
// atomic value swap alg | |
function Atom (state) { | |
return { | |
state, | |
atomicCompareAndSet(current, previous, next) { | |
return current === previous ? (state = next, true) : false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 10 May 2024 | |
// Not mine! The regexp is from a tweet by Kyle Simpson | |
// https://twitter.com/getifyX/status/1788895673821118886 | |
var reEmailAddress = /^[^@]+@[^@.]+(?:\.[^@.]+)+$/; | |
["a@b.c", { toString: () => "a@b.c" }, ["a@b.c"]].map(email => reEmailAddress.test(email)); | |
// Array(3) [ true, true, true ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 6 May 2024 | |
// hex to rgb | |
// made you look | |
// originary defamatory statement | |
// https://twitter.com/the_moisrex/status/1787444601571221892 | |
// uncomplicated, performs well enough (suite runs under 1ms). | |
// supports 3 or 6 character strings with or without leading octothorpe. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 5 may 2024 | |
// use queueMicrotask and friends to get away from IIFEs and semicolons | |
'use strict'; | |
(function () { | |
console.group("collision") | |
try { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 26 April 2024 | |
// promise handler that returns promises as {value} or {error: {message}} | |
// structures - that is, a resolved promise with a value field, or a rejected | |
// promise with an error field that in turn contains a message field. | |
// goaded by Austin Gil's tweet 25 April 2024: | |
// https://twitter.com/heyAustinGil/status/1783622633000710321 | |
// his solution, slightly modified... | |
/* | |
function IP(p) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 12-13 April 2024 | |
// array queue | |
// first implementation uses a single array and deletes slots on "pull", while | |
// using "push" to append new items. | |
// second implementation uses a single array but uses "splice" for both "push" | |
// and "pull" commands, the benefit being we don't have to manage empty slots; | |
// however, splice results in the array indexes being shuffled internally... |
NewerOlder