Friday, October 16, 2015

The hello world web app of OAuth 2.0 client for Google App Engine

The sample project is here.

However, the missing installation and setup instructions for development server are:
(1) download the above project sample and say put it in project folder called helloworld
(2) install google-api-python-client in the project folder helloworld
(2a) Create a file in the project folder with the following contents
from google.appengine.ext import vendor

# Add any libraries installed in the "lib" folder.

(2b) Download google-api-python-client and related libraries into the lib sub-folder of the project folder
cd helloworld
mkdir lib
# if your Mac doesn't have pip do this -> sudo easy_install -U pip
pip install -t lib google-api-python-client

(3) Follow the instructions in here to setup OAuth 2.0 in the developer console for web app in Google App Engine Developer Console

(4) Make sure to enable Google+ API in the console or else you will get KeyError: 'id' when testing

(5) Fill in Authorised Javascript origins and Authorised redirect URIs in the developer console and click create or save

(6) copy the created Client ID and Client secret from the developer console and fill in the file client_secrets.json, like below

(7) Wait a few minutes and start the development server and test

Here is how to add other OAuth 2.0 apps such as Windows Live or facebook.
(1) Setup and revoke websites are :
# Google+ APIs
# Manage Application -
# Revoke Consent -
# OAuth 2.0 info

# Windows Live API
# Manage Application -
# Revoke Consent -
# OAuth 2.0 info

# Facebook auth apis
# Manage Application -
# Revoke Consent Procedure
# Log on to Facebook.
# Click the drop-down arrow in the upper right, then select "Settings"
# Select "Apps" on the left sidebar.
# Scan the list and click the "x" on the right of any app you want to clear.

(2.1) The client_secrets_windows_live.json file is like this
  "web": {
    "client_id": "0000000012345678",
    "client_secret": "abcdefg1lHiJK5HCnlZb-aaaaaXX",
    "redirect_uris": ["http://localhost:8080/windows_live_callback"],
    "auth_uri": "",
    "token_uri": ""

(2.2) The client_secrets_facebook.json files is like this
  "web": {
    "client_id": "123456789012345",
    "client_secret": "a1234567e123456bc4b123456ab6543g",
    "redirect_uris": ["http://localhost:8080/facebook_callback"],
    "auth_uri": "",
    "token_uri": ""

(3.1) The decorator_windows_live is like these
# Scopes are space-separated, e.g. 'wl.signin wl.basic'.
decorator_windows_live = appengine.oauth2decorator_from_clientsecrets( os.path.join(os.path.dirname(__file__), 'client_secrets_windows_live.json'), scope='wl.signin wl.basic', message=MISSING_CLIENT_SECRETS_MESSAGE)

(3.2) The decorator_facebook is like this
# Multiple Scopes should be comma-separated, e.g. 'user_about_me,email'.
decorator_facebook = appengine.oauth2decorator_from_clientsecrets( os.path.join(os.path.dirname(__file__), 'client_secrets_facebook.json'), scope='user_about_me,email', message=MISSING_CLIENT_SECRETS_MESSAGE)

Monday, October 12, 2015

The Hello World of Google Protocol RPC (javascript part)

The Hello World of Google Protocol RPC using python is here

with an example on Testing the Service from the Command Line

Here I add the javascript part on how to test the RPC service in the browser using the google app engine
templates/index.html    Select all
<!DOCTYPE html> <html><head><title>post service demo</title> <script src="//"></script> <script language="javascript" type="text/javascript"> function submitform() { $.ajax({ headers: { "Accept": "application/json", "Content-Type": "application/json" }, type: "POST", url : "/hello.hello", dataType : "json", data : JSON.stringify({"my_name": $("#my_name").val()}), error: function () { alert("loading Ajax failure"); }, onFailure: function () { alert("Ajax Failure"); }, statusCode: { 404: function() { alert("missing info"); } }, success: function (response) { alert("The server says: " + JSON.stringify(response)); } }) .done(function(data) { $("#result").text(data["hello"]); }); };</script></head> <body> <h1>Hello world!</h1><br> <p><form id="myform" method="post" action="/hello.hello"><input type="text" id="my_name" name="my_name" value="javacom"><input type="button" id="submit" value="submit" onclick="submitform();"></form></p> <p><div id="result"></div></p> </body> </html>    Select all
import os import jinja2 import webapp2 TEMPLATE_DIR = 'templates' JINJA_ENVIRONMENT = jinja2.Environment( loader=jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__), TEMPLATE_DIR)), extensions=['jinja2.ext.autoescape'], autoescape=True) class MainHandler(webapp2.RequestHandler): def get(self): template = JINJA_ENVIRONMENT.get_template('index.html') self.response.write(template.render()) app = webapp2.WSGIApplication([ ('/', MainHandler) ], debug=True)

