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 os, re | |
| import logging | |
| from subprocess import Popen, PIPE | |
| def get_git_revision(): | |
| return _get_git_revision() | |
| def _get_git_revision(): | |
| # this is actually very fast. Takes about 0.01 seconds on my machine! | |
| home = os.path.dirname(__file__) |
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 setuptools import setup | |
| import sys, os | |
| version = '0.2.3' | |
| here = os.path.dirname(__file__) | |
| def read(fname): | |
| return open(os.path.join(os.path.dirname(__file__), fname)).read() | |
| def md2stx(s): |
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
| exports.EditDistanceMatcher = function(against, alphabet) { | |
| this.against = against; | |
| this.alphabet = alphabet || "abcdefghijklmnopqrstuvwxyz"; | |
| this.edits1 = function(word) { | |
| var n = word.length; | |
| var al = this.alphabet.length; | |
| var set = new Array(), t; | |
| // deletion | |
| for (var i=0, len=n; i < len; i++) { |
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
| var EditDistanceMatcher = require('../edit_distance').EditDistanceMatcher; | |
| var testCase = require('nodeunit').testCase; | |
| module.exports = testCase({ | |
| test_match: function(test) { | |
| var edm = new EditDistanceMatcher(["peter"]); | |
| test.equal(typeof edm.match('petter'), 'object'); | |
| test.equal(typeof edm.match('junk'), 'object'); | |
| // edm.match returns an array and remember, | |
| // in javascript ['peter'] == ['peter'] => false |
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 tornado.web | |
| class route(object): | |
| """ | |
| decorates RequestHandlers and builds up a list of routables handlers | |
| Tech Notes (or "What the *@# is really happening here?") | |
| -------------------------------------------------------- | |
| Everytime @route('...') is called, we instantiate a new route object which | |
| saves off the passed in URI. Then, since it's a decorator, the function is |
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 _BaseForm(object): | |
| def clean(self): | |
| cleaned_data = super(_BaseForm, self).clean() | |
| for field in cleaned_data: | |
| if isinstance(cleaned_data[field], basestring): | |
| cleaned_data[field] = \ | |
| cleaned_data[field].replace('\r\n','\n')\ | |
| .replace(u'\u2018',"'").replace(u'\u2019',"'").strip() | |
| return cleaned_data | |
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 HTTPSMixin(object): | |
| def is_secure(self): | |
| return self.request.headers.get('X-Scheme') == 'https' | |
| def httpify_url(self, url=None): | |
| url = url if url else self.request.full_url() | |
| if url.startswith('/'): | |
| parsed = urlparse(self.request.full_url()) | |
| return 'http://%s%s' % (parsed.netloc, url) |
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
| OAUTH_SETTINGS = { | |
| 'client_id': '1ccb7f00082bc45047e7', # peterbe | |
| 'client_secret': 'b406117bf98898e0ffe1b1757e64f76a3c439bea', | |
| 'base_url': 'https://github.com/login/oauth/', | |
| 'redirect_url': 'http://www.peterbe.com/tornadogists/callback' | |
| } | |
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 main(): # pragma: no cover | |
| tornado.options.parse_command_line() | |
| if options.showurls: | |
| for path, class_ in route.get_routes(): | |
| print path | |
| return | |
| http_server = tornado.httpserver.HTTPServer(Application()) | |
| print "Starting tornado on port", options.port | |
| if options.prefork: |
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 LazyNotImplementedError: | |
| def __init__(self, error_msg): | |
| self.error_msg = error_msg | |
| def __call__(self, *__): | |
| raise NotImplementedError(self.error_msg) | |
| __str__ = __add__ = __call__ | |
| # settings.py example | |
| BASE = LazyNotImplementedError("You must set this in your settings_local") |
OlderNewer