Docker is available for Linux, MacOS, and Windows.
Docker for Mac is best installed with Homebrew and Homebrew Cask. For other ways to install on MacOS, see Install Docker for Mac in Docker's docs.
brew cask install docker # Install Docker| import datetime | |
| from typing import Union | |
| def get_start_of_week(dt: Union[datetime.datetime, datetime.date], weeks_from_now: int = 0) -> datetime.datetime: | |
| """ Given a `datetime.date` or `datetime.datetime` instance, return | |
| a `datetime.datetime` instance corresponding to the first day | |
| (i.e., Sunday) of that week. | |
| This function makes it really easy to calculate days-of-the-week from now. |
Docker is available for Linux, MacOS, and Windows.
Docker for Mac is best installed with Homebrew and Homebrew Cask. For other ways to install on MacOS, see Install Docker for Mac in Docker's docs.
brew cask install docker # Install Docker| #!/bin/bash | |
| set -e | |
| DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
| GCLOUD_ORG_ID="" | |
| GCLOUD_BILLING_ACCOUNT_ID="" | |
| # These variables should be edited for project id uniqueness | |
| RANDOM_STR="kasdfj" # for entropy |
| import functools | |
| import itertools | |
| import logging | |
| import time | |
| log = logging.getLogger(__name__) | |
| def retry(times, timeout=0.2, exceptions=None): |
| """Python 3 has a ContextDecorator class mixin that allows context | |
| managers to be used as decorators also. Even better, the decorator | |
| has optional arguments. | |
| If python2, $ pip install contextlib2 | |
| """ | |
| from __future__ import absolute_import | |
| import functools |
| #!/usr/bin/env python | |
| """ Run multiple flask apps in the same process, hosted at different domain names. | |
| I choose a domain alias for my app, say `myapp.com` then add to my hosts file. Then | |
| my hosts file will have these entries:: | |
| 127.0.0.1 myapp.com www.myapp.com admin.myapp.com | |
| You can use a `defaultdict` with `redirect_create_app` to redirect all requested hostnames | |
| not in `SubdomainDispatcher.registry` to a default location. As an example, after starting the server |
| class SentinelInt(int): | |
| """Makes unique sentinel values that look like integers but equality | |
| is overridden. | |
| >>> SentinelInt(0) == SentinelInt(0) | |
| False | |
| >>> s = SentinelInt(0) | |
| >>> s == s | |
| True | |
| """ |
| import functools | |
| import itertools | |
| import logging | |
| import time | |
| log = logging.getLogger(__name__) | |
| def retry(times, timeout=0.2, exceptions=None): |
| """ We have discovered some test packages weren't autodiscovered | |
| because they didn't have an __init__.py file. This module walks through | |
| the directory tree to ensure that each directory with a Python file also | |
| has __init__.py. | |
| TODO: add directory exclusion handling. | |
| Cool. Now walk it out | |
| """ | |
| from functools import wraps |
| from contextlib import contextmanager | |
| import sys | |
| @contextmanager | |
| def transform_exception(new_exception, new_message=None, exceptions=None): | |
| """Ok, this is hacky. Takes any exception listed in `exceptions`, | |
| reraises as `new_exception` type but preserves the old stack trace. | |
| This is useful if you are writing a library and want to transform a |