2009年4月23日星期四

韩寒淘宝店的猜想


韩寒淘宝店的猜想


昨晚上参观了一下韩寒的淘宝店 http://shop57860513.taobao.com/,人气果然犀利。从他的公告上知道19号才开的店,昨天晚上看的时候还有三本书,现在我再逛的时候(现在是北京时间2009-04-24 13:30)就已经只有二本了,《三重门》只库存3本也将马上售完,《光荣日》好一点也只有42本了。以一本书准备了150左右计,估计也就这么五天的时间售出去1000-1500本之间,如果不是缺货的原因我想应该售出更多。

韩寒,确实牛!牛人就是牛人。

我想以他的性格与独特的想法,他的下一本书很可能自己包销了,反正也不差钱哦~~!

和出版社签个印刷合同,你们就好好把书印好得了。谁想卖都不行,我自己搞定,独家销售,保证正版,高兴了整个签名本。

(留字验证ING)


销售速度见图。

2009年4月15日星期三

YSlow评分

YSlow评分

75分,如图。其实还是有空间滴……

实际使用中发现YSlow的评分会有波动,好象每次都不大一样,不知道哪位达人能够指教一二?


2009年4月3日星期五

解决supermemo 2006 Q&A txt格式导入时中文不显示的问题











解决supermemo 2006 Q&A txt格式导入时中文不显示的问题

原始的Q&A 文件格式如下,导入sumpermemo后无法显示答案,经过与supermemo导出Q&A txt文件比较后发现,原来需要将中文部分转为unicode的内码格式,才能正常导入。这个就容易了,直接写个python小程序就搞定。

------ 无法显示答案的Q&A txt文件格式------
Q: what
A: 什么

------ supermemo导出Q&A txt文件格式 ------
Q: what
A: 什么


#######################
# python 代码
#######################
def getCode(cd):
    oCd = ord(cd)
    if oCd > 255 :
        return '&#%s;' % oCd
    else :
        return cd
    
if __name__ == "__main__":
    #不正确格式的Q&A txt文件
    f = open('c:/cet.txt','r')   
    #正确的可以导入的输出文件
    o = open('c:/smcet.txt', 'a')
    
    for line in f:
        o.write(''.join('%s' % getCode(c) for c in unicode(line)))
    
    f.close()
    o.close()


2009年4月1日星期三

vim中的查找替换一例

vim中的查找与替换一例

拿到一个单词表,想要将之导入到supermemo 2006中去。然而与supermemo 2006中的Q&A txt 格式不一样,所以需要处理一下。用程序当然就用python了,不过想试试vim是否能够搞定。

单词表格式如下:
…………
9.slip v. 滑动,滑落;忽略

10.slide v.
滑动,滑落 n. 滑动;滑面;幻灯片

11.bacteria n.
细菌

12.breed n.
种,品种 v. 繁殖,产仔

13.budget n.
预算 v. 编预算,作安排

14.candidate n.
候选人

15.campus n.
校园

16.liberal a.
慷慨的;丰富的;自由的

17.transform v.
转变,变革;变换

…………


supermemo中的Q&A txt格式如下:
…………
Q: slip
A
: v. 滑动,滑落;忽略

Q
: slide
A
: v. 滑动,滑落 n. 滑动;滑面;幻灯片
…………

1:先将单词复制到vim保存到一个文件
2:首先将单词与中文解释分成二行,第二行需要以A: 开始
命令模式下输入:%s/\(\l\) \(ad\|vt\|vi\|a\|n\|v\)\./\1\rA: \2\./g后得到如下
9.slip
A: v. 滑动,滑落;忽略
10.slide
A: v. 滑动,滑落 n. 滑动;滑面;幻灯片

3:将以数字开始的行,替换为以Q: 开始的行,并在前添加一空白行
命令模式下输入:%s/\d\+\./\rQ: /g后得到

Q: slip
A: v. 滑动,滑落;忽略

