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 _urlSimilartor($url) | |
{ | |
//This is an example | |
$url = preg_replace("/[0-9]+/", "XXX", $url); | |
$qs = parse_url($url, PHP_URL_QUERY); | |
if ($qs) { | |
$parts = array(); | |
parse_str($qs, $parts); |
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
/* | |
$ http GET https://api.github.com/users/dshafik/repos | |
HTTP/1.1 200 OK | |
Server: nginx/1.0.13 | |
Date: Wed, 25 Apr 2012 01:57:50 GMT | |
Content-Type: application/json; charset=utf-8 | |
Transfer-Encoding: chunked | |
Connection: keep-alive | |
Status: 200 OK | |
X-RateLimit-Limit: 5000 |
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
#!/usr/bin/env python | |
""" | |
Highlight stdin using pygments and output to stdout | |
Re-uses httpie. | |
Auto-detects the input language. | |
Will not colorize if piped into something else. |
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 | |
$pdo = new PDO("mysql:host=HOSTNAME", "USERNAME", "PASSWORD"); | |
$query = $pdo->prepare("SHOW DATABASES"); | |
$query->execute(); | |
foreach ($query->fetchAll(PDO::FETCH_OBJ) as $row) { | |
$db = $row->Database; | |
echo "= $db =" . PHP_EOL; | |
$pdo->exec("USE $db"); |
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
The media type quality factor associated with a given type is determined by finding the media range with the highest precedence which matches that type. For example, | |
Accept: text/*;q=0.3, text/html;q=0.7, text/html;level=1, | |
text/html;level=2;q=0.4, */*;q=0.5 | |
would cause the following values to be associated: | |
text/html;level=1 = 1 | |
text/html = 0.7 | |
text/plain = 0.3 | |
image/jpeg = 0.5 |
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
#!/usr/bin/env python | |
""" | |
Convert JSON data to human-readable form. | |
(Reads from stdin and writes to stdout) | |
""" | |
import sys | |
import json |
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
#!/usr/bin/env python | |
""" | |
Convert JSON data to human-readable form. | |
(Reads from stdin and writes to stdout) | |
""" | |
import sys | |
import json |
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 | |
$array = new SplFixedArray($size); | |
$array[0] = 'foo'; | |
$array[1] = 'bar'; | |
... | |
$array[100000] = 'baz'; | |
?> |
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 | |
$interval = DateInterval::createFromDateString("1 hour"); | |
$dateTime->add($interval); | |
echo $dateTime->format(DateTime::ATOM); // 2012-09-01T23:20:01+01:00 | |
?> |
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 | |
$good_salt = '$2y$10$22randomcharactershere$'; | |
$logged_in = false; | |
if (strpos($stored_password, '$2a$') === 0) { | |
$bad_hash = '$2x$' .substr($stored_password, 4); | |
if (crypt($input_password, $bad_hash) == $bad_hash)) { | |
// generate a new password |