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
| # python version of http://mourner.github.com/simplify-js/ | |
| class Point(object): | |
| def __init__(self, x, y): | |
| self.x = x | |
| self.y = y | |
| def __repr__(self): | |
| return "<Point x=%s y=%s>" % (self.x, self.y) | |
| def sqDist(p1, p2): |
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
| #! python2 | |
| # | |
| # Gaute Hope <eg@gaute.vetsj.com> 2011 | |
| # | |
| # Note: This script was only made to serve its purpose one time, and is not | |
| # necessarily very user friendly. But have been used with success migrating | |
| # Google Reader data to a Google Apps account. | |
| # | |
| # Stars and likes items in Google Reader, used to migrate starred | |
| # and liked items from old account to new. Subscriptions already |
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.core.files.uploadhandler import TemporaryFileUploadHandler | |
| from django.core.files.base import File | |
| from dropbox.client import DropboxClient | |
| from dropbox.session import DropboxSession | |
| from django.conf import settings | |
| import os | |
| class DropboxFileUploadHandler(TemporaryFileUploadHandler): | |
| def __init__(self, *args, **kwargs): | |
| super(DropboxFileUploadHandler, self).__init__(*args, **kwargs) |
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
| def run_pg_fouine(): | |
| info = host_info[env.host_string] | |
| db_name = info.tags.get('Name') | |
| sudo('perl -pi -e "s/log_min_duration_statement = .*/log_min_duration_statement = 0/" /etc/postgresql/9.*/main/postgresql.conf') | |
| sudo('/etc/init.d/postgresql reload') | |
| time.sleep(30) | |
| sudo('perl -pi -e "s/log_min_duration_statement = .*/log_min_duration_statement = 500/" /etc/postgresql/9.*/main/postgresql.conf') | |
| sudo('/etc/init.d/postgresql reload') | |
| run('tail -n 100000 /var/log/postgresql/postgresql-9.*-main.log > /tmp/pgfouine.txt') | |
| run('gzip -f /tmp/pgfouine.txt') |
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 logging | |
| import tornado.escape | |
| import tornado.ioloop | |
| import tornado.options | |
| import tornado.web | |
| import tornado.websocket | |
| import os.path | |
| import asyncmongo | |
| import time | |
| import functools |
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.views.generic import ListView | |
| class SimpleFilteringListView(ListView): | |
| """ | |
| List view with extra filtering and grouping in context data. | |
| ``filters`` dict is created as follows: {'context_variable_name', 'filtering_object_method_name'} | |
| It calls filtering method on each object in object_list and if it returns True - this object is added | |
| to proper context variable. |
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
| #!/usr/bin/python | |
| # Equivalent of "tail -f" as a webpage using websocket | |
| # Usage: webtail.py PORT FILENAME | |
| # Tested with tornado 2.1 | |
| # Thanks to Thomas Pelletier for it's great introduction to tornado+websocket | |
| # http://thomas.pelletier.im/2010/08/websocket-tornado-redis/ | |
| import tornado.httpserver |
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 ListFormMixin(MultipleObjectMixin, FormMixin): | |
| '''フォームを持つListViewの実装のためのMixin | |
| memo: | |
| get_context_dataメソッドが重複する | |
| ''' | |
| class BaseListFormView(ListFormMixin, View): | |
| def get(self, request, *args, **kwargs): |
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 LoginRequiredMixin(object): | |
| """ | |
| View mixin which requires that the user is authenticated. | |
| """ | |
| @method_decorator(login_required) | |
| def dispatch(self, request, *args, **kwargs): | |
| return super(LoginRequiredMixin, self).dispatch( | |
| self, request, *args, **kwargs) |