小编Til*_*ilo的帖子

如何动态获取方法的源代码以及此方法所在的文件

我想知道我是否可以动态获取源代码源代码,以及我是否可以获取此方法的文件.

喜欢

A.new.method(:a).SOURCE_CODE
A.new.method(:a).FILE
Run Code Online (Sandbox Code Playgroud)

ruby

83
推荐指数
4
解决办法
4万
查看次数

在Elixir/Phoenix中呈现"OK"的最简约方法是什么?

在Rails中,您可以直接渲染文本,例如 render :text => 'OK'

Elixir/Phoenix中是否有快捷方式直接渲染文本,而无需定义模板或布局?

我找到的最短路是:

  defmodule MyApp.PageController do
    use MyApp.Web, :controller

    def index(conn, _params) do
      # the file ok.html.eex contains just the string OK
      render conn, "ok.html", layout: false
    end
  end
Run Code Online (Sandbox Code Playgroud)

是否有更短的方式来呈现"OK",而无需提供模板文件"ok.html"?

phoenix-framework

17
推荐指数
1
解决办法
4676
查看次数

生产中重新启动/自动修复Mongodb

我想要实现的是拥有一个/etc/init.d脚本,它可以更可靠地启动Mongodb,即使它很难用 - 它应该在系统处于锁定状态时尝试自动修复.

是的,我可以自己编写脚本,但我认为那里的人肯定已经这样做了.

我注意到在服务器出现故障后,Mongodb处于不通过/etc/init.d/mongod脚本重启的状态.显然需要删除锁定文件,并且需要首先使用--repair选项启动并更正--dbpath,然后才能成功重新启动.在某些情况下,还需要将db-files的所有权更改为运行mongodb的用户.另外一个问题是标准的/etc/init.d/mongod脚本在这种情况下不会报告失败,而是以"OK"状态快速且错误地返回,报告Mongod已启动,尽管事实并非如此.

$ sudo /etc/init.d/mongod start
Starting mongod: forked process: 9220
all output going to: /data/mongo/log/mongod.log
                                                           [  OK  ]
$ sudo /etc/init.d/mongod status
mongod dead but subsys locked
Run Code Online (Sandbox Code Playgroud)

操作系统是CentOS或Fedora.

有没有人修改过/etc/init.d脚本或指向这种脚本的指针,在这种情况下会自动尝试修复? 还是有另一种工具可以作为Mongod的看门狗吗?

有关为什么试图自动修复mongodb可能是个坏主意的任何意见?

$ sudo /etc/init.d/mongod status
mongod dead but subsys locked

$ sudo ls -l /var/lib/mongo/mongod.lock 
-rw-r--r--. 1 mongod mongod 5 Nov 19 11:52 /var/lib/mongo/mongod.lock


$ sudo tail -50 /data/mongo/log/mongod.log
************** 
old lock file: /data/mongo/db/mongod.lock.  probably means unclean shutdown
recommend removing file and running --repair
see: http://dochub.mongodb.org/core/repair …
Run Code Online (Sandbox Code Playgroud)

linux centos fedora mongodb

12
推荐指数
1
解决办法
9234
查看次数

更新系统后RubyGems错误

在使用'sudo gem update --system'更新我的ruby设置后尝试启动rails控制台时,我尝试通过发出执行rails控制台 rails c

