Skip to content

Instantly share code, notes, and snippets.

View rbuckton's full-sized avatar

Ron Buckton rbuckton

View GitHub Profile
rbuckton / Change Nozzle.gcode
Last active February 3, 2024 21:11
Nozzle Change script
;Printer: Ender 3 Pro
;; Copyright 2023 Ron Buckton
;; Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
;; documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
;; rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
;; permit persons to whom the Software is furnished to do so, subject to the following conditions:
;; The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
// a simple SafeHandle with a public `dangerousGetHandle` method.
class SafeHandle {
static #finalizer = new FinalizationRegistry(({ handle, releaseHandle }) => {
#data = null;
constructor(handle, releaseHandle) {
this.#data = { handle, releaseHandle };
rbuckton /
Last active September 9, 2022 19:45
Pattern Matching Exploration

Pattern Matching Exploration

The following sections explore various ways we could consider introducing pattern matching to ECMAScript, and can be used to inform a discussion on how best to layer the proposal. The various explorations in this document are not intended to be taken as a whole, as some sections directly conflict with others. Any exploration will specifically call out other explorations that are related.

This list is by no means complete. Suggestions for additions or changes are welcome.

Extending Existing Syntax

rbuckton /
Created September 7, 2022 23:23
Pattern Matching Tenets

Pattern Matching Tenets

  1. Patterns should be [concise][]
  2. Patterns should be [expressive][]
  3. Patterns should be [explicit][]
  4. Patterns should be [extensible][]
  5. Pattern matching should be [exhaustive][]

Tenet 1 — Patterns should be concise

Notational Conventions

Examples in this document may use ECMAScript internal-values as specified in Such values will appear in ECMAScript examples as ~value-name~ and are not intended to denote new synatx.

This document uses abstract operations defined either in or in this document. Such abstract operations will be differentiated from normal ECMAScript functions by names like %OperationName% and are not intended to denote new syntax.

Portions of this document are enclosed in block-quotes. These sections reference portions of

rbuckton / ADT enum
Last active August 11, 2021 18:44
Example of how ADT enums could be implemented using

If I were to change the definition of @@toEnum slightly, we could build ADT-style enums into

Currently, @@toEnum takes three arguments: key, value and autoValue. If we change this to take a more complex context argument, we have more flexibility:

interface ValueEnumFactoryContext {
    base: typeof Enum;
    name: string | symbol;
    kind: "value";


var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
    if (kind === "method") throw new TypeError("Private method is not writable");
    if (kind === "accessor" && !f) throw new TypeError("Private accessor was defined without a setter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
    return (kind === "accessor" ?, value) : f ? f.value = value : state.set(receiver, value)), value;
rbuckton /
Created January 15, 2021 01:15
Regular Expression library flags across different engines

Based on list of Regular Expression Engines from

Engine Language Flags Note
[Boost.Regex][] C++ [imsx][Boost.Regex(flags)]
[DEELX][] C++ [imsg][DEELX(flags)]
[Glib/GRegex][] C++ [imsx][Glib/GRegex(flags)]
[GRETA][] C++ Could not find documentation.
[Gregex][] RTL, HLS Could not find documentation.
[RXP][] RTL Could not find documentation.
rbuckton /
Last active October 7, 2020 01:04
Syntax for grouped accessors and auto-accessors to classes and object literals.

Grouped Accessors and Auto-Accessors for ECMAScript classes and Object Literals

This introduces new syntax for grouped accessors and auto-accessors to classes and object literals. A grouped accessor is a single declaration that contains either or both both of the get and set methods for an accessor. An auto-accessor is a simplified variant of a grouped accessor that elides the bodies of the get and set methods and introduces a private backing field used by both the getter and setter.

Syntax - Grouped Accessors

rbuckton / string
Created September 22, 2020 03:09
Rough design for improving the native API for strings in ECMAScript
  • Intl.StringInfo
    • .charCodes(s) - Returns an Iterable that yields each code unit within the string s.
    • .codePoints(s) - Returns an Iterable that yields each code point within the string s (essentially just yield* s).
    • .graphemeClusters(s) - Returns an Iterable that yields each grapheme cluster substring within the string s.
    • .codePointCount(s) - Counts the number of code points within the string s.
    • .graphemeClusterCount(s) - Counts the number of grapheme clusters within the string s.
    • .nthCodePoint(s, n) - Gets the n-th code point (as a number) within the string s.
    • .nthGraphemeCluster(s, n) - Gets the n-th grapheme cluster (as a substring) within the string s.
    • .codePointSize(codePoint) - Gets the size, in code units, of the provided code point.
  • .getUnicodeCategory(s, i) - Gets the unicode category for the code point at the specified index i in string s.