Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
import simplejson | |
from boto.s3.connection import S3Connection | |
from boto.s3.key import Key | |
class S3KeyStore(object): | |
def __init__(self, access_key, secret_key, bucket): | |
self.conn = S3Connection(access_key, secret_key) | |
self.bucket = self.conn.create_bucket(bucket) | |
def get(self, key): |
name: ${HOSTNAME} | |
# The cluster should be named with the name of the AD domain | |
cluster: | |
name: bldrprod-0.14.0 | |
routing: | |
allocation: | |
# As small as possible, very large performance hits during recovery | |
concurrent_recoveries: 1 |
__author__ = 'duydo' | |
from base64 import encodestring | |
from json import loads as json_encode | |
from requests import get | |
class SearchAPI(object): | |
MAX_RESULTS = 10 |
import gevent | |
from gevent import monkey, queue | |
monkey.patch_all() | |
import urllib2 | |
from time import sleep | |
import traceback | |
import logging |
from __future__ import with_statement | |
from kombu import BrokerConnection | |
from collections import defaultdict | |
import gevent | |
from gevent import monkey | |
monkey.patch_all() | |
class WorkerHub(): | |
""" | |
WorkerHub controls the local mailboxes that the @worker decorator assigns. |
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""Simple async crawler/callback queue based on gevent.""" | |
import traceback | |
import logging | |
import httplib2 | |
import gevent |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
Article by Faruk Ateş, [originally on KuraFire.net][original] which is currently down
One of the most commonly overlooked and under-refined elements of a website is its pagination controls. In many cases, these are treated as an afterthought. I rarely come across a website that has decent pagination, and it always makes me wonder why so few manage to get it right. After all, I'd say that pagination is pretty easy to get right. Alas, that doesn't seem the case, so after encouragement from Chris Messina on Flickr I decided to write my Pagination 101, hopefully it'll give you some clues as to what makes good pagination.
Before going into analyzing good and bad pagination, I want to explain just what I consider to be pagination: Pagination is any kind of control system that lets the user browse through pages of search results, archives, or any other kind of continued content. Search results are the o
# Don't use this. | |
import zmq | |
import os | |
class Worker: | |
def __init__(self): | |
print "parent: %d, pid: %d" % (os.getppid(), os.getpid()) | |
self.pid = os.getppid() | |
self.context = zmq.Context() | |
self.sub = self.context.socket(zmq.SUB) |
import signal | |
def signal_handler(signum, frame): | |
raise Exception("Timed out!") | |
signal.signal(signal.SIGALRM, signal_handler) | |
signal.alarm(10) # Ten seconds | |
try: | |
long_function_call() |