煮茶煮酒煮时光

文章 评论 浏览 30

煮茶煮酒煮时光 2025-02-21 01:11:45

我使用我发现的库。它绘制了许多2D原语,例如行,框等。真的很容易使用。称为“ c3.mnogame.primitives2d”,可以在此处找到:
https://github.com/z2oh/c3.monogame.primitives.primitives2d

这是一个screenshot我使用许多方法写的演示:

这只是一个约500行的一个文件。如果您不喜欢git或使用库,则只需复制&将其粘贴到您的项目中。

I use a library I found. It draws a number of 2D primitives, like lines, boxes, etc. Really easy to use. Called "C3.MonoGame.Primitives2D", it can be found here:
https://github.com/z2oh/C3.MonoGame.Primitives2D

Here's a screenshot of a demo I wrote using many of its methods:

C3.Monogame.Primitives2D

It's just one file of around 500 lines. If you don't like Git or using libraries, you can just copy & paste it into your project.

我如何在单体组中绘制线条?

煮茶煮酒煮时光 2025-02-20 20:25:57

如果您尽可能更好地干净,例如,

on(storeActions.updateCurrentChat, (state, { currentChat }) => {
    return {
      ...state,
      currentChat: { ...currentChat },
    };
  })

您可以实际上可以突变数据并传递它们,

public stopPriting(id: string) {
    const updatedCurrenctChat = structuredClone(this.currentChat$);
    const message = updatedCurrenctChat.messages.find(
      (chat) => chat.id === id
    ) as ConvI;
    // WhichType<typeof this.currentChat$,'isPrinted'>

    (message as MeowGPTI).isPrinted = true;
    // (<MeowGPTI>message).isPrinted = true;

    this.store.dispatch(
      storeActions.updateCurrentChat({ currentChat: updatedCurrenctChat })
    );
  }