Q: slide
A: v. 滑动,滑落 n. 滑动;滑面;幻灯片

4:保存,此格式Q&A文件应该可以导入到supermemo中,作为一个单词库。
老夫试了一下发现单词都出来了,就是中文部分要不是乱码要不就是空白,说明文件格式是正确的,就是可能答案部分的编码不正确的原因,需要研究一个supermemo 2006的Q&A txt文件的格式。

替换命令如下


:[范围]s/from/to/[选项]


[范围]:


如果不输入,则为当前行。也可以是形如1,30表示1到20行。%表示全文搜索。.表示当前行。$表示最后一行。所以可以用.,$表示当前行到最后一行


[选项]:


g所有匹配项,c确认替换



from部分:


*    任意次匹配


\+    匹配一次以上


\=    匹配0次或一次


\{3,5} 匹配3到5次


\|    或者


\&    二个并列的同时匹配


\d    数字


\D    非数字


\x    十六进制数


\X    非十六进制数


\s    空白字符


\S    非空白字符


\l      小写字母


\L    非小写字母


\u    大写字母


\U    非大写字母


to部分:



反向引用\1...\9表示第一到第九个匹配的内容,\0整个匹配的内容

下面解释一下二个替换命令


:%s/\(\l\) \(ad\|vt\|vi\|a\|n\|v\)\./\1\rA: \2\./g
 1       2   ------------3---------   4 5      6   7
        --------8------------------ ------9---
1:%表示全局查找
7:g表示全部替换
2:一个小写字母
3:ad或者vt或vi或a或n或v
8:表示查找【小写字母+空格+ad.或者vt.或vi.或a.或n.或v.】
4:第一个匹配内容即2
5:换行
6:第二个匹配内容即3
9:表示替换为【匹配的小写字母+换行+A:+空格+匹配的ad.或者vt.或vi.或a.或n.或v.】
如:
9.slip v.
滑动,滑落;忽略
替换为

9.slip
A: v. 滑动,滑落;忽略

:%s/\d\+\./\rQ: /g
 1    -2--- -3---
1:%表示全局查找
2:表示查找以一个以上数字+.
3:表示替换为换行+Q:空格
如:
9.slip
替换成

Q: slip


2009年3月27日星期五

grep使用15招






grep使用15招

原文链接Get a Grip on the Grep! - 15 Practical Grep Command Examples
 


首先创建我们练习grep命令时需要用到的demo文件demo_file。


$ cat demo_file
THIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE.
this line is the 1st lower case line in this file.
This Line Has All Its First Character Of The Word With Upper Case.

Two lines above this line is empty.
And this is the last line.

1.从单个文件中搜索指定的字串

grep的基础用法是如下例的从指定的文件中搜索特定的字串。


语法:
grep "literal_string" filename

 


$ grep "this" demo_file
this line is the 1st lower case line in this file.
Two lines above this line is empty.
And this is the last line.

2. 在多个文件中检索指定的字串


语法:
grep "string" FILE_PATTERN

 
先拷贝demo_file为demo_file1。grep的结果在符合条件的行前将包括文件名。当文件名包含元字符时,linux shell会将匹配的所有文件作为输入到grep中去。



$ cp demo_file demo_file1

$ grep "this" demo_*
demo_file:this line is the 1st lower case line in this file.
demo_file:Two lines above this line is empty.
demo_file:And this is the last line.
demo_file1:this line is the 1st lower case line in this file.
demo_file1:Two lines above this line is empty.
demo_file1:And this is the last line.

3. 用 grep -i 进行大小写无关的搜索


语法:
grep -i "string" FILE

 
也是一个基本用法,对搜索的字串忽略大小写,因此下例中匹配“the”, “THE” and “The”。



$ grep -i "the" demo_file
THIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE.
this line is the 1st lower case line in this file.
This Line Has All Its First Character Of The Word With Upper Case.
And this is the last line.

4. 使用用正则表达式


