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
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
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
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 binascii | |
>>> bin(int(binascii.hexlify('hello'), 16)) | |
'0b110100001100101011011000110110001101111' | |
>>> n = int('0b110100001100101011011000110110001101111', 2) | |
>>> binascii.unhexlify('%x' % n) | |
'hello' |
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
#port forwading | |
ssh -L 4040:localhost:4040 server -f | |
#port forwarding from server2 to client use server1 | |
ssh -L 3306:localhost:13306 server1 -f "ssh -L 13306:localhost:3306 server2 -f" |
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 os | |
import smtplib | |
import mimetypes | |
from email.mime.multipart import MIMEMultipart | |
from email.mime.text import MIMEText | |
from email.MIMEBase import MIMEBase | |
from email import Encoders | |
msg = MIMEMultipart('alternative') |
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
% sudo aptitude install xvfb wkhtmltopdf | |
% xvfb-run wkhtmltopdf test.html test.pdf | |
# http://stackoverflow.com/questions/13215120/how-do-i-make-python-qt-and-webkit-work-on-a-headless-server |
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
# -*- coding: utf-8 -*- | |
# http://360percents.com/posts/php-random-user-agent-generator/ | |
from datetime import timedelta, date | |
from random import randint, randrange, choice | |
PROCESSORS = { | |
'linux': ['i686', 'x86_64'], | |
'mac': ['Intel', 'PPC', 'U; Intel', 'U; PPC'] | |
} |
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
%\chapter{Введение} % нумерованный чаптер | |
\anonchapter{Введение} % ненумерованный | |
\begin{figure}[h] | |
\center{\includegraphics[width=1\linewidth]{Ch3_3_web_interface_schema}} | |
\caption{Схема главной страницы веб-интерфейса.} | |
\label{Ch3_3_web_interface_schema:image} | |
\end{figure} |