-
统计字母出现的次数
所属栏目:[百科] 日期:2020-12-17 热度:100
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 #Counts the number of times a 'letter' appears in a 'phrase'def CountLetterOccurrence(letter,phrase,matchCase) # Gets the length of the phra[详细]
-
费马素性检验
所属栏目:[百科] 日期:2020-12-17 热度:72
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 def fermat(num,iter) #num is the number to test,iter is the maximum number of iterations (higher is more accurate) rand = 1+rand(num-1) for[详细]
-
工资税率算法
所属栏目:[百科] 日期:2020-12-17 热度:174
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 #税率算法kk#张总的年终奖为48万元,算出的应纳税额为118625元,最终税后收入为36.1375万元。#李总的年终奖为48.0001万元,应纳税额为140625.3元,最[详细]
-
Rails 删除数据库关联记录(外键)
所属栏目:[百科] 日期:2020-12-17 热度:189
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 drop database Contact;create database Contact;use Contact;CREATE TABLE Employee ( id int unsigned not null auto_increment primary key,Name V[详细]
-
Ruby Tk 使用 Frame 组件
所属栏目:[百科] 日期:2020-12-17 热度:167
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 require 'tk'top=TkRoot.new{title "Shopping Details"}fname_label=TkLabel.new(top){ text "First Name" place('relx'=0.0,'rely'=0.1)}fname_entry[详细]
-
Rails 连接到 POP3 邮箱,并检查是否有邮件
所属栏目:[百科] 日期:2020-12-17 热度:175
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 require 'net/pop'mail_server = Net::POP3.new('mail.mailservernamehere.com')begin mail_server.start('username','password') if mail_server.mai[详细]
-
Ruby 连接并登录到 FTP 服务器
所属栏目:[百科] 日期:2020-12-17 热度:135
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 require 'net/ftp'require 'uri'uri = URI.parse('ftp://ftp.ruby-lang.org/')Net::FTP.open(uri.host) do |ftp| ftp.login 'anonymous','[email?prot[详细]
-
Ruby 查询域名的 MX 记录
所属栏目:[百科] 日期:2020-12-17 热度:130
今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 require 'resolv'Resolv::DNS.open do |dns| mail_servers = dns.getresources("google.com",Resolv::DNS::Resource::IN::MX) mail_servers.each do |[详细]
-
为已存在的controller添加rspec测试
所属栏目:[百科] 日期:2020-12-17 热度:146
rails g rspec : controller ControllerName 比如 rails g rspec : controller users 出自:http://stackoverflow.com/questions/4235763/how-do-i-generate-specs-for-existing-controllers[详细]
-
uri、open-uri、encode、encode_www_form_component
所属栏目:[百科] 日期:2020-12-17 热度:60
URI.encode 和 URI.encode_www_form_component 来自uri open-uri继承自uri,对open进行了重写,可以抓取网页 encode和 encode_www_form_component 不一样,如果对网址转码,需要用 encode_www_form_component ,否则可能会转不完全 剩下的以后再补充[详细]
-
ipython比pry好用的地方
所属栏目:[百科] 日期:2020-12-17 热度:80
python的shell工具有个大名鼎鼎的ipython,ruby也出了一个shell工具,并且带语法高亮,如同ruby社区的其它产品,一如既往的炫。本想用pry代替ipython做系统管理操作,但发现pry相比ipython有个致命的缺陷 在交互式shell中有时候需要修改前面定义的一个代码块[详细]
-
一段去除pyqt examples版权信息的ruby脚本
所属栏目:[百科] 日期:2020-12-17 热度:51
如果发布程序,不能去掉,要尊重作者的版权,这里所说的去掉仅仅是为了自己阅读examples代码的时候方便,ruby字符串处理比较方便,就用ruby了 #coding: utf-8require 'find'Find.find('/home/111/pyfiles/pyqt4_examples').to_a.keep_if{ |f| f.end_with?'.p[详细]
-
ruby判断一个数组是否有重复元素
所属栏目:[百科] 日期:2020-12-17 热度:119
a = [1,1,2,3]if a.dup.uniq! puts '数组a有重复元素'end[详细]
-
Ruby的source_location
所属栏目:[百科] 日期:2020-12-17 热度:162
Ruby可以通过source_location定位方法的定义位置 [7] pry(main) require "open-uri"= false[8] pry(main) URI.method(:join).source_location= ["C:/Ruby193/lib/ruby/1.9.1/uri/common.rb",784][9] pry(main)[详细]
-
Ruby中的常量和变量
所属栏目:[百科] 日期:2020-12-17 热度:127
常量以大写字母开头,如: Abc 、 ABC 全局变量以$开头,如: $a 、 $abc 、 $b 局部变量以小写字母或下划线开头,如: a 、 abc 、 _b 类变量以@@开头,如: @@a 、 @@abc 实例变量以@开头,如: @a 、 @abc 、 @b[详细]
-
为rails项目初始化安装rspec
所属栏目:[百科] 日期:2020-12-17 热度:184
$ rails g rspec:install[详细]
-
rvm创建和设置默认的gemset
所属栏目:[百科] 日期:2020-12-17 热度:80
rvm 2.2.1 --default? ? ??????????????????????????? #设置默认ruby版本 rvm gemset create rails420????? ????????????? #创建gemset rvm 2.2.1@rails420 --default ??????????????? ? #设置这个gemset为系统默认 rvm gemset delete rails420?? ??? ??????[详细]
-
vagrant启动后nginx无法启动的解决办法
所属栏目:[百科] 日期:2020-12-17 热度:148
这篇博客里说的很明白 http://razius.com/articles/launching-services-after-vagrant-mount/ 原因是启动nginx的时候本地目录还没映射到虚拟机,nginx当然启动不了,解决办法就是在目录映射完以后再次启动nginx。 vi /etc/init/vagrant.conf; 加入以下内容:[详细]
-
使用binding.pry调试ruby on rails程序
所属栏目:[百科] 日期:2020-12-17 热度:112
在需要调试的地方加入一行 binding. pry 然后刷新页面的时候页面就会卡住,在终端就进入了pry的控制台,可以在控制台里面操作当前代码的上下文变量。exit退出 示例代码 class SessionsController ApplicationController def new test = 'hahaha' binding.pry[详细]
-
windows平台下为ruby安装mysql2的奇幻旅程
所属栏目:[百科] 日期:2020-12-17 热度:151
windows下用RailsInstaller安装的ruby和rails gem install mysql2 的时候出现错误,从网上找的各种方法都不行,windows平台开发ruby果然是各种折腾,找到stackoverflow,一个安装低版本的建议,竟然成功了 gem install mysql2 - v 0.2 . 6 出处 http://stack[详细]
-
rvm设置ruby版本和返回到系统默认版本
所属栏目:[百科] 日期:2020-12-17 热度:60
设置回系统默认版本: rvm use system 设置某个版本(前提是这个版本已经安装): rvm 2.2.1 --default[详细]
-
使用Vagrant在Windows下部署开发环境
所属栏目:[百科] 日期:2020-12-17 热度:77
做Web开发少不了要在本地搭建好开发环境,虽然说目前各种脚本都有对应的Windows版,甚至是一键安装包,但很多时候和Windows环境的相性并不是那么好,各麻烦的问题是实际部署的环境通常是Linux,常常还要面临着开发和部署环境不一致,上线前还要大量的调试。[详细]
-
ruby 全局变量
所属栏目:[百科] 日期:2020-12-17 热度:86
$! 最近一次的错误信息 $@ 错误产生的位置 $_ gets最近读的字符串 $. 解释器最近读的行数(line number) $ 最近一次与正则表达式匹配的字符串 $~ 作为子表达式组的最近一次匹配 $n 最近匹配的第n个子表达式(和$~[n]一样) $= 是否区别大小写的标志 $/ 输入记录[详细]
-
Rails的session操作
所属栏目:[百科] 日期:2020-12-17 热度:150
创建session变量: session[:user_id] = 123 删除session变量: session[:user_id] = nil 清空所有session: reset_session[详细]
-
ruby在if条件不成立的时候自动设置变量为nil
所属栏目:[百科] 日期:2020-12-17 热度:191
$ pry[1] pry(main) aNameError: undefined local variable or method `a' for main:Objectfrom (pry):1:in `__pry__'[2] pry(main) if 1 == 2[2] pry(main)* a = 'aaa'[2] pry(main)* end = nil[3] pry(main) a= nil ruby的语法有些怪异,倒是挺方便,把 el[详细]