天's profileMy spaceBlogLists Tools Help

My space

上善若水,厚德载物! xuedipiaofei@hotmail.com

Install LAMP quickly through yum/apt with the linux cd copy

1. Import the key to the current system. For example under redhat.

rpm –import /media/cdrom/RPM-GPG-KEY-redhat-release

2. Mount the cd files to the current system.

mount –t ios9600 /media/RHEL5.3i386DVD /mnt/cdrom

3. Set the yum repository

vim /etc/yum/repos.d/*.repo

[rhel5-local]
  name=Red Hat Enterprise Linux 5 Local Repository
baseurl=file:///mnt/cdrom/Server
enabled=1
gpgcheck=0

4. Install apache, mysql, php

yum install httpd, mysql-server, mysql, php, php-mysql

5. create a file with index.php in /var/www/html

<?php phpinfo(); ?>

6. Browser the http://IP/index.php

7. Set mysql password

mysqladmin –u –root password ‘newpassword’

8. Start httpd, mysql and add them into start menu.

service httpd start

service mysqld start

chkconfig httpd on

chkconfig mysqld on

March 20

MSChart

I created some charts for our dashboard website using MSChart. MSChart is a control library which belonged to another company. And then MS acquired the company. The Chart Control API is object-oriented, extensible and highly flexible.

 

Chart Elemnets Overview

ChartElementsFinished

 

There is a bug in the control. There will be a “executing child request for ChartImg.axd” error sometimes.

<add

name="ChartImageHandler" preCondition="integratedMode" verb="POST,GET,HEAD" path="ChartImg.axd"

<add path="ChartImg.axd"verb="POST,GET,HEAD"type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler,

Add the "POST" keywords into the place. 

We can use httphandler or localstroage to present the chart. I prefer to using httphandler to storage.

<add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;deleteAfterServicing=false;
webDevServerUseConfigSettings=false
" />

Add the greed font to your web.config file. It can delete the images automatically. 

Enjoy it! :)

Chart

February 17

Python 学习笔记

版权声明:可以任意转载,但转载时必须标明原作者charlee、原始链接http://tech.idv2.com/2008/11/03/python-memo/以及本声明。

 

基本概念

  • Python居然支持复数。如(-5+4j)。但要注意虚数单位单独使用时要写成 1j,不能写成 j。
  • 与Perl和PHP的区别:单引号和双引号没有任何区别。没有插值功能。
  • 三引号:''' 和 """ 相当于Perl的heredoc。
  • 行尾不需要用分号,分号仅用于一行写多条语句的情况。跟BASIC的冒号有些相似。
  • 缩进是有语义的!建议使用TAB缩进
  • 逻辑运算符只有 and or not,没有 && || !
  • 没有自增自减运算符,--a 相当于 -(-a),a--语法错
  • 赋值语句不是表达式,如 y = (x = 1) 语法错
  • 字符串切片是很好用的: 'Hello'[0] == 'H',以前只有Basic才有这个功能,其他语言都没有。当然Python比Basic要强大得多
  • cmp函数相当于Perl的 <=> 和 cmp,由于python有类型,所以无需像perl那样用两个运算符
  • []、()、{} 的布尔值是False,跟JavaScript不同(JavaScript中空数组和空对象都是true)。与Perl类似,但Perl可以用环境来解释。

运算符与表达式

  • 运算符 ** 乘幂,Perl也有。
  • 字符串的 * 表示重复,相当于Perl的 x 运算符。
  • 居然还有专用于整除的 // 。别跟Perl 6的 // 混淆了。

控制流

  • if-elif-else,Perl为if-elsif-else,bash为if-elif-fi
  • if、elif等控制流语句后面要加冒号,很像PHP的语法
  • while和for循环可以带else,循环正常结束时就会执行else。不用像C语言那样,循环结束时要检查循环变量是否等于终值,以判断是否正常结束。赞
  • range函数生成的结果不包括终点。比较:Perl的 .. 运算符包括终点。所以,Python的range(a,b)理解成C语言的 for(i=a;i<b,i++) 好些。
  • 什么都不做的pass语句,算是个python特色
  • enumerate能同时迭代key和value,很不错。for key, value in enumerate(LIST):

函数

  • 函数中使用全局变量需要用global关键字,类似于PHP
  • DocString,又一个python特色,函数的第一个逻辑航的字符串作为文档字符串。类似于POD和javadoc,不过是写在函数体内的。还能通过"函数名.__doc__"访问
  • lambda:类似于perl的闭包
  • int()函数在字符串转整数时,不能用来转浮点数字符串,也不能转包含字母的字符串。如int("1.2")、int("123abc")都是语法错误,而并不返回 1、123。

数据结构

  • 列表:定义方式为 a=[1,2]。等价于perl的数组/列表
  • 元组(tuple):定义方式为 a=(1,2)。
  • 要注意列表中的列表不会被打散,如 a=[1,2], b=[a,3,4],结果就是 b=[[1,2],3,4]。这一点与Perl不同。
  • 字典:定义方式为 c={'a':1, 'b':2}。等价于perl的散列。注意两点:
    • 定义和访问时,key必须用引号引起来。
    • 使用{}定义,使用[]访问,即c['a']。与Perl不同。
  • 列表赋值是引用赋值。要想拷贝,必须用切片:b = a[:]。Perl程序员要注意。
  • 列表的sort会改变原列表。

例外

  • try-except-finally,相当于java的try-catch-finally
  • 还有else,当没有发生异常、正常结束try块时执行。跟for/while的else块一样
  • 故意抛出异常叫raise,java里面叫throw

面向对象

  • 数字和字符串(对象)是不可变的。那么如何理解a=a+1?实际上是a+1创建了一个新对象赋给a,而a原来的对象被回收了。学习Python必须改变原来的“变量是个盒子”的看法
  • (-1, 100)之间的整数会被缓存,就是说即使写成 a=10; b=10; ,a和b还是同一个对象(a is b == True)
  • python的长整型是无限大的
  • 类的__init__函数类似于C++的构造函数;__del__函数类似于C++的析构函数。
  • 类方法定义的第一个参数必须为self,调用时这个参数会被传递为对象本身。类似于perl,perl中第一个参数也会被传递为对象本身,不过需要程序员自己写 my $self = shift; 来接收。
  • 用C++的话来说,所有成员函数都是虚函数。
  • 调用基类方法时要手工传递self,如 Parnet.__init__(self, name)。

模块

  • import foo; 相当于perl的 use foo;
  • from foo import bar 相当于perl的 use foo qw/bar/;

Linux vim configuraion for python

1. Set term color

Add the following command into /etc/profile

export TERM=xterm-color

2. Download python.vim and copy it to vim installation folder such as /usr/share/vim/vim63/

3. Create the .vimrc under the current user home directory such as root

4. Add the following command

autocmd BufRead,BufNewFile *.py syntax on
autocmd BufRead,BufNewFile *.py set ai

5. Download pydiction plugin form vim official website and copy it into /usr/share/vim/vim63/tools

Add the following command into the .vimrc file at the same time

" python auto-complete code

" Typing the following (in insert mode):

" os.lis<Ctrl-n> " will expand to:

" os.listdir( " Python 自动补全功能,只需要反覆按 Ctrl-N 就行了

if has("autocmd")

    autocmd FileType python set complete+=k~/.vim/tools/pydiction

endif

6. Python_Fold to collapse python code. Download it and copy it into /usr/share/vim/vim63/plugin

7. Download taglist and copy it into /usr/share/vim/vim63/plugin. Taglist is close by default. You can use :Tlist to open taglist or add the following cmd into .vimrc file

let Tlist_Auto_Open=1

8. Download Ctags and copy it into /usr/share/vim/vim63/. Run ctags –R to a worksapce.

9. Relate taglist and ctags. Add the following cmd into taglist.vim

let Tlist_Ctags_Cmd="/usr/bin/ctags"

10. Load tags as defualt when vim is running. Add the following cmd into .vimrc

:set tags=/workspace/tags