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
| (defn split [seq delimiter] | |
| (letfn [(check-non-delimiter [val] (not (= val delimiter)))] | |
| (cond | |
| (empty? seq) | |
| seq | |
| (every? check-non-delimiter seq) | |
| (list seq) | |
| :default | |
| (cons | |
| (take-while check-non-delimiter seq) |
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 collections import deque, Iterable | |
| def flatten(l): | |
| """ | |
| >>> [i for i in flatten([1, [2,3], [5, [6,7]]])] | |
| [1, 2, 3, 5, 6, 7] | |
| """ | |
| queue = deque(l) | |
| while len(queue) > 0: | |
| p = queue.popleft() |
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 functools import wraps | |
| def __extend_keys(l): | |
| ret = [[]] | |
| for p in l: | |
| for r in list(ret): | |
| if isinstance(p, list): | |
| ret.remove(r) | |
| for e in p: | |
| nr = list(r) |
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
| TAG_TYPES = ["location", "category"] | |
| class Tag(db.Model, BaseEntityMixIn, | |
| IgnoreDeletionMixIn): | |
| __tablename__ = "tag" | |
| name = db.Column(db.Unicode(255), index=True) | |
| type = db.Column(db.Enum(*TAG_TYPES, native_enum=False), index=True) | |
| __mapper_args__ = {'polymorphic_on': type} | |
| g = globals() |
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://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm | |
| """ | |
| def kmp_make_table(word): | |
| table = len(word) * [0] | |
| pos = 2 | |
| cnd = 0 | |
| table[0] = -1 | |
| table[1] = 0 |
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 app(environ, start_response): | |
| response_body = 'Hello World!' | |
| status = '200 OK' | |
| response_headers = [('Content-Type', 'text/plain'), | |
| ('Content-Length', str(len(response_body)))] | |
| start_response(status, response_headers) | |
| return [response_body] |
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 App(object): | |
| def __init__(self, environ, start_response): | |
| self.environ = environ | |
| self.start_response = start_response | |
| def __iter__(self): | |
| status = '200 OK' | |
| response_body = "Hello World!" | |
| response_headers = [('Content-Type', 'text/plain'), | |
| ('Content-Length', str(len(response_body)))] |
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 wsgiref.simple_server import make_server | |
| httpd = make_server('', 8000, app) | |
| httpd.serve_forever() |
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 dump_environ_app(environ, start_response): | |
| response_body = "\n".join(["{0}: {1}".format(k, environ[k]) for k in environ.keys()]) | |
| status = '200 OK' | |
| response_headers = [('Content-Type', 'text/plain'), | |
| ('Content-Length', str(len(response_body)))] | |
| start_response(status, response_headers) | |
| return [response_body] |
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 werkzeug import url_decode | |
| class MethodRewriteMiddleware(object): | |
| """ | |
| app = MethodRewriteMiddleware(app) | |
| """ | |
| def __init__(self, app, input_name = '__method__'): | |
| self.app = app | |
| self.input_name = input_name |
OlderNewer