我有一个包含具有 4 个参数(x、y、iD 和 myType)的对象的 ArrayList。我想验证此 ArrayList 中是否存在具有特定坐标的对象,独立于它们的 iD 和 myType 参数。我想使用Arrays.asList(yourArray).contains(yourValue)但它是当对象只有一个参数时。
这是整个代码:
public class MyObject {
public float x;
public float y;
public int iD;
public String myType;
public MyObject (float x, float y, int iD, String myType)
{
this.myType = myType;
this.iD = iD;
this.x = x;
this.y = y;
}
@Override
public String toString() {
return ("[iD="+iD+" x="+x+" y="+y +" type="+myType+"]");
}
}
ArrayList<MyObject> myArrayList = new ArrayList<MyObject>();
void setup()
{
size(100, 60);
myArrayList.add(new MyObject(3.5, …Run Code Online (Sandbox Code Playgroud) 我有一个数组word_array,我想在其中添加句子的所有单词.例如:
word_array = []
sentence_1 = "my first sentence"
sentence_2 = "my second sentence"
Run Code Online (Sandbox Code Playgroud)
然后有:
word_array = ["my", "first", "sentence", "my", "second", "sentence"]
Run Code Online (Sandbox Code Playgroud)
如果我使用split():
word_array << sentence_1.split
word_array << sentence_2.split
Run Code Online (Sandbox Code Playgroud)
我明白了:
word_array = [["my", "first", "sentence"], ["my", "second", "sentence"]]
Run Code Online (Sandbox Code Playgroud)
我怎样才能避免在这里使用2D阵列?
我正在尝试在 Swift 中创建一个自定义相机。我找到了很多关于此的帖子,并设法打开相机,有一个“开始录制”按钮。但是,当单击“开始录制”按钮时,出现以下错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCaptureMovieFileOutput startRecordingToOutputFileURL:recordingDelegate:] No active/enabled connections'
Run Code Online (Sandbox Code Playgroud)
当查找这个错误时,它应该是由于我在函数中没有设置相机的质量引起的beginSession:
func beginSession(captureDevice: AVCaptureDevice) {
var err : NSError? = nil
var input = AVCaptureDeviceInput?()
do {
input = try AVCaptureDeviceInput(device: captureDevice)
} catch _ {
//Error handling, if needed
}
captureSession.addInput(input)
captureSession.sessionPreset = AVCaptureSessionPresetHigh;
if err != nil {
print("error: \(err?.localizedDescription)")
}
previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
self.view.layer.addSublayer(previewLayer!)
previewLayer?.frame = self.view.layer.frame
captureSession.startRunning()
let btn: UIButton = UIButton(frame: CGRectMake((self.view.frame.size.width-350)/2, (self.view.frame.size.height-80), 350, 70)) …Run Code Online (Sandbox Code Playgroud) 我使用 Tailwind css 和 Vue.js 创建模式。由于 Tailwind 不支持 Vue 2,我必须添加过渡。您可以在这里看到所需的效果: https://tailwindui.com/components/application-ui/overlays/modals
这是代码:
<template>
<div>
<button @click="show = true">Click</button>
<!-- This example requires Tailwind CSS v2.0+ -->
<div v-show="show" class="fixed z-10 inset-0 overflow-y-auto" aria-labelledby="modal-title" role="dialog" aria-modal="true">
<div class="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0">
<!--
Background overlay, show/hide based on modal state.
Entering: "ease-out duration-300"
From: "opacity-0"
To: "opacity-100"
Leaving: "ease-in duration-200"
From: "opacity-100"
To: "opacity-0"
-->
<transition name="ease-out-overlay">
<div v-show="show" class="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity"></div>
</transition>
<!-- …Run Code Online (Sandbox Code Playgroud) 我的托管服务提供商自动更新到4.5,导致Visual Composer插件出错.
我阅读了这些帖子: Wordpress 4.5更新后插件抛出TypeError
Visual Composer不加载并给出TypeError:_. trylate(...).trim不是函数
未捕获的TypeError:$ template.get不是函数
并将html2element函数替换为提供的函数.但是,由于很多人对这些帖子发表了评论,我收到了一个新错误:
composer-view.js?ver=4.6.1:139 Uncaught TypeError: Cannot read property 'attributes' of undefined
Run Code Online (Sandbox Code Playgroud)
这是我的功能:
html2element: function(html) {
var $template, attributes = {},
template = html;
$template = $(template(this.model.toJSON()).trim()), _.each($template.get(0).attributes, function(attr) {
attributes[attr.name] = attr.value
}), this.$el.attr(attributes).html($template.html()), this.setContent(), this.renderContent()
},
Run Code Online (Sandbox Code Playgroud)
错误似乎来自这一行:
$template.get(0).attributes
Run Code Online (Sandbox Code Playgroud)
有没有人想出如何解决它?
谢谢你的帮助
我正在尝试在执行控制器操作 3 分钟后运行作业。
我用 DelayedJob 试过这个:
# in my controller
def index
@books = Book.all
Delayed::Job.enqueue(ReminderJob.new(params[:user_id]))
end
Run Code Online (Sandbox Code Playgroud)
在ReminderJob.rb文件中:
class ReminderJob < Struct.new(:user_id)
def perform
p "run reminder job"
# do something
end
handle_asynchronously :perform, :run_at => Proc.new { 3.minutes.from_now }
end
Run Code Online (Sandbox Code Playgroud)
但是,在访问索引页面时,我在日志中没有看到任何内容,3 分钟后什么也没有发生。
我做错了什么 ?是否有另一种推荐的方法可以在不使用的情况下“在 X 分钟内”运行任务sleep?
我添加了规格以使用rspec覆盖sidekiq作业,但是现在,当我启动Rails服务器,控制台或仅sidekiq时,出现以下警告:
WARNING: Sidekiq testing API enabled, but this is not the test environment. Your jobs will not go to Redis.
Run Code Online (Sandbox Code Playgroud)
而且工作确实没有被排队。
如何切换回开发API?
我想在rails-jquery-autocomplete我的rails应用程序中使用gem.但是我收到了这个错误:
couldn't find file 'jquery-ui/autocomplete' with type 'application/javascript'
Run Code Online (Sandbox Code Playgroud)
我的jquery-rails版本是4.3.1,jquery-ui-rails版本是6.0.1.
的application.js
//= require jquery
//= require jquery_ujs
//= require jquery-ui/autocomplete
//= require autocomplete-rails
//= require bootstrap-sprockets
//= require moment
//= require bootstrap-datetimepicker
//= require jquery.payment
//= require credit_card
//= require map
//= require owl.carousel.min
//= require carousel
//= require react
//= require react_ujs
//= require components
Run Code Online (Sandbox Code Playgroud)
application.scss
*= require_self
*= require jquery-ui
Run Code Online (Sandbox Code Playgroud)
先感谢您!
这是一个帮助别人的问题,我实际上已经解决了它,但无法轻易找到答案:
我在使用 Sidekiq Pro 时遇到问题,无法找到如何从 heroku 上的私有 gem 服务器 (contrybsys) 安装 Sidekiq Pro。
Heroku 拒绝了我的部署,说道:
remote : Authentication is required for gems.contribsys.com.
remote: Please supply credentials for this source. You can do this by running:
remote: bundle config gems.contribsys.com username:password
remote: Bundler Output: Authentication is required for gems.contribsys.com.
remote: Please supply credentials for this source. You can do this by running:
remote: bundle config gems.contribsys.com username:password
Run Code Online (Sandbox Code Playgroud)
我在本地安装了 gem。本地一切正常,但无法部署。
我正在使用 Rails 5.1+,我想根据两个条件查询模型,它可以有多个值,但总是两个两个。
假设我有一个User模型,它有一个first_name和last_name。我正在寻找具有以下任一特征的用户:
first_name: "John"
last_name: "Doe"
Run Code Online (Sandbox Code Playgroud)
或者
first_name: "Jane"
last_name: "Snow"
Run Code Online (Sandbox Code Playgroud)
我怎样才能写一个指定这个的查询?我总是可以生成一个 SQL 查询字符串,我会传递给一个where子句,但我想知道是否有更好的方法。
sql activerecord ruby-on-rails rails-activerecord ruby-on-rails-5
javascript ×2
jquery ×2
ruby ×2
sidekiq ×2
activerecord ×1
arraylist ×1
arrays ×1
avfoundation ×1
camera ×1
css ×1
delayed-job ×1
heroku ×1
java ×1
jquery-ui ×1
sql ×1
swift ×1
tailwind-css ×1
vue.js ×1
wordpress ×1