Skip to main content

Posts

Web App Scaling with Flask Blueprint and Namespaces

A real-world Flask-RESTX-based API  may have multiple namespaces. The best practice for scaling a web application is to use a blueprint along with multiple namespace. The namespace is used to group a set of CRUD operations for a specific resource.  Blueprint can be used to combine (mixing) multiple namespaces. Here’s an example directory structure: project\ ├── app.py # Application file ├── apis #    ├── v20 # API directory    │   ├── __init__.py    │   ├── specs.py # API namespaces and REST methods    │   ├── steps.py # API namespaces and REST methods    └── v20bp.py # API blueprint file Here is an example app.py. Using a blue print allow you to mount your API on any url prefix. from flask import Flask from apis.v20bp import blueprint as api app = ...

Documenting REST API with Flask-Restx

This tutorial aims to use the Flask-restx library to implement and to document the REST API. Other similar libraries in the Flask framework include the   flask_resful and  Flask-restplus libraries.  The generated document is shown below.  All the operations are group into a default namespace. All the CRUD operations get, create, and update (except for the the delete operation) are displayed  below.  References -  https://flask-restx.readthedocs.io/en/latest/ -  https://preslav.me/2018/12/02/designing-well-structured-rest-apis-with-flask-restplus-part-1/ -  https://www.freecodecamp.org/news/structuring-a-flask-restplus-web-service-for-production-builds-c2ec676de563/ -  https://github.com/cosmic-byte/flask-restplus-boilerplate

API implementation in the Python Flask Web Application Framework

Flask is a lightweight web application framework based on Python.  The Flask framework only supply the core components of a web applications and leaves the remaining design and architecture level decisions to the developer. This is my study note on how to extend  how to extend a web application with an application programming interface (or API) .  REST (REpresentational State Transfer) is one of the standard architectural design for web services and web APIs. he following example is based on Flask Mega Tutorial  . There is a section dedicated for implementing API for a web application.  The quick start section of the   flask_resful library provides explanation for the following modules.   Resource reqparse  -  provide simple and uniform access to any variable on the   flask.request  object in Flask fields marshal - Flask      - https://en.wikipedia.org/wiki/Flask_(web_framework) - BluePrint     ...

IBM Watson Annotator for Clinical Data

IBM Watson Annotator for Clinical Data Is Now Generally Available on May 12, 2020  Explore healthcare insights from unstructured data with this new service on IBM Cloud. The practice of medicine is intertwined with patient data that allows doctors and nurses to diagnose illnesses. What symptoms does a patient have, and how does a healthcare worker describe a set of symptoms for others to treat? In today’s globalized world, the treatment can even be carried out by doctors and nurses on the other side of the globe. IBM Watson Annotator for Clinical Data —now generally available on IBM Cloud—delivers natural language processing (NLP) that is tailored for healthcare and life sciences and designed to enable organizations to utilize insights derived from unstructured text.  The medical domain NLP service features a variety of annotators for detecting metadata (such as entities, concepts, concept values, negated spans, hypothetical spans) and a...

Window OS

Here is a list of tools I have used in the Window OS Window Environment Window Command Line Window gflags.exe EmacsW32 TortoiseSVN Microsoft Visual Studio 2008 Incredibuild WinMerge Notepad++ Miktex(Protext) Jabref Bibtex4Word - to use bibTeX in Microsoft Word Cygwin TODO: Opening a huge text file in window Splitting a huge text file into multiple small files Window Environment My Computer > Properties > Advanced > Environment Variables > PATH To maximize a window, use the Alt-Space-x Window-E --> To lunch explorer Window-L --> To lock the screen Window-R --> To open up the run window Window-D --> To minimize all the window Window Command Lines proxycfg --> To find out the proxy server xcopy Tortoise SVN TSVNcache.exe is used by Tortoise SVN to continously check the status of sandboxes. This process requires a lot of resources. To disable the TSVNcache.exe, go to > All Program > Tortoise SVN > Settings > Icon Overlays > Status Cache > None E...

firefox 3.0 full screen mode

In my ubuntu 8.10 system, I don't like the new feature of firefox 3.0 that always starts in a full screen mode. To disable the feature, go to the user's profile folder which is located in ~/.mozilla/firefox/ folder, and find the file "localstore.rdf". Rename the file to something else, such as "localstore_rdf_bak", and it should fix the problem.

mounting fat32 partition in Ubuntu 8.10

I like to use a fat32 partition as a shared partition, and want to be able to read and write in that partition. Thus, I modify my /etc/fstab to include the following command, i.e. /dev/sda2 /media/sda2 vfat defaults,utf8,umask=077,gid=1000,uid=1000 0 0 the key is to specify 1. umask=077; it means only the user has the right to read-write-execute. 2. uid=1000,gid=1000 are the user id and the group id of the owner. well, it is not perfect but it suits my need.

Installing latex-beamer on local directory

