Skip to content

Instantly share code, notes, and snippets.

View conartist6's full-sized avatar

Conrad Buck conartist6

View GitHub Profile
@conartist6
conartist6 / test.js
Last active November 2, 2020 21:14
Generator throw behavior
const item = {
done: true,
value: null,
};
function* wrap(source) {
try {
yield* source;
} catch (e) {
// this never happens
@conartist6
conartist6 / index.js
Created December 8, 2020 15:01
babel-plugin-transform-self-import
const { join, normalize, dirname, relative } = require('path');
const { sync: readPkgUp } = require('read-pkg-up');
function pkgname(path) {
const match = /(^@?[^/]+\/[^/]+|[^/]+)(.*)/.exec(path);
return match && [match[1], match[2]];
}
const pkg = readPkgUp({ normalize: false });
const root = dirname(pkg.path);
@conartist6
conartist6 / .editorconfig
Created December 11, 2020 02:36
Simple editorconfig
# EditorConfig is awesome: http://EditorConfig.org
root = true
[*]
end_of_line = lf
insert_final_newline = true
[{*.{js,json,md}}]
charset = utf-8
@conartist6
conartist6 / whatsapp_TOS_2020.diff
Last active January 5, 2021 02:39
Changes in the whatsapp 2020 terms of service
2c2,4
< WhatsApp Inc. (“WhatsApp,” “our,” “we,” or “us”) provides messaging, Internet calling, and other services to users around the world. Please read our Terms of Service so you understand what’s up with your use of WhatsApp. You agree to our Terms of Service (“Terms”) by installing, accessing, or using our apps, services, features, software, or website (together, “Services”).
---
> If you live in the European Region, WhatsApp Ireland Limited provides WhatsApp to you under this Terms of Service and Privacy Policy.
>
> WhatsApp LLC (“WhatsApp,” “our,” “we,” or “us”) provides messaging, Internet calling, and other services to users around the world. Please read our Terms of Service so you understand what’s up with your use of WhatsApp. You agree to our Terms of Service (“Terms”) by installing, accessing, or using our apps, services, features, software, or website (together, “Services”).
56c58
< Forum and Venue. If you are a WhatsApp user located in the United States or Canada, the “Special Arbitration Provi
@conartist6
conartist6 / visitor.ts
Last active January 10, 2021 17:36
Regex AST Visitor
import { AST as T } from 'regexpp';
export type Expression = T.Pattern | T.Group | T.CapturingGroup | T.LookaroundAssertion;
export type Visit<R> = (node: T.Node) => R;
export interface Visitors<R> {
RegExpLiteral?: (node: T.RegExpLiteral, visit: Visit<R>) => R;
Pattern?: (node: T.Pattern, visit: Visit<R>) => R;
Alternative?: (node: T.Alternative, visit: Visit<R>) => R;
@conartist6
conartist6 / bracket.txt
Last active February 27, 2021 15:04
Battlebots Bracket 2021
Battlebots Bracket 2021
B is a buy, where the result was known when the bracket was made
(1) HYDRA BLOODSPORT (2)
(32) HYPERSHOCK GRUFF (31)
B (HYDRA) BLOODSPORT
B (GIGABYTE) TANTRUM
(16) MALICE FUSION (15)
(17) GIGABYTE TANTRUM (18)
@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 };
}
@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 / 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-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);