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 / mirrors.ts
Last active July 13, 2024 07:02
Prototype of possible mirroring API for decorators (and/or Object.mirror)
// extensions to global Reflect object
declare namespace Reflect {
function mirror(value: (...args: any[]) => any): FunctionMirror;
function mirror(value: new (...args: any[]) => any): ClassMirror;
function mirror(value: any): ObjectMirror;
function mirror(value: any, propertyKey: PropertyKey): MemberMirror;
}
// Extensions to the Object() constructor function object.
interface ObjectConstructor {
@rbuckton
rbuckton / ts-proposal-range-types.md
Last active June 20, 2024 05:26
Proposal: Range Types for TypeScript

Range Types (T[X:Y]) for TypeScript

A Range Type is a type that produces a new tuple or array type that derives from T by dropping the excess ordered elements of T outside of the range starting at offset X (inclusive) through offset Y (exclusive).

A Range Type is denoted using a : operator in what would otherwise be an Indexed Access Type:

type T = [1, 2, 3][0:2];
@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.

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promise, generator) {
return new Promise(function (resolve, reject) {
generator = generator.call(thisArg, _arguments);
function cast(value) { return value instanceof Promise && value.constructor === Promise ? value
: new Promise(function (resolve) { resolve(value); }); }
function onfulfill(value) { try { step("next", value); } catch (e) { reject(e); } }
function onreject(value) { try { step("throw", value); } catch (e) { reject(e); } }
function step(verb, value) {
var result = generator[verb](value);
result.done ? resolve(result.value) : cast(result.value).then(onfulfill, onreject);