语法:
grep "REGEX" filename

 
如果你能有效地利用正则表达式,这是个很有用的特点。在下面的例子中,搜索全部以“lines”开始以“empty”结束的字串,如搜索“lines[之间任意字]empty” ,并且忽略大小写。



$ grep -i "lines.*empty" demo_file
Two lines above this line is empty.


正则表达式遵循的几个重复的操作


  • ? 最多匹配一次
  • * 匹配零次或者任意多次
  • + 匹配一次以上
  • {n} 匹配n次
  • {n,} 最少匹配n次
  • {,m} 最多匹配m次
  • {n,m} 匹配n到m次

5. 用grep -w搜索整个词,而不是词中的部分字串


使用-w选项搜索一个单词,并且避免搜索到词中的部分字串。

 

下例搜索"is"。如果不加-w选项,将显示“is”, “his”, “this” 等所有包含“is”的行。


$ grep -i "is" demo_file
THIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE.
this line is the 1st lower case line in this file.
This Line Has All Its First Character Of The Word With Upper Case.
Two lines above this line is empty.
And this is the last line.

 

下例使用了-w选项,请注意结果中不包含
“This Line Has All Its First Character Of The Word With Upper Case”, 虽然 “This”中包含“is”。


$ grep -iw "is" demo_file
THIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE.
this line is the 1st lower case line in this file.
Two lines above this line is empty.
And this is the last line.

6. 使用grep -A, -B and -C显示之前、之后、前后的几行


当使用grep搜索大文件时,显示匹配行附近的多行数据是一个很有用的功能。


 

创建如下文件


$ cat demo_text
4. Vim Word Navigation

You may want to do several navigation in relation to the words, such as:

* e - go to the end of the current word.
* E - go to the end of the current WORD.
* b - go to the previous (before) word.
* B - go to the previous (before) WORD.
* w - go to the next word.
* W - go to the next WORD.

WORD - WORD consists of a sequence of non-blank characters, separated with white space.
word - word consists of a sequence of letters, digits and underscores.

Example to show the difference between WORD and word

* 192.168.1.1 - single WORD
* 192.168.1.1 - seven words.

6.1 显示匹配行之后的N行


-A


语法:
grep -A "string" FILENAME

 

下例显示匹配行和之后的3行数据


$ grep -A 3 -i "example" demo_text
Example to show the difference between WORD and word

* 192.168.1.1 - single WORD
* 192.168.1.1 - seven words.

6.2显示匹配行之前的N行


-B


语法:
grep -B "string" FILENAME

 

下例显示匹配行和之前的2行数据


$ grep -B 2 "single WORD" demo_text
Example to show the difference between WORD and word

* 192.168.1.1 - single WORD

6.3显示匹配行前后的N行


-C 显示之前的n行,之后的n行数据.


$ grep -C 2 "Example" demo_text
word - word consists of a sequence of letters, digits and underscores.

Example to show the difference between WORD and word

* 192.168.1.1 - single WORD

7.通过GREP_OPTIONS高亮显示搜索的字串


如果你希望搜索的字串高亮显示在结果中,可以试用以下的办法。
 

通过修改GREP_OPTIONS对搜索字串高亮显示。



$ export GREP_OPTIONS='--color=auto' GREP_COLOR='100;8'

$ grep this demo_file
this line is the 1st lower case line in this file.
Two lines above this line is empty.
And this is the last line.

8. 用grep -r递归搜索全部的文件


如果想查找当前目前以及其子目录的全部文件时,可以使用 -r 选项。如下例


$ grep -r "ramesh" *

9. 使用grep -v进行不匹配



可以使用-v选项显示不匹配搜索字串的行。下例显示demo_text文件中不包含“go”的行


$ grep -v "go" demo_text
4. Vim Word Navigation

You may want to do several navigation in relation to the words, such as:

WORD - WORD consists of a sequence of non-blank characters, separated with white space.
word - word consists of a sequence of letters, digits and underscores.

