Skip to content

Instantly share code, notes, and snippets.

@zerosignalproductions
zerosignalproductions / phone-regex.js
Last active August 29, 2015 13:56
Validate a phone number allowing for the format 1-(XXX)-XXX-XXXX, but not 1XX-XXX-XXX or XXX-555-XXXX.
//https://www.debuggex.com/r/H3Wz2nlxZUJcs7sV/3
/^(\+?1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-??(?!5{3})[2-9]\d{2}-?\d{4}$/
@zerosignalproductions
zerosignalproductions / gist:9766252
Created March 25, 2014 16:55
DOM-based Routing from Wordpress Roots theme
/* ========================================================================
* DOM-based Routing
* Based on http://goo.gl/EUTi53 by Paul Irish
*
* Only fires on body classes that match. If a body class contains a dash,
* replace the dash with an underscore when adding it to the object below.
*
* .noConflict()
* The routing is enclosed within an anonymous function so that you can
* always reference jQuery with $, even when in .noConflict() mode.
@zerosignalproductions
zerosignalproductions / estimated-reading-time.php
Created March 31, 2014 18:12
Estimated Reading time in PHP
<?php
$mycontent = $post->post_content; // wordpress users only
$word = str_word_count(strip_tags($mycontent));
$readingRate = 200;
$m = floor($word / readingRate);
$s = floor($word % readingRate / (readingRate / 60));
$est = $m . ' minute' . ($m == 1 ? '' : 's') . ', ' . $s . ' second' . ($s == 1 ? '' : 's');
?>
<p>Estimated reading time: <?php echo $est; ?></p>