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
def clean(self): | |
if not self.cleaned_data['date_from'] and not self.cleaned_data['date_to']: | |
raise forms.ValidationError(_("At least one date field is required.")) | |
return super(SearchByDateRangeForm, self).clean() |
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
(reduce + (map #(Character/getNumericValue %) (seq (str (reduce * (range (bigint 1) (bigint 100))))))) |
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
(nth (map first (iterate (fn [[a b]] [b (+ a b)]) (double-array [1 1]))) 1475) |
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
def split_per_x_chars(m, step): | |
return [m[x:x+step] for x in range(0, len(m), step)] | |
split_per_x_chars('abcdefghijklmnop', 3) | |
# ['abc', 'def', 'ghi', 'jkl', 'mno', 'p'] |
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 collections import defaultdict | |
counters = defaultdict(int) | |
counters['foo'] += 1 | |
counters['foo'] | |
# Out: 1 | |
counters['bar'] | |
# Out: 0 |
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
def most_common_problems(): | |
problems = ( | |
"People that come from PHP", | |
"Coming up with variable names", | |
"Off-by-one index calculations", | |
) | |
print "The three most common problems in programming are:" | |
for x in range(1, len(problems)): | |
print "* %s" % problems[x] |
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
foos = [1, 2, 4, 1, 1, 5, 2, 1] | |
# continue | |
for foo in foos: | |
if foo == 1: | |
print "ONE" | |
continue | |
print foo | |
# 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
import xmlrpclib | |
import pip | |
def check_for_updates(): | |
pypi = xmlrpclib.ServerProxy('http://pypi.python.org/pypi') | |
for dist in pip.get_installed_distributions(): | |
available = pypi.package_releases(dist.project_name) | |
if not available: | |
# Try to capitalize pkg name | |
available = pypi.package_releases(dist.project_name.capitalize()) |
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
{val: range(5, 0, -1)[key] for key, val in enumerate(range(1, 6))} | |
# {1: 5, 2: 4, 3: 3, 4: 2, 5: 1} |
OlderNewer