审判长

文章 评论 浏览 29

审判长 2025-02-15 23:24:53

我认为这些是您在标准库中的选择。由于它没有非空的收集类型,因此不幸的是,如果这是您的含义,那么您将无法获得编译时的安全性。

  1. 继续使用 maxby()。通过使用它,您可以断言您应该安全使用。我认为这是与您创建的范围相同的范围中的收藏时,可以做到这一点的干净方法。比 MaxByornull()!更清洁,因为如果您错了,错误消息将更合适。

  2. 也许不是超级简洁,但是您可以将 maxbyornull()与猫王操作员和默认值一起使用。在适当的情况下,这可能是优雅的。 .maxbyornull {it.height}?:0.0

  3. 使用 maxbyornull()带有猫王和 error 呼叫。这基本上就像使用 maxby()!! ,但消息传递更好。 `maxbyornull {it.height}?:错误(“收集为空”)

否。 1基于否。 3可能是创建一个链函数来断言该集合并不空。类似:

fun <T> Iterable<T>.assertNotEmpty() =
    (this as? Collection<T> ?: toList()).also {
        require(it.isNotEmpty()) { "Not empty assertion failed." }
    }

然后,您可以在调用 Maxby 之前调用此功能,因此稍后您在查看代码时, Maxby 呼叫不太可能引起眉毛。

I think these are the choices you have in the standard library. Since it doesn't have non-empty Collection types, you unfortunately can't get compile-time safety, if that's what you mean by elegant.

  1. Go ahead and use maxBy(). By using it you are asserting that you know it should be safe to use. I consider this is the clean way to do it when working with a collection in the same scope that you created it. Cleaner than maxByOrNull()!! since the error message will be more appropriate if you were wrong.

  2. Maybe not super concise, but you can use maxByOrNull() with an Elvis operator and default. This might be elegant in situations where it's appropriate to have a default. .maxByOrNull { it.height } ?: 0.0

  3. Use maxByOrNull() with an Elvis and an error call. This is basically like using maxBy()!! but with better messaging. `maxByOrNull { it.height } ?: error("collection was empty")

An improvement on no. 1 that builds on no. 3 might be to create a chain function for asserting the collection isn't empty. Something like:

fun <T> Iterable<T>.assertNotEmpty() =
    (this as? Collection<T> ?: toList()).also {
        require(it.isNotEmpty()) { "Not empty assertion failed." }
    }

Then you could call this before calling maxBy so later when you're reviewing code, the maxBy call won't be as likely to raise eyebrows.

惯用的kotlin与列表合作的方式我们知道不会是空的

审判长 2025-02-15 11:23:46

我认为您可能需要在请求上设置标头,

请尝试将配置对象添加为第三参数

const config = {
        headers: {'Content-Type': 'application/json'}
    }


const handleSubmit = async (e) => {
    e.preventDefault()
    try{
      const response = await axios.post('http://localhost:8000/send', 
      {formData}, config)
      console.log(response)
    } catch(error){
      console.log(error)
    }
  }

I think you might need to set a header on the request

try adding config object as a 3rd argument

const config = {
        headers: {'Content-Type': 'application/json'}
    }


const handleSubmit = async (e) => {
    e.preventDefault()
    try{
      const response = await axios.post('http://localhost:8000/send', 
      {formData}, config)
      console.log(response)
    } catch(error){
      console.log(error)
    }
  }

当我发送数据时,节点服务器给我不确定

审判长 2025-02-15 05:22:42

您需要使用

$(命令)

`command-here`

示例

#!/bin/bash

VAR1="$1"
VAR2="$2"

MOREF="$(sudo run command against "$VAR1" | grep name | cut -c7-)"

echo "$MOREF"

You need to use either

$(command-here)

or

`command-here`

Example

#!/bin/bash

VAR1="$1"
VAR2="$2"

MOREF="$(sudo run command against "$VAR1" | grep name | cut -c7-)"

echo "$MOREF"

如何为bash中命令的输出设置变量?