这是一种更好的方法,我相信有不同的方法来克隆对象,例如json.parse(json.stringify(obj obj(obj) )loadash,但这全部取决于您的情况

It is a much better approach if you better your reducer's as clean as possible like this for example

on(storeActions.updateCurrentChat, (state, { currentChat }) => {
    return {
      ...state,
      currentChat: { ...currentChat },
    };
  })

where you could actually mutate the data and pass them

public stopPriting(id: string) {
    const updatedCurrenctChat = structuredClone(this.currentChat$);
    const message = updatedCurrenctChat.messages.find(
      (chat) => chat.id === id
    ) as ConvI;
    // WhichType<typeof this.currentChat$,'isPrinted'>

    (message as MeowGPTI).isPrinted = true;
    // (<MeowGPTI>message).isPrinted = true;

    this.store.dispatch(
      storeActions.updateCurrentChat({ currentChat: updatedCurrenctChat })
    );
  }

I believe there's different ways of cloning objects like JSON.parse(JSON.stringify(obj) or with loadash but it all depends on your case

编辑(突变)对象属性在NGRX中的还原器中

煮茶煮酒煮时光 2025-02-20 00:42:09
Words.All(s=>s.Length==Words.Length)

使用检查所有字符串的长度与第一个字符串相同。午夜不适用于空数组

Words.All(s=>s.Length==Words.Length)

Use check if all strings have same length as first one. Nite will not work on empty array

如何测试数组中的所有字符串是否具有相同的长度

煮茶煮酒煮时光 2025-02-19 16:53:54

您可以使用LocalStorage在选项卡之间进行通信(实际上,对于此 broadcastChannel
)。无论如何,这是一个解决方案的草图,该解决方案是针对某些错误开放的,但是如果您喜欢,它可以改进。

<h2>page 1</h2>
<button onclick="close_others();">close others</button>
<script>
    window.id = Math.random();
    var key = "close-but-me"

    function close_others() {
        localStorage.setItem(key, window.id);
        window.setTimeout(function() {
            localStorage.removeItem(key);
        }, 2000)
    }

    setInterval(function() {
        console.log(localStorage.getItem(key))
        if (localStorage.getItem(key) && localStorage.getItem(key)!=window.id) {
            window.close();
        } 
    }, 1000)
</script>
<h2>page 2 - SAME code</h2>

<button onclick="close_others();">close others</button>
<script>
    window.id = Math.random();
    var key = "close-but-me"

    function close_others() {
        localStorage.setItem(key, window.id);
        window.setTimeout(function() {
            localStorage.removeItem(key);
        }, 2000)
    }

    setInterval(function() {
        console.log(localStorage.getItem(key))
        if (localStorage.getItem(key) && localStorage.getItem(key)!=window.id) {
            window.close();
        } 
    }, 1000)
</script>

You can communicate between the tabs using localStorage (actually there might be even a better API for this BroadcastChannel
). Anyway, this is a sketch of a solution which is open for some bugs but if you like it , it can be improved.

<h2>page 1</h2>
<button onclick="close_others();">close others</button>
<script>
    window.id = Math.random();
    var key = "close-but-me"

    function close_others() {
        localStorage.setItem(key, window.id);
        window.setTimeout(function() {
            localStorage.removeItem(key);
        }, 2000)
    }

    setInterval(function() {
        console.log(localStorage.getItem(key))
        if (localStorage.getItem(key) && localStorage.getItem(key)!=window.id) {
            window.close();
        } 
    }, 1000)
</script>
<h2>page 2 - SAME code</h2>

<button onclick="close_others();">close others</button>
<script>
    window.id = Math.random();
    var key = "close-but-me"

    function close_others() {
        localStorage.setItem(key, window.id);
        window.setTimeout(function() {
            localStorage.removeItem(key);
        }, 2000)
    }

    setInterval(function() {
        console.log(localStorage.getItem(key))
        if (localStorage.getItem(key) && localStorage.getItem(key)!=window.id) {
            window.close();
        } 
    }, 1000)
</script>

有什么方法可以使用JavaScript转移到以前的浏览器选项卡?

煮茶煮酒煮时光 2025-02-19 09:59:57

您有模块化项目,因此您需要在module-info.java文件中包含以下行,以访问guava api:

requires com.google.common;

使用当前的guava发行版(31.1-jre),此模块名称在内部定义meta-inf/subest.mf文件中的JAR文件通过该行:

Automatic-Module-Name: com.google.common

You have modular project, so you need to include the following line in your module-info.java file to access the guava API:

requires com.google.common;

With current guava distributions (31.1-jre), this module name is defined inside the jar file in the META-INF/MANIFEST.MF file via the line:

Automatic-Module-Name: com.google.common

Gradle实施不与Javafx合作

煮茶煮酒煮时光 2025-02-19 06:19:02

假设您有一个初始默认状态变量show设置为某个明智的默认值,则可以将其值明确设置为0。

因此,假设您有:


import { useState } from "react";

const [show, setShow] = useState(1) // 1: show, 0: hide

const deleteComponent = () => {
  setShow(0);
}

// elsewhere

{ show && <ComponentToShowHide> }

显示/隐藏非常简单。请注意,我正在使用usestate挂钩。我不知道您是否能够利用它,但是我强烈建议您使用它。

Assuming you have an initial default state variable show set to some sensible default, you can explicitly set its value to 0.

So, assuming you had:


import { useState } from "react";

const [show, setShow] = useState(1) // 1: show, 0: hide

const deleteComponent = () => {
  setShow(0);
}

// elsewhere

{ show && <ComponentToShowHide> }

showing/hiding is pretty straightforward. Note that I am using the useState hook. I don't know if you are able to leverage it, but I do highly recommend that you use it.

如何设置状态内数组数组数组数组的特定值

煮茶煮酒煮时光 2025-02-19 01:23:59

我更新了@Redox的答案以获取确切的输出。

df_ = pd.DataFrame({'Labels': df.reset_index()[['Actual', 'Predicted', 'index']].values.ravel(), 
                   'Confidence': np.array(list(zip(np.repeat(1, len(df)), df['Confidence'].values, np.repeat(0, len(df))))).ravel()})
df_.loc[df_['Labels'].astype(str).str.isdigit(), 'Labels'] = ''

plt.figure(figsize=(15, 6))

ax=sns.barplot(data = df_, x=df_.index, y='Confidence', hue='Labels',dodge=False, ci=None)
ax.set_xticklabels(['Actual', 'Predicted', '']*len(df))
plt.setp(ax.get_xticklabels(), rotation=90)
ax.tick_params(labelsize=14)
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)

输出:

在此处输入图像描述“

  • 删除循环以提高性能
  • 添加了空白条值以相同的组图表。

I updated @Redox answer to get the exact output.

df_ = pd.DataFrame({'Labels': df.reset_index()[['Actual', 'Predicted', 'index']].values.ravel(), 
                   'Confidence': np.array(list(zip(np.repeat(1, len(df)), df['Confidence'].values, np.repeat(0, len(df))))).ravel()})
