A shorten url app

一不小心又是大概有一年多时间没有用过Django了。最近经常有之前部门的同事来讨论Django和Python Web开发,大概是他们用asp做的客服系统终于要换架构了。今天国庆提前放假,用了一个下午的时间重温一下。Django的Template还是相对弱一些,居然无法在template里调用model的方法。这样auth模块里判断用户登录的is_authticated()方法就不能在template里调,如此非得在view判断(Django是MTV模型,它的view即MVC里的controller),那如果是用generic_view,这个似乎就无解了??

贴个图。体验一下Firefox3.5开始支持的@font-face,Webkit核心和Opera浏览器都支持这个功能。不过我Ubuntu上的Midori貌似遇到Mootools就直接崩溃,看来要等到gnome2.28里epiphany了。

忘了提了,域名是我yy的,之所以有这样的效果是修改了hosts

首页更新

半年没碰那个首页了,最近看到commandlinefu提供了jsonp接口,顺手把commandlinefu加了进来:
Classicning7.clifu();

这个程序是去年此时还在用JavaScript工作的时候写的,隔了一年再看,很难不感慨啊。话说,大家要是发现一些好玩的,好用的JSONP服务可以分享一下。

0:2

以下是今天的闲言碎语。

  1. 其实中超真挺好看的,我不是说球,纯技术的欣赏还是交给伪球迷吧。群雄逐鹿,乱七八糟,踢球的踢球,骂人的骂人。广州的徐亮应该算是现在国内足坛最TM有个性的球员了,有点当年范志毅郝海东的意思了,可惜这样的球员还是少,多点的话就更热闹了。舜天队还是那个样子,今天的比赛看了半场,也不像是不想赢,但是派个傻大个在前面挥霍机会,难道是轻敌了?下半场据说是风云突变,反正最后黑色三分钟,就冲这个架势,看来夺冠还是纯YY。
  2. 办人事档案的手续,发现同样是纳爱斯,也有真纳爱斯和假纳爱斯,或者说是伪纳爱斯。同样是春风,有的是吹面不寒杨柳风,有的是二月春风似剪刀,后者用范伟的话说,咔咔的。说来说去还是家乡人淳朴,不像那个哪,看谁都跟骗子一样。
  3. 看建国大业了,豆瓣上有个说法叫视频幻灯片,很典型。印象深的,除了某幕后人员,配角里就属最后刘德华,因为看了两遍。国军衣服就是好看,当时那张脸就是典型的“如果说一切都是天意一切都是命运很早已注定”,苦啊,在肚子里。不说电影本身了,倒是想想这个事情,从井冈山被打得到处跑,到胡宗南占了延安又是到处跑,无数的挫折、看似没有希望,从一开始到最后成功漫长的20年,且不跟你们讨论这件事到底怎么样,但是把它当成一个人或者说一个团体的事业,实在是壮观壮丽。
  4. 回上海,在火车站看到广告说“学习北京奥运会,办好上海世博会”,说实在的,真学的话,要是地铁能两块钱随便坐,全国人民也请上海人民和上海黑户坐一年地铁那是最好了。估计是不可能了,怎么办,唯有调整心态:话说我每天都请北京的谁谁还有谁谁谁坐地铁坐公交,有这种心态,刷卡过闸机的时候动作会相对潇洒一些。
  5. 工作那边,要准备申请立个项目,项目的点子是部门的负责人想的,咱来do it。让个应届生当PM又不靠谱,架构师来挂个名,可是人家忙得要死,只能深情款款地对我说,开发暂时就你一个人。现在项目组变成运维、测试、项管群殴我一个,就着这两天的所见所闻,大约也能想象今年剩下几个月的日子。
  6. 又到了一年一度的recruitment,看着大家跃跃欲试,我在这里祝大家过得比我好。

洗完澡回来补一枪,上周买了一本这个,周五在火车上看了前面一两章,感觉还不错,尤其是压力测试方面解决了我最近的一些疑问。同时我也感觉到写这么一本书确实要有一大瓶水和可观的时间和精力,这个还是很难的。熟悉俺的人都知道出本误人子弟的书是俺长久以来的梦想,不过看了这位28本书的作者的状况,我这个梦想离照进现实还是有距离的。

Performance Visualization with Gnuplot, continued

After I post my command to commandlinefu.com, there is an alternative command followed:
(echo “set terminal png;plot ‘-’ u 1:2 t ‘cpu’ w linespoints;”; sudo vmstat 2 10 | awk ‘NR > 2 {print NR, $13}’) | gnuplot > plot.png

This one is appreciated for using pipes and redirection. It works on Ubuntu Jaunty, on which, gnuplot doesn’t provide a -e option. The author also showed an link to an open source project ‘vmplot’ on freshmeat. Vmplot is written in python, which combines parameters with scripts and end up with an os.system call. Grab the source from here. (Why use python instead on a simple bash command? because it’s difficult to draw a multiplot without temp file or variables, you cannot read ‘-’ twice.)

