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/env python | |
| # -*- coding: utf-8 -*- | |
| """Resolve where some test fixture lives | |
| Provides CLI: | |
| * start -- location in tree of directories to start | |
| * resolve -- resource to resolve | |
| """ | |
| from glob import glob |
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/env python | |
| # -*- coding: utf-8 -*- | |
| """Resolve where some test fixture lives | |
| Provides CLI: | |
| * start -- location in tree of directories to start | |
| * resolve -- resource to resolve | |
| """ | |
| from glob import glob |
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 datetime import datetime, timedelta | |
| for year in range(2006, 2020): | |
| for month in range(1, 13): | |
| # Get the last day of the previous month | |
| d = datetime(year, month, 1) - timedelta(1) | |
| print(d.strftime("%Y-%m-%d")) |
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 elasticsearch import Elasticsearch | |
| from elasticsearch_dsl import Search, Index | |
| client = Elasticsearch() | |
| idx = client.indices.stats() | |
| for key in idx['indices'].keys(): | |
| if key.startswith('unittest'): | |
| print(key) | |
| Index(key, using=client).delete() |
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/env python | |
| import os | |
| from datetime import datetime | |
| from hashlib import sha1 | |
| OMITTED_FILES = set([".DS_Store"]) | |
| def sha1file(filename): |
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 a(throw_please=False): | |
| _ret = None | |
| _exc = None | |
| try: | |
| print("try") | |
| if throw_please: | |
| b = [] | |
| b[1] = 3 | |
| _ret = 4 | |
| except Exception as exc: |
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
| tzs = [ | |
| ("GMT", 0), | |
| ("Boston", -4), | |
| ("Denver", -6), | |
| ("Singapore", +8), | |
| ("Kyiv", +3), | |
| ] | |
| def time_in(city, offset): |
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
| ParamValidationMixin | |
| public_api/rest_generics/controllers.py | |
| - uses flask.request.view_args: http:/x.com/project/<pid> | |
| - derived from flask.MethodView, so REST methods are generated automatically | |
| - http://flask.pocoo.org/docs/0.12/views/#method-based-dispatching | |
| - values are accessible through dict named self.params | |
| - ParamValidationMixin.param_validator_class | |
| QueryValidationMixin | |
| public_api/rest_generics/filters.py |
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 flask import request | |
| request.view_args | |
| @app.route("/data/<section>") | |
| def data(section): | |
| assert section == request.view_args['section'] | |
| For URL Query parameter, use request.args | |
| search = request.args.get("search") | |
| page = request.args.get("page") |
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 foo(n): | |
| a = [] | |
| for i in range(n): | |
| a.append(i * 2) | |
| return a | |
| def bar(n): | |
| return [i * 2 for i in range(n)] | |
| >>> import timeit |