df_.loc[df_['Labels'].astype(str).str.isdigit(), 'Labels'] = ''

plt.figure(figsize=(15, 6))

ax=sns.barplot(data = df_, x=df_.index, y='Confidence', hue='Labels',dodge=False, ci=None)
ax.set_xticklabels(['Actual', 'Predicted', '']*len(df))
plt.setp(ax.get_xticklabels(), rotation=90)
ax.tick_params(labelsize=14)
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)

Output:

enter image description here

  • Removed loop to improve performance
  • Added blank bar values to look alike group chart.

曲线图在x轴中具有不同参数

煮茶煮酒煮时光 2025-02-18 12:52:47

写自己的功能怎么样?

这是代码。

count_rows = function(df, val)
{
    checks = 0
    for (i in 1:ncol(df))
    {
       if(any(df[,i] > 0))
          checks = checks + 1
    }
    return (checks)
}

A = matrix(runif(100), 10, 10)

count_rows(A, 0.5)

How about writing your own function?

Here's the code.

count_rows = function(df, val)
{
    checks = 0
    for (i in 1:ncol(df))
    {
       if(any(df[,i] > 0))
          checks = checks + 1
    }
    return (checks)
}

A = matrix(runif(100), 10, 10)

count_rows(A, 0.5)

如何找到包含大于或等于给定数字的值的R矩阵的列数?

煮茶煮酒煮时光 2025-02-18 11:58:04

您需要提供文件的完整路径。您是对的,它正在寻找相对路径。当您仅传递config.json路径时,它正在您当前的工作目录中查看。

You need to provide the full path to the file. You are right that it is looking for the relative path. When you are just passing the Config.json path it is looking in your current working directory for this.

如何在Python函数中读取文件并从其他Python文件中调用该函数?

煮茶煮酒煮时光 2025-02-18 08:02:06

假设您使用Django模型,我将使用Django信号将数据保存到第二个模型:根据您的问题,“元数据”。

特别是post_save信号:

https://docs.djangoproject.com/en/4.0/ref/signals/#django.db.models.signals.post_save

@receiver(post_save, sender=User)
def post_save_user(sender, instance, created, **kwargs):
    # Save Stuff To Metadata Model.
    meta = MetaData(user=instance)
    meta.save()

您需要在您的型号内导入这些信号/代码>放置在文件底部。


至于通知,我将遵循 @kristina的建议并使用django频道。

只需提醒您的应用程序需要是ASGI(异步)即可。因此,您的应用程序服务器需要像 uvicorn daphne

Assuming you are making use of the Django Models, I would use the Django Signals for saving the data to a second model: "MetaData" according to your question.

Specifically the post_save signal:

https://docs.djangoproject.com/en/4.0/ref/signals/#django.db.models.signals.post_save

@receiver(post_save, sender=User)
def post_save_user(sender, instance, created, **kwargs):
    # Save Stuff To Metadata Model.
    meta = MetaData(user=instance)
    meta.save()

You need to import those signals inside your models.py placed at the bottom of the file.


As for the notifications, I would follow @kristina's advice and use Django Channels.

Just remind that your application needs to be ASGI (Async). So your application server needs to be one like uvicorn, daphne, hypercorn, etc.

Django:根据数据库更改在用户上发送通知

煮茶煮酒煮时光 2025-02-18 06:43:56

您可以使用RabbitAdmin动态创建队列,因此您需要将Rabbitadmin bean添加到配置类中:

@Bean
public AmqpAdmin amqpAdmin() {
    return new RabbitAdmin(connectionFactory());
}

然后您可以使用autowire rabbitadmin binding队列配置:

@Autowired
private AmqpAdmin admin;

@Autowired
private Binding binding;

@Autowired
private Queue queue;

最后您可以根据自己的方式创建队列:

admin.declareQueue(queue);
admin.declareBinding(binding);

您可以在配置或服务类中创建队列。

您可以在构造函数中在服务类中实现它:

@Service
public class RabbitMQService {

        private final Logger logger = LoggerFactory.getLogger(RabbitMQService.class);

        private AmqpAdmin admin;

        private Binding binding;

        private Queue queue;

        @Autowired
        public RabbitMQService (AmqpAdmin admin, Binding binding, Queue queue) {
                this.admin = admin;
                this.binding = binding;
                this.queue = queue;
                admin.declareQueue(queue);
                admin.declareBinding(binding);
        }


