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
/** | |
* Get the ID of an element. | |
* | |
* Get the ID of an element, generating one if none exists and the second | |
* parameter is set to true. | |
* Makes use of {@link https://gist.github.com/craiga/4075392 randomString}. | |
* | |
* @author Craig Anderson <[email protected]> | |
* @link https://gist.github.com/3279884 | |
*/ |
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 memory usage. | |
* | |
* Makes use of {@link https://gist.github.com/1849563 _log} and {@link https://gist.github.com/2880386 formatMemory}. | |
* | |
* @author Craig Anderson <[email protected]> | |
* @link https://gist.github.com/3336985 | |
*/ | |
protected function _logMemoryUsage() |
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); |
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
<?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
/** | |
* 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
/** | |
* 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
<?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
/** | |
* 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; | |
} |