This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function assoc_replace ($templateStr, $replacementList) { | |
$searchStrings = []; | |
$replacements = []; | |
foreach ($replacementList as $key => $val) { | |
array_push($searchStrings, '{{'.$key.'}}'); | |
array_push($replacements, $val); | |
} | |
return str_replace($searchStrings, $replacements, $templateStr); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function db_connect ($options = []) { | |
if (!empty($options)) { | |
$hostName = !empty($options['hostName']) ? $options['hostName'] : 'someHostName'; | |
$databaseName = !empty($options['databaseName']) ? $options['databaseName'] : 'someDatabaseName'; | |
$dbUserName = !empty($options['dbUserName']) ? $options['dbUserName'] : 'someUsername'; | |
$dbPassword = !empty($options['dbPassword']) ? $options['dbPassword'] : 'somepassword'; | |
} else { | |
$hostName = 'someHostName'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//es5 | |
function mapObjStyleAttrs(obj) { | |
return Object.keys(obj) | |
.map(function (key) { | |
return [key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(), obj[key]] | |
.join(':'); | |
}) | |
.join(';'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// es5 | |
function encodeQueryData(data) { | |
return '?' + Object.keys(data).map(function(key) { | |
return [key, data[key]].map(encodeURIComponent).join("="); | |
}).join("&"); | |
} | |
// es6 | |
const encodeQueryData = data => '?' + Object.keys(data).map(key => [key, data[key]].map(encodeURIComponent).join("=")).join('&'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$limit = 25; | |
$pageDisplayLimit = 10 - 1; | |
$currentPage = $offset / $limit + 1; | |
$totalPages = ceil($count / $limit); | |
$pagesRemaining = $totalPages - $currentPage; | |
$lastPageToDisplay = $currentPage + $pageDisplayLimit <= $totalPages | |
? $currentPage + $pageDisplayLimit | |
: $totalPages; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# From Stack Overflow | |
# http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential | |
function isAssoc($array) { | |
return array_keys($array) !== range(0, count($array) - 1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let emailRegEx = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/; | |
if (emailRegEx.test(email)) { | |
$email.removeClass('invalid').addClass('valid'); | |
} else { | |
$email.removeClass('valid').addClass('invalid'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<select name="state"> | |
<option value="AL">Alabama</option> | |
<option value="AK">Alaska</option> | |
<option value="AZ">Arizona</option> | |
<option value="AR">Arkansas</option> | |
<option value="CA">California</option> | |
<option value="CO">Colorado</option> | |
<option value="CT">Connecticut</option> | |
<option value="DE">Delaware</option> | |
<option value="DC">District Of Columbia</option> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gulpfile.js | |
// Heavily inspired by Mike Valstar's solution: | |
// http://mikevalstar.com/post/fast-gulp-browserify-babelify-watchify-react-build/ | |
"use strict"; | |
const gulp = require( 'gulp' ); | |
const browserify = require( 'browserify' ); | |
const babelify = require( 'babelify' ); | |
const uglifyify = require( 'uglifyify' ); | |
const watchify = require( 'watchify' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyRegEx { | |
static email(){ | |
return /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/; | |
} | |
static ssn(){ | |
return /^(?!000|666|900|999)(\d{3})-?(?!00)(\d{2})-?(?!0000)(\d{4})$/; | |
} | |
} |
OlderNewer