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
pprint({'здравствуй': u'мир'}) | |
pprint({'"здравствуй"': u'"мир"'}) | |
pprint({"'здравствуй'": u"'мир'"}) | |
pprint({"'\xd0\xb7\xd0\xb4\xd1\x80\xd0\xb0\xd0\xb2\xd1\x81\xd1\x82\xd0\xb2\xd1\x83\xd0\xb9'": u"'\u043c\u0438\u0440'"}) | |
print pformat({"'\xd0\xb7\xd0\xb4\xd1\x80\xd0\xb0\xd0\xb2\xd1\x81\xd1\x82\xd0\xb2\xd1\x83\xd0\xb9'": u"'\u043c\u0438\u0440'"}) |
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 socket | |
import struct | |
class IPATONField(models.IntegerField): | |
''' | |
Для прозрачной обратной совместимости с данными, которые записывались при помощи INET_ATON | |
''' | |
__metaclass__ = models.SubfieldBase |
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
def is_img_url(url): | |
ext = os.path.splitext(url)[1] | |
return ext[1:].lower() in ['jpg','jpeg','png','gif', 'bmp'] | |
youtube_re = re.compile(r'^http://www.youtube.com/watch') | |
def is_youtube_url(url): | |
match = youtube_re.match(url) | |
if match: | |
key = urlparse.parse_qs(urlparse.urlparse(url).query)['v'] | |
if 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
from django.db import connection | |
class DictQuery(object): | |
def __init__(self, query, params=()): | |
self.query = query | |
self.params = params | |
self._cursor = None | |
self._iterator = None |
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#include <unistd.h> | |
#define MAX_INT 9999999 | |
int randint(int from, int to) { | |
return (from + rand() % to); |
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
def calc_ean_13_checksum(ean): | |
import math | |
sum = 0 | |
for x, c in enumerate(str(ean)[::-1]): | |
if (x+1) % 2 == 0: | |
sum += int(c) | |
else: | |
sum += int(c) * 3 | |
return int(math.ceil(sum / 10.0) * 10) - sum |
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#define OPEN_BRACKET_STATE 1 | |
#define CLOSE_BRACKET_STATE 2 | |
#define NUMBER_STATE 3 | |
#define OPERATOR_STATE 4 | |
char OPERATORS[] = {'/', '*', '-', '+'}; |
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
class KeyAttributeDict(dict): | |
''' | |
>>> kd = KeyAttributeDict({'a':1}) | |
>>> kd['a'] | |
1 | |
>>> kd.a | |
1 | |
''' | |
def __getattribute__(self, name): | |
try: |
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 wizard | |
order_wizard = wizard.Wizard('order_wizard) | |
@order_wizard.register(step=1, url='/basket/') | |
def basket(request): | |
... | |
@order_wizard.register(step=2, url='/step_1/') | |
def step_1(request): |
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
def make_response_for_xls(xls_content, xls_filename): | |
'''Make xls response by xls_content as binary sttring and xls_filename | |
from django.http import HttpResponse | |
response = HttpResponse(xls_content, mimetype="application/ms-excel") | |
response["Content-Disposition"] = u"attachment; filename=\"{0}\"".format(xls_filename) | |
return response |