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 | |
/* | |
* isAjax determines whether a server request is a standard browser-based request or if it is being loaded via AJAX. | |
* | |
* REMEMBER: Do NOT use this for security purposes as it is VERY easy to spoof headers. | |
* | |
* @return bool | |
*/ | |
function isAjax() { |
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 showAllArgs( $item1, $item2, $item3, etc...) { | |
$i = 0; | |
foreach( func_get_args() as $key => $val ) { | |
// $val is the value that you supplied to the parameter. | |
print "You supplied '$val' for argument #$i. \n"; | |
$i++; | |
} | |
} |
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 | |
class Foo { | |
function __construct( $array ) { | |
$this->storage = $this->store($array); | |
} | |
function store( $array ) { |
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 | |
// Full disclosure: I wrote this while writing a Twitter Bootstrap enabled site, so the class tags are Twitter bootstrap enabled. Shouldn't be hard to style, though. | |
$subReddit = "webdev"; // Enter the subreddit name here with no /r/ in front | |
$selfTextLimit = 250; // Character limit for self text entries | |
$pageData = json_decode( file_get_contents( "http://www.reddit.com/r/$subReddit/.json" ) ); | |
foreach( $pageData->data->children as $post ): ?> |
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 | |
// Full disclosure: I found this solution here: http://www.richardcastera.com/blog/php-convert-array-to-object-with-stdclass and implemented it both here and in my project. | |
function arrayToObject( $array ) { | |
if ( !is_array( $array ) && !is_object( $array ) ) { | |
return $array; | |
} | |
$obj = new stdClass(); | |
if( ( is_array( $array ) || is_object( $array ) ) && count( $array ) > 0 ) { | |
foreach( $array as $k=>$v ) { |
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 Snippets { | |
public $snips; | |
function __construct() { | |
$this->snips = new stdClass; | |
} |
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
var githubSchema = new Schema({ | |
"url": String, | |
"html_url": String, | |
"number": Number, | |
"state": String, | |
"title": String, | |
"body": String, | |
"user": { | |
"login": String, | |
"id": Number, |
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 | |
private function dig( $obj , $level = 0 ) { | |
$return = ""; | |
$tabs = str_repeat( "\t" , $level ); | |
foreach( $obj as $k => $v ) { | |
if( self::keyed( $v ) ) { | |
$return .= $tabs . "$k object: \n"; |
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
{ | |
"Success": true, | |
"ResultsReturned": 1, | |
"TotalResults": 1065493, | |
"Artists": [ | |
{ | |
"MnetId": "1097", | |
"Name": "Alicia Keys", | |
"Images": { | |
"Artist180x80": "http://images.mndigital.com/artists/000/001/097/b.jpeg", |
OlderNewer