First, let the latex aware of the new local directory: Check out the current configuration file by:kpsewhich texmf.cnf Copy the texmf.cnf into /home/userName/texmf Modify the texmf.cnf by add the new directory into the variable TEXMF into texmf.cnf set up the environment variable TEXMFCNF=/home/userName/texmf either in bashrc or cshrc Notice that kpsewhich texmf.cnf will return the new local directory after that By doing so, from now on, latex is going to check the local directory for any style file. Now, assume the local installation directory is going to be /home/userName/texmf/ Download latex-beamer-versionNumber.tar.gz Create directories /home/userName/texmf/tex/latex/ ln -s /path/to/latex-beamer-versionNumber.tar.gz /home/userName/texmf/tex/latex/ Extract the latex beamer over ther, i.e. tar -xzvf latex-beamer-versionNumber.tar.gz sudo update-texmf sudo texhash

using kdevelop to setup moses machine translation decoder

To setup ~/tl/dbgC/D0901aMoses/ver11 Make sure language model SRILM is compiled in ~/tl/binC/B0901aSRILM157/ver01. Specifically we need the include and lib directories. Create a new subproject, and name it as Amoses, copy *.cpp and *.h files into the subproject, and remove LanguageModelIRSTLM.cpp. Link the include file of srilm project into this folder. Create a new subproject, and name it as AmosesCmd. Include the library from srilm, i.e. liboolm.a, libmisc.a, and libdstruct.a. Moreover, we need /usr/lib64/libz.a or -lz. In LINK LIBRARY OUTSIDE PROJECT add/edit the link to external library path and static library, e.g. -L/storage/sda9/tl09/binC/B0901aSRILM157/ver01/lib/i686-m64,-L/storage/sda9/tl09/dbgC/D0901aMoses/ver11/debug/src/Amoses/, -lmosesA, -lmisc, -loolm, -ldstruct, -lz. Set CXXFLAGS in SUBPROJECT Option using the following compiler setting: -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -DHAVE_CONFIG_H -DHAVE_SRILM

compiling HTK 3.4 under Ubuntu 64 bit machine

Make sure you have install Install sudo apt-get install libc6-dev-i386 download getlibs from http://ubuntuforums.org/showthread.php?t=474790 sudo dpkg -i --force-all package_name.deb install 32-bit version of x11 using the command sudo getlibs -p libx11-dev Configure ./configure CC=gcc-3.4 --prefix=installation/location --disable-hlmtools

fancyvrb

I like to type source code in latex. Here is the latex code to include source code in a latex file. \begin{Verbatim}[frame=single, label=Title is here, commentchar=!, rulecolor=\color{red}] Verbatim line. \end{Verbatim} See Also: http://gentoo.chem.wisc.edu/tex-archive/macros/latex/contrib/fancyvrb/fancyvrb.pdf

Open pdf in pagewidth mode

I like to open a pdf file in fit width mode and without the taskbar, etc. One may use the following latex cod \usepackage{hyperref} % link from toc \hypersetup{ pdfstartview=FitH, % Fit, FitH, FitV, FitR, FitB, FitBH, FitBV pdfpagemode=None, % None FullScreen UseThumbs UseOutlines colorlinks=true, % false: boxed links; true: colored links linkcolor=blue, % color of internal links } See Also: http://www.andy-roberts.net/misc/latex/pdftutorial.html

Kdevelop failed to build even a simple "hello world" program (kdevelop and libtool)

Kdevelop failed to build even a simple "hello world" program, the reason is due to libtool: Create a new project using the "C++/Hello World Program" template Replace the project's ltmain.sh by /usr/share/libtool/ltmain.sh build the project For more explanation, please visit http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=351358 N.B. In Ubuntu 8.10, the file is located in /usr/share/libtool/config/ltmain.sh

ls in ubuntu emacs

Emacs shell mode can be executed using (M-x shell). When doing a listing using 'ls', the control characters mixed in with the listing. The solution is to unalias ls bash> alias ls alias ls='ls --color=auto' bash> unalias ls bash> ls

skype on 64 bit ubuntu 8.10

I was not able to use skype on ubuntu 8.10 due to audio issue, e.g. ALSA lib ../../../src/pcm/pcm.c:2156:(snd_pcm_open_conf) Cannot open shared library /usr/lib32/alsa-lib/libasound_module_pcm_bluetooth.so The solution I use is bash >> sudo killall -9 pulseaudio

Installing SRILM 156 in Ubuntu 8.04

0. untar the source distribution in SRILM_DIR 1. set the environment variable bash> export SRILM=SRILM_DIR 2. check the gcc version and the location of tcl library e.g. bash> gcc --version bash> which gcc bash> whereis tcl 3. edit the common/Makefile.machine.i686-gcc4 bash> chmod u+rwx Makefile.machine.i686-gcc4 bash> emacs -nw Makefile.machine.i686-gcc4 # GCC_FLAGS = -mtune=pentium3 -Wreturn-type -Wimplicit # CC = /usr/local/lang/gcc-4.2.2/bin/gcc $(GCC_FLAGS) # CXX = /usr/local/lang/gcc-4.2.2/bin/g++ $(GCC_FLAGS) -DINSTANTIATE_TEMPLATES GCC_FLAGS = -mtune=pentium3 -Wreturn-type -Wimplicit CC = /usr/bin/gcc $(GCC_FLAGS) CXX = /usr/bin/g++ $(GCC_FLAGS) -DINSTANTIATE_TEMPLATES ... #ADDITIONAL_INCLUDES = ADDITIONAL_INCLUDES = -I/usr/include/tcl 4. Make bash> make 1> logFile 2> errFile 5. That is it