短叹

文章 评论 浏览 27

短叹 2025-02-12 08:39:09

grid

.center {
    display: grid;
    justify-items: center;
    align-items: center;
}

.center {
    display: grid;
    justify-items: center;
    align-items: center;
}

.box {
    width: 200px;
    height: 100px;
    background: red;
}
<div class="box center">My text</div>

GRID

.center {
    display: grid;
    justify-items: center;
    align-items: center;
}

.center {
    display: grid;
    justify-items: center;
    align-items: center;
}

.box {
    width: 200px;
    height: 100px;
    background: red;
}
<div class="box center">My text</div>

我如何在DIV块内(水平和垂直)中心文本?

短叹 2025-02-11 18:21:21

您不能直接使用crosstab,这只会为您提供学生和项目的组合。

您可以做的是首先在“ project_id”上执行数据框的合并以获取每个项目的所有组合,然后使用crosstab

df2 = df.merge(df, on='project_id', suffixes=('1','2'))

pd.crosstab(df2['student_id1'], df2['student_id2'])

nb。请小心,中间数据框df2将增加许多行,因为每个项目都有学生

df = pd.DataFrame({'project_id': ['P1', 'P1', 'P2', 'P3', 'P3', 'P3'],
                   'student_id': [1,2,3,4,1,2]})

student_id2  1  2  3  4
student_id1            
1            2  2  0  1
2            2  2  0  1
3            0  0  1  0
4            1  1  0  1

组合

! );

s = df.groupby('student_id')['project_id'].agg(set)
a = s.to_numpy()
out = pd.DataFrame(a&a[:, None], index=s.index, columns=s.index).applymap(len)

或者:

from itertools import combinations_with_replacement

s = df.groupby('student_id')['project_id'].agg(set)

df2 = pd.Series([len(a&b) for a,b in combinations_with_replacement(s, 2)],
                index=pd.MultiIndex.from_tuples(combinations_with_replacement(s.index, 2))).unstack()

out = df2.combine_first(df2.T).convert_dtypes()

You cannot directly use crosstab, this will only give you the combinations of students and projects.

What you can do is first perform a merge of the DataFrame with itself on "project_id" to get all combinations of students per project, then use crosstab:

df2 = df.merge(df, on='project_id', suffixes=('1','2'))

pd.crosstab(df2['student_id1'], df2['student_id2'])

NB. be careful, the intermediate dataframe df2 will have add many rows as there are combinations of students per project!.

Example input:

df = pd.DataFrame({'project_id': ['P1', 'P1', 'P2', 'P3', 'P3', 'P3'],
                   'student_id': [1,2,3,4,1,2]})

Output:

student_id2  1  2  3  4
student_id1            
1            2  2  0  1
2            2  2  0  1
3            0  0  1  0
4            1  1  0  1

alternatives

Another approach using python sets (slower but more memory efficient);

s = df.groupby('student_id')['project_id'].agg(set)
a = s.to_numpy()
out = pd.DataFrame(a&a[:, None], index=s.index, columns=s.index).applymap(len)

Or:

from itertools import combinations_with_replacement

s = df.groupby('student_id')['project_id'].agg(set)

df2 = pd.Series([len(a&b) for a,b in combinations_with_replacement(s, 2)],
                index=pd.MultiIndex.from_tuples(combinations_with_replacement(s.index, 2))).unstack()

out = df2.combine_first(df2.T).convert_dtypes()

数据帧乘法创建邻接矩阵

短叹 2025-02-11 06:12:43

Flexbox方式,孤儿块伸展到父母的完整宽度(flex-grow:0;将其关闭)。有自己的缺点和更多的代码。

#about { 
  display: flex;
  flex-wrap: wrap;
}

#about > * {
  flex-basis: 100%;
}

