Skip to content

Instantly share code, notes, and snippets.

View parisminton's full-sized avatar

James Thomas parisminton

View GitHub Profile
@parisminton
parisminton / handlePhoneInput.js
Created July 26, 2016 17:48
Front-end validation and formatting help for a phone number input. Relying on keycodes was problematic on Android.
function handlePhoneInput (evt) {
var inpt = evt.target,
op;
if (inpt.value.length > prev_inpt.length) {
op = 'typed';
}
else if (inpt.value.length < prev_inpt.length) {
op = 'deleted';
}
@parisminton
parisminton / everything_but.sh
Created November 7, 2015 16:59
Loop through filenames and operate on the ones that *don't* match a pattern
for i in $(ls ~/wherevs/*.png); do
if [ ! $(echo $i | ack whatevs) ]; then
rm -P $i
fi
done
@parisminton
parisminton / commaify.js
Created July 8, 2013 17:44
This function will automatically insert commas after the thousands place of any number. Returns a string. Useful for calculations that appear in copy. Call 'commaify(some_dynamic_integer);'
function commaify (num) {
var num_string,
i,
len,
threes = [],
remainders;
num_string = num.toString();
len = num_string.length;
remainders = len % 3;
@parisminton
parisminton / mobilechromedebug.bash
Last active December 15, 2015 06:39
For Mac. Fire up adb, start port forwarding and debug Web pages live on your Droid with one command. Save this function in, or source it from, your .bash_profile. Needs Eclipse, the Android Debug Bridge and desktop Chrome installed.
#!/bin/bash
function mobilechromedebug () {
previous_directory="$(pwd)"
cd /path/to/platform-tools/goes/here/
./adb forward tcp:9222 localabstract:chrome_devtools_remote
open -a "/Applications/Google\ Chrome.app" http://localhost:9222
cd $previous_directory
}
@parisminton
parisminton / bigify_css.sed
Created January 17, 2013 23:06
Break a minified style sheet string into readable, indented text. Save it to bigify_css.sed and run 'sed -Ef bigify_css.sed < oldfile > newfile'. Boom. Easier to read.
s/}/\
}\
\
/g
s/{/ {\
/g
s/;/;\
/g
@parisminton
parisminton / convertToOrdinal.js
Created December 14, 2012 01:16
Simple JavaScript to convert a numeral to its ordinal. Values less than 10 are written as words. Values equal to 10 or greater are written with leading numerals. The optional second argument is a boolean representing whether the collection of numbers is zero-based, as in an array.
function convertToOrdinal (i, zero_based) {
var number = zero_based ? ((i - 0) + 1) : (i - 0), // bootleg coercion
one = /\d+1$/,
two = /\d+2$/,
three = /\d+3$/,
zero_and_four_through_nine = /\d+[0456789]$/;
// For whatever goofy reason, typeof NaN == 'number'
if (typeof number == 'number' && !isNaN(number)) {
if (number == 0) {