Skip to content

Instantly share code, notes, and snippets.

View conartist6's full-sized avatar

Conrad Buck conartist6

View GitHub Profile
@conartist6
conartist6 / builders.js
Last active May 6, 2022 00:12
CST traversal prototype
class Builder {
*ensure(...tokens) {
for (const token of tokens) {
yield* token.type === 'Thunk' ? token.ensure(this) : this.advance(token);
}
}
*allow(...tokens) {
for (const token of tokens) {
yield* token.type === 'Thunk' ? token.allow(this) : this.advance(token, true);
@conartist6
conartist6 / index.md
Last active May 25, 2022 17:26
Node package scripts

Node packages usually ship with scripts that are useful to developers. Common scripts might be build, test, or lint, but you will need to look inside the package.json file to see what scripts are actually available for a particular package. Here is what a common package with a build script might look like:

{
  "name": "my-package",
  "version": "0.1.0",
  "scripts": {
    "build": "transpile -f lib/index.ts -o /lib/index.js"
  },
 "devDependencies": {
@conartist6
conartist6 / diagrams.md
Last active March 28, 2022 18:15
Regex engine refactor diagrams

Before

                                                            ┌───────────────┐
                                                            │  Expression   │
                                                            │  root: true   │
                                                            │ globalIdx: 1  │
                                                            └───────┬───────┘
                                                          parentSeq │ ▲
                                                                    │ │ expr
                                  ┌──────────────┐          ┌───────┴─┴─────┐
@conartist6
conartist6 / data-structure
Last active March 22, 2022 13:04
@iter-tools/regex data structure
┌───────────────┐
│ Expression │
│ root: true │
│ globalIdx: 1 │
└───────┬───────┘
parentSeq │ ▲
│ │ expr
┌──────────────┐ ┌───────┴─┴─────┐
│ State │ │ State │
│ type: cont │ │ type: success │
@conartist6
conartist6 / json-tokenizer.js
Created March 20, 2022 21:29
Peekerate json tokenizer
import peekerate from '@iter-tools/peekerate';
export function* tokenize(input) {
const peekr = peekerate(input);
while (!peekr.done) {
const char = peekr.value;
if (char === '"') {
// yields three tokens: " content "
yield* tokenizeString(peekr);
@conartist6
conartist6 / json-tokenizer.js
Last active March 20, 2022 21:29
No-lib json tokenizer
const t = {
token: (value) => ({ type: 'token', value }),
literal: (value) => ({ type: 'literal', value }),
};
const escapes = {
'"': '"',
'\\': '\\',
b: '\b',
f: '\f',
n: '\n',
@conartist6
conartist6 / json-parser.js
Last active January 17, 2023 17:33
A human-friendly json parser with parserate
import parserate from '@iter-tools/parserate';
const t = {
token: (value) => ({ type: 'token', value }),
literal: (value) => ({ type: 'literal', value }),
};
const escapes = {
'"': '"',
'\\': '\\',
@conartist6
conartist6 / resume.md
Last active March 1, 2023 15:02
Conrad Buck - A resume for humans

This is my resume for humans! It is meant to be read, not parsed, and that is on purpose. My goal here is to start conversations, so you are welcome to email me any questions or comments.

Conrad Buck

conartist6@gmail.com
https://github.com/conartist6
https://burningpotato.com
Remote, Eastern Time

I consider myself to be foremost a linguist and a champion of developer experience. I am always considering how it should be possible to express technical concepts with readable code, how to uphold and combine the fundamental principles of development, and what the next step is on the path to much larger goals. I hope that you will read the code I have written and find it unremarkable, but I hope that you understand also that this reflects what I believe is an exceptional ability to reach into many, many different projects, languages, and disciplines to triage and fix bugs, build missing functionality, and most importantly to make the right

@conartist6
conartist6 / error_parser.ne
Last active October 9, 2021 03:55
Basic moo/nearley parser for JS errors
@{%
const lexer = moo.states({
error: {
CausedBy: { match: /^\s*[cC]ause(?:d [bB]y)?:/, value: () => "Caused by:" },
At: { match: /^[ \t]*at /, push: "frame", value: () => "at " },
Space: /[ \t]+/,
Newline: { match: "\n", lineBreaks: true },
// Any line ending with file:line:col is a stack frame
// file:line:col may be wrapped in parens, or may be the literal 'native'
@conartist6
conartist6 / babel-parse-auto.js
Created March 6, 2021 15:47
Infer babel settings from file type
const recast = require('recast');
const babylon = require('@babel/parser');
function getParseCallOptions({ parse, ...parseOptions }) {
return { parse, parseOptions };
}
function getPrintCallOptions({ print, ...printOptions }) {
return { print, printOptions };
}