#about > blockquote {
  flex-basis: 50%;
  flex-grow: 1;
  margin: 0;
  
  /* just to higlight the structure */ 
  box-sizing: border-box;
  border: 1px solid #00f1;
  background: #f001;
}
<div id="about">
  <h1>About</h1>
  <blockquote>1</blockquote>
  <blockquote>2</blockquote>
  <blockquote>3</blockquote>
  <p>some text</p>
  <blockquote>4</blockquote>
  <blockquote>5</blockquote>
  <blockquote>6</blockquote>
  <blockquote>7</blockquote>
</div>

The Flexbox way, with an orphan blockquote stretched to the parent's full width (flex-grow: 0; to turn it off). Has it's own cons and slightly more code.

#about { 
  display: flex;
  flex-wrap: wrap;
}

#about > * {
  flex-basis: 100%;
}

#about > blockquote {
  flex-basis: 50%;
  flex-grow: 1;
  margin: 0;
  
  /* just to higlight the structure */ 
  box-sizing: border-box;
  border: 1px solid #00f1;
  background: #f001;
}
<div id="about">
  <h1>About</h1>
  <blockquote>1</blockquote>
  <blockquote>2</blockquote>
  <blockquote>3</blockquote>
  <p>some text</p>
  <blockquote>4</blockquote>
  <blockquote>5</blockquote>
  <blockquote>6</blockquote>
  <blockquote>7</blockquote>
</div>

两列中的blockquotes(或divs)

短叹 2025-02-11 02:33:55

在检查状态之前,您需要锁定订单。

如果2个并发请求执行检查请求。 ||订单。拒绝?与您的解决方案同时获得false,并在锁定下进行。

更改您的模型

class Request < ApplicationRecord
  def self.reject_request(key)
    request = Request.where(:reject_key => key).first
    order = request&.order

    # make sure both request and order objects are not empty
    raise ActiveRecord::Rollback if request.blank? || order.blank?

    # lock your object
    order.lock!
    request.lock!

    # put your conditions here after the `lock`
    raise ActiveRecord::Rollback if request.rejected? || order.rejected?


    request.status = 'rejected'
    request.save!
    order.update(status: 'rejected')
    true
  end
end

You need to lock an order before checking it's status.

If 2 concurrent requests execute check for request.rejected? || order.rejected? simultaneously with your solution, both gets false and proceed consequentially under the lock.

Changes for your model

class Request < ApplicationRecord
  def self.reject_request(key)
    request = Request.where(:reject_key => key).first
    order = request&.order

    # make sure both request and order objects are not empty
    raise ActiveRecord::Rollback if request.blank? || order.blank?

    # lock your object
    order.lock!
    request.lock!

    # put your conditions here after the `lock`
    raise ActiveRecord::Rollback if request.rejected? || order.rejected?


    request.status = 'rejected'
    request.save!
    order.update(status: 'rejected')
    true
  end
end

如何仅允许一个请求执行诉讼并拒绝所有其他并发请求?

短叹 2025-02-11 02:23:09

您的问题可能是0 .data 字段中的是字符串,如果是数字。
我可以使用format_value('0',“%0.03F”)重现相同的错误。

