Skip to content

Instantly share code, notes, and snippets.

Перевод книги 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
@Guest007
Guest007 / upprint.py
Created September 28, 2015 07:58 — forked from shvechikov/upprint.py
UnicodePrettyPrinter
# -*- 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'
@Guest007
Guest007 / bobp-python.md
Created November 5, 2015 08:13 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@Guest007
Guest007 / models.py
Last active November 10, 2015 13:48
Model inheritance. Create child by signal after parent's create.
# -*- 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
@Guest007
Guest007 / Deploy Notes
Created November 19, 2015 14:16 — forked from fission6/Deploy Notes
Deployment notes for Ubuntu Instance Nginx, uwsgi, postgres, django, virtualenv stack
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