AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / coding / 问题

全部问题(coding)

Martin Hope
Simon Elms
Asked: 2025-04-28 19:32:17 +0800 CST

在 PowerShell 中创建不使用构造函数的 .NET 类型的实例

  • 9

我有一个用于在 IIS 中设置网站的 PowerShell 脚本。它包含以下功能:

function Set-IisWebsiteBinding (
    [Parameter(Mandatory = $true)]
    [string]$SiteName, 
    
    [Parameter(Mandatory = $true)]
    [Microsoft.Web.Administration.Site]$Website,
    
    [Parameter(Mandatory = $true)]
    [array]$WebsiteBindingSettings
)
{
    # Set up website bindings ...
}

我正在尝试在 Pester 中为该函数编写测试。我想创建一个虚拟的 $Website 对象传递给被测函数。问题是该类型没有构造函数。如果没有构造函数Microsoft.Web.Administration.Site,如何在 PowerShell 中创建该类型的对象?Microsoft.Web.Administration.Site

我可以通过 创建一个,IISServerManager.Sites.CreateElement()但我想避免依赖于使用真实的IISServerManager。或者,我可以去掉函数参数 的类型强制转换$Website,这样测试代码就可以传入一个哈希表而不是 Microsoft.Web.Administration.Site 对象。不过,我更倾向于保留类型强制转换,这样脚本的未来维护者就能清楚地知道对象的类型$Website。

有没有办法解决缺少构造函数的问题,而不使用实数IISServerManager或删除类型强制?

powershell
  • 1 个回答
  • 92 Views
Martin Hope
Mahsa Fathi
Asked: 2025-04-28 19:15:05 +0800 CST

使用redis扫描命令删除golang中的模式时出现无限循环

  • 6

我在 Golang 中使用 scan 命令,根据提供的模式获取 Redis 键。我使用的是 Redis 集群,因此为了避免键丢失,我使用了 ForEachMaster。以下是我使用的代码:

func deleteCacheKeys(ctx context.Context, pattern string, count int64, retries int) error {
    redisClient := redis.NewClusterClient(&redis.ClusterOptions{
        Addrs: []string{redisCluster},
    })
    if err := redisClient.Ping(ctx).Err(); err != nil {
        return err
    }

    var cursor uint64
    err = redisClient.ForEachMaster(ctx, func(ctx context.Context, nodeClient *redis.Client) error {
        for {
            keys, cursor := nodeClient.Scan(ctx, cursor, pattern, count).Val()
            if len(keys) > 0 {
                cmd := nodeClient.Del(ctx, keys...)
                if cmd.Err() != nil {
                    return cmd.Err()
                }
            }
            if cursor == 0 {
                break
            }
        }
        return nil
    })

    return err
}

在这个函数中,棘手的部分在于每个节点客户端扫描命令中使用的计数。当我将其设置为 1000000 时,一切正常。但是当我使用更低的数值,例如 100 甚至 100000 时,这段代码就会陷入无限循环(我等待的最长时间是 30 分钟)。当使用 1000000 作为计数时,删除模式通常需要几秒钟的时间。

之前我们用 100 万个数据都没问题,直到我们的 Redis 数据集变得非常大,这个数量也引发了无限循环。我目前正在寻找一种安全的方法来删除这些模式,而不用担心这个数量。我真的很想知道为什么会发生这种情况。

我试过把它设置为 -1,但还是卡住了。我也试过用 Unlink 代替 Del 命令,但结果还是一样。

go
  • 1 个回答
  • 91 Views
Martin Hope
Asher Hoskins
Asked: 2025-04-28 19:12:21 +0800 CST

Lit 渲染嵌套列表的顺序是否乱了?

  • 6

我正在使用 Lit 渲染一个嵌套列表。如果我将列表元素推送到一个数组中,并将子列表推送为完整的 Lithtml模板对象,那么一切正常,我就可以用模板渲染嵌套列表了html`<ul>${myArray}</ul>` 。