审判长 2025-02-14 21:38:52

因为 \ z 断言在字符串末端的位置,但是在您的情况下,您有管道符号,我假设过程ID,这意味着您的输入字符串和Regex之间没有匹配。

如果您确定这就是该行所包含的全部,则可以在A/PM之后尝试匹配所有内容:
^\ d {1,2} \/\ d {1,2} \/\ d {4} \ d {1,2}。\ d {1,2}。 [ap] m。*

否则,匹配直到下一个不同的定界符。

Because \zasserts position at the end of the string, but in your case you have pipe symbol and I assume process ID, which means there's no match between your input string and regex.

If you are certain that this is all that the line contains, you can try and match everything after A/P M:
^\d{1,2}\/\d{1,2}\/\d{4} \d{1,2}.\d{1,2}.\d{1,2} [AP]M.*

Otherwise, match till next distinct delimiter.

使用Regex在AWK中使用正则验证的日期验证

审判长 2025-02-14 20:31:56

Alamofire和Apple的网络框架通常不支持上传的TUS协议。您要么需要手动实现该流并上传流,要么切换到Vimeo文档中概述的基于表单的方法。

Alamofire, and Apple's network frameworks in general, don't support the TUS protocol for uploads. You either need to implement that manually and upload a stream, or switch to using the form-based approach outlined in the Vimeo docs.

如何通过Swift上传视频到Vimeo

审判长 2025-02-14 18:49:07

丢弃的错误是由于 process.env.jwt_secret 是未定义的,因此在身份模块中秘密。 ENV变量不确定的原因是由于您的应用程序中的环境配置设置。

要使此变量在Auth模块中可以访问,您应该在Auth Module中动态导入 configmodule ,或者像这样在全球上定义它:

ConfigModule.forRoot({
  isGlobal: true,
});

一旦可访问变量,您就不必在<<<代码>登录方法。是的,设置了到期,因为它与环境变量配置无关。

The error thrown is due to process.env.JWT_SECRET being undefined and hence the secret in auth module. And the reason behind the env variable being undefined is due to the environment configuration setting in your application.

To make this variable accessible in auth module, you should either dynamically import ConfigModule in auth module or define it globally like this:

ConfigModule.forRoot({
  isGlobal: true,
});

Once the variable is accessible, you don't have to explicitly define it in the login method. And yes the expiration is set because it has nothing to do with environment variable configuration.

[nestjs]:jwtmodule.register()不起作用

审判长 2025-02-14 10:08:54

这是一个数组[]

[
    {
        "person": 
        [
            {
                "firstName": "john",
                "lastName": "carter"
            },
            {
                "firstName": "mary",
                "lastName": "ann"
            },
            {
                "firstName": "jack",
                "lastName": "thomas"
            }
        ]
    }
]

This is an Array []

[
    {
        "person": 
        [
            {
                "firstName": "john",
                "lastName": "carter"
            },
            {
                "firstName": "mary",
                "lastName": "ann"
            },
            {
                "firstName": "jack",
                "lastName": "thomas"
            }
        ]
    }
]

如何使用JasperReports JSON元数据出口商生成包含对象的对象数组

审判长 2025-02-14 02:12:15

您只需要将所有模型定义代码包装到具有两个参数的函数中: quelize datatypes 。请参阅这个问题注册模型和协会。

You just need to wrap all model definition code into a function that has two parameters: sequelize and DataTypes. See this question and my answer there to get an idea how to register models and associations.

续集:每个用户的不同SQLITE数据库

审判长 2025-02-13 11:53:20

最佳解决方案。

该组件已通过小文本输入进行了严格测试。它充分解决了重复概述的要求,并提供了广泛的自定义选项。

您可以进行更多的自定义:

小文本:

”

大文本:

代码实现

文件: custom_snackbars.dart

