Saturday, October 11, 2014

Nginx + fastcgi/wsgi

Python web application normally should use wsgi as interface, but nginx only support fascgi, scgi,uwsgi and no wsgi support.

flup is python library which could convert your wsgi application into fastcgi server. Since it is a library, you don't need to setup other extra standalone application. flup could hep to set up fastcgi through Unix socket domain or TCP port. It is also support scgi. webpy could use flup directly. app = web.application(urls,locals())
if __name__ == '__main__':
#web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr) for unix socket domain
#web.wsgi.runwsgi = lambda func, addr="/tmp/test.sock": web.wsgi.runfcgi(func, addr) for Tcp port
#web.wsgi.runwsgi = lambda func, addr=("localhost",7070): web.wsgi.runfcgi(func, addr) used with spawn-fcgi
app.run()
different addr could be config as different fastcgi behavior. app.run() just simply refer to web.wsgi.runwsgi.

uwsgi needs to be isntalled if you want use wsgi + nginx. I don't see webpy could support uwsgi protocal directly.

Wednesday, October 08, 2014

https build with nginx + startssl

startssl provide free ssl certification. I have updated my website with https connection.

first step is to apply a ssl certifciation on startsll. Please notice there is no username/passwd to login startsll website instead of certification on your browser which is installed by startssl. second is to follow website to fill personal information, validation your email and produce private key. private key (ssl.key) is not stored in startsll server, but it will download to your computer. Then you need to wait for sometimes to fetch public key (ssl.crt) and retrieve it from "Retrieve Certificate" in Toolbox.

second step is to configure nginx to use ssl.key and ssl.crt, see this link for detail. You also could use this website to check if any problem

Last thing needs to notice is firewall configuration on your server. Please open 443 port and remove other un-necessory configuration rule for 443. Previously I forwarded 443 to 8080 for shadowsocks and it toke me long time to find that is root caused for my https connection failure

Tuesday, September 30, 2014

Linode VPS installation

first step is to init pacman and update system

  1. init pacman for package verification function according to link
  2. update system to latest one: pacman -Syu

next step is to add user and configure ssh

  1. add normal login user with useradd. Add user to group: wheel,log and systemctl-journal
  2. add user git with useradd
  3. update sudo with visudo
  4. add public key in .ssh/authorized_keys for git and normal login user
  5. install git and change user git shell to git-shell.
  6. test ssh public key access and git clone from local computer
  7. disable ssh root access and passwd login
  8. install sshguard