但是,如果我将子列表作为它们各自的部分(<ul>,,<li>Sub-First...,</ul>)推送,那么 UL 元素似乎会按无序方式呈现<ul></ul><li>Sub-First。

完整的工作示例(假设您已经下载了 Lit 代码的副本lit-all.min.js):

渲染列表.html

<!DOCTYPE html>
<html>
<head>
    <script type="module" src="render-list.js"></script>
</head>
<body>
    <render-list type="1"></render-list>
    <render-list type="2"></render-list>
</body>
</html>

渲染列表.js

import {LitElement, html} from "./lit-all.min.js";

export class RenderList extends LitElement {
    static properties = {
        type: {type: Number}
    };

    constructor() {
        super();
        this.type = 0;
    }

    render() {
        if (this.type == 1) {
            let lst = [];
            lst.push(html`<li>One`);
            lst.push(html`<li>Two`);
            let sublst = [];
            sublst.push(html`<li>Sublist One`);
            sublst.push(html`<li>Sublist Two`);
            lst.push(html`<ul>${sublst}</ul>`);
            lst.push(html`<li>Three`);
            return html`
                <h1>This list rendering works</h1>
                <ul>${lst}</ul>
            `;
        }
        else {
            let lst = [];
            lst.push(html`<li>One`);
            lst.push(html`<li>Two`);
            lst.push(html`<ul>`);
            lst.push(html`<li>Sublist One`);
            lst.push(html`<li>Sublist Two`);
            lst.push(html`</ul>`);
            lst.push(html`<li>Three`);
            return html`
                <h1>This list rendering doesn't work</h1>
                <ul>${lst}</ul>
            `;
        }
    }
}
customElements.define("render-list", RenderList);

呈现如下:

浏览器截图

查看开发人员工具显示第二个列表呈现为:

<ul>
<li>One
<li>Two
<ul></ul>
<li>Sublist One
<li>Sublist Two
<li>Three
<ul>

显然我不太理解 Lit 使用模板的方式。为什么第二种解决方案不起作用?

javascript
  • 2 个回答
  • 34 Views
Martin Hope
Dark S
Asked: 2025-04-28 18:57:02 +0800 CST

Azure AD B2C 使用带有自定义用户属性的 Graph API 添加用户 C#

  • 5

我正在使用 MS Graph API 在 AD B2C 上注册用户,当我尝试不添加其他用户属性时,它可以工作,但它失败并出现错误

属性不可用

当我尝试添加那些用户自定义属性时。

我确实遵循了其他解决方案线程,并clientid在字典中设置属性名称时添加了不带“-”的符号,但没有起作用。

这是我的代码片段:

public class UserService : IUserService
{
    private readonly ILogger<UserService> logger;
    private readonly GraphServiceClient graphServiceClient;
    private readonly string[] supportedRegionCodes;
    private readonly string  _clientId;

    public UserService(ILogger<UserService> logger, IOptions<B2CConfiguration> options)
    {
        this.logger = logger;

        ClientSecretCredentialOptions credentialOptions = new()
        {
            AuthorityHost = AzureAuthorityHosts.AzurePublicCloud,
        };

        ClientSecretCredential clientSecretCredential = new(
            options.Value.TenantId,
            options.Value.ClientId,
            options.Value.ClientSecret,
            credentialOptions);

        _clientId = options.Value.ClientId;

        this.graphServiceClient = new GraphServiceClient(clientSecretCredential, options.Value.Scopes);
        this.supportedRegionCodes = options.Value.SupportedRegionCodes;
    }