查看当前我们可以看到,它从字符串中删除了所有尾随零,尤其是format_value('100',“%0.03F”)给出1
这是一个错误,应替换正则义务(例如,使用:
https://stackoverflow.com/A

请注意,当您提供一个数字(例如100或0)时,该数字首先替换为字符串(100.0000.000),因此该函数不会用数字(int或float)调用时显示其错误。

此外,shap的开发版本(尚未发布)不会遭受此问题的困扰,因为当调用非数字值时,函数waterfall_plot不会调用format_value,请参阅:

​/Github.com/slundberg/shap/issues/2581#issuecomment-11555134604“ rel =“ nofollow noreferrer”> https://github.com/slundberg/slundberg/shap/shap/shap/shap/shap/shap/shap/2581#issuecomment-11555134604604

likely your issue is that 0 in your .data field is a string instead if a number.
I can reproduce the same error with format_value('0', "%0.03f").

Looking at current format_value we can see that it removes all trailing zeros from a string and in particular format_value('100', "%0.03f") gives 1.
This is a bug and that the regex should be replaced (for example with this: https://stackoverflow.com/a/26299205/4178189)

Note that when you supply a number (e.g. 100 or 0) the number is first replaced with a string (100.000 or 0.000) so the function does not show its bug when called with a number (int or float).

Also the development version of shap (not yet released), would not suffer from this issue since when called with a non number value the function waterfall_plot would not call format_value, see: https://github.com/slundberg/shap/blob/8926cd0122d0a1b3cca0768f2c386de706090668/shap/plots/_waterfall.py#L127

note: this question is also a github issue, see https://github.com/slundberg/shap/issues/2581#issuecomment-1155134604

如何解决此shap.waterfall_plot错误?

短叹 2025-02-11 01:58:25

6个不同的方法可以通过数组循环循环,

您可以通过许多不同的方法循环循环数组。我已经从上到下整理了6种喜欢的方法。

1。使用 javascript用于循环

代码> 循环是我的首选。

let array = [1, 2, 3, 4, 5];
for (let i = 0; i < array.length; i++) {
  console.log(array[i]);
}

2。使用foreach循环

foreach循环是循环循环段的现代方法。同样,它具有更大的灵活性和控制阵列和元素。

let array = [1, 2, 3, 4, 5];
array.forEach((element) => {
  console.log(element);
});

3。使用... of

for ... of循环使您可以直接访问数组元素。

let array = [1, 2, 3, 4, 5];
for (let element of array) {
  console.log(element);
}

4。使用... in循环

for ... in为您提供一个可以访问数组元素的键。

let array = [1, 2, 3, 4, 5];
for(let index in array){
  console.log(array[index]);
}

5。在循环时使用时

,也可以使用循环循环循环。

let array = [1, 2, 3, 4, 5];
let length = array.length;
while(length > 0){
  console.log(array[array.length - length]);
  length--;
}

6。使用...循环

同样,我使用do ... while循环

let array = [1, 2, 3, 4, 5];
let length = array.length;
do {
  console.log(array[array.length - length]);
  length--;
}
while (length > 0)

6 different methods to loop through the array

You can loop through an array by many different methods. I have sorted my 6 favorite methods from top to bottom.

1. Using JavaScript for loop

When it's to simply loop through an array, the for loop is my first choice.

let array = [1, 2, 3, 4, 5];
for (let i = 0; i < array.length; i++) {
  console.log(array[i]);
}

2. Using forEach loop

forEach loop is a modern way to loop through the array. Also, it gives more flexibility and control over the array and elements.

let array = [1, 2, 3, 4, 5];
array.forEach((element) => {
  console.log(element);
});

3. Using for...of

for...of loop gives you direct access to the array elements.

let array = [1, 2, 3, 4, 5];
for (let element of array) {
  console.log(element);
}

4. Using for...in loop

for...in gives you a key using which you can access array elements.

let array = [1, 2, 3, 4, 5];
for(let index in array){
  console.log(array[index]);
}

5. Using while loop

while loop is can be used to loop through the array as well.

let array = [1, 2, 3, 4, 5];
let length = array.length;
while(length > 0){
  console.log(array[array.length - length]);
  length--;
}

6. Using do...while loop

Likewise, I use do...while loop

let array = [1, 2, 3, 4, 5];
let length = array.length;
do {
  console.log(array[array.length - length]);
  length--;
}
while (length > 0)

通过JavaScript中的数组循环

短叹 2025-02-10 19:29:24

这是因为您试图在字符串上调用.addeventListener(在这种情况下为“ .quiz-for”)。您应该在HTML元素上调用它(在您的情况下<代码>表单)。

更改:

const form = document.querySelector = ('.quiz-form');

到:

const form = document.querySelector('.quiz-form');

让我知道您是否需要更多解释。

It's because you are trying to call the .addEventListener on a string (".quiz-for" in this case). You should be calling it on an HTML element (form in your case).

Change:

const form = document.querySelector = ('.quiz-form');

to:

const form = document.querySelector('.quiz-form');

Let me know if you need any more explanation.

为什么form.addeventlistener不是函数?

短叹 2025-02-10 15:56:03

由于您没有提供您的代码,所以我写了一些东西。

// example with list
const [list, setList] = React.useState([]);

// do as much as checkbox as you want, but
// with different value
<input
  type={"checkbox"}
  value={some_value}
  checked={list.includes(some_value)}
  onChange={(e) => {
    e.target.checked
      ? setList([...list, e.target.value])
      : setList([...list].filter((o) => o !== e.target.value));
  }}
/>;

// on submit or click of button
const onSubmit = () => {
  setList([]);
};

As you did not provide your code, I wrote something with my sense.

// example with list
const [list, setList] = React.useState([]);

// do as much as checkbox as you want, but
// with different value
<input
  type={"checkbox"}
  value={some_value}
  checked={list.includes(some_value)}
  onChange={(e) => {
    e.target.checked
      ? setList([...list, e.target.value])
      : setList([...list].filter((o) => o !== e.target.value));
  }}
/>;

// on submit or click of button
const onSubmit = () => {
  setList([]);
};

如何在React Hook中编程的复选框列表中的所有复选框取消选中?

短叹 2025-02-10 10:57:26
value['courses'].forEach((val) {
print(val);
});

//你可以尝试一下吗

value['courses'].forEach((val) {
print(val);
});

// Can you try this

如何从Firestore从数组字段打印值?

短叹 2025-02-10 02:42:35

您可以尝试将以下属性添加到文本字段:

1- textAlignVertical:textalignvertical.center

2-输入depecoration添加contentpadding:edgeinsets.only(top:0)

3-在iconbutton in iconbutton添加addding:edgeinsets.only(top:0)

TextField(
  textAlignVertical: TextAlignVertical.center,
  decoration: InputDecoration(
    contentPadding: EdgeInsets.only(top: 0),
    prefixIcon: Icon(
      Icons.search,
    ),
    hintStyle: TextStyle(
      fontSize: 20,
    ),
    suffixIcon: IconButton(
      padding: EdgeInsets.only(top: 0),
      icon: Icon(Icons.cancel),
      onPressed: null,
    ),
    hintText: "Search"
  )
)

You can try to add the following properties to your text field:

1- textAlignVertical: TextAlignVertical.center

2- In InputDecoration add contentPadding: EdgeInsets.only(top: 0)

3- In IconButton add padding: EdgeInsets.only(top: 0)

enter image description here

TextField(
  textAlignVertical: TextAlignVertical.center,
  decoration: InputDecoration(
    contentPadding: EdgeInsets.only(top: 0),
    prefixIcon: Icon(
      Icons.search,
    ),
    hintStyle: TextStyle(
      fontSize: 20,
    ),
    suffixIcon: IconButton(
      padding: EdgeInsets.only(top: 0),
      icon: Icon(Icons.cancel),
      onPressed: null,
    ),
    hintText: "Search"
  )
)

当没有任何输入

短叹 2025-02-09 13:44:07

尽管没有直接回答这个问题,但我想在其他答案之上分享一个想法。从我那里得到的每一个都将提供一定程度的复杂性来实现跨平台独立性。

在我的情况下,我最初想要的只是设置一个变量来控制服务器是否使用JWT身份验证(用于开发目的)

在阅读答案后,我决定简单地创建2个不同的文件,并分别打开身份验证,并关闭身份验证。

  "scripts": {
    "dev": "nodemon --debug  index_auth.js",
    "devna": "nodemon --debug  index_no_auth.js",
  }

这些文件只是调用原始index.js文件的包装器(我将其重命名为appbootstrapper.js):

//index_no_auth.js authentication turned off
const bootstrapper = require('./appbootstrapper');
bootstrapper(false);

//index_auth.js authentication turned on
const bootstrapper = require('./appbootstrapper');
bootstrapper(true);

class AppBootStrapper {

    init(useauth) {
        //real initialization
    }
}

也许这可以帮助他人

Although not directly answering the question I´d like to share an idea on top of the other answers. From what I got each of these would offer some level of complexity to achieve cross platform independency.

On my scenario all I wanted, originally, to set a variable to control whether or not to secure the server with JWT authentication (for development purposes)

After reading the answers I decided simply to create 2 different files, with authentication turned on and off respectively.

  "scripts": {
    "dev": "nodemon --debug  index_auth.js",
    "devna": "nodemon --debug  index_no_auth.js",
  }

The files are simply wrappers that call the original index.js file (which I renamed to appbootstrapper.js):

//index_no_auth.js authentication turned off
const bootstrapper = require('./appbootstrapper');
bootstrapper(false);

//index_auth.js authentication turned on
const bootstrapper = require('./appbootstrapper');
bootstrapper(true);

class AppBootStrapper {

    init(useauth) {
        //real initialization
    }
}

Perhaps this can help someone else

如何从package.json内部设置环境变量?

短叹 2025-02-08 21:13:41

您对is_tax()的条件是正确的,应该可以正常工作。

如果您的ACF字段在分类学术语页面上,则需要在get_field中指定术语的对象 - 在文档中解释了这一点 - 将ACF添加到税收

如果是这样,则应该有效。

function taxonomy_style() {
    if ( is_tax( 'project_category' ) ) {
        $project_category_css = get_field( 'project_category_css', get_queried_object() );
        wp_enqueue_style( 'project_category_css', get_stylesheet_directory_uri() . $project_category_css );
    }
}
add_action( 'wp_enqueue_scripts', 'taxonomy_style', 99 );

Your conditional for is_tax() is correct, and should be working.

If your ACF field is on the Taxonomy Term admin page, then you need to specify the Term's Object in the get_field - This is explained in the docs - Adding ACF to Tax

If that's the case, then this should work.

function taxonomy_style() {
    if ( is_tax( 'project_category' ) ) {
        $project_category_css = get_field( 'project_category_css', get_queried_object() );
        wp_enqueue_style( 'project_category_css', get_stylesheet_directory_uri() . $project_category_css );
    }
}
add_action( 'wp_enqueue_scripts', 'taxonomy_style', 99 );

如何在WordPress中为自定义分类学档案中的样式表添加样式表?

短叹 2025-02-08 12:20:08

我的专业文件:

QT += core
QT -= gui

CONFIG += c++11

TARGET = openCV
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app
INCLUDEPATH += C:\opencv\release\install\include

LIBS += C:\opencv\release\bin\libopencv_core455.dll
LIBS += C:\opencv\release\bin\libopencv_highgui455.dll
LIBS += C:\opencv\release\bin\libopencv_imgcodecs455.dll
LIBS += C:\opencv\release\bin\libopencv_imgproc455.dll
LIBS += C:\opencv\release\bin\libopencv_calib3d455.dll
LIBS += C:\opencv\release\bin\libopencv_features2d455.dll
LIBS += C:\opencv\release\bin\libopencv_video455.dll
LIBS += C:\opencv\release\bin\libopencv_videoio455.dll
LIBS += -L"(C:\Program Files(x86)\Tesseract-OCR)" -ltesseract

INCLUDEPATH += /usr/include/tesseract

INCLUDEPATH += C:\Program Files(x86)\Tesseract-OCR)

LIBS += C:\Program Files(x86)\Tesseract-OCR)

