Skip to content

Instantly share code, notes, and snippets.

View rbuckton's full-sized avatar

Ron Buckton rbuckton

View GitHub Profile
const fs = require("fs");
const path = require("path");
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
async function main() {
console.log("Setting up real/link folders...");
try { fs.mkdirSync(path.join(__dirname, "real/sub/folder"), { recursive: true }); } catch { }
try { fs.unlinkSync(path.join(__dirname, "real/sub/folder/test.txt")); } catch { }
try { fs.symlinkSync(path.join(__dirname, "real"), path.join(__dirname, "link"), "junction"); } catch { }
await delay(1_000);
@rbuckton
rbuckton / Change Nozzle.gcode
Last active February 3, 2024 21:11
Nozzle Change script
;FLAVOR:Marlin
;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 }) => {
releaseHandle(handle);
});
#data = null;
constructor(handle, releaseHandle) {
this.#data = { handle, releaseHandle };
@rbuckton
rbuckton / pattern-matching-exploration.md
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
rbuckton / pattern-matching-tenets.md
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 https://tc39.es/ecma262/#sec-value-notation. 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 https://github.com/tc39/proposal-pattern-matching 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 https://github.com/codehag/pattern-matching-epic.

@rbuckton
rbuckton / ADT enum example.md
Last active August 11, 2021 18:44
Example of how ADT enums could be implemented using https://github.com/rbuckton/proposal-struct

If I were to change the definition of @@toEnum slightly, we could build ADT-style enums into https://github.com/rbuckton/proposal-struct.

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";

__classPrivateFieldSet

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" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
@rbuckton
rbuckton / regexp_flags.md
Created January 15, 2021 01:15
Regular Expression library flags across different engines

Based on list of Regular Expression Engines from https://en.wikipedia.org/wiki/Comparison_of_regular-expression_engines

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
rbuckton / grouped-and-auto-accessors.md
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