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 | |
// http://www.geekality.net/2010/11/17/php-output-a-number-of-bytes-in-a-human-readable-way/ | |
function make_pretty($bytes) | |
{ | |
$symbols = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'); | |
$exp = floor(log($bytes) / log(1024)); | |
return sprintf('%.2f '.$symbols[$exp], $bytes/pow(1024, floor($exp))); |
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 | |
// found http://stackoverflow.com/questions/1634782/what-is-the-most-accurate-way-to-retrieve-a-users-correct-ip-address-in-php | |
function get_ip_address() | |
{ | |
foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key){ | |
if (array_key_exists($key, $_SERVER) === true){ | |
foreach (explode(',', $_SERVER[$key]) as $ip){ | |
$ip = trim($ip); // just to be safe |
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 | |
define('CONS_KEY', 'Application consumer key'); | |
define('CONS_SECRET', 'Application consumer secret'); | |
require_once __DIR__.'/silex.phar'; | |
$app = new Silex\Application(); | |
// register the session extension | |
$app->register(new Silex\Extension\SessionExtension()); |
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 | |
// found at http://php.net/manual/en/function.array-filter.php | |
function array_reindex(array $source, $blacklist = array()) | |
{ | |
$i = 0; | |
foreach ($source as $key => $val) { | |
if ($key != $i) { | |
unset($source[$key]); |
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
-- http://www.mysqlperformanceblog.com/2008/02/04/finding-out-largest-tables-on-mysql-server/ | |
SELECT CONCAT(table_schema, '.', table_name), | |
CONCAT(ROUND(table_rows / 1000000, 2), 'M') rows, | |
CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G') DATA, | |
CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G') idx, | |
CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') total_size, | |
ROUND(index_length / data_length, 2) idxfrac | |
FROM information_schema.TABLES | |
ORDER BY data_length + index_length DESC |
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
if __name__ == '__main__': | |
parser = OptionParser() | |
options_a = [ | |
["-s", "--spiders", dict(dest="spiders", type="int", default=1, help="sends more than one spider")], | |
["-S", "--nospinner", dict(dest="spinner", action="store_false", default=True, help="turns off the spinner")], | |
["-v", "--verbose", dict(dest="verbose", action="store_true", default=False, help="outputs every request (implies --nospiner)")], | |
["-d", "--depth", dict(dest="depth", type="int", default=-1, help="does a breadth-first crawl, stopping after DEPTH levels (implies --breadth)")], | |
["-b", "--breadth", dict(dest="breadth", action="store_true", default=False, help="does a breadth-first crawl; may be used with --depth")], | |
] | |
for s, l, k in options_a: |
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
SELECT DISTINCT message_id | |
FROM SELECT *, id AS message_id FROM user_messages WHERE user_id = ? | |
AND read = false AND parent_id IS NULL AS initial_messages | |
UNION | |
SELECT *, parent_id AS message_id FROM user_messages WHERE user_id = ? | |
AND read = false AND parent_id IS NOT NULL AS replies; |
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 | |
function uuid_pad($pad = 6) | |
{ | |
return substr(md5(uniqid(rand(), true)), $pad, $pad); | |
} | |
// example | |
echo uuid_pad(); |
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
// ---------------------------------------------------------- | |
// A short snippet for detecting versions of IE in JavaScript | |
// without resorting to user-agent sniffing | |
// ---------------------------------------------------------- | |
// If you're not in IE (or IE version is less than 5) then: | |
// ie === undefined | |
// If you're in IE (>=5) then you can determine which version: | |
// ie === 7; // IE7 | |
// Thus, to detect IE: | |
// if (ie) {} |
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 os | |
def split(filehandler, delimiter=',', row_limit=10000, | |
output_name_template='output_%s.csv', output_path='.', keep_headers=True): | |
""" | |
Splits a CSV file into multiple pieces. | |
A quick bastardization of the Python CSV library. | |
Arguments: |