        @RabbitListener(queues = "${peopleevents.queue}")
        public void receivedMessage(@Payload Message message) {
            logger.info("User Details Received is.. " + message.toString());
        }
}

You can use RabbitAdmin to create queues dynamically, so you need to add to your configuration class the RabbitAdmin bean:

@Bean
public AmqpAdmin amqpAdmin() {
    return new RabbitAdmin(connectionFactory());
}

Then you can autowire RabbitAdmin with the Binding and Queue configurations:

@Autowired
private AmqpAdmin admin;

@Autowired
private Binding binding;

@Autowired
private Queue queue;

Finally you can create queues as you like:

admin.declareQueue(queue);
admin.declareBinding(binding);

You can create the queue in your configuration or service class.

You can implement it in your service class within a constructor:

@Service
public class RabbitMQService {

        private final Logger logger = LoggerFactory.getLogger(RabbitMQService.class);

        private AmqpAdmin admin;

        private Binding binding;

        private Queue queue;

        @Autowired
        public RabbitMQService (AmqpAdmin admin, Binding binding, Queue queue) {
                this.admin = admin;
                this.binding = binding;
                this.queue = queue;
                admin.declareQueue(queue);
                admin.declareBinding(binding);
        }


        @RabbitListener(queues = "${peopleevents.queue}")
        public void receivedMessage(@Payload Message message) {
            logger.info("User Details Received is.. " + message.toString());
        }
}

用春天在兔子中创建一个新队列

煮茶煮酒煮时光 2025-02-18 05:05:33

在写一个问题时,我提出了一个解决方案:

git diff -I "\{[A-F0-9]{8}\-[A-F0-9]{4}\-[A-F0-9]{4}\-[A-F0-9]{4}\-[A-F0-9]{12}\}" | git apply --cached

这是所有差异所包含的所有差异,而不仅仅是GUIDS,因此

-    ['{837CA9B4-25A0-4C73-B608-60980131BB15}']
+    ['{279B6000-C097-4D14-A479-BC12C277300E}']
+    procedure XSDValidate;

由于额外的线路,这仍然是上演的。这是次优的,但总比没有好。如果有人也能找到解决方案,我将非常感谢它。

While writing the question I came up with a solution:

git diff -I "\{[A-F0-9]{8}\-[A-F0-9]{4}\-[A-F0-9]{4}\-[A-F0-9]{4}\-[A-F0-9]{12}\}" | git apply --cached

This stages all the differences which contain more than just the GUIDs, so this is still staged

-    ['{837CA9B4-25A0-4C73-B608-60980131BB15}']
+    ['{279B6000-C097-4D14-A479-BC12C277300E}']
+    procedure XSDValidate;

because of the extra line. This is suboptimal but way better than nothing at all. If someone can find a solution for this too I would very much appreciate it.

如何丢弃向GUIDS变更

煮茶煮酒煮时光 2025-02-17 23:59:10

这是打字稿版本(对于需要的人)。

vite.config.ts (通常在根部找到)

import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'

// Docs: https://vitejs.dev/config/
export default defineConfig({
  plugins: [svelte()],
  server: {
    proxy: {
      '/api': 'http://localhost:8080'
    }
  }
})

Here's the Typescript version (for those that need that).

vite.config.ts (usually found at root)

import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'

// Docs: https://vitejs.dev/config/
export default defineConfig({
  plugins: [svelte()],
  server: {
    proxy: {
      '/api': 'http://localhost:8080'
    }
  }
})

如何在开发模式下代理Svelte-Kit

煮茶煮酒煮时光 2025-02-17 23:15:58

我又遇到了同一问题,这就是我设法修复它的方式:

  1. 设置适当的Conan Generator来生成所需的config cmake文件,
  • 我使用generator =“ cmake_find_package_multi”,如这个问题
  1. “ https://github.com/conan-io/conan-center-index/issues/6251#issuecomment-877777303859” rel = 全部&lt; pkg&gt; config/target.cmake files(在我的情况下),我们需要指向cmake在 noreflow noreferrer“> conan docs” “>”
  2. https://cmake.org/cmake/help/v3.0/variable/cmake_prefix_path.html“ rel =” cmake docs中的nofollow noreferrer > autouic 和autorcc应该与此配置一起使用:
