Skip to content

Instantly share code, notes, and snippets.

Avatar

Dennis Snell dmsnell

View GitHub Profile
@dmsnell
dmsnell / url-regex-patterns.js
Created Jun 30, 2018
printing out the regex patterns generated by `url-regex`
View url-regex-patterns.js
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
Print info about each commit for a given author
View lines-per-person.js
// @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 Mar 11, 2018
Build output images from Lightroom exports
View Makefile
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 Jan 20, 2018
Comparing webpack and rollup
View scope-a.js
export const name = 'bob'
@dmsnell
dmsnell / init-common.js
Last active Jan 20, 2018
comparing `require()` vs. `import` module-init semantics
View init-common.js
console.log( 'this is really bad' )
export const value = 5
@dmsnell
dmsnell / a.js
Last active Dec 28, 2017
Comparing CommonJS vs. ES modules
View a.js
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 Oct 29, 2017
Run the parser from Gutenberg over test documents to measure its speed
View benchmark-gutenberg-php-parser.php
<?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 / rot13.bf
Last active Jun 14, 2017
ROT13 in BF from Wikipedia
View rot13.bf
-,+[ 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
@dmsnell
dmsnell / bf.peg
Last active Jun 14, 2017
An interpreter for BF in PEGjs
View bf.peg
// 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 / calypsoComments.purs
Last active May 26, 2017
Building a description of the Comment object in Calypso
View calypsoComments.purs
module Main where
import Prelude
import Data.Foldable (fold)
import Data.Generic
import Data.Maybe
import TryPureScript
data CommentId = CommentId Int
type DateTime = String {- this interactive editor doesn't have the right type -}