Skip to content

Instantly share code, notes, and snippets.

View dmsnell's full-sized avatar

Dennis Snell dmsnell

View GitHub Profile
@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 / 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 / scope-a.js
Last active January 20, 2018 21:51
Comparing webpack and rollup
export const name = 'bob'
@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 / 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 / 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 / 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 / Block.elm
Created November 21, 2018 16:18
Gutenberg blocks written in Elm
port module Main exposing (Flags, Model, Msg(..), init, main, subscriptions, update, view)
import Browser
import Html exposing (Html, button, div, input, text)
import Html.Attributes exposing (type_)
import Html.Events exposing (onClick, onInput)
port setAttributes : Flags -> Cmd msg
port getAttributes : (Flags -> msg) -> Sub msg
@dmsnell
dmsnell / Dockerfile
Last active March 29, 2019 03:07
WordPress Core Unit Tests
FROM ubuntu
WORKDIR /tmp
ENV PACKAGES="\
composer \
curl \
git \
imagemagick \
locales-all \
@dmsnell
dmsnell / Main.elm
Created April 4, 2019 05:25
Using the URL fragment/query args to determine which "sub app" to render, using initial URL to inform state
module Main exposing (main)
import Browser as B
import Browser.Navigation as BN
import Html as H
import Html.Attributes as HA
import Html.Events as HE
import Url as U