A "Best of the Best Practices" (BOBP) guide to developing in Python.
- "Build tools for others that you want to be built for you." - Kenneth Reitz
- "Simplicity is alway better than functionality." - Pieter Hintjens
| Перевод книги Problem Solving with Algorithms and Data Structures Using Python | |
| http://aliev.me/runestone/ | |
| https://github.com/aliev/runestone |
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| import urllib2 | |
| gh_url = 'https://api.github.com' | |
| req = urllib2.Request(gh_url) | |
| password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() |
| // using jQuery | |
| function getCookie(name) { | |
| var cookieValue = null; | |
| if (document.cookie && document.cookie != '') { | |
| var cookies = document.cookie.split(';'); | |
| for (var i = 0; i < cookies.length; i++) { | |
| var cookie = jQuery.trim(cookies[i]); | |
| // Does this cookie string begin with the name we want? | |
| if (cookie.substring(0, name.length + 1) == (name + '=')) { | |
| cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); |
| class Retry(object): | |
| """ | |
| Retries function with exponential delay if it's releasing exception. | |
| """ | |
| def __init__(self, tries, exceptions=None, delay=1, exponent=1.5): | |
| self.tries = tries | |
| if exceptions: | |
| self.exceptions = tuple(exceptions) | |
| else: | |
| self.exceptions = (Exception,) |
| #coding=utf8 | |
| import sys | |
| import SocketServer | |
| import SimpleHTTPServer | |
| import requests | |
| from bs4 import BeautifulSoup | |
| import string | |
| class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): |
| # -*- coding: utf-8 -*- | |
| import scrapy | |
| from scrapy.http.request import Request | |
| from scrapy.selector import Selector | |
| import urllib2 | |
| import re | |
| import PyV8 | |
| import json |
| # -*- coding: utf-8 -*- | |
| import sys | |
| from pprint import PrettyPrinter | |
| class UnicodePrettyPrinter(PrettyPrinter): | |
| """Unicode-friendly PrettyPrinter | |
| Prints: | |
| - u'привет' instead of u'\u043f\u0440\u0438\u0432\u0435\u0442' |
| # -*- coding: utf-8 -*- | |
| from django.db import models | |
| from organizations.models import Organization | |
| from truckback.core.tools import get_file_name | |
| from versatileimagefield.fields import VersatileImageField | |
| from django.utils.translation import ugettext_lazy as _ | |
| from django.db.models.signals import post_save | |
| from django.dispatch import receiver | |
| Deployment notes for Ubuntu Instance | |
| Nginx, uwsgi, postgres, django, virtualenv stack | |
| * ssh root | |
| root access (need pem) | |
| ssh -i whatever.pem ubuntu@ec2-*-*-*-*.compute-1.amazonaws.com | |
| * secure box | |
| - cut off all ports but 22 and 80 using AWS Management Console | |
| - edit /etc/ssh/sshd_config ensure PasswordAuthentication no |