This file contains hidden or 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 | |
/** | |
* Flatten an array, preserving keys. | |
* | |
* @author Craig Anderson <[email protected]> | |
* @link https://gist.github.com/craiga/5855194 | |
*/ | |
function flattenArray($in) { | |
$out = array(); |
This file contains hidden or 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 | |
/** | |
* Enthusiastically URL encode a string. | |
* | |
* URL encode everything that's not an alphanumeric character. | |
* | |
* @author Craig Anderson <[email protected]> | |
* @link https://gist.github.com/craiga/4991769#file-enthusiasticurlencode-php | |
*/ |
This file contains hidden or 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
/** | |
* Parse query string into an object. | |
* | |
* @author Craig Anderson <[email protected]> | |
* @link https://gist.github.com/4760400 | |
*/ | |
function parseQueryString(unparsed) { | |
if(typeof unparsed == "undefined") { | |
unparsed = window.location.search; | |
} |
This file contains hidden or 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 | |
/** | |
* Dump a simple view of the current call stack. | |
* | |
* @author Craig Anderson <[email protected]> | |
* @link https://gist.github.com/4687895 | |
*/ | |
function stackdump() { | |
$stack = debug_backtrace(); | |
foreach($stack as $stackIndex => $stackEntry) { |
This file contains hidden or 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
/** | |
* Generate a random string. | |
* | |
* @param alphabet (optional) The alphabet used to generate a random string. | |
* @param minLength (optional) The minimum length of the string. 10 by default. | |
* @param maxLength (optional) The maximum length of the string. 20 by default. | |
* | |
* @author Craig Anderson <[email protected]> | |
* @link https://gist.github.com/4075392 | |
*/ |
This file contains hidden or 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
/** | |
* Based on http://stackoverflow.com/a/6020820/323826 | |
*/ | |
var htmlEscapes = { | |
'&': '&', | |
'<': '<', | |
'>': '>', | |
'"': '"', | |
"'": ''', |
This file contains hidden or 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 | |
/** | |
* Parse a description of a number of bytes to an actual number of bytes. | |
* | |
* @author Craig Anderson <[email protected]> | |
* @link https://gist.github.com/3759346 | |
*/ | |
function strtobytes($dataSize) | |
{ |
This file contains hidden or 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 | |
/** | |
* Log progress. | |
* | |
* Log progress with a message along the lines of "Processed 600 of 20,000 items (3%)." | |
* Makes use of {@link https://gist.github.com/1849563 _log}. | |
* | |
* @author Craig Anderson <[email protected]> | |
* @link https://gist.github.com/3444731 |
This file contains hidden or 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 formatInt(num) { | |
num = parseInt(num); | |
str = new String(num); | |
if(str.length > 4) { | |
var formatted = ""; | |
do { | |
var lastChar = str.length; | |
formatted += "," + str.slice(lastChar - 3); | |
str = str.slice(0, lastChar - 3); | |
} while(str.length > 3); |