我收到此错误:

Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find json (~> 1.4) amongst [Ascii85-1.0.1, abstract-1.0.0, actionmailer-3.1.1, actionmailer-3.1.0, actionmailer-3.0.9, actionmailer-3.0.5, actionmailer-3.0.3, actionpack-3.1.1, actionpack-3.1.0, actionpack-3.0.9, actionpack-3.0.5, actionpack-3.0.3, activemodel-3.1.1, activemodel-3.1.0, activemodel-3.0.10, activemodel-3.0.9, activemodel-3.0.5, activemodel-3.0.3, activerecord-3.1.1, activerecord-3.1.0, activerecord-3.0.9, activerecord-3.0.5, activerecord-3.0.3, activeresource-3.1.1, activeresource-3.1.0, activeresource-3.0.9, activeresource-3.0.5, activeresource-3.0.3, activesupport-3.1.1, activesupport-3.1.0, activesupport-3.0.10, activesupport-3.0.9, activesupport-3.0.5, activesupport-3.0.3, addressable-2.2.6, ansi-1.3.0, arel-2.2.1, arel-2.0.10, arel-2.0.9, arel-2.0.7, bcrypt-ruby-3.0.1, bcrypt-ruby-3.0.0, bcrypt-ruby-2.1.4, builder-3.0.0, builder-2.1.2, bundler-1.0.21, bundler-1.0.18, bundler-1.0.11, choices-0.2.4, cocaine-0.2.0, coffee-rails-3.1.1, coffee-rails-3.1.0, coffee-script-2.2.0, coffee-script-source-1.1.2, devise-1.4.8, devise-1.4.2, erubis-2.7.0, erubis-2.6.6, execjs-1.2.9, execjs-1.2.6, execjs-1.2.4, faraday-0.7.4, faraday-0.6.1, faraday_middleware-0.7.0, …
Run Code Online (Sandbox Code Playgroud)

rubygems ruby-on-rails rvm ruby-on-rails-3.1

10
推荐指数
1
解决办法
2万
查看次数

Ruby生成自签名证书

我正在尝试在ruby中生成自签名证书,但遇到了麻烦.这就是我现在所拥有的:

require 'openssl'

if ARGV.length != 3 then
    puts "USAGE: #{__FILE__} <type[der|pem]> <private-out> <public-out>"
    exit
end

type = ARGV[0].downcase
privateKeyFile = ARGV[1]
publicKeyFile = ARGV[2]

values = [{ 'C' => 'US'},
          {'ST' => 'SomeState'},
          { 'L' => 'SomeCity'},
          { 'O' => 'Organization'},
          {'OU' => 'Organizational Unit'},
          {'CN' => "somesite.com"}]

name = values.collect{ |l| l.collect { |k, v| "/#{k}=#{v}" }.join }.join

key = OpenSSL::PKey::RSA.generate(1024)
pub = key.public_key
ca = OpenSSL::X509::Name.parse(name)
cert = OpenSSL::X509::Certificate.new
cert.version = 2 
cert.serial = 1 
cert.subject = …
Run Code Online (Sandbox Code Playgroud)

ruby openssl ssl-certificate x509certificate

7
推荐指数
2
解决办法
6183
查看次数

需要Nokogiri?没有这样的文件加载

我正在尝试开始使用Nokogiri.我跑了命令

gem install nokogiri
Run Code Online (Sandbox Code Playgroud)

作为Windows 7(64位)的管理员.控制台说"成功安装"和"1安装宝石".

当我输入

gem list --local OR gem q --local
Run Code Online (Sandbox Code Playgroud)

我将Nokogiri列入"本土宝石"名单.

但是,当我尝试通过require语句(在NetBeans中)使用它时,我收到一条错误,即"没有这样的文件要加载".

我究竟做错了什么?我不是Ruby专业人士.这也是我安装的第一个宝石.请为我愚蠢.

ruby netbeans rubygems jruby nokogiri

7
推荐指数
3
解决办法
1万
查看次数

常见问题解答插件或Gem for Rails 3?

常见问题解答似乎是Web应用程序中非常常见的功能..但似乎没有可用于Rails的宝石或插件.

你能推荐一个为Rails应用程序提供FAQ的gem或插件吗?

显然,您可以使用Rails快速制作一个简单的常见问题解答,但可以添加更多功能:投票,搜索,类别,角色,评论,标记,嵌入式链接,标签......仅举几例.

似乎人们正在为FAQ重新发明轮子

gem rubygems ruby-on-rails ruby-on-rails-3

7
推荐指数
1
解决办法
3002
查看次数

使用Ruby NArray而不是Array有什么好处?

我刚刚遇到了Ruby的NArray库 - 请原谅我这个问题时的无知:)

使用NArray库比标准Ruby Array实现有什么好处?

我已经看到NArray面向数值计算,但是看看API,看起来只有几个扩展而不是数字值 - 没有你不能用Array做的事情.

  1. 为什么不使用Array?
  2. 是否有巨大的速度优势?
  3. 有巨大的记忆优势吗?
  4. 使用常规Ruby Array类还有什么优势?

谷歌并没有真正想出这个问题的有用解释.

参考资料我发现:

http://rubydoc.info/gems/narray-ruby19/0.5.9.7/NArray

http://narray.rubyforge.org/index.html.en

http://raa.ruby-lang.org/project/narray/

ruby arrays numerical-computing narray

7
推荐指数
2
解决办法
1899
查看次数

rake资产:预编译不起作用(rails 3.1.1)

我正在部署到heroku但我看到没有提供css文件(它们也无法在heroku上找到).

我读到我需要做rake资产:首先在本地预编译然后当我这样做时,我得到:

C:\project>bundle exec rake assets:precompile --trace

** Invoke assets:precompile (first_time)
** Execute assets:precompile
rake aborted!
undefined: Unexpected token: operator (<)
  (in C:/project/app/assets/javascripts/application.js)

Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
Run Code Online (Sandbox Code Playgroud)

我在application.js中什么也没有,所以我不明白错误在哪里..

application.js是

// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not …
Run Code Online (Sandbox Code Playgroud)

windows rake assets heroku ruby-on-rails-3

7
推荐指数
3
解决办法
7450
查看次数

PostGIS:如何找到与给定集合最接近的 N 组点?

我正在使用 PostGIS/Rails 并且有一组带有地理位置的点。

class DataSet < ActiveRecord::Base  # these are the sets containing the points
  has_many :raw_data
  # attributes: id , name
end

class RawData < ActiveRecord::Base  # these are the data points
  belongs_to :data_set
  # attributes: id, location which is "Point(lon,lat)"
end
Run Code Online (Sandbox Code Playgroud)

对于给定的一组点,我需要找到 N 个最近的组和它们的距离;

或者: 对于给定的最大距离和一组点,我需要找到 N 个最近的组。

使用 PostGIS 执行此操作的最佳方法是什么?

我的版本是带有 PostGIS 2.1.2 的 PostgreSQL 9.3.4

gis postgresql postgis ruby-on-rails geospatial

6
推荐指数
1
解决办法
2984
查看次数