Example to show the difference between WORD and word

* 192.168.1.1 - single WORD
* 192.168.1.1 - seven words.

10. 显示不匹配全部模式的行


语法:
grep -v -e "pattern" -e "pattern"

 

创建如下例子文件


$ cat test-file.txt
a
b
c
d

$ grep -v -e "a" -e "b" -e "c" test-file.txt
d

11.用grep -c 统计匹配的行数



语法:
grep -c "pattern" filename

 


$ grep -c "go" demo_text
6

 

统计不匹配的行数


$ grep -v -c this demo_file
4

12. 用grep -l 只显示文件名



$ grep -l this demo_*
demo_file
demo_file1

13. 只显示匹配的字串


缺省显示匹配字串的所在行,可以使用-o选项只显示匹配的字串。这项功能当使用正则表达式时比较有用处。

 

$ grep -o "is.*line" demo_file
is line is the 1st lower case line
is line
is is the last line

14. 显示匹配的位置



语法:
grep -o -b "pattern" file

 


$ cat temp-file.txt
12345
12345

$ grep -o -b "3" temp-file.txt
0:3
6:3

 
注意: 以上输出显示的不是行内的位置,而是整个文件中的字节byte位置


15. 用 grep -n 在输出时显示行号


行号从1开始


$ grep -n "go" demo_text
5: * e - go to the end of the current word.
6: * E - go to the end of the current WORD.
7: * b - go to the previous (before) word.
8: * B - go to the previous (before) WORD.
9: * w - go to the next word.
10: * W - go to the next WORD.
 

2009年3月25日星期三

有风险,会被雷






有风险,会被雷

某日,闲逛到一网页,发现一下载,点之,弹出“有风险,未安装迅雷”,当下被雷得外焦里嫩,以图为证。
看来迅雷开始学习N年前的“您的计算机可能被病毒入侵,请安装XXX”的恐吓手法,莫非是同一个人的杰作?
多少年了一点怎么进步都没有?


2009年3月23日星期一

ubuntu8.10下的java开发环境安装与配置






ubuntu8.10下的java开发环境安装与配置

1:jdk1.5的安装


到sun的网站上下载jdk-1_5_0_17-linux-i586.bin

$chmod u+x jdk-1_5_0_17-linux-i586.bin
$./jdk-1_5_0_17-linux-i586.bin
$sudo vi /etc/environment
--红色为新添加部分--------------
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/jdk1.5.0_17/bin:.:"
LANGUAGE="zh_CN:zh:en_US:en"
LANG="zh_CN.UTF-8"
JAVA_HOME="/usr/local/jdk1.5.0_17"
CLASSPATH="/usr/local/jdk1.5.0_17:."


$source /etc/environment
或者重新启动之后,查看java版本
$java -version
java version "1.5.0_17"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_17-b04)
Java HotSpot(TM) Client VM (build 1.5.0_17-b04, mixed mode, sharing)

jdk安装完成!!

2:tomcat5.5的安装

http://tomcat.apache.org/download-55.cgi
下载tomcat 5.5 tar.gz包

$ tar zxvf apache-tomcat-5.5.27.tar.gz
tar: 它似乎不像是一个 tar 归档文件
tar: 跳转到下一个头
tar: 由于前面延迟的错误而退出


改为其他方式
$gzip -d apache-tomcat-5.5.27.tar.gz
$tar xvf apache-tomcat-5.5.27.tar
$sudo mv apache-tomcat-5.5.27/ /usr/local/
进入tomcat/bin
$./startup.sh 启动tomcat
访问http://127.0.0.1:8080/

tomcat安装成功!!

3:eclipse3.4.1的安装

下载eclipse3.4.1

$tar zxvf eclipse-jee-ganymede-SR1-linux-gtk.tar.gz
$mv eclipse eclipse3.4.1
$sudo eclipse3.4.1/ /usr/local/

在桌面创建快捷方式

eclipse安装成功!