-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c3c26ee
Showing
290 changed files
with
556,432 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Contributing to Apress Source Code | ||
|
||
Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers. | ||
|
||
## How to Contribute | ||
|
||
1. Make sure you have a GitHub account. | ||
2. Fork the repository for the relevant book. | ||
3. Create a new branch on which to make your change, e.g. | ||
`git checkout -b my_code_contribution` | ||
4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted. | ||
5. Submit a pull request. | ||
|
||
Thank you for your contribution! |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Freeware License, some rights reserved | ||
|
||
Copyright (c) 2018 Manuel Amunategui and Mehdi Roopaei | ||
|
||
Permission is hereby granted, free of charge, to anyone obtaining a copy | ||
of this software and associated documentation files (the "Software"), | ||
to work with the Software within the limits of freeware distribution and fair use. | ||
This includes the rights to use, copy, and modify the Software for personal use. | ||
Users are also allowed and encouraged to submit corrections and modifications | ||
to the Software for the benefit of other users. | ||
|
||
It is not allowed to reuse, modify, or redistribute the Software for | ||
commercial use in any way, or for a user’s educational materials such as books | ||
or blog articles without prior permission from the copyright holder. | ||
|
||
The above copyright notice and this permission notice need to be included | ||
in all copies or substantial portions of the software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Apress Source Code | ||
|
||
|
||
|
||
This repository accompanies [*Monetizing Machine Learning*](http://www.apress.com/9781484238721) by Manuel Amunategui and Mehdi Roopaei (Apress, 2018). | ||
|
||
|
||
|
||
[comment]: #cover | ||
|
||
![Cover image](9781484238721.jpg) | ||
|
||
|
||
|
||
Download the files as a zip using the green button, or clone the repository to your machine using Git. | ||
|
||
|
||
|
||
## Releases | ||
|
||
|
||
|
||
Release v1.0 corresponds to the code in the published book, without corrections or updates. | ||
|
||
|
||
|
||
## Contributions | ||
|
||
|
||
|
||
See the file Contributing.md for more information on how you can contribute to this repository. |
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from flask import Flask | ||
|
||
# EB looks for an 'application' callable by default. | ||
application = Flask(__name__) | ||
|
||
@application.route("/", methods=["GET"]) | ||
def hello(): | ||
return "Hello World!" | ||
|
||
if __name__ == "__main__": | ||
application.run() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Flask |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
runtime: python27 | ||
api_version: 1 | ||
threadsafe: true | ||
|
||
handlers: | ||
- url: /static | ||
static_dir: static | ||
- url: /.* | ||
script: main.app | ||
- url: /favicon.ico | ||
static_files: static/images/favicon.ico | ||
upload: static/images/favicon.ico | ||
|
||
libraries: | ||
- name: ssl | ||
version: latest |
4 changes: 4 additions & 0 deletions
4
chapter1/serverless-hosting-on-google-cloud/appengine_config.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from google.appengine.ext import vendor | ||
|
||
# Add any libraries installed in the "lib" folder | ||
vendor.add('lib') |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from flask import Flask | ||
app = Flask(__name__) | ||
|
||
@app.route("/") | ||
def hello(): | ||
return "Hello World!" | ||
|
||
if __name__ == '__main__': | ||
app.run() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Flask>=0.12 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from flask import Flask | ||
app = Flask(__name__) | ||
|
||
@app.route("/") | ||
def hello(): | ||
return "Hello World!" | ||
|
||
if __name__ == '__main__': | ||
app.run() |
122 changes: 122 additions & 0 deletions
122
chapter1/serverless-hosting-on-microsoft-azure/ptvs_virtualenv_proxy.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# ############################################################################ | ||
# | ||
# Copyright (c) Microsoft Corporation. | ||
# | ||
# This source code is subject to terms and conditions of the Apache License, Version 2.0. A | ||
# copy of the license can be found in the License.html file at the root of this distribution. If | ||
# you cannot locate the Apache License, Version 2.0, please send an email to | ||
# vspython@microsoft.com. By using this source code in any fashion, you are agreeing to be bound | ||
# by the terms of the Apache License, Version 2.0. | ||
# | ||
# You must not remove this notice, or any other, from this software. | ||
# | ||
# ########################################################################### | ||
|
||
import datetime | ||
import os | ||
import sys | ||
import traceback | ||
|
||
if sys.version_info[0] == 3: | ||
def to_str(value): | ||
return value.decode(sys.getfilesystemencoding()) | ||
|
||
def execfile(path, global_dict): | ||
"""Execute a file""" | ||
with open(path, 'r') as f: | ||
code = f.read() | ||
code = code.replace('\r\n', '\n') + '\n' | ||
exec(code, global_dict) | ||
else: | ||
def to_str(value): | ||
return value.encode(sys.getfilesystemencoding()) | ||
|
||
def log(txt): | ||
"""Logs fatal errors to a log file if WSGI_LOG env var is defined""" | ||
log_file = os.environ.get('WSGI_LOG') | ||
if log_file: | ||
f = open(log_file, 'a+') | ||
try: | ||
f.write('%s: %s' % (datetime.datetime.now(), txt)) | ||
finally: | ||
f.close() | ||
|
||
ptvsd_secret = os.getenv('WSGI_PTVSD_SECRET') | ||
if ptvsd_secret: | ||
log('Enabling ptvsd ...\n') | ||
try: | ||
import ptvsd | ||
try: | ||
ptvsd.enable_attach(ptvsd_secret) | ||
log('ptvsd enabled.\n') | ||
except: | ||
log('ptvsd.enable_attach failed\n') | ||
except ImportError: | ||
log('error importing ptvsd.\n') | ||
|
||
def get_wsgi_handler(handler_name): | ||
if not handler_name: | ||
raise Exception('WSGI_ALT_VIRTUALENV_HANDLER env var must be set') | ||
|
||
if not isinstance(handler_name, str): | ||
handler_name = to_str(handler_name) | ||
|
||
module_name, _, callable_name = handler_name.rpartition('.') | ||
should_call = callable_name.endswith('()') | ||
callable_name = callable_name[:-2] if should_call else callable_name | ||
name_list = [(callable_name, should_call)] | ||
handler = None | ||
last_tb = '' | ||
|
||
while module_name: | ||
try: | ||
handler = __import__(module_name, fromlist=[name_list[0][0]]) | ||
last_tb = '' | ||
for name, should_call in name_list: | ||
handler = getattr(handler, name) | ||
if should_call: | ||
handler = handler() | ||
break | ||
except ImportError: | ||
module_name, _, callable_name = module_name.rpartition('.') | ||
should_call = callable_name.endswith('()') | ||
callable_name = callable_name[:-2] if should_call else callable_name | ||
name_list.insert(0, (callable_name, should_call)) | ||
handler = None | ||
last_tb = ': ' + traceback.format_exc() | ||
|
||
if handler is None: | ||
raise ValueError('"%s" could not be imported%s' % (handler_name, last_tb)) | ||
|
||
return handler | ||
|
||
activate_this = os.getenv('WSGI_ALT_VIRTUALENV_ACTIVATE_THIS') | ||
if not activate_this: | ||
raise Exception('WSGI_ALT_VIRTUALENV_ACTIVATE_THIS is not set') | ||
|
||
def get_virtualenv_handler(): | ||
log('Activating virtualenv with %s\n' % activate_this) | ||
execfile(activate_this, dict(__file__=activate_this)) | ||
|
||
log('Getting handler %s\n' % os.getenv('WSGI_ALT_VIRTUALENV_HANDLER')) | ||
handler = get_wsgi_handler(os.getenv('WSGI_ALT_VIRTUALENV_HANDLER')) | ||
log('Got handler: %r\n' % handler) | ||
return handler | ||
|
||
def get_venv_handler(): | ||
log('Activating venv with executable at %s\n' % activate_this) | ||
import site | ||
sys.executable = activate_this | ||
old_sys_path, sys.path = sys.path, [] | ||
|
||
site.main() | ||
|
||
sys.path.insert(0, '') | ||
for item in old_sys_path: | ||
if item not in sys.path: | ||
sys.path.append(item) | ||
|
||
log('Getting handler %s\n' % os.getenv('WSGI_ALT_VIRTUALENV_HANDLER')) | ||
handler = get_wsgi_handler(os.getenv('WSGI_ALT_VIRTUALENV_HANDLER')) | ||
log('Got handler: %r\n' % handler) | ||
return handler |
1 change: 1 addition & 0 deletions
1
chapter1/serverless-hosting-on-microsoft-azure/requirements.txt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Flask>=0.12 |
44 changes: 44 additions & 0 deletions
44
chapter1/serverless-hosting-on-microsoft-azure/web.3.4.config
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0"?> | ||
<configuration> | ||
<appSettings> | ||
<add key="WSGI_ALT_VIRTUALENV_HANDLER" value="main.app" /> | ||
<add key="WSGI_ALT_VIRTUALENV_ACTIVATE_THIS" | ||
value="D:\home\site\wwwroot\env\Scripts\python.exe" /> | ||
<add key="WSGI_HANDLER" | ||
value="ptvs_virtualenv_proxy.get_venv_handler()" /> | ||
<add key="PYTHONPATH" value="D:\home\site\wwwroot" /> | ||
</appSettings> | ||
<system.web> | ||
<compilation debug="true" targetFramework="4.0" /> | ||
</system.web> | ||
<system.webServer> | ||
<modules runAllManagedModulesForAllRequests="true" /> | ||
<handlers> | ||
<remove name="Python27_via_FastCGI" /> | ||
<remove name="Python34_via_FastCGI" /> | ||
<add name="Python FastCGI" | ||
path="handler.fcgi" | ||
verb="*" | ||
modules="FastCgiModule" | ||
scriptProcessor="D:\Python34\python.exe|D:\Python34\Scripts\wfastcgi.py" | ||
resourceType="Unspecified" | ||
requireAccess="Script" /> | ||
</handlers> | ||
<rewrite> | ||
<rules> | ||
<rule name="Static Files" stopProcessing="true"> | ||
<conditions> | ||
<add input="true" pattern="false" /> | ||
</conditions> | ||
</rule> | ||
<rule name="Configure Python" stopProcessing="true"> | ||
<match url="(.*)" ignoreCase="false" /> | ||
<conditions> | ||
<add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true" /> | ||
</conditions> | ||
<action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" /> | ||
</rule> | ||
</rules> | ||
</rewrite> | ||
</system.webServer> | ||
</configuration> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Nothing to see here - PythonAnywhere has everything it needs directly on its website for this section. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from flask import Flask | ||
app = Flask(__name__) | ||
|
||
@app.route("/") | ||
def hello(): | ||
return "Hello World!" | ||
|
||
if __name__ == '__main__': | ||
app.run() |
Oops, something went wrong.