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
from django.core.paginator import ObjectPaginator | |
class QuickObjectPaginator(ObjectPaginator): | |
max_safe_pages = 0 | |
def __init__(self, object_list, per_page, orphans=0, max_safe_pages=0): | |
self.max_safe_pages = max_safe_pages | |
super(QuickObjectPaginator, self).__init__(object_list, per_page, orphans) | |
def validate_page_number(self, page_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
# From http://amix.dk/blog/post/19574 | |
def calculate_score(votes, item_hour_age, gravity=1.8): | |
return (votes - 1) / pow((item_hour_age+2), gravity) |
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 GenericVariable | |
{ | |
private $var; | |
function __construct($variable) | |
{ | |
$this->var = $variable; | |
} | |
function __get($var) |
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 Autokill { | |
var $start_mtime_included_files = array(); | |
function Autokill() { $this->__construct(); } | |
function __construct() { | |
clearstatcache(); | |
$files = get_included_files(); |
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 control_daemon_repeat() { | |
$ps = "/bin/ps aux | /bin/grep -i ".$_SERVER["argv"][0]." | /bin/grep -v grep | wc -l"; | |
$exec = exec($ps, $output, $return); | |
if ($output[0] > 1) die("*** Ya esta en ejecucion\n"); | |
} | |
// Example | |
control_daemon_repeat(); |
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
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: |
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
// ---------------------------------------------------------- | |
// 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 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 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; |
NewerOlder