在玩!(2.2-M2)我有一个类似于的JsValue:
val people: JsValue = [{"name":"Alice","subdomain":"alice","color":"orange"},{"name":"Jorge","subdomain":"jorge","color":"blue"},{"name":"Bob","subdomain":"robert","color":"green"}...]
Run Code Online (Sandbox Code Playgroud)
我只想要这个JsValue中的元素数量.我可以匆匆地通过
(people \\ "name").size
Run Code Online (Sandbox Code Playgroud)
但是这个大小计算位于一个方法中,该方法接收具有不同内容的JsValues,并且name不会总是存在,例如
val places: JsValue = [{"country":"UK", "country":"ES", ...]
Run Code Online (Sandbox Code Playgroud)
要么
val things: JsValue = [{"widget":"foo", "price":"1", "widget":"bar" ... ]
Run Code Online (Sandbox Code Playgroud)
我把头发拉出来,我如何才能获得这些JsValues中的元素数量?
如果我要显示未知数量的项目,每个项目都在自己的列中,是否有办法让它们平均包装而不必为每个项目创建新行?
我有
<div class="row">
<!-- 1st col --><div class="col-md-3 col-sm-4 col-xs-6"><h1>Title lorem</h1><p>Short</p></div>
<!-- 2nd col --><div class="col-md-3 col-sm-4 col-xs-6"><h1>Title lorem</h1><p>Description lorem</p></div>
...
<!-- nth col --><div class="col-md-3 col-sm-4 col-xs-6"><h1>Title lorem</h1><p>Description lorem that might be long</p></div>
</div>
Run Code Online (Sandbox Code Playgroud)
列将具有不同的高度,这有时会导致不均匀分布的列:

有没有可能让列总是包含4列(对于中),3列(对于小)或2列(对于超小)的行只有CSS,或者我需要一些JS或使用一些服务器端编程创建新行?
在我的Rails 4应用程序中,我正在使用Rspec进行测试.我的目录结构是
spec
-- controllers
-- factories
-- features
-- spec_helper.rb
-- support
Run Code Online (Sandbox Code Playgroud)
当我运行时rspec spec,它运行我的测试controllers,但不是features.我可以指定rspec spec/features并且它们会运行,但我希望能够立即运行所有测试spec.我的猜测是它没有features因为配置设置而查看,但我不知道它在哪里.
我尝试了不同的咒语,开始rspec但没有运气.
我正在使用Nokogiri抓取HTML文档,其中许多可能有未封闭的标签.例如,我想关闭"未关闭"的<p>标签.
我查看了文档并查看"Nokogiri纠正了坏标记"的位置,但我没有看到一个很好的方法来做到这一点.
也许它需要遍历每个元素并关闭任何不匹配的标签?
我有一个自定义邮件程序(UserMailer.rb)和一些方法来覆盖欢迎电子邮件和忘记密码电子邮件的默认设计方法.邮件程序使用自定义模板来设置电子邮件的样式 - 而且效果很好.
在config/initializers,我有一个文件
module Devise::Models::Confirmable
# Override Devise's own method. This one is called only on user creation, not on subsequent address modifications.
def send_on_create_confirmation_instructions
UserMailer.welcome_email(self).deliver
end
...
end
Run Code Online (Sandbox Code Playgroud)
(同样,UserMailer已设置好并且适用于欢迎电子邮件和重置密码电子邮件.)
但是什么不起作用是"重新发送确认指令"的选项.它使用默认的Devise样式发送,我希望它使用我的邮件程序布局的样式.我知道我可以手动将布局添加到默认的Devise布局,但我想保持DRY生效而不必这样做.
我试图重写send_confirmation_instructions方法找到这里,但我得到一个wrong number of arguments (1 for 0)错误create(gem) devise-2.2.3/app/controllers/devise/confirmations_controller.rb的
7 # POST /resource/confirmation
8 def create
9 self.resource = resource_class.send_confirmation_instructions(resource_params)
Run Code Online (Sandbox Code Playgroud)
在我的初始化文件中,我可以通过为Devise添加新的覆盖来解决此错误,但我可能没有正确执行此操作:
module Devise::Models::Confirmable::ClassMethods
def send_confirmation_instructions
UserMailer.send_confirmation_instructions(self).deliver
end
end
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我是一个Scala/Java noob,很抱歉,如果这是一个相对简单的解决方案 - 但我正在尝试访问外部文件中的模型(Apache Open NLP模型),并且不确定我哪里出错了.以下是您在Java中的使用方法,以下是我正在尝试的内容:
import java.io._
val nlpModelPath = new java.io.File( "." ).getCanonicalPath + "/lib/models/en-sent.bin"
val modelIn: InputStream = new FileInputStream(nlpModelPath)
Run Code Online (Sandbox Code Playgroud)
哪个工作正常,但尝试基于该二进制文件中的模型实例化对象是我失败的地方:
val sentenceModel = new modelIn.SentenceModel // type SentenceModel is not a member of java.io.InputStream
val sentenceModel = new modelIn("SentenceModel") // not found: type modelIn
Run Code Online (Sandbox Code Playgroud)
我也尝试了一个DataInputStream:
val file = new File(nlpModelPath)
val dis = new DataInputStream(file)
val sentenceModel = dis.SentenceModel() // value SentenceModel is not a member of java.io.DataInputStream
Run Code Online (Sandbox Code Playgroud)
我不确定我缺少什么 - 也许是一些方法将Stream转换为一些二进制对象,我可以从中提取方法?谢谢你的任何指示.