There are several people vote me down for my command! It must be primers whose use ubuntu and knows the world via Synaptic only, because they failed to run the command on their dated machine (*_*)

Performance Visualization with Gnuplot

Gnuplot is considered to be one of the most famous plotting tools on both linux and windows. With Gnuplot, generation of charts becomes agile and easy. Gnuplot supports sorts of terminals range from gui, image to printer. To enable png terminal support, we will build gnuplot with following steps. (However, on most linux distributions you don’t have to do these manually, install gnuplot with package manager is doubtlessly the best choice for most cases.)

Well, for a naked machine, it won’t be too long to type commands in gnuplot.

Installing libpng

linpng provides functionality to write png images.
Grab source form libpng’s website:
wget http://downloads.sourceforge.net/project/libpng/00-libpng-stable/1.2.39/libpng-1.2.39.tar.gz?use_mirror=ncu

Uncompress the package:
tar xfz libpng-1.2.39.tar.gz

cd to result directory and build it:
cd libpng-1.2.39
./configure
make
make install

Installing libgd

gd provides api for programmer to draw images like Graphics2d in java. Gnuplot uses gd to draw charts on images.
Grab source from gd’s website:
wget http://www.libgd.org/releases/gd-2.0.35.tar.gz

Uncompress it:
tar xfz gd-2.0.35.tar.gz

build it:
cd gd-2.0.35
./configure
make
make install

Compiling and building Gnuplot

Grab source from sourceforge:
wget http://downloads.sourceforge.net/project/gnuplot/gnuplot/4.2.6/gnuplot-4.2.6.tar.gz?use_mirror=ncu

Uncompress and compile:
tar xfz gnuplot-4.2.6.tar.gz
cd gnuplot
./configure
make
make install

if “‘@LIBICONV@’ not found” encountered during make, just edit src/Makefile to replace -l@LIBICONV@ to -liconv, and make again.
Try to start gnuplot simply with:
gnuplot

Now you may be stopped by error message like libiconv.so.2 not found, then you have to copy it from somewhere(such as /usr/local/lib) to /usr/lib, the it will work.

Using Gnuplot

As the installation completed, we start to use it.

vmstat is a great utility shows you the status of your process queue, memory, swap, io rates, interrupts and cpu usage. With command-line arguments, we can dump these data in a fixed interval and fixed count:
vmstat 5 10

awk is a well-known editor to analyze and extract text from input, we can filter specified fields with awk like this:
vmstat 5 10 | awk ‘NR > 2 {print NR-2, $13}’
The header was ignored by the conditional expression NR>2 which NR stands for Number-of-Row

The output is just enough for gnuplot, now use pipe to connect them together:
vmstat 5 10 | awk ‘NR > 2 {print NR, $13}’ | gnuplot -e “set terminal png; set output ‘v.png’; plot ‘-’ u 1:2 t ‘cpu’ w linespoints;”

To gather more information at one time, a more complex command is needed:
vmstat 10 360 | awk ‘NR > 2 {print NR, $4, $9, $10, $13}’ > vmstat.dat ; gnuplot -e “set terminal png;set output ‘vmstat.png’;set grid; set multiplot;set size 0.5, 0.5;set origin 0, 0;plot ‘vmstat.dat’ u 1:2 t ‘freemem’ w linespoints;set size 0.5, 0.5;set origin 0.5, 0;plot ‘vmstat.dat’ u 1:3 t ‘bi’ w linespoints;set size 0.5, 0.5;set origin 0, 0.5;plot ‘vmstat.dat’ u 1:4 t ‘bo’ w linespoints;set size 0.5, 0.5;set origin 0.5, 0.5;plot ‘vmstat.dat’ u 1:5 t ‘cpu’ w linespoints;unset multiplot;”

Unfortunately, gnuplot in Ubuntu jaunty is at version of 4.2.4, which doesn’t support -e option. So you cannot send gnuplot commands directly in command-line. The solution is split it to several steps:
vmstat 10 360 | awk ‘NR > 2 {print NR, $4, $9, $10, $13}’ > vmstat.dat
gnuplot
>set terminal png;
>set output ‘vmstat.png’;
>set grid;
>set multiplot;
>set size 0.5, 0.5;
>set origin 0, 0;
>plot ‘vmstat.dat’ u 1:2 t ‘freemem’ w linespoints;
>set size 0.5, 0.5;
>set origin 0.5, 0;
>plot ‘vmstat.dat’ u 1:3 t ‘bi’ w linespoints;
>set size 0.5, 0.5;
>set origin 0, 0.5;plot ‘vmstat.dat’ u 1:4 t ‘bo’ w linespoints;
>set size 0.5, 0.5;
>set origin 0.5, 0.5;
>plot ‘vmstat.dat’ u 1:5 t ‘cpu’ w linespoints;
>unset multiplot;

This picture is a stat result of performance test this afternoon

For more detailed tutorials, check the article on ibm dw:
http://www.ibm.com/developerworks/library/l-gnuplot/