To keep your prompt (PS1) with color shown in tmux screen, add the following property in .bashrc:
force_color_prompt=yes
Tuesday, December 17, 2019
Create docker container with the simple flask application
I will try to create a docker container with the simple flask application created some times ago.
First, I create a shell script for starting the flask application, namely "boot.sh":
boot.sh
#!/bin/sh
export FLASK_APP=simple.py
flask run --host 0.0.0.0
export FLASK_APP=simple.py
flask run --host 0.0.0.0
Second, we need to create a requirements.txt file:
requirements.txt
flask==1.1.1
Actually you can run the following to get the requirements.txt:
pip freeze > requirements.txt
Third, together with the simple.py file created in the simple flask application, put those 3 files in an "app" directory:
app/
- boot.sh
- requirements.txt
- simple.py
Forth, create a Docker file outside the app directory:
Dockerfile
FROM python:3.6-alpine
WORKDIR /home/app
COPY app/ ./
RUN chmod +x ./boot.sh
RUN pip install -r requirements.txt
EXPOSE 5000
ENTRYPOINT ["./boot.sh"]
WORKDIR /home/app
COPY app/ ./
RUN chmod +x ./boot.sh
RUN pip install -r requirements.txt
EXPOSE 5000
ENTRYPOINT ["./boot.sh"]
Build the docker image using the Dockerfile:
docker build -t simple:latest .
Run the docker container with the docker image we just created:
docker run -d -p 5000:5000 simple:latest
Check "http://localhost:5000" to check the Flask application.
Simple Flask sample
Just wanna to create a very simple Flask application in a single python source file:
simple.py
To run this Flask application, run the following:
Now, navigate "http://localhost:5000" to see the word "Hello World" displayed on the browser.
simple.py
from flask import Flask
application = Flask("simple")
@application.route("/")
def index():
return "Hello World"
To run this Flask application, run the following:
- export FLASK_APP=simple.py
- flask run
- flask run --host 0.0.0.0
Now, navigate "http://localhost:5000" to see the word "Hello World" displayed on the browser.
Monday, December 16, 2019
Navigate tmux splitted pane using mouse
To enable navigation on tmux splitted pane using mouse
In tmux environment, do the following:
In tmux environment, do the following:
- Ctrl-b
- Type :setw -g mouse on
Done, try to switch your tmux pane with mouse.
Note:
To make this setting persistent, save this line in .tmux.conf:
setw -g mouse on
To make this setting persistent, save this line in .tmux.conf:
setw -g mouse on
Tuesday, December 10, 2019
Assign locale for moment.js
To assign locale in moment.js, we can use the following:
moment.locale("en")
It will returns "en". However, if you assign an unaccepted locale to it, it won't update its value. For example:
moment.locale("zh")
It still returns "en", since "zh" is not an accepted locale for moment.js.
Up till now, moment.js accepts:
zh-hk
zh-tw
zh-cn
Reference: momentjs
moment.locale("en")
It will returns "en". However, if you assign an unaccepted locale to it, it won't update its value. For example:
moment.locale("zh")
It still returns "en", since "zh" is not an accepted locale for moment.js.
Up till now, moment.js accepts:
zh-hk
zh-tw
zh-cn
Reference: momentjs
Tuesday, December 3, 2019
QGIS freezes while editing features
There are many possibilities for QGIS to hang / freezes while editing features. But for my experience, I found it often hangs when using a Shapefile layer.
To minimize this kind of problem, I tried to use other feature format (e.g. SpatialLite). And the problem is relieved to some extent.
Have a try and let me know if it helps or not.
To minimize this kind of problem, I tried to use other feature format (e.g. SpatialLite). And the problem is relieved to some extent.
Have a try and let me know if it helps or not.
Monday, December 2, 2019
Windows equivalent of "wc -l" command in Linux
To count the number lines of files / stdout in Linux, we uses "wc -l" to achieve. In Windows, we use the following instead:
For example, suppose we have a file "sample_file.txt" and we want to know the number of lines of that file, we can perform the following:
- find /c /v ""
For example, suppose we have a file "sample_file.txt" and we want to know the number of lines of that file, we can perform the following:
- type sample_file.txt | find /c /v ""
Sunday, December 1, 2019
Handling table names with underscore ("_") in flask_sqlalchemy / Python
When you create table class using flask_sqlalchemy (the Flask extension for SQLAlchemy), it can maps the modal class to a proper table automatically. This is cool but if you have a table name with underscore (e.g. MY_SAMPLE_TABLE) and you name your model class with the underscore ('_') as usual, you will find SQLAlchemy will map your table name as something the following:
"MY__SAMPLE__TABLE"
Each single underscore (_) with becomes a double underscores (__). This is annoying and you might believe this is a bug, but in fact you can resolve this issues by naming your table class using the PEP8 naming convention, and named your class as:
class MySampleTable(db.Model):
field_id = db.Column(db.Integer, primary_key = True)
field_data = db.Column(db.String(200))
The the SQLAlchemy will map the MySampleTable class to table name as "MY_SAMPLE_TABLE" correctly.
For more information about PEP8, click here for details.
"MY__SAMPLE__TABLE"
Each single underscore (_) with becomes a double underscores (__). This is annoying and you might believe this is a bug, but in fact you can resolve this issues by naming your table class using the PEP8 naming convention, and named your class as:
class MySampleTable(db.Model):
field_id = db.Column(db.Integer, primary_key = True)
field_data = db.Column(db.String(200))
The the SQLAlchemy will map the MySampleTable class to table name as "MY_SAMPLE_TABLE" correctly.
For more information about PEP8, click here for details.
Subscribe to:
Posts (Atom)
Sync multiple git repo at once
Use the following command in Linux will do the job: ls -d RepoNames* | xargs -I{} git -C {} pull
-
When Office2003 couldn't find file SKU011.CAB: regedit -> [HKEY_LOCAL_MACHINE] -> [SOFTWARE] -> [Microsoft] -> [Office] -&...
-
The resolution can be changed by editing the BlueStack's registry: HKLM\SOFTWARE\BlueStacks\Guests\Android\FrameBuffer\0\Height and ...
-
To count the number lines of files / stdout in Linux, we uses "wc -l" to achieve. In Windows, we use the following instead: find...