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
# Copyright (c) 2010 Pedro Matiello <pmatiello@gmail.com> | |
# Juarez Bochi <jbochi@gmail.com> | |
# | |
# Permission is hereby granted, free of charge, to any person | |
# obtaining a copy of this software and associated documentation | |
# files (the "Software"), to deal in the Software without | |
# restriction, including without limitation the rights to use, | |
# copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the | |
# Software is furnished to do so, subject to the following |
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
# -*-coding: utf-8 -*- | |
from struct import * | |
class BinaryStream: | |
def __init__(self,base_stream): | |
self.base_stream = base_stream | |
self.offset = 0 | |
def readBytes(self,length): | |
string, = unpack_from(str(length) + 's',self.base_stream[self.offset:]) |
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 __future__ import with_statement | |
import os | |
from django.core import management | |
# We have to re-name this to avoid clashes with fabric.api.settings. | |
import ohbooklist.conf.local.settings as django_settings | |
management.setup_environ(django_settings) | |
from fabric.api import * |
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 md5 | |
class HashRing(object): | |
def __init__(self, nodes=None, replicas=3): | |
"""Manages a hash ring. | |
`nodes` is a list of objects that have a proper __str__ representation. | |
`replicas` indicates how many virtual points should be used pr. node, | |
replicas are required to improve the distribution. |
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
#-*-coding:utf-8-*- | |
from BeautifulSoup import BeautifulSoup | |
import requests | |
from PIL import Image | |
from StringIO import StringIO | |
r = requests.get('http://www.xiaomi.com') | |
assert(r.status_code == 200) | |
soup = BeautifulSoup(r.text) | |
urls = soup.findAll('img') |
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
"""Beautiful Soup | |
Elixir and Tonic | |
"The Screen-Scraper's Friend" | |
http://www.crummy.com/software/BeautifulSoup/ | |
Beautiful Soup parses a (possibly invalid) XML or HTML document into a | |
tree representation. It provides methods and Pythonic idioms that make | |
it easy to navigate, search, and modify the tree. | |
A well-formed XML/HTML document yields a well-formed data |
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 tornado.ioloop | |
import tornado.web | |
import tornado.escape | |
import tornado.options | |
import tornado.httputil | |
import jinja2 | |
import pyjade.compiler | |
import coffeescript | |
import markdown |
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
{ | |
"china,canton,guangzhou": "guangdong", | |
"shenzhen,guangdong,china": "guangdong", | |
"china,,\u82cf\u5dde": "jiangsu", | |
"peking,china": "beijing", | |
"pudong,district,,shanghai,,china": "shanghai", | |
"beijing,.china": "beijing", | |
"huadu,district,guangzhou,guangdong,china": "guangdong", | |
"beihang,university,,beijing,,china": "beijing", | |
"shanghai,china": "shanghai", |