2014年9月18日 星期四

Install Flask on CentOS 7.0

1. Install pip on CentOS 7.0

## First install the EPEL repo as per your Operating system version and architecture.
rpm -ivh http://mirror01.idc.hinet.net/EPEL/7/x86_64/e/epel-release-7-1.noarch.rpm
yum install -y python-pip

2. Install Flask

pip install Flask

## Test
vi hello.py

from flask import Flaskapp = Flask(__name__)
@app.route("/")def hello():    return "Hello World!"
if __name__ == "__main__":    app.run()

## Verify
python hello.py

* Running on http://0.0.0.0:80/

2014年7月17日 星期四

Python: ConfigParser

[core]
cmd = /usr/bin/vim

[mod]
safe_edit = yes
time_interval = 20

python 程式如下:
#!/usr/bin/python
from ConfigParser import SafeConfigParser
parser = SafeConfigParser()
parser.read('test.conf')

#傳回字串 /usr/bin/vim
parser.get('core', 'cmd')

#傳回 boolean 值 True
parser.getboolean('mod', 'safe_edit')

#傳回整數值 20
parser.getint('mod', 'time_interval')


references:
http://williewu.blogspot.tw/2007/10/python-configparser.html
https://wiki.python.org/moin/ConfigParserExamples
https://docs.python.org/2.6/library/configparser.html

How to find script's directory

import os
print os.path.dirname(os.path.realpath(__file__))

reference:
http://stackoverflow.com/questions/4934806/python-how-to-find-scripts-directory

2014年7月15日 星期二

strip in C programming


strtok(Name, "\n");

references:
http://stackoverflow.com/questions/2693776/removing-trailing-newline-character-from-fgets-input