Skip to content

Instantly share code, notes, and snippets.

View dmsnell's full-sized avatar

Dennis Snell dmsnell

View GitHub Profile
@dmsnell
dmsnell / regexpCollapser.js
Created June 30, 2018 23:07
collapses alternation groups in a regex
const trie = require('trie-prefix-tree');
const tldList = require('tlds');
//const corpus = tldList;
const corpus = [ 'ca', 'cat', 'cot', 'car', 'catastrophe', 'catastrophic', 'dog' ];
//const corpus = [ 'cat' ];
const tlds = trie( corpus ).tree();
//
@dmsnell
dmsnell / url-regex-patterns.js
Created June 30, 2018 11:30
printing out the regex patterns generated by `url-regex`
const noOptions = /(?:(?:(?:[a-z]+:)?\/\/)|www\.)(?:\S+(?::\S*)?@)?(?:localhost|(?:(?<=\s|^)(?=[a-fA-F\d:])|(?<=[a-fA-F\d:])(?=\s|$))(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}(?:(?<=\s|^)(?=[a-fA-F\d:])|(?<=[a-fA-F\d:])(?=\s|$))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[\/?#][^\s"]*)?/gi
const notStrict = /(?:(?:(?:[a-z]+:)?\/\/)?|www\.)(?:\S+(?::\S*)?@)?(?:localhost|(?:(?<=\s|^)(?=[a-fA-F\d:])|(?<=[a-fA-F\d:])(?=\s|$))(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}(?:(?<=\s|^)(?=[a-fA-F\d:])|(?<=[a-fA-F\d:])(?=\s|$))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:travelersinsurance|northwesternmutual|vermögensberatung|vermögensberater|sandvikcoromant|kerryproperties|americanexpress|cookingchannel|weatherchannel|afamilycompany|americanfamily|
@dmsnell
dmsnell / lines-per-person.js
Last active May 26, 2018 13:01
Print info about each commit for a given author
// @ts-check
/* eslint-disable no-console */
/**
* Calculates commit info per person in a git repo
*
* Run: node lines-per-person.js 'first@email.com' 'first@go.email.com' 'iamthesame@pers.on'
*/
const Git = require("nodegit");
@dmsnell
dmsnell / Makefile
Last active March 11, 2018 21:54
Build output images from Lightroom exports
output-jpgs = $(addprefix $1/,$(subst .tif,.jpg,$(wildcard *.tif)))
# $(call transform,quality,convert-args,optim-args)
define transform
convert $< -quality 98 $2 $@ && \
jpegoptim $@ -m$1 --all-progressive $3
endef
all: small-jpgs medium-jpgs large-jpgs
@dmsnell
dmsnell / scope-a.js
Last active January 20, 2018 21:51
Comparing webpack and rollup
export const name = 'bob'
@dmsnell
dmsnell / init-common.js
Last active January 20, 2018 21:05
comparing `require()` vs. `import` module-init semantics
console.log( 'this is really bad' )
export const value = 5
@dmsnell
dmsnell / a.js
Last active December 28, 2017 23:29
Comparing CommonJS vs. ES modules
export function add( a, b ) { return a + b }
export function sum( list ) { return list.reduce( add, 0 ) }
@dmsnell
dmsnell / benchmark-gutenberg-php-parser.php
Last active October 29, 2017 14:37
Run the parser from Gutenberg over test documents to measure its speed
<?php
/**
* Set the $RUNS and run `php -f benchmark-gutenberg-php-parser.php`
*/
// I ran this file from the `Gutenberg/lib` directory
require_once( 'parser.php' );
$RUNS = 2000;
@dmsnell
dmsnell / bf.peg
Last active June 14, 2017 15:26
An interpreter for BF in PEGjs
// Brain-Fried Language
// Load document from this GIST for a secret message
// https://gist.githubusercontent.com/dmsnell/b5e9465e97d352556249500c80ae6cbd/raw/bf547f71291e44c890ce9fe80c3c3b5217aae715/rot13.bf
{
const stdin = 'Jbeq Pnzc'.split('').map( c => c.charCodeAt( 0 ) ).concat( 0 );
const incDP = m => Object.assign( {}, m, { dp: m.dp + 1, maxRegister: Math.max( m.maxRegister, m.dp + 1 ) } )
@dmsnell
dmsnell / rot13.bf
Last active June 14, 2017 15:25
ROT13 in BF from Wikipedia
-,+[ Read first character and start outer character reading loop
-[ Skip forward if character is 0
>>++++[>++++++++<-] Set up divisor (32) for division loop
(MEMORY LAYOUT: dividend copy remainder divisor quotient zero zero)
<+<-[ Set up dividend (x minus 1) and enter division loop
>+>+>-[>>>] Increase copy and remainder / reduce divisor / Normal case: skip forward
<[[>+<-]>>+>] Special case: move remainder back to divisor and increase quotient
<<<<<- Decrement dividend
] End division loop
]>>>[-]+ End skip loop; zero former divisor and reuse space for a flag