Tuesday, December 26, 2006

让 wget 忽略 robot.txt

如果想用wget来抓网页或者镜像站点但是遇到 robot.txt 不允许怎么办?比如这样的 robot.txt

User-agent: *
Disallow: /snapshots/
Disallow: /cgi-bin/
Disallow: /cgi2-bin/


在 $HOME/.wgetrc 中加入

robots = off

一切OK,镜像sina?

wget -c -m -p -q -b http://www.sina.com

-c 是继续传送, -m 是镜像, -p 是下载媒体文件,比如图片, -q 是安静模式, -b 是后台运行

Sunday, December 24, 2006

用正则表达式抓取网页


import re
import urllib
import os
import time
from urllib import urlretrieve
def spider_url(url):
r = re.compile('')
page=urllib.urlopen(url).read()
b=r.findall(page)
for x in b:
try:
type, rest = urllib.splittype(x)
host, path = urllib.splithost(rest)
#if not path or path[-1] == "/":
#path = path + "index.html"
#if os.sep != "/":
# path = os.sep.join(path.split("/"))
#if os.name == "mac":
# path = os.sep + path
path = os.path.join(host, path)
dir, base = os.path.split(path)
#i=str(time.time())+".htm"
makedirs("C:/temp/"+dir)
#i="1.htm"
#urlretrieve(x,"C:/temp/"+i)
f = open("C:/temp/"+path, "wb")
page1=urllib.urlopen(x).read()
f.write(page1)
f.close()
#self.message("saved %s", path)
print "saved %s" % x
except:pass
#return b
def makedirs(dir):
if not dir:
return
if os.path.exists(dir):
if not os.path.isdir(dir):
try:
os.rename(dir, dir + ".bak")
os.mkdir(dir)
os.rename(dir + ".bak", os.path.join(dir, "index.html"))
except os.error:
pass
return
head, tail = os.path.split(dir)
if not tail:
print "Huh? Don't know how to make dir", dir
return
makedirs(head)
os.mkdir(dir, 0777)

python抓取网页代码实例


# -*- encoding:UTF-8 -*-
'''
This is geturl.
Wirtten by yuzebin : yuzebin@gmail.com
Important:this script is running in cygwin or linux,if you run at windows
you need the curl and wget for windows .
'''
class='''
CGetPage is charge of to get a url , it have three methods to get a page : urllib,curl and wget;
CParsePage is charge of to parse the page , and return the match;
CGetMatch is the forcad class to wrap the CGetPage and CParsePage.
'''
history='''
2006.07.10 version 0.0.0.9 :
Publish this code to internet , ;-)

2006.06.27 version 0.0.0.7 :
refrectoring class CParsePage : return re.match only
refrectoring class CGetCount : rename to CGetMatch

2006.06.26 version 0.0.0.3 :
modify class CParsePage , return re.match

2006.06.22 version 0.0.0.2 :
add class CGetCount
this version is the first workable version.
add cnsky.

2006.06.21 initial version 0.0.0.1 :
add class CGetPage and CParsePage
cannot work ;-)
'''
import string,re,os,fnmatch,sys,copy,gzip,time,datetime,urllib
from types import *

isDebugMode = False

funcUrlRead = lambda url: urllib.urlopen(url).read()

def funcOutputMessage(msg):
print str(msg)

def funcDebugInfo(msg):
if(isDebugMode==True):
print str(msg)

class CGetPage:
def __init__(self,url):
if self.urlCheck(url)==True:
self.url=url
else:
return None

def urlCheck(self,url):
#todo , check the url is valid url.
return True

def getPage(self):
self.page = funcUrlRead(self.url)

def curlPage(self):
#call curl to get a page,this requir curl is installed.
self.page = os.popen("curl -A "" -s "" + self.url + """).read()

def setPath(self,path):
self.path = path

def wgetPage(self):
#call wget to download a url to path,this requir wget is installed.
os.chdir(self.path)
os.system('wget -c ' + self.url)

class CParsePage:
def __init__(self,rule,page):
if (self.ruleCompile(rule)!=False):
self.page = page
else:
return None

def ruleCompile(self,rule):
#compile the rule
try:
self.rule = re.compile(rule)
except:
return False

def parsePage(self):
self.match = re.search(self.rule,unicode(self.page,self.getCharset(self.page)))
funcDebugInfo(type(self.match))

def getCharset(self,string):
import chardet
#todo : automatic discern the charset
charset = chardet.detect(string)
return charset['encoding']

class CGetMatch:
def __init__(self,url,rule):
self.url = url
self.rule = rule
self.cgetpage = CGetPage(self.url)
self.cgetpage.getPage()
self.page = self.cgetpage.page
self.cparsepage = CParsePage(self.rule,self.cgetpage.page)

def getMatch(self,url,rule):
self.url = url
self.rule = rule
self.cgetpage.url = url
self.cparsepage.rule = rule
self.cgetpage.getPage()
self.page = self.cgetpage.page
self.cparsepage.page = self.cgetpage.page
self.cparsepage.parsePage()
self.match = self.cparsepage.match

if __name__ == '__main__':
funcOutputMessage('===This is a get url script===')
runTest()

def runTest():
#initialization
ccount = CGetMatch('http://www.sina.com.cn','')
i=0

#1
try:
sitename = 'huajun'
rule = 'hit[587]='47588,([0-9]+)'
url = 'http://www.onlinedown.net/soft/hitjs/hits47.js'
i += 1
ccount.getMatch(url,rule)
funcOutputMessage(str(i).rjust(2) + '.' + sitename.ljust(12) +':' + str(ccount.match.group(1)))
except:
pass

#2
try:
sitename = 'skycn'
rule = u'下载次数:  ([0-9]+)'
url = 'http://www.skycn.com/soft/23265.html'
i += 1
ccount.getMatch(url,rule)
funcOutputMessage(str(i).rjust(2) + '.' + sitename.ljust(12) +':' + str(ccount.match.group(1)))
except:
pass

Friday, December 22, 2006

使用Emacs作为Python开发环境

Emacs号称是编辑器之王,无所不能。可把他作为一个Python的集成开发环境

尽管Emacs那么的牛,但是从前用的多的还是简单的 vi。受不了吸引,决定开始使用Emacs进行Python的编程。

python.org上emacs的主页和对应wiki中,对python-mode竟然没有太多的介绍,反而在另外一个网站上找到了一些 emac 的资料,特别是 安装过程

安装过程总结一下:

  1. 使用最新的emacs:大于21.1的XEmacsen,或者大于20.7的Emacsen.

  2. 确保安装了prog-modes这个包,在debian中很简单:
    #apt-get install prolog-el

  3. python-mode项目中,下载python-mode.el

  4. 字节编译,在emacs中输入命令(警告信息可忽略):
    C-x C-f /path/to/python-mode.el RET
    M-x byte-compile-file RET


  5. 确保python-mode.el在加载路径中,测试方法:
    M-x locate-library RET python-mode RET
    如果没有,加入下行到自己的.emacs文件中:
    (setq load-path (cons "/dir/of/python-mode/" load-path))

  6. 文件关联,自动将py后缀的文件和pyhton-mod关联,在自己的.emacs文件中添加:
    (setq auto-mode-alist
    (cons '("\\.py$" . python-mode) auto-mode-alist))
    (setq intercodeter-mode-alis
    (cons '("python" . python-mode)
    intercodeter-mode-alist))


  7. 自动加载,将 python-mode 和文件 python-mode.elc关联,在自己的.emacs文件中添加:
    (autoload 'python-mode "python-mode" "Python editing mode." t)

  8. 语法加亮,这个功能可不能少哟:) 同样在自己的.emacs文件中添加:
    ;;; add these lines if you like color-based syntax highlighting
    (global-font-lock-mode t)
    (setq font-lock-maximum-decoration t)


  9. 支持中文,在.emacs中添加:
    (set-language-environment 'Chinese-GB)
    (set-keyboard-coding-system 'euc-cn)
    (set-clipboard-coding-system 'euc-cn)
    (set-terminal-coding-system 'euc-cn)
    (set-buffer-file-coding-system 'euc-cn)
    (set-selection-coding-system 'euc-cn)
    (modify-coding-system-alist 'process "*" 'euc-cn)
    (setq default-process-coding-system
    '(euc-cn . euc-cn))
    (setq-default pathname-coding-system 'euc-cn)



  10. 好了!进入emacs试验一下:

    $ emacs abc.py

    可以看到emacs的底部显示:Using the CPython shell。可以试着输入一些代码,加亮显示没有问题,支持自动缩进,支持自动括号匹配提示.... 使用C-h m你可以看到python模式的详细帮助文件,功能果然很强大!

Python 网页抓取

PythonGoogle公司最重要的三大开发语言之一(C++, Java, Python)

用Python语言写搜索引擎蜘蛛的脚本非常简单、轻松。给大家分享两种抓网页内容的方法

一、用urllib2/sgmllib包,将目标网页的所有URL列出。


import urllib2

from sgmllib import SGMLParser

class URLLister(SGMLParser):
def reset(self):
SGMLParser.reset(self)
self.urls = []

def start_a(self, attrs):
href = [v for k, v in attrs if k=='href']
if href:
self.urls.extend(href)

f = urllib2.urlopen("http://www.donews.com")

if f.code == 200:
parser = URLLister()
parser.feed(f.read())
f.close()
for url in parser.urls: print url


二、用python调用IE抓取目标网页(Require win32com, pythoncom)的所有图像的url和大小


import win32com.client, pythoncom
import time

ie = win32com.client.DispatchEx('InternetExplorer.Application.1')
ie.Visible = 1
ie.Navigate("http://news.sina.com.cn")
while ie.Busy:
time.sleep(0.05)

doc = ie.Document
for i in doc.images:
print i.src, i.width, i.height


这种方法可以利用IE本身的Javascript. DHTML的支持,来做自动提交Form,和处理Javascript。
有关样例可以参考http://win32com.de

Wordpress分页标签

用过wordcodess 1.5版本的朋友应该都知道编辑器有个默认的"page"按钮,这是长文章分页用的,到了wordcodess 2.0版本之后,这个默认的"page"按钮就没有了,被"more"按钮取代了,其实我们还是可以使用他,<!--nextpage--> 这个分页标签就可以做到,如果想要添加编辑器按钮,在tinymce或者简单的编辑环境中都可以,只要取掉注释就可以了

  1. 在简单的编辑环境中,wp-includes/js/quicktags.js 文件中找到

    edButtons[edButtons.length] =
    new edButton('ed_next'
    ,'page'
    ,'<!--nextpage-->'
    ,''
    ,'p'
    ,-1
    );

    去掉注释代码就可以了

  2. 在TinyMCE环境中,wp-includes/js/tinymce/plugins/wordcodess/editor_plugin.js,找到 TinyMCE_wordcodess_getControlHTML 函数,替换为

    function TinyMCE_wordcodess_getControlHTML(control_name) {
    switch (control_name) {
    case "wordcodess":
    var titleMore = tinyMCE.getLang('lang_wordcodess_more_button');
    var titlePage = tinyMCE.getLang('lang_wordcodess_page_button');
    var titleHelp = tinyMCE.getLang('lang_wordcodess_help_button');
    var buttons = '';
    return buttons;
    }
    return '';
    }

    就可以了

Thursday, December 21, 2006

PSP版[地牢围攻:痛苦王座]图文攻略

本作流程和“大菠萝”(暗黑破坏神)类似,共分三大幕,每一大幕里主线任务和分支任务穿插进行。当然你也可以完全忽略分支任务,但这样做的结果就是你将失去很多得到高级装备的机会,而庞大的装备库系统则是这款游戏的一大亮点。

斜体字部分是地名,可以参照我的大地图。

A C T . 1 THE BROKEN LANDS大地图一


psp

  1. (1)OUT OF THE FRYING PAN… 接任务处:自带。

  2. 游戏开始的一个小任务,很简单。地图右边有个BOSS。可以杀也可以不杀,出口在地图左端。

  3. 来到大地图后去SEAHAVEN VILLAGE。找到队长谈话,然后找到HENDRICK谈话,任务完成。

  4. (2)Healing the Forest 接任务处:TAAR

  5. (3)Feeding The Village 接任务处:HENDRICK
  6. (5)Big Game Hunter 接任务处:ARENA





这三个任务可以一起接了,顺路一起完成。TAAR在村庄地图右下。

  1. 出村庄后,上面有个圣坛—SHRINE OF LIFE,站在圣坛上按→键调出道具栏,选STUFF按X使用EMPTY VIAL,装买圣水。

  2. 来到左上的SCORCHED HAMLET,进去后一路向上,找到如下图的七个箱子,拿光里面的物品。返回原路出地图。
    psp

  3. 来到地图右下角的RAPTORS NEST,找到RAPTOR并杀够一定的量既可。怪物长相见下图,地图里有很多RAPTOR,一路杀过来打到小BOSS这基本就能完成任务了。够没够量可以查看任务日志,或是屏幕出现your quests have been updated这句英文都可。
    psp

  4. 初期没回城卷轴可让怪物打死快速回城。当你挂了后选择REVIVE IN SEAHAVEN这句就直接回城了。

  5. 任务奖励:一些钱、装备,和一个新随从TAAR(自然系法师,辅助MM,很有用)。



(7)Trcaking The Hunters 接任务处:HENDRICK

去地图东部找幸存者。具体位置看我的大地图,搜索位置⑥,或看下图。完成任务后回城交任务。

4.jpg

(6)LOST SETTLERS 接任务处:HENDRICK

进入地图WEEPING FOREST,找到幸存者(位置如下图),在其旁边按→键调出道具栏,选STUFF按X使用PORTAL GEM,幸存者被传送回去,回城交任务,任务完成。

psp

(10)SIN OF PRIDE 接任务处:HENDRICK

  1. 先和卖药水的NPC(ABBOT FARNS)谈话。

  2. 进入地图WINDSTONE ABBEY (这个地图没截到,不好意思,大家看自己的大地图就OK)。注:先找到下图的小山洞(CRATER RIM)然后方可传到上面去。(山洞在大地图一⑤处)

  3. 在第一层左侧找到GORVINUS并干掉它。位置见下图。
    psp

  4. 在左边找到第二层入口(DEFILED SANCTUARY)进去。在右下处可找到一祭坛(见下图),这里有4个15级的BOSS守护着,打的时候用远程攻击一个一个的消灭。 PS:我是为了截图才站这,你也站着打那就等着躺吧。。
    psp game

  5. 然后去左边的小道一直走,在下图的一个房间里还有一个BOSS,消灭它。
    game PSP


Wednesday, December 20, 2006

Google发布2006度的各种热门搜索

googleGoogle发布了其2006度的各种热门搜索,除了一般的年度热门关键字索和热门新闻搜索,这次还包括了 "热门”,“实事”,“重要事件”,“娱乐”,“体育”这几类的搜索排名。其中在“实事”中的三个TOP关键字就是“伊拉克”、“北韩”和“伊朗”。在娱乐方面,看来都是美国人比较喜欢他们"Live Show",TOP的三字关键词是"Dancing With the Stars vs. American Idol vs.Project Runway",虽然这些只是英文世界的TREND,不过有的东西还是可以借鉴一下的,BAIDU的2006度搜索报告呢?不会在那上面出现广告吧? ;)

Google.com - Top Searches in 2006



  1. bebo

  2. myspace

  3. world cup

  4. metacafe

  5. radioblog

  6. wikipedia

  7. video

  8. rebelde

  9. mininova

  10. wiki



Google News - Top Searches in 2006



  1. paris hilton

  2. orlando bloom

  3. cancer

  4. podcasting

  5. hurricane katrina

  6. bankruptcy

  7. martina hingis

  8. autism

  9. 2006 nfl draft

  10. celebrity big brother 2006

Tuesday, December 19, 2006

Smarty的section镶套

数组

Array ( [0] => Array ( [HelpClassName] => 常见问题 [HelpClassID] => 1
[Help] => Array ( [0] => Array ( [HelpSubjectName] => PERL! [HelpSubjectID] => 1 ) [1] => Array ( [HelpSubjectName] => PYTHON[HelpSubjectID] => 4 )[2] => Array ( [HelpSubjectName] => RUBY? [HelpSubjectID] => 14 ) ) )

[1] => Array ( [HelpClassName] => 关于概念 [HelpClassID] => 3 [Help] => Array ( [0] => Array ( [HelpSubjectName] => 到底什么是PHP [HelpSubjectID] => 6 ) [1] => Array ( [HelpSubjectName] => php与PYTHON的区别是什么? [HelpSubjectID] => 7 ) ) )


[2] => Array ( [HelpClassName] => 新人必读 [HelpClassID] => 4 [Help] => Array ( [0] => Array ( [HelpSubjectName] => 怎样在PHP? [HelpSubjectID] => 13 ) [1] => Array ( [HelpSubjectName] => PHP使用说明(一) [HelpSubjectID] => 15 ) [2] => Array ( [HelpSubjectName] => PYTHON使用说明(二) [HelpSubjectID] => 16 ) [3] => Array ( [HelpSubjectName] => 如何PHP? [HelpSubjectID] => 17 ) [4] => Array ( [HelpSubjectName] => RUBY(三) [HelpSubjectID] => 18 ) ) ) );

?>


smarty,section镶套












Sunday, December 17, 2006

一半的寂寞

不知道为什么会用“一半的寂寞”为题目,可能我想一半刚刚好,说明现在的我并不是完整的,现在的时间并不是完整的,现在的工作不是完整的,现在天气不是完整,总是,可能一切对我都不是完整的。所以一半就是正确的,而不是否定某某,更不是怀疑某某。不否认自己的过错,也不想拖累,于是一半也是刚刚好好,然而为什么的寂寞的?难道一半的不是一种寂寞吗?

几天和KAKA小王吃饭,他们买房子了,为他们高兴啊,不知道是什么原因,看到他们的笑容自己也是觉得幸福的,我也知道,真正幸福的是他们,或是想想来说,幸福对与这一对是应该的,你可能觉得幸福来的突然,来得简单,来得刚刚好,但对他们来说,幸福就是这个样子的 ;) 居然忘记用手机给他们拍张照片纪念一下。

值得纪念的不单单是他们吧,总是有很多的人都是值得纪念他们的这段时间,比如方哥,哈哈,嘿嘿。恩,是的看到周围的人幸福也是一种幸福。;)

值得纪念是不是还有我?2006年最后一个月的最后一次弱智?我不是观察家,不能正确看待周围的一切,原来,我真的不是。明天又是一周,上班了,发两张买的PSP的图片就睡觉吧。有了PSP,Miniplayer还是要用的~(难道不爽的时候就想买东西?不过PSP是我上个月就打算买的,后来又没有买,不过现在把钱留起来也没有什么用了,还不如用它来缓解一下弱智的神经 :( ) KAKA他们问我下个目标是什么?是DC?我也不知道,于是我说到 ”等我把PSP耍坏了再说吧“,我们都笑了 ;)

psp

psp

psp

psp

Saturday, December 16, 2006

給自己的情歌 梁詠琪

gigi
更新日期:2006-12-13 12:49:19
藝人名稱:梁詠琪
專輯名稱:給自己的情歌
發行公司:豐華
音樂型態:Pop

推薦指數:無再聽見梁詠琪,歌聲依然溫暖的如此熟悉,即使經歷了如此多的風風雨雨,即使身邊環境已是漫天芭樂狗血,即使已不再是最初懵懂而天真的小女孩,GiGi仍然繼續唱著屬於她的心聲,屬於她的歌曲。因為音樂最貼近了GIGI的情感,也因為源自於對音樂的喜愛,她始終堅持而努力著。全新專輯「給自己的情歌」是GiGi在2006年底交出的音樂作品,10首歌曲中我們聽到了不一樣的梁詠琪,卻都有著一致濃濃的真實情感,在目前國語流行樂壇與大眾媒體的強烈口味需求之下,這整張專輯可喜的並不特別強調悲傷的基調,雖然主題都圍繞在城市裡每一段交織的愛情氛圍,卻是傷心、掙扎、無奈、寂寞、出口等等所有都會人矛盾又糾結的情緒,透過GiGi特具溫暖質感的聲音表現,讓所有人痛徹心扉、感同身受,因為每首歌所探討的盡皆是都會人關於戀愛、之於生活最真實的心情寫照。或許是不懂戀愛分分合合的道理,或許是希望掙脫忙碌而乏味的日常生活,或許渴望著一段美好的奇遇,也或許是對於生命衷心的感謝,「給自己的情歌」這一張具有都會透視感的情歌專輯,是這幾年來悄悄成長的GiGi獻給樂迷,也送給自己最溫暖的年終禮物。

「給自己的情歌」紀錄著梁詠琪一年來的音樂心情日記,整張專輯由四大製作人李偲菘、馬毓芬、阿弟仔、邁克林擔綱製作;周杰倫、伍家輝、小安;陳鎮川、黃俊郎、徐世珍、易家揚、鄭淑妃、彭學斌等詞曲創作者的聯手打造,在商業通俗中呈現獨特專屬的質感與氣味,營造一種更深刻的意境,單就音樂的本質在聆聽上就自然而然產生感同身受,人性化情感力量的渲染,詞意的精準與深切更完全打動人心。


GiGi's Blog: http://www.wretch.cc/blog/gigimusic

Thursday, December 14, 2006

使用Skype在ubuntu上通话

Skype安装Skype For Debian的最新版本(我安装的是1.3.0.53)
$wget http://skype.com/go/getskype-linux-deb
$sudo dpkg -i skype_debian-1.3.0.53-1_i386.deb

注意因为在Ubuntu/Debian系统中可能会因为SCIM输入法或者其他原因导致无法启动Skype,可以用下面的启动方式解决

$ export LANG=c
$ QT_IM_MODULE=xim skype

或者在KDE环境下安装 qtimm 软件包。不过注意使用第一种方法会造成个别中文字符显示的不完整。至少可以使用SKYPE通话啦,输入法和中文的问题相信很快会解决的。

Javascript document.write

对于javascript的初学者来说,document.write 是一个非常实用的函数,它可以把Javascript中的变量等写入到HTML上


JavaScript Cookies

What is a Cookie?
A cookie is a variable that is stored on the visitor's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With JavaScript, you can both create and retrieve cookie values.

Examples of cookies:

  • Name cookie - The first time a visitor arrives to your web page, he or she must fill in her/his name. The name is then stored in a cookie. Next time the visitor arrives at your page, he or she could get a welcome message like "Welcome John Doe!" The name is retrieved from the stored cookie

  • Password cookie - The first time a visitor arrives to your web page, he or she must fill in a password. The password is then stored in a cookie. Next time the visitor arrives at your page, the password is retrieved from the cookie

  • Date cookie - The first time a visitor arrives to your web page, the current date is stored in a cookie. Next time the visitor arrives at your page, he or she could get a message like "Your last visit was on Tuesday August 11, 2005!" The date is retrieved from the stored cookie


Create and Store a Cookie
In this example we will create a cookie that stores the name of a visitor. The first time a visitor arrives to the web page, he or she will be asked to fill in her/his name. The name is then stored in a cookie. The next time the visitor arrives at the same page, he or she will get welcome message.

First, we create a function that stores the name of the visitor in a cookie variable:

function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

The parameters of the function above hold the name of the cookie, the value of the cookie, and the number of days until the cookie expires.

In the function above we first convert the number of days to a valid date, then we add the number of days until the cookie should expire. After that we store the cookie name, cookie value and the expiration date in the document.cookie object.

Then, we create another function that checks if the cookie has been set:

function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=")
if (c_start!=-1)
{
c_start=c_start + c_name.length+1
c_end=document.cookie.indexOf(";",c_start)
if (c_end==-1) c_end=document.cookie.length
return unescape(document.cookie.substring(c_start,c_end))
}
}
return ""
}

The function above first checks if a cookie is stored at all in the document.cookie object. If the document.cookie object holds some cookies, then check to see if our specific cookie is stored. If our cookie is found, then return the value, if not - return an empty string.

Last, we create the function that displays a welcome message if the cookie is set, and if the cookie is not set it will display a prompt box, asking for the name of the user:

function checkCookie()
{
username=getCookie('username')
if (username!=null && username!="")
{alert('Welcome again '+username+'!')}
else
{
username=prompt('Please enter your name:',"")
if (username!=null && username!="")
{
setCookie('username',username,365)
}
}
}

All together now:

点击浏览器的后退按钮后表单内容的控制

为什么我在点击浏览器的后退按钮后,所有字段的信息都被清空了?

这是由于在表单提交页面中使用了 session_start 函数。该函数会强制当前页面不被缓存。解决办法为,在你的 session_start 函数后加入

header("Cache-control: private");

注意在本行之前你的PHP程序不能有任何输出。

还有基于 session 的解决方法,在 session_start 前加上

session_cache_limiter('nocache'); // 清空表单
session_cache_limiter('private'); //不清空表单,只在session生效期间
session_cache_limiter('public'); //不清空表单,如同没使用session一般

JavaScript的Cookie操作函数


//获得Cookie解码后的值
function GetCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}


//设定Cookie值
function SetCookie(name, value) {
var expdate = new Date();
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
+((secure == true) ? "; secure" : "");
}


//删除Cookie
function DelCookie(name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}


//获得Cookie的原始值
function GetCookie(name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return GetCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}

Wednesday, December 13, 2006

Ruby on Rails Windows安装问题

Ruby on Rails使用Windows上安装Ruby on Rails的时候,在使用gem安装Rails的时候遇到这样的问题
gem install rails --include-dependencies
错误提示找不到 ssleay32.dllzlib.dll,这时候需要下载下面这几个文件放到 \ruby-version\bin 这个目录下

Tuesday, December 12, 2006

DBD::mysql安装问题

在安装perl的DBD::mysql模块的时候遇到一些问题

$ perl -MCPAN -e shell
[....]
Can't exec "mysql_config": No such file or directory at Makefile.PL line 76.

Cannot find the file 'mysql_config'! Your execution PATH doesn't seem
not contain the path to mysql_config. Resorting to guessed values!
Can't exec "mysql_config": No such file or directory at Makefile.PL line 454.
Can't exec "mysql_config": No such file or directory at Makefile.PL line 454.
Can't exec "mysql_config": No such file or directory at Makefile.PL line 454.
Can't exec "mysql_config": No such file or directory at Makefile.PL line 454.
Can't exec "mysql_config": No such file or directory at Makefile.PL line 454.
Can't exec "mysql_config": No such file or directory at Makefile.PL line 454.
Failed to determine directory of mysql.h. Use
[....]

进入DBD::mysql的代码安装目录

$ cd $HOME/.cpan/build/DBD-mysql-3.0008
$ perl --mysql_config=$MYSQL_PREFIX_DIR/bin/mysql_config
$ make
$ make test
$ make install

这样就安装成功了

Perl安装问题

Perl在测试服务器上安装perl5.8.8

$./configure.gnu --codefix=$HOME/local
make

结果出错啦~

make[1]: Leaving directory `/home/.salk/ndw/src/perl-5.8.6/x2p'

Making B (dynamic)
opendir(./../../../../..): Permission denied at ../../lib/File/Find.pm line 597
Use of chdir('') or chdir(undef) as chdir() is decodecated at ../../lib/File/Find.pm line 741.
opendir(./..): Permission denied at ../../lib/ExtUtils/MakeMaker.pm line 165
Couldn't change to directory /home/.salk/ndw/C: No such file or directory at Makefile.PL line 18
Writing Makefile for B
Warning: No Makefile!
make[1]: Entering directory `/home/.salk/ndw/src/perl-5.8.6/ext/B'
make[1]: *** No rule to make target `config'. Stop.
make[1]: Leaving directory `/home/.salk/ndw/src/perl-5.8.6/ext/B'
make config failed, continuing anyway...
make[1]: Entering directory `/home/.salk/ndw/src/perl-5.8.6/ext/B'
make[1]: *** No rule to make target `all'. Stop.
make[1]: Leaving directory `/home/.salk/ndw/src/perl-5.8.6/ext/B'
make: *** [lib/auto/B/B.so] Error 2


$make minitest
来测试,结果在98.5%的地方出错了,没有办法,GOOGLE上搜索了一下,结果是编译的地方出错了,在 /tmp 下面编译一点问题都没有,看来是不是以后都要改变一下编译的习惯了? ;)
/tmp$ ./configure.gnu --codefix=$HOME/local && make && make test && make install

PHP下的文本换行替换

PHP今天遇到一个PHP下文本的换行替换问题,好无聊,在Windows或者Linux上有区别?不用管,用这个就好了
codeg_replace("~(?:\r)?\n~s", "", $str);

Sunday, December 10, 2006

QQ2006 Mobile Test 下载

qqQQ2006 Mobile是腾讯最近发布的QQ手机版本,与以前的不同,这个版本几乎拥有的PC版本QQ的所有功能,不过前提是你的手机型号是有要求的,一般来说智能手机是可以用上的,我的N3230当然可以了,现在就在用,在昨天下载的时候却遇到问题,怎么都下不到N3230版本的,后来在ZJ的帮助下,我得到了这个N3230的QQ2006test MOBILE,不需要支持其他费用,只需要支持手机上网的WAP或者GPRS费用就可以了。主要功能:
qq

  1. 好友分组

  2. QQ群

  3. 语音消息

  4. 视频聊天

  5. 传送图片

  6. 聊天室

  7. QQ秀

  8. 查看好友详细资料


怎么样,不错吧,其实腾讯早可以推出QQ的手机版本了的,为什么到等到现在,我觉得主要有这几个原因:

  1. 原来手机上使用QQ是要收费的,腾讯当然是要对赚点钱先

  2. 中国移动扬言SP业务不外包,大家都在找后路

  3. 手机通讯的巨大市场潜力,说不定两年后移动设备上的通讯将超过PC端

  4. 很多第三方面QQ手机版本的出现,好象当年的传奇私服,盛大就是一个好的例子,腾讯会凡同样的错误吗?



Friday, December 8, 2006

ruby on rails with Dream Host

Ruby on Rails最近KAKA在DH上搭建了一个Django的测试环境,感觉Python还是很强大,不过似乎做有些小而快速的WEB应用就不那么实在。今天在 Dream Host 上测试 Ruby on Rails,非常成功,安装非常简单,只要在DH的控制面板中把你Domain的FastCGI支持打开就可以了,我使用的是子目录的形式建立Ruby on Rails应用的。

不过在自己的windows上搭建开发环境的时候遇到了一点问题,在启动了服务之后出现
Application error (Rails)
的错误,后来google了一下,原来是服务的启动方式不对,必须使用
ruby script/server
才能正常工作 ;)

关于在windows上搭建 Ruby on Rails 的开发环境完全可以使用这个软件包

Jay Chou 黃金甲 - 周杰伦

Jay Chou周杰伦的新歌《黄金甲》最近发布了,可以点这里观看MV,再按这里收听电台的首播。

  周杰伦撇开擅长的R&B曲风,首度将重摇滚、街头饶舌与中国风三合一,为新片《满城尽带黄金甲》量身打造气势磅礡的主题曲《黄金甲》,花了一个月的时间才宣告完成。

  继成功打造《头文字D》及《霍元甲》主题曲,周杰伦应导演张艺谋之邀再度投身创作电影主题曲,写歌难不倒他,但要满足张导的要求,小天王坦言备感压力,在许多夜里与老搭档方文山讨论中国风歌词,也长时间待在录音室与制作人林迈可研究编曲,最后会选择“摇滚”曲风,就是为营造出千军万马的奔腾气势。

  向来以R&B曲风见长的周杰伦,往年创作仅《双刀》、《双截棍》两首歌比较偏向摇滚,如今想要突破旧思维,从现代重摇滚下手创作电影主题曲,堪称周杰伦在音乐曲风的一大突破,提及最崇拜的摇滚乐手?周杰伦陷入深思,随后才答到还满欣赏五月天的。但下一张新专辑是否会向摇滚乐靠拢或与五月天合作?他不置可否说:“再说吧!”

  推出《黄金甲》单曲EP,周杰伦除附赠自导的《黄金甲》MV,更附送《依然范特西》10首MV,他表示,此张单曲可说是集他执导的MV之大成,制作成本上千万,足够拍摄一部国片,但是否会在近期内由MV导演晋升为电影导演?阿尔发唱片表示,这需要长期规划,周杰伦也希望能早日成为电影导演,毕竟这是他的梦想。


Jay Jay Jay Jay

Wednesday, December 6, 2006

Dreamhost vs Youtube?

DreamHostLet your Dreamhost hosting as a Youtube? You can upload AVI/MOV/MPEG/MPG media files and Dreamhost can convert it to flv format for you! Like the Youtube, but, you can give faster speed to visitors, and upload media files as much as your Dreamhost space limited! I have 200G~(+1.0 GB / week). BTW, you can get more information about the media tool on Dreamhost, now!

Mini Linux

mini linux

很可能第一眼看到你会以为是一台无线路由器,可它去是你台MINI LINUX设备,甚至比MINI MAC都还要小巧,它叫做“Linutop”。

9.3 x 2.7 x 15 cm的大小和280克的重量,比Mac Mini更加小巧。采用AMD Geode低电压处理器(无需风扇,真正的静音PC),256MB内存和512MB ROM(Pocket PC?),4个USB2.0接口,100M网卡,VGA视频输出和音频输入/输出功能。估计Linutop的售价不会超过RMB1000元。

软件方面:Linutop自带Firefox浏览器、AbiWord文本编辑软件、Gaim即时通讯软件和Totem媒体播放器。很适合学校、图书馆、政府部门和一般企业的互联网应用。也可以作为Car PC。如果支持中文系统的话,可以弄一台给老爸老妈上网用。

Mini Linux Desktop

Monday, December 4, 2006

MSN80048820错误

刚刚到Office发现MSN不能连接啦 :( 搜索了一下,原来是MSN的老问题,看看我的系统间,非常正常,后来用下面这几行代码就成功修复了,保存下面的代码为msn-80048820-solved.bat 点击运行就可以了。


@ECHO OFF
ECHO.如果你msn中修复不了就运行吧.
ECHO *************************************
ECHO * This file is provided by msn-problems.com *
ECHO * Copyright (C) 2004-2005 *
ECHO *************************************
ECHO.
ECHO 等一下.

REM Following files only needed in windows XP
IF NOT "%os%"=="Windows_NT" GOTO WIN9X
regsvr32 Dssenh.dll /s
regsvr32 Gpkcsp.dll /s
regsvr32 Slbcsp.dll /s
regsvr32 Sccbase.dll /s

:WIN9X
IF NOT "%os%"=="Windows_NT" CD %windir%\System\
REM Needed by both XP and 9X
regsvr32 Softpub.dll /s
regsvr32 Wintrust.dll /s
regsvr32 Initpki.dll /s
regsvr32 Rsaenh.dll /s
regsvr32 Mssip32.dll /s
regsvr32 Cryptdlg.dll /s
regsvr32 Msxml3.dll /s
ECHO.
ECHO 搞定,还不可以到这网站的论坛询问 www.msn-problems.com
ECHO.
pause

Sunday, December 3, 2006

Top 10 Killer Apps For Linux

Nobody wants to use an operating system. They just want it be able to run the software they need. Therefore, its very important for an OS to have killer apps. Here’s a list of software that make Linux worth using.

1. Apache

Needs no introduction. The legendary web server app that probably almost every website runs on. If you even try to compare this with Microsoft’s IIS, I’m just going to burst out laughing my ass off.

2. Synaptic/Adept/YUM

How do 90% of computer users (the current windows + mac market share) even use their computers without a package manager ? Before switching to Linux, I was warned that installing software was going to be very very difficult and that alone would make me want to crawl back to my hda1 partition. The guy who said that has obviously never hurd (pun intended) of package managers.

3. Konqueror

Window File Managers simply cannot get better than this. Konqueror’s competitors - Finder and Explorer are nowhere near as good as it is. I would have try to describe the features, but there are just too many to write about. Check the wikipedia article for those details.

4. Beryl/Compiz

After 2 months of Beryl on my Ubuntu box, I can’t dream of a world without wobbly windows. Not to mention the Blur, Water, Desktop Cube, Animations, Trailfocus, Expose-like features, and Fading Windows. Makes me feel sorry for Windows users who have to stare at Luna everyday.

5. AmaroK

Brilliant music player that kicks iTunes proverbial bckside in every respect. Features include Podcasts, Internet Radio, Lyrics, Wikipedia information about the currently artist, and probably a zillion more that i haven’t discovered yet. Highly extensible with scripts and themes. The recent release also features a music store for digital music downloads (with free codeviews).

6. K3b

Windows users would say Nero is way better than K3b in terms of features and I would be forced to agree. But why the hell does a person who just wants to burn some discs also need a media player, an always-on media cataloging software, audio editor and other useless crap bundled ? K3b does what its supposed to do from a good interface and does it perfectly.

7. Apollon (frontend for giFT)

This program that surprisingly few people use is the best P2P software out there without doubt. I’ll just say this - it supports the FastTrack, Gnutella, Ares and OpenFT networks and has no added spyware. Now, if you need more convincing than that, you deserve to have your system “Kazaa-d”.

8. MPlayer + MEncoder

MPlayer is that media player that you’ve always wanted - the one that can play absolutely anything and doesn’t cost an arm, a leg and a couple of toes. And if you’re part of “the scene” there’s no better software than MEncoder to to rip those DVDs, and convert them to AVIs. And if you’re not hardcore geek enough to handle the command-line interface there are about a couple of thousand GUIs for these two programs floating around the net.

9. Deskbar

The Deskbar applet for the Gnome Panel searches liles and folders, Wikipedia, browser bookmarks and history, dictionary, Del.icio.us, address book contacts, Gmail and opens programs, web pages and even triples as a calculator. If you find another Search+Launcher+Calculator program, tell me.

10. Screem HTML/XML Editor

Yes I’ve used Dreamweaver and its very easy to use and all but if you want to really become a good web designer, you need to get rid of the WYSISWYG and actually look at the code that you put in. With Screem, you can use the markup you want rather than what the application thinks you need.

There are a lot of other programs for Linux that are really great (Firefox, OpenOffice.org, VLC Player) but they have Windows versions too and don’t qualify as killer apps for Linux. (EDIT: Apache is an exception. Although it runs on Windows and other operating systems too, it is almost always used as part of the LAMP configuration which invloves Linux)

Installing Ruby on Rails with mod_fcgi for Apache 2

railsAfter a few hours of trial and error using advice from many different sites/posts, this is the process that I found successful in getting Ruby on Rails working with the Apache 2 fcgi module on linux. I hope this helps someone hang onto a few more hair follicles.

Before we begin, I can say that this was only successful when I did the setup in this order. Perhaps others have done it in a different way, but this worked for me. BTW, I using Redhat Enterprise 4.

First, we'll install ruby.
curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.4.tar.gz
tar xvfz ruby-1.8.4.tar.gz
cd ruby-1.8.4
./configure --codefix=/usr/local
make
make install
cd ..

Just to make sure everything installed properly try this:
ruby --version
It should return something like this:
ruby 1.8.4 (2005-12-24) [i686-linux]

Now let's install ruby gems.
curl -O http://rubyforge.org/frs/download.php/5207/rubygems-0.8.11.tgz
tar xvfz rubygems-0.8.11.tgz
cd rubygems-0.8.11
ruby setup.rb
cd ..


Now we need to install the FastCGI development kit.
curl -O http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz
tar xvfz fcgi-2.4.0.tar.gz
cd fcgi-2.4.0
./configure --codefix=/usr/local
make
make install
cd ..

Allrighty then. We're moving now.