Skip to content

Instantly share code, notes, and snippets.

@joemaller
joemaller / regexp-exec-vs-string-match.md
Created April 21, 2017 14:39
RegExp.exec and String.match are the same, right?

In JavaScript RegExp.exec() and String.match() should be interchangeable so long as the inputs are the same. Right?

const pat = /(dog).*(bird)/g;
const str = 'dog cat bird';

const foo = str.match(pat);
const bar = pat.exec(str);
@joemaller
joemaller / 4k-sizes.json
Created May 15, 2017 18:39
Approximate sizes of 4k HDTV screens
{
"55": {"w": 48.75, "h": 28.5},
"60": {"w": 53.75, "h": 31},
"65": {"w": 57, "h": 33}
}
@joemaller
joemaller / executable node module.md
Created August 25, 2017 17:51
Run node.js modules from the command line

Add one line to a node.js module and it becomes a callable script:

// hello-module.js
module.exports = function() {
return "Hello!";
};

if (!module.parent) module.exports();
@joemaller
joemaller / index.js
Created September 6, 2017 14:27
Initial, rough AWS lambda script for the webcam.
"use strict";
const aws = require("aws-sdk");
const s3 = new aws.S3({ apiVersion: "2006-03-01" });
const dynamodb = new aws.DynamoDB();
const isNum = n => !isNaN(parseFloat(n)) && isFinite(n);
exports.handler = (event, context, callback) => {
const jsonFileName = "14th-street-webcam.json";
@joemaller
joemaller / wpengine-boilerplate-gitignore-sorted
Created October 20, 2015 21:07
A sorted copy of the gitignore file from wpengine.com/git updated to a sorted copy of the gitignore file found in a default installation. (view the diff)
*.3gp
*.3gpp
*.asf
*.asx
*.avi
*.bak
*.bin
*.deb
*.dll
*.dmg
@joemaller
joemaller / seo-framework-filters.php
Created November 2, 2017 16:49
Two filters for tweaking The SEO Framework plugin.
<?php
// Hide author's name from SEO Framework block
add_filter('sybre_waaijer_<3', '__return_false');
// Move SEO Framework metabox below all custom fields
add_filter('the_seo_framework_metabox_priority', function () {
return 'low';
});
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Version: 0.5.0-0
# Try reading package.name from ./site/package.json
begin
$hostname = JSON.parse(File.read(__dir__ + '/site/package.json'))['name']
$themename = $hostname
rescue StandardError
end
@joemaller
joemaller / vagrant-hostmanager-nopasswd
Last active February 15, 2018 04:03
Sudoers additions for password-free Vagrant up. Save this file to /etc/sudoers.d/ with uid 0.
# Recommended with the Basic WordPress Vagrant project: https://github.com/ideasonpurpose/basic-wordpress-vagrant
# https://gist.github.com/41912f5d027a4adc7c14
Cmnd_Alias VAGRANT_HOSTMANAGER_UPDATE = /bin/cp *.vagrant.d/tmp/hosts.local /etc/hosts
%admin ALL=(root) NOPASSWD: VAGRANT_HOSTMANAGER_UPDATE
@joemaller
joemaller / PS1 Color Functions for Shell Prompts.sh
Last active March 9, 2018 21:33
A set of simple color functions to help customize the shell's $PS1 prompt. These wrap the nasty color and background escape codes into more humane functions. Due to shell string escaping oddness, these must be used with `PROMPT_COMMAND` instead of directly in PS1. A complete git-aware .bashrc prompt is here: https://gist.github.com/joemaller/f7d…
# https://gist.github.com/joemaller/4503986
#
# A set of color functions to help with fancy $PS1 prompts
#
# This:
# PROMPT_COMMAND='PS1="\e[32;1m\]\u@\[\e[35;1m\]\H \[\e[0m\]\w]\$ "''
#
# Can be more clearly written as:
# PROMPT_COMMAND='PS1="$(DARK_GREEN \\u@)$(PURPLE \\H) \w]\$ "''
#
@joemaller
joemaller / Git-branch aware Bash prompt .bashrc .sh
Last active March 17, 2018 16:57
A custom terminal (Bash) prompt which shows name and state of the current Git branch (if available). Brings together ideas from https://gist.github.com/joemaller/4503986 and https://gist.github.com/joemaller/4527475
# https://gist.github.com/joemaller/3165ace4b1f8a50924990ad373236ce8
#
# Append this file to the end of your ~/.bashrc file
# Your terminal prompt will look something like this:
#
# username@hostname /output/of/pwd [git-branch]$
# https://gist.github.com/4503986
#