next step is to configure network,time and other system configuration

  1. configure netctl for dhcp (enable both IPv4 and IPv6) and enable this profile as startup service. (I couldn't sucess for static IP configuration) (update: change to system-networkd for statis ip)
  2. set timezone with timedatectl
  3. install ntp and enable it as startup service
  4. set up iptables rules in /etc/iptables/iptables.rules and ip6tables.rules
  5. install bash-completion

next step is to install different application

  1. install vnstat
  2. install shadowsocks
  3. install nginx, spawn-fcgi,python2-webpy,python2-flup,python2-matplotlib,python2-iso8601
  4. install python2-pip and pip2 install --upgrade google-api-python-client
  5. install my own webapplication *.service file and start app

Monday, May 12, 2014

进化的速度

昨天看了polyhedron做得汉族起源的人类分子学研究的演讲,感触很多。按照Y染色体和线粒体的分析,非洲以外的人类都是由10万年前一小支走出非洲的人类演化而来。而汉族大概是由六千年前的五至七个超级祖先繁衍而形成的。可以想像,也许几千年以后,地球上的大部分人类都是由现在地球上几个人的后代,而其余几十亿人类的基因将在慢慢的历史长河中丢失。

update1: this link has similar conclusion has社会达尔文主义如何造就了现代中国

Saturday, February 01, 2014

民众的认识和知识的专业化

过年期间总有很多机会参与家人对政治经济和社会问题的讨论,尤其是男人之间。这种问题的讨论往往天马行空:从习近平反腐,股市为何长期低迷不振到马甸的老太太白手起家挣了8套房子。每个人都对这些不同的问题有一个自己认同的答案和理解,有些问题大家有共识,而有些问题则很难达成一致。但真正的问题在于:这些共识或者不一致的认识是否正确?

百年前也许还有所谓百科全书式的学者,但现代社会则很难出现类似的人物了。随着人类知识的不断暴涨和人脑有限容量的限制,学者专家们越来越局限于自己不断缩小的一亩三分地了。新浪微博上的很多讨论可以完美的呈现这个矛盾:比如之前有人在微博上说有中科院教授在课堂上说面膜无用,而且面膜会让面部细菌大量繁殖。但很快就有医院的皮肤科大夫给予反驳,面膜对改善皮肤的确用处不大,但其中的添加剂可以有效抑制细菌繁殖。对于皮肤相关的问题,皮肤科大夫的解读往往要比生物学教授专家靠谱很多。

政治经济问题的研究很复杂,民众一方面很少有机会去浏览和阅读相关材料,更为糟糕的是有些结论的推理过程过于复杂,结论往往和直觉相反,民众也很难理解和接受。如果大家对问题的理解都是错误的,讨论还有什么意义,我们的社会还能“正确”地发展吗?

Thursday, January 30, 2014

ALSA and HDMI

ALSA could use alisa (aplay -L) to distinguish different sound card and device (aplay -l). Then each application need to decide which alisa is used to output sound. mplayer, aplay and other application could use alisa as options. But flash plugins generally only use default, see link

For HDMI audio output, first application need to know which card/device is for HDMI output and then use related alisa as output. But flashplugins in Linux could only use default as output, then it is needed to assign default to HDMI device, see Wiki in Archlinux

PCM slave is used to forward ALSA plugins to related sound card and device.

Background: there is no audio through HDMI when I connect my laptop with TV and use TV as screen for tv.sohu.com. I have to follow workaround from wiki.archlinux.org to reset default in .asoundrc. It is caused by flash only use default for output.

Sunday, January 12, 2014

Database

I read three manuals or tutorials for database recently: SQL, mongo and Berkeley DB. SQL is rational database which you could treat it as a bigger "excel". Berkeley DB is simply key to data database. And mongo is document database which handle special json like document.

Berkeley DB is popular database in Unix/Linux world. It is the successor for gdbm. Oracle bought Berkeley DB and developed it with more function like transaction (group command), concurrency (prevent write one record by two guys together) and SQL capacity.Since it is key-data database, it is very convinient to store contact with bdb.

Mongo is database for json like document. From my understanding, Mongo is optimized for distribution/cluster and index. It is all for big-data.

SQL is most popular database for nearly all things. In SQL, everything is organized as tables. Everything record is one row which has several values/attributions. Also you could link two tables together if they has common values/attributions. SQL is used everywhere: blog, news site, bank, schools.

Sunday, January 05, 2014

Summary for 2013

2013年对我而言是人生发生重大变化的一年: 结婚,买房,婚礼,蜜月旅行,老婆怀孕,工作上也发生了很多变化。

婚姻及怀孕

这一年最大的变化就是结婚了。从2013年1月领证,8月婚礼及其后的欧洲蜜月之旅,10月回新疆又小办了一次,一切都来的这么迅速及幸福。更大的惊喜是小宝宝在年底突然出,这也让生活完全呈现出另外一种幸福和紧张。可以说2014年的最大的希望就是小宝宝能顺利出生,妈妈和TA都健健康康的。

房子

房子终于在2013年尘埃落定。从2012年下半年开始看房到2013年3月过户,期间发生了很多曲折和辛苦。但最具有戏剧性的是,短短半年这套房子就增值了很多。我曾开玩笑的跟老婆说,从我们的经验看,房子是最具增值性的投资手段了。我曾经很确定地认为房价就是一个bubble,但现在也越来越怀疑这个conclusion了。

工作

2013年工作也发生了很大的变化。年初开始接触TDD node,去瑞典transfer;9月升senior; 年底LL从瑞典归来,部门组织架构调整,我做了3年之久的2k也将转出。由于TDD node的缘故,2013年中对于SW,RBS系统架构都有了更深的了解。

Social network

2013年主要的social network是微博和Google+。Google+由于GFW和帖子质量的问题,光顾的次数不多。可以说新浪微博占据了我大部分的闲暇时间。这一年朋友和同事圈立的帖子数量下降很大。但特定爱好群体的帖子质量和发帖数量都保持了稳定的水平。目前我关注的主要群体是医生及健身爱好者; 科学研究者(主要是生物类); 科普工作者;经济研究者; 码农。对于其它social network: twitter/facebook的帐号已经删除; 偶尔去newsmth看一眼网络武侠的讨论;QQ基本上不用; 目前很火的微信只是去土耳其出差时用过一段时间,回来之后就删除了。

Programming

2013年里继续使用linux。去土耳其出差期间用gnuplot和awk处理数据,极大的缩减了我处理数据的工作量; 年底开始用pygraphic画流程图,学习django和git。另外开始用python学习fft,数字滤波,这对我理解工作上的某些事情也有很大的帮助。由于GFW升级,ssh tunnel 和openvpn开始失效,目前主要使用shadowsock翻墙。

Science

这一年在科学学习上并无太多成就。2013年痴迷于pad游戏和微博,并没有看太多的科学书籍。主要还是通过微博浏览中医批判,反转基因批判,进化心理学及生物相关的微博。