LIBS +=-LC:\Program Files(x86)\Tesseract-OCR)
-ltesseract.dll
-llept.dll

LIBS += -LC:\Qt\opencv_cv2\OPENCV1\build-qt\lib
-lopencv_calib3d249d
-lopencv_contrib249d
-lopencv_core249d
-lopencv_features2d249d
-lopencv_flann249d
-lopencv_gpu249d
-lopencv_highgui249d
-lopencv_imgproc249d
-lopencv_legacy249d
-lopencv_ml249d
-lopencv_nonfree249d
-lopencv_objdetect249d
-lopencv_ocl249d
-lopencv_photo249d
-lopencv_stitching249d
-lopencv_superres249d
-lopencv_ts249d
-lopencv_video249d
-lopencv_videostab249d

SOURCES += main.cpp

DEFINES += QT_DEPRECATED_WARNINGS

my pro file:

QT += core
QT -= gui

CONFIG += c++11

TARGET = openCV
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app
INCLUDEPATH += C:\opencv\release\install\include

LIBS += C:\opencv\release\bin\libopencv_core455.dll
LIBS += C:\opencv\release\bin\libopencv_highgui455.dll
LIBS += C:\opencv\release\bin\libopencv_imgcodecs455.dll
LIBS += C:\opencv\release\bin\libopencv_imgproc455.dll
LIBS += C:\opencv\release\bin\libopencv_calib3d455.dll
LIBS += C:\opencv\release\bin\libopencv_features2d455.dll
LIBS += C:\opencv\release\bin\libopencv_video455.dll
LIBS += C:\opencv\release\bin\libopencv_videoio455.dll
LIBS += -L"(C:\Program Files(x86)\Tesseract-OCR)" -ltesseract

