我给出的数字k在1到10000的范围内.问题是找到只能用数字1写的最小倍数(称为repunit).因此,对于k = 3,解是111,因为3除以111,但是3不除1或11.对于k = 7,解是111111(六个).
如何计算任何k的解?
我知道我需要使用余数,因为解决方案可能非常大(或者我想使用BigInteger类)
我在我的电脑上安装了 rvm,默认的 ruby gemset 是 2.4.1
rvm list
ruby-2.4.0 [ x86_64 ]
=* ruby-2.4.1 [ x86_64 ]
ruby-2.6.3 [ x86_64 ]
# => - current
# =* - current && default
# * - default
Run Code Online (Sandbox Code Playgroud)
我想安装 rails 5 但sprockets安装失败,需要 2.5 ruby。然而,rails 5 应该适用于 2.2.2 以上的任何 ruby:
gem install rails -v 5.1.4
Fetching: activesupport-5.1.4.gem (100%)
Successfully installed activesupport-5.1.4
Fetching: actionview-5.1.4.gem (100%)
Successfully installed actionview-5.1.4
Fetching: actionpack-5.1.4.gem (100%)
Successfully installed actionpack-5.1.4
ERROR: Error installing rails:
sprockets requires Ruby version >= …Run Code Online (Sandbox Code Playgroud) 我对rails非常陌生,我在理解关联方面遇到了一些麻烦.我想建立一个快速的论坛(只是线程 - 发布机制没有别的).我的模型由以下生成:
1. rails generate scaffold Forumthread title:string
2. rails generate scaffold Forumpost title:string content:text username:string
Run Code Online (Sandbox Code Playgroud)
在我的模型中,我添加了协会,即:
class Forumthread < ActiveRecord::Base
has_many :forumposts, dependent: :destroy
end
class Forumpost < ActiveRecord::Base
belongs_to :forumthread
end
Run Code Online (Sandbox Code Playgroud)
在一个线程的显示页面上,我希望能够为该线程进行forumpost.我试图这样做:view:<%= notice%>
<p>
<strong>Title:</strong>
<%= @forumthread.title %>
</p>
<% form_for(@post) do |f| %>
<div class="field">
<%= f.label :title %><br>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :content %><br>
<%= f.text_area :content %>
</div>
<div class="field">
<%= f.label :username %><br>
<%= f.text_field :username %>
</div> …Run Code Online (Sandbox Code Playgroud) 我想有条件地在我的表单中显示错误。
formik 的工作方式是,如果您更改一个字段,则会运行所有验证并返回所有错误,即使您只更改了一个字段。
我只想在该字段被 TOUCHED 时显示错误,并且我希望一个字段在更改时被 TOUCHED。对该字段的第一次更改应使其触动。
目前,formik 只是在提交时触及字段。我如何才能在更改时触摸它?
这是我目前的表格:
const optionsForSelect = (collection) => {
return collection.map(item => ({
value: item.id,
label: item.name
}))
}
const validationSchema = yup.object().shape({
length: yup
.number()
.min(1, 'Length should be a positive non-zero integer')
.required(),
frame_rate: yup
.string()
.required()
})
class SpecificationsForm extends React.PureComponent {
render() {
const {
values,
handleChange,
handleInputChange,
handleSelectChange,
handleBlur,
errors,
touched
} = this.props;
const debouncedHandleChange = debounce(handleChange, 200)
console.log(errors)
console.log('TOUCHED')
console.log(touched)
return (
<div className="panel panel-default specifications-panel" …Run Code Online (Sandbox Code Playgroud) 我试图在Postgres数据库中查询某个值.我有一个groups在users表中命名的字段,可以用以下任何一种方式表示:
1.
groups: {"data"=>[{"serie"=>5, "year"=>3, "specialization"=>"Matematica", "management_id"=>1, "group_number"=>2}, {"serie"=>5, "year"=>3, "specialization"=>"Matematica", "management_id"=>1, "group_number"=>2}]}
Run Code Online (Sandbox Code Playgroud)
2.
groups: [{"serie"=>5, "year"=>3, "specialization"=>"Matematica", "management_id"=>1, "group_number"=>2}, {"serie"=>5, "year"=>3, "specialization"=>"Matematica", "management_id"=>1, "group_number"=>2}]
Run Code Online (Sandbox Code Playgroud)
我对这两种表述都很好.但是,我似乎无法找到如何让所有在系列5中的用户让我们说.我尝试了多个查询:
@users = User.where("groups ->> 'data' @> ?", {serie: 5})
@users = User.where("groups -> 'data' @> '?'", {serie: 5})
@users = User.where("groups ->> 'data' ->> 'serie' = ?", 5)
Run Code Online (Sandbox Code Playgroud)
还有许多其他尝试,有些比其他尝试更愚蠢(见上文).我该怎么办?
我已经能够确定:
select groups -> 'data' ->> 'serie' from users;
ERROR: cannot extract field from a non-object.
Run Code Online (Sandbox Code Playgroud)
但是以下查询有效:
select json_array_elements(groups -> 'data') …Run Code Online (Sandbox Code Playgroud) 我有以下表格:
import React from 'react'
import PanelInputField from './form_components/panel_input_field'
import * as yup from 'yup'
import { withFormik, FormikErrors, FormikProps } from "formik";
const validationSchema = yup.object().shape({
length: yup
.number()
.min(200, 'NOT BIG ENOUGH')
.required()
})
class SpecificationsForm extends React.PureComponent {
render() {
const {
values,
handleInputChange,
handleSelectChange,
touched,
errors
} = this.props;
console.log(errors)
return (
<div className="panel panel-default specifications-panel" id="js-turbosquid-product-specifications-panel">
<div className="panel-heading">
<a href="#" className="js-more-info" data-toggle="collapse" data-target="#specifications-panel-instructions" tabIndex="-1">
Specifications
<i className="fa fa-question-circle" />
</a>
</div>
<div className="panel-body panel-collapse collapse …Run Code Online (Sandbox Code Playgroud) 我有下表 RENTAL(book_date, copy_id, member_id, title_id, act_ret_date, exp_ret_date)。其中 book_date 显示预订图书的日期。我需要为一个月中的每一天编写一个查询(所以从 1-30 或从 1-29 或从 1-31 取决于月份)它会显示我预订的书籍数量。
我目前知道如何显示表格中租借的天数
select count(book_date), to_char(book_date,'DD')
from rental
group by to_char(book_date,'DD');
Run Code Online (Sandbox Code Playgroud)
我的问题是:
假设我们有以下 2 个表:
purchases
-> id
-> classic_id(indexed TEXT)
-> other columns
purchase_items_2(a temporary table)
-> id
-> order_id(indexed TEXT)
-> other columns
Run Code Online (Sandbox Code Playgroud)
我想在两个表之间进行 SQL 连接,如下所示:
Select pi.id, pi.order_id, p.id
from purchase_items_2 pi
INNER JOIN purchases p ON pi.order_id = p.classic.id
Run Code Online (Sandbox Code Playgroud)
这东西应该用索引吧?它不是。
有什么线索吗?
这是查询的解释
INNER JOIN purchases ON #{@table_name}.order_id = purchases.classic_id")
Run Code Online (Sandbox Code Playgroud)
purchases
-> id
-> classic_id(indexed TEXT)
-> other columns
purchase_items_2(a temporary table)
-> id
-> order_id(indexed TEXT)
-> other columns
Run Code Online (Sandbox Code Playgroud)
当我执行 where 查询时
Select pi.id
from purchase_items_2 pi
where …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种在前端(React)和后端(Node.js、Koa、GraphQL)中实现授权的方法。我偶然发现了 casl 包: https: //github.com/stalniy/casl。
虽然后端授权对我来说似乎非常简单,但我不明白的是如何将我的授权规则从后端共享到前端。一篇中等帖子建议使用 JWT 代币。如何使用 JWT 令牌来做到这一点?
https://medium.com/dailyjs/casl-and-cancan-permissions-sharing- Between-ui-and-api-5f1fa8b4bec
我想选择一个类的所有元素.然后将该类更改为另一个类.0.5秒后,我想将元素恢复到原来的类.我必须连续8次这样做.即使我的代码实现了(在某种程度上)我无法看到按钮中的颜色变化.谁能帮我 ?这是我猜的时间问题.这是js代码:
$(document).ready(function(){
$('#start').click(function(){
game();
})
function game(){
var ordine = new Array();
for(var t = 1; t <= 8; t++){
var y = 0;
for (var k = 0; k < t; k++) {
var x = Math.floor((Math.random() * 4) + 1);
ordine[y++] = x;
change1(x);
setTimeout(change2(x), 500);
}
}
}
function change1(y){
var z = 'cls' + y;
var t = 'cls' + y + 2;
$("." + z).removeClass(z).addClass(t);
}
function change2(y){
var z = 'cls' + y …Run Code Online (Sandbox Code Playgroud)