find_package(Qt5 CONFIG REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

稍后我遇到了两种类型的不同问题……


AutoMoc error
-------------
"SRC:/src/<thisfilename>.cpp"
contains a "Q_OBJECT" macro, but does not include "<thisfilename>.moc"!
Consider to
  - add #include "<thisfilename>.moc"
  - enable SKIP_AUTOMOC for this file

这是通过移动q_object class解决的解决方案。进入标题或添加#include&lt; thisfilename.moc&gt;在类下方,cmake会自动填充该文件的直接路径而无需嵌套路径。例如,如果我有一个称为“ test.cpp”的文件,我必须这样做:

#include <QObject>

class TestObject : public QObject
{
    Q_OBJECT
};

#include <test.moc>

链接器错误,未解决的引用对metaObjectqt_metacastqt_metacall,等等……
在这种情况下,这意味着MOC的生成源代码未添加到汇编中。
它可以通过添加标头文件以及.cpp文件在add_executable中解决

file(GLOB SOURCES
    include/*.h
    src/*.cpp
)
add_executable(${PROJECT_NAME} ${SOURCES})

。 生成MOC的

q_object中, 另一种修复方法是修复它的另一种解决方法是在#include&lt; moc_thisfilename.cpp&gt;中。
test.hpp

#include <QObject>

class TestObject : public QObject
{
    Q_OBJECT
};

test.cpp

#include <test.hpp>
#include <moc_test.cpp>

我尚未找到一种方法来忘记这种Moc Generation Magic,并在包含包含q_Object 相关的东西

I've encountered the same issue again and this is how I managed to fix it:

  1. Set an appropriate conan generator to generate needed config CMake files
  • I use generators = "cmake_find_package_multi" as mentioned in this issue (Again my own issue)
  1. Conan now generates a whole lot of <PKG>Config/Target.cmake files (in my case), we need to point CMake to look for configurations in that folder as specified in conan docs and here in CMake docs
  2. At that point AUTOMOC, AUTOUIC and AUTORCC should work with this piece of config:
find_package(Qt5 CONFIG REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

I've encountered two types of different issues later on …


AutoMoc error
-------------
"SRC:/src/<thisfilename>.cpp"
contains a "Q_OBJECT" macro, but does not include "<thisfilename>.moc"!
Consider to
  - add #include "<thisfilename>.moc"
  - enable SKIP_AUTOMOC for this file

This is resolved either by moving Q_OBJECT class into header or adding #include <thisfilename.moc> below the class, CMake automatically populates direct path to this file without paths nesting. For example if I have a file called "test.cpp" I have to do this:

#include <QObject>

class TestObject : public QObject
{
    Q_OBJECT
};

#include <test.moc>

Linker errors with unresolved references to metaObject, qt_metacast, qt_metacall, etc …
In that case it means that moc's generated source code was not added into compilation.
It can be resolved either with adding header files along with .cpp files in add_executable call:

file(GLOB SOURCES
    include/*.h
    src/*.cpp
)
add_executable(${PROJECT_NAME} ${SOURCES})

the above has an obvious downside, after each newly created header you have to reconfigure CMake to generate moc stuff

The other way to fix it is to include a file #include <moc_thisfilename.cpp> in the Q_OBJECT's cpp implementation file like that:
test.hpp

#include <QObject>

class TestObject : public QObject
{
    Q_OBJECT
};

test.cpp

#include <test.hpp>
#include <moc_test.cpp>

I haven't yet find a way to forget about this moc generation magic and make CMake autoinclude everything in a smart way when including header containing Q_OBJECT related stuff

无法制作柯南&#x2b; cmake&#x2B; QT一起工作。未找到目标的有效QT版本

煮茶煮酒煮时光 2025-02-17 11:03:01

``

summary = []

for i, j in zip(uniq, iocvalue):

   i.update(j)
   summary.append(i)

# Answer: [{'uniq-name': '2022-06-26 14:21:25.298167', 'value': '116.30.7.55'}, {'uniq-name': '2022-06-26 14:21:25.298204', 'value': '31.215.70.187'}]

``

`

summary = []

for i, j in zip(uniq, iocvalue):

   i.update(j)
   summary.append(i)

# Answer: [{'uniq-name': '2022-06-26 14:21:25.298167', 'value': '116.30.7.55'}, {'uniq-name': '2022-06-26 14:21:25.298204', 'value': '31.215.70.187'}]

`

结合两个相等长度的字典列表

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

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