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
# https://code.djangoproject.com/ticket/17209 | |
import urlparse | |
from django.conf import settings | |
from django.core.urlresolvers import reverse_lazy | |
from django.http import HttpResponseRedirect, QueryDict | |
from django.utils.decorators import method_decorator | |
from django.utils.http import base36_to_int | |
from django.utils.translation import ugettext as _ | |
from django.views import generic |
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
# 'set' | |
# can then be used with getattr(__builtins__, XXX)() | |
# or, even simpler, eval(XXX)() | |
''.join(help.__doc__[i] for i in [35, 47, 71]) | |
str(bool())[-2:] + str(bool(' '))[0].lower() | |
(2 * '%s' % tuple(map(bool, range(2)))).lower()[3:6] | |
''.join(__import__('json').dumps(bool(x)) for x in range(2))[3:6] # not me | |
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 contextlib import contextmanager | |
@contextmanager | |
def hacketyhack(val): | |
yield val | |
class Foo(object): | |
bar = 42 |
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 Mapping | |
from functools import wraps | |
def normalize_key(method): | |
"""A decorator for dict methods that take a key argument. | |
This decorator normalizes the key through the instance's keyfunc function. | |
""" | |
@wraps(method) | |
def wrapped(self, key, *args): |
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 MutableMapping | |
class BinMatrix(MutableMapping): | |
def __init__(self, width, height): | |
self.width = width | |
self.height = height | |
self.ALIVE = 1 | |
self.DEAD = 0 | |
self._set = set() |
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 re | |
class conv(object): | |
@staticmethod | |
def int(s): | |
return int(s) | |
@staticmethod | |
def oct(s): | |
return int(s, base=8) |
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
* pass comand to add/remove admins | |
* pass command to join/leave a channel |
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://preshing.com/20110926/high-resolution-mandelbrot-in-obfuscated-python | |
from struct import pack | |
WIDTH, HEIGHT = 1500, 1000 | |
f = open('M.bmp','wb') | |
f.write('BM' + pack('<QIIHHHH', WIDTH * HEIGHT * 3 + 26, 26, 12, WIDTH, HEIGHT, 1, 24)) | |
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 intfract(p, q, precision=10): | |
"""Return a tuple from the integer division p/q. | |
The first element is the integer part (p // q). | |
The second is a list of length `precision` containing the decimals. | |
Note: if the division is exact, the decimals list will not contain the | |
trailing 0s. | |
""" | |
intpart, rest = divmod(p, q) |
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
# Problem F at https://ep2012.europython.eu/pyddle | |
# 50 chars | |
import math;sum(map(int,str(math.factorial(1e3)))) |
OlderNewer