Skip to content

Instantly share code, notes, and snippets.

DAY, WEEK, MONTH, YEAR = map(timedelta, (1, 7, 30, 365))
def newer_than(fieldname, delta)
# positive values go to past, negative to future. counterintuitive?
time = datetime.now() - delta
fieldname = fieldname + "__gte"
return Q(**fieldname: past)
# For more granularity. Probably YAGNI
# HTTP view decorators inspired by property.setter
# See also a class-based solution in http://gist.github.com/85410
class MethodDispatcher(object):
def __init__(self):
self.views = {}
def __call__(self, request, *args, **kwargs):
m = request.method.upper()
if m in self.views:
from django.core.urlresolvers import get_resolver, RegexURLResolver
root = get_resolver(None)
def print_indented(level, s):
indent = 4 * level * ' '
print indent + s
def print_include_tree(resolver=root, indent_level=0):
name = resolver.urlconf_name
from itertools import groupby
from operator import itemgetter
data = [dict(name="Tyler Bennett", id="E10297", salary=32000, department="D101"), ...]
department = itemgetter('department')
for dep, persons in groupby(sorted(data, key=department), department):
print "\nDepartment", dep
print " Employee Name Employee ID Salary Department"
for person in sorted(persons, key=itemgetter('salary'):
From be4b3a6b8c59c0a5ca291d40a187f970ccc4084d Mon Sep 17 00:00:00 2001
From: Antti Rasinen <[email protected]>
Date: Fri, 23 Oct 2009 08:21:30 +0000
Subject: [PATCH] Fixed latitude/longitude parsing.
"I assume that you worked out that whole
longitude-latitude thing. I know you get confused
sometimes."
"You're right, you're right. I keep mixing them
def make_array(n, first=True):
return map(make_array, range(n), ()) if first else lambda: n
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance | NO | NO | NO |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| FEDERATED | NO |
100430 15:25:17 mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
100430 15:25:17 [Warning] '--default-character-set' is deprecated and will be removed in a future release. Please use '--character-set-server' instead.
100430 15:25:17 [Warning] '--default-collation' is deprecated and will be removed in a future release. Please use '--collation-server' instead.
100430 15:25:17 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
100430 15:25:17 InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name /var/db/mysql/ibdata1
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.
function FindProxyForURL(url, host) {
var socked = ["*.wikipedia.org", "twitter.com"];
var proxied = ["*simpletext.ws", "api.twitter.com"];
var i;
for (i = 0; i < socked.length; i++) {
if shExpMatch(url, socked[i])
return "SOCKS 10.0.2.3:9999";
}
@arsatiki
arsatiki / gist:834063
Created February 18, 2011 17:44
jgc's google script
# Script to perform Google searches and extract the domain names of
# the returned results. The order in which the domain names are
# returned is used to determine a ranking between different companies.
# This is the list of domains to look for in Google searches. To
# search for more or different domains simply alter this list. The
# order of this list determines the order in which the results are
# saved.
domains = [ 'foo.com', 'bar.com', 'baz.com' ]