    public async Task<string?> RegisterUserToB2C(object userDetails)
    {
        try
        {
            string clientId = _clientId.Replace("-", string.Empty);
            var user = new User
            {
                Identities = new List<ObjectIdentity>
                {
                    new ObjectIdentity
                    {
                        SignInType = "userName",
                        Issuer ="empxxxqa.onmicrosoft.com",
                        IssuerAssignedId = "testuser011"
                    }
                },

                DisplayName = "Test User",
                GivenName = "Test",       
                Surname = "User",
                Mail = "[email protected]",
                OtherMails = new List<string> { "[email protected]" },
                PasswordProfile = new PasswordProfile
                {
                    Password = "@w0rd123!",
                    ForceChangePasswordNextSignIn = true
                },
                UserType = "Member",
                AdditionalData = new Dictionary<string, object>
                    {
                        {$"extension_{clientId}_CardId","TEST"}
                    }
            };

            var created = await graphServiceClient.Users.PostAsync(user);

            return created?.Id;
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
    }
}

这是我收到的错误:

以下扩展属性不可用:extension_3a84xxxxxxxxxxx126f_CardId。

我还添加了我们在 b2c 中创建的属性的屏幕截图:

在此处输入图片描述

我对 AD B2C 和 MS Graph API 比较陌生,需要在 B2C 层面添加什么吗?由于没有额外的自定义用户属性,我尝试注册时成功了,所以我认为应该没有权限问题导致注册失败。

  • 1 个回答
  • 60 Views
Martin Hope
leon
Asked: 2025-04-28 18:56:11 +0800 CST

在 React Three Fiber 中使用 CameraControls 时如何实现视图偏移平移?

  • 5

在 camera-controls 源代码中,有一个视图偏移的示例。如何使用包装在“@react-three/drei”中的 CameraControls 来实现这个功能?

let offsetUpdated = false;
const viewOffset = new THREE.Vector2();
const cameraControls = new CameraControls( camera, renderer.domElement );
cameraControls._truckInternal = ( deltaX, deltaY ) => {

    viewOffset.x += deltaX;
    viewOffset.y += deltaY;

    camera.setViewOffset(
        width,
        height,
        viewOffset.x,
        viewOffset.y,
        width,
        height,
    );
    camera.updateProjectionMatrix();
    offsetUpdated = true;

}

示例来源:查看代码

现场演示:查看演示

更新:

@Łukasz-daniel-mastalerz 非常感谢!你的代码可以运行,但是有一个奇怪的着色问题MeshReflectorMaterial。我复制了你的代码,并添加了更多对象:我的场景演示

平移后出现奇怪的阴影: 阴影问题

three.js
  • 1 个回答
  • 52 Views
Martin Hope
David Beaumont
Asked: 2025-04-28 18:47:05 +0800 CST

如何在创建分支时设置自定义上游?

  • 5

我有一个工作流程,其中本地分支的名称最终我并不想在远程存储库中显示。我希望在创建本地分支时设置上游名称,这样在使用时就不需要记住这样做了git push。

我在这里查看了很多问题/答案,并且看到了两条关于设置上游分支名称的建议:

  1. 使用git config --local remote.origin.push LOCAL_BRANCH:REMOTE_BRANCH
  2. 使用git branch --set-upstream-to REMOTE_BRANCH
  3. 使用git push -u或git push origin LOCAL_BRANCH:REMOTE_BRANCH

第一个“有点工作”,因为如果我推送本地分支,它会推送到预期的远程,但它也会重置该配置条目中的任何现有值,而这是我不想要的。

当远程分支不存在时,第二个不起作用,给我:

fatal: the requested upstream branch 'foobar' does not exist
hint: 
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint: 
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.
hint: Disable this message with "git config advice.setUpstreamFailure false"

第三个显然不是我想要的,因为我希望这在分支创建时发生。

我尝试推送到一个新的(不同名称的)远程并设置以下条目出现在本地配置中:

branch.foo.remote=origin
branch.foo.upstream=foobar
branch.foo.merge=refs/heads/foobar

但是,如果我删除它们,并使用不同的名称手动重新创建它们,当我推送它(没有-u)时,它只想使用本地分支名称。

所以我开始认为实际上没有好的方法来做到这一点。

再次重申一下,我想要的是:

一种配置新本地分支的方法,使其在首次推送时具有不同的远程分支名称,而无需在首次推送时明确设置该名称

这可能吗?

编辑:事实证明,虽然给出的答案适用于命令行 git,但它似乎不适用于 IntelliJ(也许 IntelliJ 缓存了 git 配置信息?)。

git
  • 1 个回答
  • 89 Views
Martin Hope
Evan Lynch
Asked: 2025-04-28 18:15:56 +0800 CST

查找列之间的数值关系

