ruby来枚举csdn未注册的用户名
require 'open-uri'
$NAME_CHARS= (?a..?z).to_a+(?0..?9).to_a
def is_name_used(name)
str=open('http://passport.csdn.net/UserExist.aspx?UserName='+name)
str=str.read
#str=str.encode('GBK','utf-8')
return true if str[/Red/]
end
def enum_names(len=2)
return if len<2
f=File.open('d:\work\a.txt',"w+")
strpack="A"*len
i,v=0,""
$NAME_CHARS.permutation(len) do |x|
v=x.pack(strpack)
break if v[/^[\d]+/]
#p i+=1
f.puts "#{i+=1} : #{v}"
f.puts "#{v} is not use!" unless is_name_used(v)
end
rescue =>ex
p "err : #{ex.to_s}(#{v})"
ensure
f.close if f
end
相关文档:
转 Adding Sound to Your Ruby Apps
Have you ever thought about including sounds in your Ruby application? Used sparingly, sound may enhance your applications by adding audio cues or a custom touch. You could, for example, play a beep or chime that announces the completion of a lengthy process. Per ......
分页中用到类变量,主要是用来标记“页码输入框”的id 如果一个页面有几个分页,“页码输入框”的id要是不同的才能分清是哪个要分页。使用类变量就是为了达到这个目的,让所有的对象实例共用一个变量,不必每次重新初始化变量。 类变量使用代码示例 1 require 'ruby-debug'
2 debugger
3 cla ......
安装环境:
OS:Windows XP
Ruby: Ruby1.9.1
Mysql: Mysql5.1.46 (username/password: root/root port:3306)
Ruby-Mysql Driver: mysql-2.8.1-x86-mswin32.gem
(注:用2.7.3版本的驱动在测试时会出现 require"mysql",找不到指定模块 错误)
IDE:RubyMine2.0.1
安装Ruby,RubyMine,Mysql的事项在这里就不多 ......
我们知道ruby中对于整数的[],[]=,<<,>>操作是针对于二进制的值来运算的。
我现在写一个针对十进制数操作的类,拥有整数的所有方法,如下:
class InterEx
def initialize(val=0)
@val=val
end
def to_s
@val.to_s
end
def [](idx)
self.to_s[idx].to_i
end
d ......
前言
在《Routing的载入》中,我大致介绍了一下Rails中最简单的route是如何加载的。这篇文章,我将来讲一讲Rails系统中更为复杂的named route和与RESTful相关的resource是如何被加载的。为了不重复太多的笔墨,这篇文章将在前文的基础上进行,如果发现单独看此文时,有少许云里雾里,建议先看一看我的前篇文章:R ......