class Snackbars {
  static simple(String message, {bool barrierDismissible = false}) {
    return SnackBar(
      dismissDirection: DismissDirection.startToEnd,
      content: SnackbarWidget( message: message ),
      backgroundColor: Colors.transparent,
      elevation: 0.0,
      behavior: SnackBarBehavior.floating,
      duration: Duration(
        days: barrierDismissible ? 1 : 0, 
        seconds: !barrierDismissible ? 10 : 0
      ),
    );
  }
}

文件: custom_snackbar_widget.dart


class SnackbarWidget extends StatelessWidget {
  const SnackbarWidget({
    super.key,
    required this.message,
  });

  final String message;

  @override
  Widget build(BuildContext context) {
    final messenger = ScaffoldMessenger.of(context);
    return Align(
      alignment: Alignment.center,
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: [
          Flexible(
            child: Container(
              decoration: BoxDecoration(
                color: Colors.black.withOpacity(0.9),
                borderRadius: BorderRadius.circular(16),
                border: Border.all(
                  color: Colors.white.withOpacity(0.2),
                  width: 2,
                ),
              ),
              padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
              child: Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Flexible(
                    child: Text(
                      message,
                      style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
                    ),
                  ),
                  const Gap(WidgetSpacing.space16),
                  IconButton(
                    icon: const Icon(Icons.close),
                    tooltip: 'Close',
                    visualDensity: VisualDensity.compact,
                    onPressed: messenger.hideCurrentSnackBar,
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}

如何测试:
要触发Snackbar,请使用以下示例:

IconButton(
  icon: const Icon(Icons.copy_rounded),
  tooltip: 'copy',
  onPressed: () async {
    final messenger = ScaffoldMessenger.of(context)..clearSnackBars();
    Clipboard.setData(ClipboardData(text: 'Example text.'));
    messenger.showSnackBar(Snackbars.simple('Example text.'));
  },
)

Optimal Solution.

This component has been rigorously tested with both small and large text inputs. It fully addresses the requirement outlined by Rebote and provides extensive customization options.

You can customize it much more:

Small text:

small_text_snackbar

Large text:
large_text_snackbar

Code Implementation:

File: custom_snackbars.dart

class Snackbars {
  static simple(String message, {bool barrierDismissible = false}) {
    return SnackBar(
      dismissDirection: DismissDirection.startToEnd,
      content: SnackbarWidget( message: message ),
      backgroundColor: Colors.transparent,
      elevation: 0.0,
      behavior: SnackBarBehavior.floating,
      duration: Duration(
        days: barrierDismissible ? 1 : 0, 
        seconds: !barrierDismissible ? 10 : 0
      ),
    );
  }
}

File: custom_snackbar_widget.dart


class SnackbarWidget extends StatelessWidget {
  const SnackbarWidget({
    super.key,
    required this.message,
  });

  final String message;

  @override
  Widget build(BuildContext context) {
    final messenger = ScaffoldMessenger.of(context);
    return Align(
      alignment: Alignment.center,
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: [
          Flexible(
            child: Container(
              decoration: BoxDecoration(
                color: Colors.black.withOpacity(0.9),
                borderRadius: BorderRadius.circular(16),
                border: Border.all(
                  color: Colors.white.withOpacity(0.2),
                  width: 2,
                ),
              ),
              padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
              child: Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Flexible(
                    child: Text(
                      message,
                      style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
                    ),
                  ),
                  const Gap(WidgetSpacing.space16),
                  IconButton(
                    icon: const Icon(Icons.close),
                    tooltip: 'Close',
                    visualDensity: VisualDensity.compact,
                    onPressed: messenger.hideCurrentSnackBar,
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}

How to Test:
To trigger the Snackbar, use the following example:

IconButton(
  icon: const Icon(Icons.copy_rounded),
  tooltip: 'copy',
  onPressed: () async {
    final messenger = ScaffoldMessenger.of(context)..clearSnackBars();
    Clipboard.setData(ClipboardData(text: 'Example text.'));
    messenger.showSnackBar(Snackbars.simple('Example text.'));
  },
)

如何根据颤音中的文字使Snackbar宽度灵活?

审判长 2025-02-13 08:43:02

replace Modifier.pagerTabIndicatorOffset(pagerState, tabPositions)
to Modifier.tabIndicatorOffset(tabPositions[tabIndex])

tabIndex value is equals to 1

see https://androidx.tech/artifacts/compose.material3/material3/1.0.0-alpha08-source/androidx/compose/material3/TabRow.kt.html

如何使用JetPack组合设置选项卡的初始启动屏幕

审判长 2025-02-13 06:26:10

也许是重新连接错误。如果您拥有企业版,请尝试使用最新的连接器,Mule的最新版本和最新的累积补丁。

Maybe a reconnection bug. Try with the latest of the connector, latest release of Mule and latest cumulative patch if you have the enterprise edition.

如何修复mule 4 sftp路径不存在错误?

审判长 2025-02-12 15:48:34

人们通常建议反对推动力的原因是因为对于许多分支机构,尤其是存储库中的主要分支机构,人们希望更新该分支机构始终是快速的合并。

如果您只在分支上工作,那么武力都没有问题,无论您是否使用 - force-with-with-with-with租赁,因为您没有修改任何人的期望。没有其他人更糟,因为您这样做了。

如果您确实决定强制武力,那是传达期望的问题。如果您有合并请求打开,那么有时人们在强迫时很难重新审查,因此您可能希望避免使用它。在这种情况下,我通常要做的是添加fixup或supss以 git commit -fixup git commit-squash 挤压他们。

无论如何,如果您与您的团队成员或其他贡献者进行有效的沟通,并让他们知道您已经强迫了,那么这可能会减少问题。在一个开源项目中,您不能总是进行这种通信,因此通常最好在可能的情况下避免使用。

The reason people generally recommend against force pushing is because for many branches, especially the main branches in a repository, people expect updating the branch to always be a fast-forward merge.

If only you are working on the branch, then there's no problem with force-pushing, whether you do it with --force-with-lease or not, because you're not modifying anyone's expectations. Nobody else is worse off because you did that.

If you do decide to force-push, it's a matter of communicating expectations. If you have a merge request open, then sometimes it can be hard for people to re-review when you've force pushed, and so you may wish to avoid it. What I typically do in such a case is to add fixup or squash commits with git commit --fixup or git commit --squash and then, after the reviewer has approved, squash them down.

Regardless, if you communicate effectively with your teammmates or other contributors and let them know that you've force-pushed, then it's likely to be less of a problem. In an open-source project where you can't always have that communication, then it typically is better to avoid it when possible.

我可以在只工作的分支上强加武装吗?

审判长 2025-02-12 10:44:22

投票是过分的;这就像每分钟检查您的邮箱以获取新电子邮件。

您的服务器(Python)应在每个更改中向所有(听力)客户发送一个事件

标准JavaScript eventsource api 是为此开发的,
但是微软从未在IE中实现它,因此,更老的..开发人员经常接触WebRTC。

对于Python代码,请参见:

代码应该外观 喜欢:

后端:

@route("/stream")
def stream():
    def eventStream():
        while True:
            # Poll data from the database
            # and see if there's a new message
            if len(messages) > len(previous_messages):
                yield "data: 
                    {}\n\n".format(messages[len(messages)-1)])"
    
    return Response(eventStream(), mimetype="text/event-stream")

前端:

let eventSource = new EventSource("/stream");
eventSource.onmessage = function(e) {
  console.warn(e.detail);
  // Yeah, the server sent something!
};

注意:没有那么多SSE上的好博客(服务器发送事件),因为B [MMMM] Microsoft从未在IE中实现它,Microsoft Edge(在Chromium上)运行A-Okay。

For PHP backend see: https://kevinchoppin.dev/blog/server-sent - events in-php

Polling is overkill; That is like checking your mailbox every minute for new email.

your Server (Python) should send an Event to all (listening) Clients, on every change

The standard JavaScript EventSource API was developed for that, 3 million years ago
But Microsoft never implemented it in IE, so ahem.. older.. developers reach for WebRTC too often.

For Python code see: Medium.com: Python generator and Server Sent Events

Code should look something like:

Backend:

@route("/stream")
def stream():
    def eventStream():
        while True:
            # Poll data from the database
            # and see if there's a new message
            if len(messages) > len(previous_messages):
                yield "data: 
                    {}\n\n".format(messages[len(messages)-1)])"
    
    return Response(eventStream(), mimetype="text/event-stream")

Front-end:

let eventSource = new EventSource("/stream");
eventSource.onmessage = function(e) {
  console.warn(e.detail);
  // Yeah, the server sent something!
};

Note: There aren't that many good blogs on SSE (Server Sent Events), because B[mmmm] Microsoft never implemented it in IE, Microsoft Edge (on Chromium) runs a-okay.

For PHP backend see: https://kevinchoppin.dev/blog/server-sent-events-in-php

SVG文件每1秒更改一次

审判长 2025-02-11 19:18:04

线程 qthread 只是用于管理 System 线程的包装对象。作为您引用的python文档, active_count 是python thread> thread 对象而不是系统线程的计数。显然,您的系统上可能还有许多其他的线程是由其他过程创建的,或者您程序使用的其他库(例如QT)。因此,您需要确定要计数哪个特定的线程子集。除了创建自己的QT外,还可以在内部创建线程,因此您可能不想计算这些线程...

如果您只想计算自己启动的那些线程,那么您已经拥有 active_count 对于Python线程。对于QT,您可以使用 qthreadpool 。另一种可能性可能是使用中央 queue 所有线程都可以访问。

Both Thread and QThread are just wrapper objects for managing system threads. As the Python documentation you quoted states, active_count is a count of Python Thread objects, not system threads. Obviously there may be many other threads active on your system that were created by other processes, or by other libraries used by your program (such as Qt). So you need to decide which particular subset of threads to count. Qt may create threads internally in addition to the ones you created yourself, so you may not want to count those as well...

If you want to count only those threads you started yourself, you already have active_count for the Python threads. For the Qt ones, you could use QThreadPool. Another possibility might be to use a central queue which could be accessed by all your threads.

如何保持主动Python和QT线程的数量

审判长 2025-02-11 09:21:25

我正在遵循同一教程,在将头撞到键盘上几个小时后,我设法正确地运行了神经网。似乎问题是很多相互矛盾的依赖性和贬值,因此,一旦正确设置了其他所有内容,您可能必须在使用哪种版本的Python(我使用Python 3.7并进行了Pip install installigaina)。

我使用PowerShell(右键单击Windows Home按钮 - &gt; Run PowerShell作为管理员)。正如教程所建议的那样,您将需要在当前工作目录中设置虚拟环境。现在,我们特别解决了您的问题 - 请确保您正在一行运行全部命令:

convert_dir_to_note_sequences --input_dir == 'C:\Users\mista\Downloads\CLEANED_DATA\CLEANED_DATA' --output_file = tmp/notesequences.tfrecord --recursive

应该开始将所有MIDI文件转换为NetseQuense对象。如果您还有一些麻烦,请跟进,我会看到我可以做些什么来提供帮助。

I am following the same tutorial and after a couple hours of bashing my head against the keyboard, I managed to run the neural net properly. It seems like the problem is a lot of conflicting dependencies and deprecations, so you may have to play around with what version of Python you're using once you set everything else up properly (I used Python 3.7 and did pip install magenta).

I used Powershell (right click on Windows home button --> run Powershell as admin). You'll want to set up a virtual environment in your current working directory, as the tutorial advises. And now we get to your problem in particular - make sure you're running the command all in one line, as such:

convert_dir_to_note_sequences --input_dir == 'C:\Users\mista\Downloads\CLEANED_DATA\CLEANED_DATA' --output_file = tmp/notesequences.tfrecord --recursive

That should start converting all the midi files to NoteSequences objects. If you have any more trouble, please follow up and I'll see what I can do to help.

使用Magenta生成歌曲的问题:SyntaxError :( Unicode错误)&#x27; unicodeescape&#x27;

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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