Skip to content

Instantly share code, notes, and snippets.

View conartist6's full-sized avatar

Conrad Buck conartist6

  • Boulder, CO
View GitHub Profile
@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 / 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 / .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 / 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 / index.js
Last active June 12, 2022 11:32
sync vs async for loops
function* range(end) {
for (let i = 0; i < end; i++) {
yield i;
}
}
const a = Array.from(range(65536));
module.exports['for await..of values from one chunk'] = {
fn: async function(deferred) {
@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
Last active July 14, 2020 20:12
Built webpackable component example
/* @macrome
* @generated-by ./index.js
*/
const React = require('react');
const styles = require('index.module.css.js');
require('index.module.css');
// The bundler needs a css require to exist for static analysis.
// Node require hooks may be used to make requiring any .css a no-op.
@conartist6
conartist6 / post.md
Last active July 14, 2020 18:56
Intro to Macrome

I'm working on a brand new build system, and I want to take a moment to address the obvious question, which is: OMGWTFBBQ why another one!?

The answer is in the trees.

The new tool, Macromé (pronounced "macro-may", imported as macrome) is powerful becase it performs in–place builds within existing directory tree structures, so that many types of data about the same underlying unit stay colocated.

For example a React component expressed as a tree-structured directory (a.k.a pod, or unit) and built by macrome might look like this:

[projectRoot]
@conartist6
conartist6 / lexer.js
Last active April 11, 2020 16:48
Proposed lexer API
const matching = {
'{': '}',
'}': '{',
};
export const tokenize = (lexEngine) => {
const { start, get, take, end, setType } = lexEngine; // token fns
const { peekChar, pushState, popState, match, matchable, allMatched } = lexEngine;
const literal = (n) => {
@conartist6
conartist6 / permutations.js
Last active August 29, 2019 17:48
Permutations generator
function swap(arr, aIdx, bIdx) {
if (aIdx < 0 || aIdx >= arr.length) throw new TypeError();
if (bIdx < 0 || bIdx >= arr.length) throw new TypeError();
const temp = arr[aIdx];
arr[aIdx] = arr[bIdx];
arr[bIdx] = temp;
}
function shiftToEnd(arr, idx) {