app.yaml    Select all
application: helloworld version: 1 runtime: python27 api_version: 1 threadsafe: yes handlers: - url: /hello.* script: - url: .* script: libraries: - name: webapp2 version: "2.5.2" - name: jinja2 version: "2.6"

Saturday, October 3, 2015

How to compile Quantlib and Boost under Windows 10

(1) Download and install Visual Studio Express 2015 for Windows Desktop. Note that Express comes in a variety of versions. The one needed to compile console programs is Express for Windows Desktop (neither Express for Web nor Express for Windows will do)

(2) Download and install boost Prebuilt windows binaries - boost_1_59_0-msvc-14.0-32.exe from
For 64 bit version, it is boost_1_59_0-msvc-14.0-64.exe
say install to D:\local\boost_1_59_0

(3) Download and unzip from
The updated version of QuantLib is 1.80

(4) Start Visual Studio Express 2015 and open project solution QuantLib_vc14.sln in the extracted quantlib folder.

(5) Multi-select all projects (except the solution) and click the setting icon to bring up the property page.

(6) Select All Configurations and All Platforms. Add D:\local\boost_1_59_0; to the Property Pages : VC++ Include directories.
And also add ;D:\local\boost_1_59_0\lib32-msvc-14.0; to the Library directories.

(7) Add /wd4819 to Command Line : Additional Options to disable C4819 warnings when compiling Quantlib.

(8) Build Debug / Release Win32 Solution using shortcut key (Fn-F7)
Choose Static Runtime Configurationif this is available

(9) After build, highlight the quantlib solution and edit the solution property pages by clicking the setting icon or use the shortcut key (Shift-Fn-F4)

(9.1) Choose a project say Bonds as startup project

(9.2) And then Debug / Release Run (Control-Fn-F5)
Choose Static Runtime Configurationif this is available

(9.3) If run test-suite, this command line argument should be added.
--log_level=message --build_info=yes --result_code=no --report_level=short

vim +196 Packages/SwiftDate-1.0.0/SwiftDate/Term.swift    Select all
mkdir -p Frameworks/boost.framework/Versions/1.60.0/Resources cat > Frameworks/boost.framework/Versions/1.60.0/Resources/Info.plist <<EOF <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" ""> <plist version="1.0"> <dict> <key>CFBundleDevelopmentRegion</key> <string>English</string> <key>CFBundleExecutable</key> <string>boost</string> <key>CFBundleIdentifier</key> <string>org.boost</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundlePackageType</key> <string>FMWK</string> <key>CFBundleSignature</key> <string>????</string> <key>CFBundleVersion</key> <string>1.60.0</string> </dict> </plist> EOF ln -s ${HOME}/boost_1_60_0/boost Frameworks/boost.framework/Versions/1.60.0/Headers ln -s ${HOME}/boost_1_60_0/doc Frameworks/boost.framework/Versions/1.60.0/Documentation ar crus Frameworks/boost.framework/Versions/1.60.0/boost boost_1_60_0/stage/lib/libboost_*.a (cd Frameworks/boost.framework/Versions; ln -s 1.60.0 Current) (cd Frameworks/boost.framework; ln -s Versions/Current/* .) mkdir -p Frameworks/ql.framework/Versions/1.7/Resources cat > Frameworks/ql.framework/Versions/1.7/Resources/Info.plist <<EOF <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" ""> <plist version="1.0"> <dict> <key>CFBundleDevelopmentRegion</key> <string>English</string> <key>CFBundleExecutable</key> <string>ql</string> <key>CFBundleIdentifier</key> <string>org.boost</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundlePackageType</key> <string>FMWK</string> <key>CFBundleSignature</key> <string>????</string> <key>CFBundleVersion</key> <string>1.7</string> </dict> </plist> EOF ln -s ${HOME}/QuantLib-1.7/Docs Frameworks/ql.framework/Versions/1.7/Documentation ln -s ${HOME}/QuantLib-1.7/prefix/usr/local/include/ql Frameworks/ql.framework/Versions/1.7/Headers ln -s ${HOME}/QuantLib-1.7/prefix/usr/local/lib/libQuantLib.a Frameworks/ql.framework/Versions/1.7/ql (cd Frameworks/ql.framework/Versions; ln -s 1.7 Current) (cd Frameworks/ql.framework; ln -s Versions/Current/* .)