ruby
文章平均质量分 57
gongguoqinghaha
哈哈哈哈哈哈哈哈哈
展开
-
Ruby多进程并行抓取网页
用Ruby写了一个脚本,用Beanstalk消息队列,把任务放入Beanstalk中,同时开启多个子进程,如20个,并行运行,同时抓取网页,先抓取完成的进程再次读取Beanstalk任务,继续执行,直到没有任务后,进程退出,主进程等待所有子进程退出后,打印抓取的消息。 Ruby的多线程实际是只能跑在单cpu上,并且同一时刻cpu只处理一个线程,所以采用多进程抓取,消息队列采用最简单的Beans转载 2013-01-22 14:55:12 · 583 阅读 · 0 评论 -
Ruby 在 Windows 下读取键盘输入
require 'Win32API'def getch @getch ||= Win32API.new('crtdll', '_getch', [], 'L') @getch.callendwhile (c = getch) != ?\e puts "You typed #{c.chr.inspect}"end原创 2013-01-23 10:28:09 · 1054 阅读 · 0 评论 -
Ruby 使用 OpenGL 的例子
require "opengl"require "glut"$light_diffuse = [1.0, 0.7, 0.7, 1.0]$light_position = [1.0, 1.0, 1.0, 0.0]$n = [ [-1.0, 0.0, 0.0], [0.2, 1.0, 0.0], [1.0, 0.0, 0.0], [0.0, -1.0, 0.0], [0.0, 0.3转载 2013-01-23 10:38:10 · 429 阅读 · 0 评论 -
ruby+rails+mysql+win or linux的安装大全
首先下载 http://rubyforge.org/frs/download.php/75468/railsinstaller-2.0.1.exe此安装包含以下组件安装完成之后去;git是一个程序版本控制管理工具,需要到github.com上注册一个免费用户,注册步骤如下图。一、安装ruby-dbi下载地址:http://rubyforge.org/projects原创 2013-01-08 16:57:46 · 557 阅读 · 0 评论 -
在ruby使用ssh连接linux服务器
require 'net/ssh' host = hostipusername = usernamepassword = pwd##显示文件和系统版本server_cmd1 = 'ls -l'server_cmd2 = 'cat /etc/issue'# 连接到远程主机 foobarssh = Net::SSH.start(host, username, :passwor原创 2013-01-23 10:30:22 · 624 阅读 · 0 评论 -
ruby编写的乘法口诀代码
TEST_FILE_NAME = '乘法口诀.txt'#创建文件File.open(TEST_FILE_NAME, 'w+') do |file| for x in 1..9 for y in 1..x if x==y file.print y,"×",x,"=",x*y,"\n" file.puts "" #加入空行,美观作用 e原创 2013-01-23 10:33:53 · 542 阅读 · 0 评论 -
Ruby 打开 Word 文档并打印
require "win32ole"docfile = "yourDoc.doc"word = WIN32OLE.new "Word.Application"word.visible = trueword.documents.open docfileword.options.printBackground = falseword.activeDocument.printOutw原创 2013-01-23 10:32:36 · 625 阅读 · 0 评论 -
ruby 163 发送 邮件
require 'rubygems'require 'mail'smtp = { :address => 'smtp.163.com', :port => 25, :domain => '163.com', :user_name => '18703609654', :password => '****', :enable_starttls_auto => true, :openssl_ve转载 2013-01-23 10:39:40 · 520 阅读 · 0 评论 -
ruby way之OOP之一
1.class ColoredRectangle def initialize(r, g, b, s1, s2) @r, @g, @b, @s1, @s2 = r, g, b, s1, s2 end def ColoredRectangle.white_rect(s1, s2) new(0xff, 0xff, 0xff, s1, s2) end def原创 2013-01-22 15:03:21 · 324 阅读 · 0 评论