Skip to content

Instantly share code, notes, and snippets.

View maxlawton's full-sized avatar

Max Lawton maxlawton

View GitHub Profile
@maxlawton
maxlawton / metaphorpsum.sh
Last active May 11, 2018 19:28
Shell script to get metaphorpsum.com filler text
#!/usr/bin/env bash
# --------------------------------------------------------------------
# metaphorpsum.sh
#
# Generate some metaphorical filler text via the API at
# metaphorpsum.com
#
# --------------------------------------------------------------------
usage() {
@maxlawton
maxlawton / dmv.sh
Created December 22, 2017 17:20
Date-move, prepend modtime to filenames
#!/bin/sh
# dmv: prefix each file with its modified date
# backup the 'field separator' characters and remove spaces from current IFS.
# this allows handling of files with spaces.
FMT="%Y%m%d-"
FML="%Y-%m-%d_"
FMH="%Y%m%d_%H%M-"
@maxlawton
maxlawton / bump-package
Created June 16, 2016 11:45
Update Bower and NPM package versions
#!/usr/bin/env bash
# ====================================================================
if echo "$1" | grep -q -e '^-\+h\(elp\)\?$'; then
(cat <<EOF
bump-package
Update Bower and NPM package versions.
@maxlawton
maxlawton / find-replace.sh
Created August 18, 2015 16:22
Bash find/sed script
#!/usr/bin/env bash
FIND=$(echo "$1" | sed -e 's/[\/&]/\\&/g')
shift
REPL=$(echo "$1" | sed -e 's/[\/&]/\\&/g')
shift
# EXPR="s/"${FIND}"/"${REPL}"/g"
OPTIONS="$@"
@maxlawton
maxlawton / jquery.populateDataProps.js
Last active August 29, 2015 14:16
Populate form inputs with content from elements with matching 'itemprop' attributes.
/**
* jQuery.populateDataProps()
* ==========================
*
* Find inputs with a [data-value-prop] attribute and set their value
* to the 'content' attribute of an children of $source whose
* [itemprop] matches the input's [data-value-prop].
*
* Example
* -------
{
"vars": {
"@gray-base": "#000",
"@gray-darker": "lighten(@gray-base, 13.5%)",
"@gray-dark": "lighten(@gray-base, 20%)",
"@gray": "lighten(@gray-base, 33.5%)",
"@gray-light": "lighten(@gray-base, 46.7%)",
"@gray-lighter": "lighten(@gray-base, 93.5%)",
"@brand-primary": "darken(#428bca, 6.5%)",
"@brand-success": "#5cb85c",
@maxlawton
maxlawton / cd-to.sh
Created October 7, 2014 18:23
Change Directory To...
#!/usr/bin/env bash
# ==========================================================================
#
# Change Directory To...
#
# INSTALLATION
#
# Source this file in your Bash configuration (e.g. .profile, .bashrc)
#
@maxlawton
maxlawton / mstamp.sh
Created October 4, 2014 21:11
Timestamp (prefix) files with their modification date
#!/bin/sh
# mstamp.sh: prefix each file with its modified date
# ==================================================================
function _mt() {
echo $(/usr/bin/stat -t $1 -f %Sm "$2")
}
@maxlawton
maxlawton / mysql-dump-like.sh
Created October 4, 2014 19:33
Dump MySQL tables matching prefix
#!/usr/bin/env bash
if [ "$#" -ge 2 ]
then
DBNAME="$1"; shift
PREFIX="$1"; shift
else
echo "usage: mysql-dump-like.sh <database> <table_prefix> [<mysql_options...>]"
exit 1
fi
@maxlawton
maxlawton / geo-distance.js
Created August 21, 2014 00:30
Functions for computing geographical distances
var GeoDistance = (function () {
var _d = {};
// Earth Radius, in Miles
_d.RADIUS = 3958.7615;
_d.RAD_LAT = 3963.1906;
_d.RAD_LNG = 3949.9028;
_d.rad = function ( x ) {