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 urllib2 | |
| from Queue import Queue | |
| from threading import Thread | |
| # global var | |
| remaind_urls = Queue() | |
| fetched_urls = set() | |
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
| class JSendMixin(object): | |
| """http://labs.omniti.com/labs/jsend | |
| JSend is a specification that lays down some rules for how JSON | |
| responses from web servers should be formatted. | |
| JSend focuses on application-level (as opposed to protocol- or | |
| transport-level) messaging which makes it ideal for use in | |
| REST-style applications and APIs. | |
| """ |
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.contrib import admin | |
| class ReadOnlyAdmin(admin.ModelAdmin): | |
| """A ModelAdmin with read only permission.""" | |
| def get_list_display(self, request): | |
| return self.get_readonly_fields(request) | |
| def get_readonly_fields(self, request, obj=None): | |
| readonly_fields = [] |
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 .models import Profile | |
| from .django_json_mixin import JSONListView, JSONDetailView | |
| class AccountList(JSONListView): | |
| model = Profile | |
| class AccountDetail(JSONDetailView): |
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 PIL import Image | |
| import six | |
| import sys | |
| # from django-avatar | |
| def create_thumbnail(filename, size, output): | |
| orig = open(filename) | |
| image = Image.open(orig) | |
| quality = 95 |
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
| types { | |
| text/html html htm shtml; | |
| text/css css; | |
| text/xml xml; | |
| image/gif gif; | |
| image/jpeg jpeg jpg; | |
| application/x-javascript js; | |
| application/atom+xml atom; | |
| application/rss+xml rss; |
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
| class JSendMixin(object): | |
| """http://labs.omniti.com/labs/jsend | |
| JSend is a specification that lays down some rules for how JSON | |
| responses from web servers should be formatted. | |
| JSend focuses on application-level (as opposed to protocol- or | |
| transport-level) messaging which makes it ideal for use in | |
| REST-style applications and APIs. | |
| """ |
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 urllib import urlencode, urlopen | |
| import json | |
| from tornado.web import RequestHandler | |
| class CasClientMixin(object): | |
| @property | |
| def cas_server_url(self): | |
| return 'http://www.example.com/cas' |
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
| # http://stackoverflow.com/a/19037624/739667 | |
| import base64 | |
| import socket | |
| import struct | |
| def decode_cookie(cookie): | |
| """decode a u cookie into an uid | |
| :param cookie: a cookie value that will be decoded into a uid |
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 Queue import Queue, PriorityQueue | |
| from threading import Thread | |
| class Scheduler(Thread): | |
| def __init__(self, *args, **kwargs): | |
| super(Scheduler, self).__init__(*args, **kwargs) | |
| self.tasks = Queue() | |
| self.workers = PriorityQueue() |
OlderNewer