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 | |
// custom error handler to suppress errors | |
function exception_error_handler($errno, $errstr, $errfile, $errline ) { | |
return ''; | |
} | |
set_error_handler('exception_error_handler'); | |
?> |
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 | |
class InvalidIpFormatException extends \InvalidArgumentException {} | |
class InvalidIpRangeException extends \InvalidArgumentException {} | |
class IpV4Validator | |
{ | |
private $_ip; | |
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
data:text/html, <style%20type%3D"text%2Fcss">%23e%7Bposition%3Aabsolute%3Btop%3A0%3Bright%3A0%3Bbottom%3A0%3Bleft%3A0%3B%7D<%2Fstyle><div%20id%3D"e"><%2Fdiv><script%20src%3D"http%3A%2F%2Fd1n0x3qji82z53.cloudfront.net%2Fsrc-min-noconflict%2Face.js"%20type%3D"text%2Fjavascript"%20charset%3D"utf-8"><%2Fscript><script>var%20e%3Dace.edit("e")%3Be.setTheme("ace%2Ftheme%2Fmonokai")%3Be.getSession().setMode("ace%2Fmode%2Fphp")%3B<%2Fscript> |
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 | |
// pdo | |
$pdo = new PDO("mysql:host=localhost;dbname=database", "username", "password"); | |
// mysqli, oo way | |
$mysqli = new mysqli('localhost', 'username', 'password', 'database'); | |
// mysqli, procedural | |
$mysqli = mysqli_connect('localhost', 'username', 'password', 'database'); |
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 | |
// pdo | |
$params = array(':username' => 'John', ':email' => $mail ); | |
$pdo->prepare(' | |
SELECT * FROM users | |
WHERE username = :username | |
AND email = :email'); | |
$pdo->execute($params); |
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 | |
// init connection | |
$pdo = new PDO("mysql:host=localhost;dbname=database", "username", "password"); | |
// Bad bad bad!!! | |
// quote - ecscape + plus quote | |
$username = $pdo->quote($_GET['user']); | |
$pdo->query("SELECT * FROM users where username = $username"); |
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
// clean language contract | |
[1..10].each(|i| puts i); | |
// | |
i = 0; | |
while true do: | |
i = i + 1 | |
if i > 10: | |
break | |
end |
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 | |
// hex | |
var_dump(0x9fa0ff0b); | |
// 5.2.1 (32bit) | |
// PHP truncates the long | |
int(2147483647) | |
// 5.2.3+ (32bit) |
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 down all fatal error | |
register_shutdown_function( function() { | |
$lastError = error_get_last(); | |
if( count($lastError) > 0 ) { | |
Logger::log('Fatal error', implode(',', $lastError)); | |
} | |
}); |
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
import urllib2 | |
import json | |
import argparse | |
import sys | |
class HealthCheck(object): | |
""" | |
Parse command line argument | |
""" | |
def parse_arg_options(self): |