-
科拉茨猜想(3N +1问题)
所属栏目:[百科] 日期:2020-12-17 热度:181
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 def collatz(n)print "#{n} "if n 1if n % 2 != 0collatz(3*n + 1)elsecollatz(n/2)endendend#Examplecollatz(21) #= 21 64 32 16 8 4 2 1 以上是编程[详细]
-
表格的读取
所属栏目:[百科] 日期:2020-12-17 热度:102
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 # from table to CSVrequire 'odbc'require 'dbi'filename = "./file.csv"writeFile = File.open(filename,"w")dbh = DBI.connect('DBI:ODBC:data_sou[详细]
-
Rails 使用数据库事务 (ActiveRecord)
所属栏目:[百科] 日期:2020-12-17 热度:85
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 my_account = Account.find 3your_account = Account.find 4Account.transaction do my_account.update_attribute(:balance,my_account.balance-300.0[详细]
-
Ruby 读取 mysql 命令输出
所属栏目:[百科] 日期:2020-12-17 热度:77
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 require 'socket' client = TCPSocket.open('127.0.0.1','finger') client.send("mysqln",0) # 0 means standard packet puts client.readlines clie[详细]
-
树状结构输出文件目录结构
所属栏目:[百科] 日期:2020-12-17 热度:146
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 ?require 'find'class Recorderattr_accessor :fileSteamdef initialize(outputFilePath)@fileSteam = File.open(outputFilePath,'w')enddef appendLi[详细]
-
Ruby 打开 Word 文档并打印
所属栏目:[百科] 日期:2020-12-17 热度:194
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 require "win32ole"docfile = "yourDoc.doc"word = WIN32OLE.new "Word.Application"word.visible = trueword.documents.open docfileword.options.pr[详细]
-
一行代码让Linux终端下雪
所属栏目:[百科] 日期:2020-12-17 热度:102
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 #先运行irb 或 pryC=`stty size`.split[1].to_i;S=[0x2743].pack("U*");a={};puts " 33[2J";loop{a[rand(C)]=0;a.each{|x,o|;a[x]+=1;print " 33[#{[详细]
-
Ruby将网页中的图片保存到本地
所属栏目:[百科] 日期:2020-12-17 热度:57
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 require 'net/http'Net::HTTP.start("www.google.com.hk") { |http| resp = http.get("/images/srpr/nav_logo27.png") open("D:/test.png","wb") { |f[详细]
-
ruby unit
所属栏目:[百科] 日期:2020-12-17 热度:69
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 #!/usr/bin/env ruby #-w# coding:gbk #''' # author: leijming# date :20120701#'''load 'public/Testhelper.rb'beginTesthelper::LoadHelper.loadpa[详细]
-
读写yaml文件
所属栏目:[百科] 日期:2020-12-17 热度:69
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 require 'yaml'hash = {1 = 'sqlite3',2 = 'postgresql',3 = 'mssql',4 = 'mysql',5 = 'oracle'}# write yaml fileFile.open("/home/user002/data.yam[详细]
-
ruby 16种 hello world 写法
所属栏目:[百科] 日期:2020-12-17 热度:59
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 print '1 hello world! ' + "n"print "2 hello world!n"print('3 hello world! ' + 10.chr )print("4 hello world!n")print %q-5 hello world! - +[详细]
-
Ruby 对字符串进行转码
所属栏目:[百科] 日期:2020-12-17 热度:162
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 require 'iconv'input_encoding = "windows-1252"output_encoding = 'utf-8'converted_doc = Iconv.new(output_encoding,input_encoding).iconv("asdf[详细]
-
Ruby/GTK 版本的 "Hello, World" 程序
所属栏目:[百科] 日期:2020-12-17 热度:58
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 require 'gtk'window = Gtk::Window::newbutton = Gtk::Button::new("Hello,World!")button.signal_connect(Gtk::Button::SIGNAL_CLICKED) { puts "Go[详细]
-
Ruby:最大公因数/最小公倍数
所属栏目:[百科] 日期:2020-12-17 热度:142
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 print "Enter one number:"n1 = gets.to_iprint "Enter another number:"n2 = gets.to_igcf = 0lcm = 0if n1 = n2dividend = n1divisor = n2elsedivid[详细]
-
命令行查词典
所属栏目:[百科] 日期:2020-12-17 热度:102
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 #!/usr/bin/env ruby# encoding: utf-8require 'net/http'require 'rexml/document'include REXMLdef translate(word) unless word.nil? or word.empt[详细]
-
Ruby 使用 Gzip 和 Tar 对文件进行打包
所属栏目:[百科] 日期:2020-12-17 热度:108
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 require 'zlib'file = 'compressed.gz'Zlib::GzipWriter.open(file) do |gzip| gzip "this is a test." gzip.closeendopen(file,'rb') { |f| f.read(1[详细]
-
Ruby 做 HTTP 请求时定制 Headers
所属栏目:[百科] 日期:2020-12-17 热度:92
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 require 'net/http'require 'uri'module Net class HTTP def HTTP.get_with_headers(uri,headers=nil) uri = URI.parse(uri) if uri.respond_to? :to_[详细]
-
Ruby线程实现经典的生产者消费者问题
所属栏目:[百科] 日期:2020-12-17 热度:181
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 require "thread" puts "ProAndCon" queue = Queue.new #用队列Queue实现线程同步 producer = Thread.new do 10.times do |i| sleep rand(i) # 让线程[详细]
-
fxruby 显示图片,GUI,跨平台,但没有wxruby方便
所属栏目:[百科] 日期:2020-12-17 热度:92
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 #---# Excerpted from "FXRuby: Create Lean and Mean GUIs with Ruby",# published by The Pragmatic Bookshelf.# Copyrights apply to this code. I[详细]
-
Ruby 处理 XML-RPC 消息
所属栏目:[百科] 日期:2020-12-17 热度:70
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 require "xmlrpc/marshal"str = XMLRPC::Marshal.dump( { 'Ruby' = 'is cool' } )puts strp XMLRPC::Marshal.load( str ) 以上是编程之家(jb51.cc)为[详细]
-
大白+大白=白胖胖
所属栏目:[百科] 日期:2020-12-17 热度:73
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 2.2.0 :011 (50..99).each{|x| puts "#{x}+#{x}=#{2*x}" if x%10 == 2*x/100 2*x/10%10 == 2*x%10 }61+61=122 = 50..99 # ab+ab = bcc # x%10 == 2*x/[详细]
-
Ruby猜数字游戏
所属栏目:[百科] 日期:2020-12-17 热度:145
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 # encoding: UTF-8class NumberKeeperattr_accessor :number,:userGuessing,:smallerNum,:biggerNum,:guessTimesdef initialize(limit)@smallerNum =[详细]
-
Ruby 编写 XMLRPC 服务
所属栏目:[百科] 日期:2020-12-17 热度:61
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 require "xmlrpc/server"class Num INTERFACE = XMLRPC::interface("num") { meth 'int add(int,int)','Add two numbers','add' meth 'int div(int,'D[详细]
-
“Ruby太慢” ruby真的慢吗?
所属栏目:[百科] 日期:2020-12-17 热度:114
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 t1 = Time.now.to_imin = Math.sqrt(1).to_imax = Math.sqrt(10**14).to_idef isH(num) num = num.to_s return num == num.reverseendfor num in (min[详细]
-
Ruby 使用 getname 方法获取 IP 地址对应的主机名
所属栏目:[百科] 日期:2020-12-17 热度:131
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 require 'resolv'ip = "192.0.34.166"begin puts Resolv.getname(ip)rescue puts "No hostname associated with #{ip}"end 以上是编程之家(jb51.cc)为[详细]