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 | |
/** | |
* The only function of this statement is to return $poll_id if it's set. Which | |
* snippet would you use and why? | |
* | |
* I (@jrtashjian) prefer and wrote snippet 1. I like how contained the | |
* function is, and the fact I'm only calling the post() function once. | |
* | |
* Each snippet works correctly, this is just preference. I find it redundant | |
* to call the post() function more than once (as shown in snippet 3). I also |
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 fetch( $url ) | |
{ | |
print "Crawling : $url\n"; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); |
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 | |
while( $i < 100 ) | |
{ | |
$i++; | |
if( $i % 15 == 0 ) { echo "FizzBuzz\n"; continue; } | |
if( $i % 3 == 0 ) { echo "Fizz\n"; continue; } | |
if( $i % 5 == 0 ) { echo "Buzz\n"; continue; } | |
echo "$i\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
<?php | |
function create( $params = array() ) | |
{ | |
$defaults = array( | |
'param_one' => '', | |
'param_two' => time(), | |
'param_three' => 0, | |
); | |
$params = array_merge($defaults, $params); |
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 | |
/** | |
* This function will read the file passed to it at 1MB/s and output it to the | |
* browser. | |
*/ | |
function readfile_chunked( $filename ) | |
{ | |
$rate = 1024; |
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 | |
// not safe | |
exec($_GET['query']); | |
exec( addslashes($_GET['query']) ); | |
// THE SAFE ROUTE | |
exec( escapeshellarg($_GET['query']) ); |
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 | |
/** | |
* Improper: | |
* - can become hard to read if the else block is large | |
* - anytime you indent you decrease legibility. | |
* - only applicable for this instance where an item will be skipped and you continue | |
* or break a loop. | |
*/ | |
foreach( $fields as $field ) |
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
// Not really an infinite loop as the system exits the process eventually, caused by the name being too long. | |
// This is what I did: | |
macbook:~ $ mkdir /var/www/directory/ | |
macbook:~ $ cp -R [bunch of files/directories] /var/www/directory/ | |
macbook:~ $ cd /var/www/directory | |
// at this point I forgot to create a subdirectory I wanted these files to be in, inside the directory I just created. | |
macbook:directory/ $ mkdir /var/www/directory/example/ |
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
Create a bookmark with the following as the address: | |
javascript:document.getElementById('noah-stokes').getElementsByTagName('header')[0].getElementsByTagName('img')[0].setAttribute('src', 'http://f.cl.ly/items/1p2a2n191f1y3U1a2J3w/raptorstokes.jpg'); | |
Then go to this page: http://thegreatdiscontent.com/noah-stokes and click the bookmark | |
RAPTOR STOKES! |
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 | |
// unnecessary | |
if( strlen($_POST['zip']) < 6 && strlen($_POST['zip']) > 4 ) | |
// better | |
if( strlen($_POST['zip']) == 5 ) |
OlderNewer