Skip to content

Instantly share code, notes, and snippets.

View dmsnell's full-sized avatar

Dennis Snell dmsnell

View GitHub Profile
dmsnell / post-no-sourced-attributes.html
Created December 7, 2022 00:10
Gutenberg serialized HTML post with no sourced attributes.
<!-- wp:paragraph {"content":"This paragraph has \u003cem\u003e\u003cstrong\u003eno sourced attributes\u003c/strong\u003e\u003c/em\u003e. It's content is fully stored inside the JSON attributes \u003cem\u003eand\u003c/em\u003e it still contains the rendered HTML useful for rendering it with no server is available."} -->
<p>This paragraph has <em><strong>no sourced attributes</strong></em>. It's content is fully stored inside the JSON attributes <em>and</em> it still contains the rendered HTML useful for rendering it with no server is available.</p>
<!-- /wp:paragraph -->
<!-- wp:image {"url":"","caption":"Image captions are usually sourced from the \u003ccode\u003efigcaption\u003c/code\u003e element.","width":650,"height":406,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large is-resized"><img src="" alt="" width="650" height="406"/><figcaption class="wp-element-captio
dmsnell / counter.mjs
Created August 29, 2020 20:31
50k `async` JS processes
export const counter = async ({send, receive}) => {
let count = 0;
while (1) {
const [action, args] = await receive();
switch (action) {
case 'inc':
dmsnell / demo.js
Last active August 27, 2020 21:56
Process Primitives
const { spawn, send } = require('./process.js')
const counter = spawn( async (receive) => {
let count = 0;
while (1) {
const message = await receive();
if (message === 'inc') {
dmsnell / sequenced-async.ts
Created August 17, 2020 16:24
JS worker processing sync and async inbound messages sequentially, inspired by Erlang gen_server
import { MessageChannel, MessagePort } from 'worker_threads';
type ServerDescription<K extends string> = {
[type in K]: (...args: unknown[]) => unknown;
type ServerHandler<M extends ServerDescription<keyof M>, S> = <T extends keyof M>(msg: T, state: S) => [ReturnType<M[T]>, S] | Promise<[ReturnType<M[T]>, S]>;
class GenericServer<M extends ServerDescription<keyof M>, S = undefined> {
count = 0;
dmsnell /
Last active July 5, 2020 01:01
Simplenote Tag Hashing Functions - generate tag entity id from tag name
import java.text.Normalizer;
import java.util.Locale;
class TagHasher {
public static String tagHash(String tagName) {
try {
String normalized = Normalizer.normalize(tagName, Normalizer.Form.NFC);
String lowercased = normalized.toLowerCase(Locale.ENGLISH);
dmsnell /
Last active April 12, 2020 03:49
Native Java BlockParser for Gutenberg Posts
import java.util.ArrayList;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class BlockParser {
dmsnell / formula-block-editor.js
Last active September 9, 2019 19:51
Formula-entry and mathematical typesetting block
const { registerBlockType } = wp.blocks;
const { TextareaControl } = wp.components;
const { createElement: el } = wp.element;
const attributes = {
formula: { type: 'string' },
rendered: {
type: 'string',
source: 'attribute',
selector: 'img',
dmsnell / Main.elm
Created April 4, 2019 05:25
Using the URL fragment/query args to determine which "sub app" to render, using initial URL to inform state
module Main exposing (main)
import Browser as B
import Browser.Navigation as BN
import Html as H
import Html.Attributes as HA
import Html.Events as HE
import Url as U
dmsnell / Dockerfile
Last active March 29, 2019 03:07
WordPress Core Unit Tests
FROM ubuntu
composer \
curl \
git \
imagemagick \
locales-all \
dmsnell / Block.elm
Created November 21, 2018 16:18
Gutenberg blocks written in Elm
port module Main exposing (Flags, Model, Msg(..), init, main, subscriptions, update, view)
import Browser
import Html exposing (Html, button, div, input, text)
import Html.Attributes exposing (type_)
import Html.Events exposing (onClick, onInput)
port setAttributes : Flags -> Cmd msg
port getAttributes : (Flags -> msg) -> Sub msg