  • 6

我从数据库中选择了一个数值列的子集,并希望遍历这些列,选择一个,target_column并将其与数据框中其他两列之间的数值运算结果进行比较。但是,我不确定如何比较结果(例如col1 * col2 = target_column)。

# For all possible combinations of numeric columns
for col1, col2 in combinations(numeric_cols, 2):
    # For a target column in numeric_columns
    for target_column in numeric_cols:
        # Skip if the target column is one of the relationship columns
        if target_column in (col1, col2):
            continue

编辑:我已经解决了一些问题,但我仍然不确定这是否是最有效的方法

def analyse_relationships(df):

numeric_cols = df.select_dtypes(include=[np.number])
threshold = 0.001
relationships = []

# For all possible combinations of numeric columns
for col1, col2 in combinations(numeric_cols, 2):
    # For a target column in numeric_columns
    for target_column in numeric_cols:
        # Skip if the target column is one of the relationship columns
        if target_column in (col1, col2):
            continue

        # Calculate different operations
        product = numeric_cols[col1] * numeric_cols[col2]
        sum_cols = numeric_cols[col1] + numeric_cols[col2]
        diff = numeric_cols[col1] - numeric_cols[col2]

        if np.allclose(product, numeric_cols[target_column], rtol=threshold):
            relationships.append(f"{col1} * {col2} = {target_column}")
        elif np.allclose(sum_cols, numeric_cols[target_column], rtol=threshold):
            relationships.append(f"{col1} + {col2} = {target_column}")
        elif np.allclose(diff, numeric_cols[target_column], rtol=threshold):
            relationships.append(f"{col1} - {col2} = {target_column}")
python
  • 1 个回答
  • 55 Views
Martin Hope
Andrei
Asked: 2025-04-28 18:14:09 +0800 CST

LINQ Order()/OrderBy() 和 Take(k) 的时间复杂度是多少?

  • 9

以下 C# 代码的时间复杂度是多少?

array.Order().Take(k).ToArray();

LINQ 会将其视为 QuickSelect 吗?还是会以复杂度O(n log n)执行完整的数组排序?

c#
  • 2 个回答
  • 119 Views
Martin Hope
Edward
Asked: 2025-04-28 18:08:31 +0800 CST

两个字幕,一个左对齐,一个右对齐,在同一行

  • 9

使用ggplot2,我希望在同一行的标题下有两个字幕,但一个左对齐,一个右对齐,以形成如下所示的多面图。

在此处输入图片描述

我可以让字幕左对齐:

p <- ggplot(mtcars, aes(mpg, hp)) + 
  geom_point() +
  facet_grid(am~.) +
  theme(plot.title=element_text(hjust=0.5))

p + labs(title="Data: mtcars", subtitle="Subtitle (left-aligned)")

或右对齐,

p + labs(title="Data: mtcars", subtitle="Subtitle (right-aligned)") +
  theme(plot.subtitle=element_text(hjust=1))

但我似乎无法同时实现两者,除非我将它们组合起来,并在它们之间留出任意数量的空格(这就是我上面绘制图表的方法)。但我不喜欢这个解决方案。还有其他方法吗?

  • 2 个回答
  • 68 Views
Martin Hope
TravelWhere
Asked: 2025-04-28 17:51:26 +0800 CST

如何在 Windows 中获取文件的 MD5 Hash?

  • 6

如何在 Windows 中使用命令行获取文件的 md5 哈希值?我只想要原始的 MD5 哈希值,不包含任何额外的文本。我尝试使用 chatgpt 命令,但它给出的命令只起到了一半的作用。

for /f "skip=1 tokens=1" %a in ('certutil -hashfile "path\to\your\file" MD5') do @echo %a & goto :done

它仍然打印CertUtil: -hashfile command completed successfully.我不希望它出现的内容

windows
  • 2 个回答
  • 74 Views
上一页
下一页

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve