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 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
//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
<?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
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteBase / | |
RewriteRule ^index\.html$ - [L] | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteCond %{REQUEST_FILENAME} !-l | |
RewriteRule . /index.html [L] |
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
.flex { | |
display : -webkit-box; | |
display : -ms-flexbox; | |
display : flex; | |
} | |
.flex-row { | |
display : -webkit-box; | |
display : -ms-flexbox; |
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
function promisify(func, ...args) { | |
if (arguments.length === 1) { | |
// Curry with the decremented arity | |
return promisify.bind(null, func) | |
} | |
return new Promise((resolve, reject) => { | |
func(...args, (error, ...cbArgs) => { | |
if (error) { | |
return reject(error) |
OlderNewer