INCLUDEPATH += /usr/include/tesseract

INCLUDEPATH += C:\Program Files(x86)\Tesseract-OCR)

LIBS += C:\Program Files(x86)\Tesseract-OCR)

LIBS +=-LC:\Program Files(x86)\Tesseract-OCR)
-ltesseract.dll
-llept.dll

LIBS += -LC:\Qt\opencv_cv2\OPENCV1\build-qt\lib
-lopencv_calib3d249d
-lopencv_contrib249d
-lopencv_core249d
-lopencv_features2d249d
-lopencv_flann249d
-lopencv_gpu249d
-lopencv_highgui249d
-lopencv_imgproc249d
-lopencv_legacy249d
-lopencv_ml249d
-lopencv_nonfree249d
-lopencv_objdetect249d
-lopencv_ocl249d
-lopencv_photo249d
-lopencv_stitching249d
-lopencv_superres249d
-lopencv_ts249d
-lopencv_video249d
-lopencv_videostab249d

SOURCES += main.cpp

DEFINES += QT_DEPRECATED_WARNINGS

QT和Tesseract链接

短叹 2025-02-08 08:28:03

首先,检查是否允许质量分配字段 > name ,<代码>电子邮件和password


public function create()
    {
        $roles = Role::where('id', '<=', 6)->orderby('id')->get();
        //$external = Role::where('id', '=', 2)->get();
        // no need in second request as you already have role with id 2 in $roles
        $external = $roles->firstWhere('id', 2);
        // if id = 2 may change in future then
        // $roles = Role::where('id', '<=', 6)->orWhere('id', $notOnly2)->orderby('id')->get();
    }

函数rando_password可以用str :: random($ length) str 代码>( docs

first of all, check if you allowed to mass assign fields name, email and password


public function create()
    {
        $roles = Role::where('id', '<=', 6)->orderby('id')->get();
        //$external = Role::where('id', '=', 2)->get();
        // no need in second request as you already have role with id 2 in $roles
        $external = $roles->firstWhere('id', 2);
        // if id = 2 may change in future then
        // $roles = Role::where('id', '<=', 6)->orWhere('id', $notOnly2)->orderby('id')->get();
    }

function random_password can be replaced with Str::random($length) (docs)

Laravel 7-登录错误(具有角色的用户)

短叹 2025-02-08 05:24:35

它在代码中是一个简单的修复程序,只需将导入语句

import ReactMarkdown from 'react-markdown';

import ReactMarkdown from 'react-markdown/react-markdown.min';

Its a simple fix in the code, just change the import statement from

import ReactMarkdown from 'react-markdown';

to

import ReactMarkdown from 'react-markdown/react-markdown.min';

开玩笑遇到了一个意外的令牌&#x2B; React Markdown

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文