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
RKIDEV
Asked: 2025-04-29 12:26:20 +0800 CST

如果存在并初始化了 2 个以上的数据框,则合并它们

  • 5

我正在尝试使用 Intersection() 合并三个数据帧。如何在运行 Intersection() 之前检查所有数据帧是否存在/已初始化,而无需使用多个 if-else 检查块?如果任何数据帧未赋值,则在执行 Intersection() 时不要使用它。有时我会收到错误 - UnboundLocalError: 赋值前引用了局部变量“df_2”,因为 file2 不存在。

或者还有其他简单的方法可以实现以下目标吗?

以下是我的方法:

if os.path.exists(file1):
        df_1 = pd.read_csv(file1, header=None, names=header_1, sep=',', index_col=None)
if os.path.exists(file2):
        df_2 = pd.read_csv(file2, header=None, names=header_2, sep=',', index_col=None)
if os.path.exists(file3):
        df_3 = pd.read_csv(file3, header=None, names=header_3, sep=',', index_col=None)

common_columns = df_1.columns.intersection(df_2.columns).intersection(df_3.columns)
filtered_1 = df_1[common_columns]
filtered_2 = df_2[common_columns]
filtered_3 = df_3[common_columns]
concatenated_df = pd.concat([filtered_1, filtered_2, filtered_3], ignore_index=True)
python
  • 2 个回答
  • 82 Views
Martin Hope
HL666
Asked: 2025-04-29 12:18:10 +0800 CST

如何使协议包装器(而非协议本身)符合 Swift 中的 Hashable

  • 5

我有一个仅限于类类型的协议:

protocol Plugin: AnyObject {}

现在我想使用插件作为哈希表的键。我不想让Plugin协议继承自Hashable,因为这样我就得any Plugin在所有地方都写一遍(因为它会从其父协议继承“自身要求”)。

为了解决这个问题,我想创建一个通用包装器。我不想使用AnyHashable,因为我希望在出现错误时使用更严格的类型。

public struct ObjectHashable<T: AnyObject>: Hashable {
  
  public let object: T
  
  public init(object: T) {
    self.object = object
  }
  
  public static func ==(lhs: Self, rhs: Self) -> Bool {
    return ObjectIdentifier(lhs.object) == ObjectIdentifier(rhs.object)
  }
  
  public func hash(into hasher: inout Hasher) {
    hasher.combine(ObjectIdentifier(object))
  }
}

现在我想做类似的事情

typealias PluginHashable = ObjectHashable<Plugin>

然而,这给了我错误:

要求指定为“T”:“AnyObject”[其中T = 任何插件]

所以我把它改成了

typealias PluginHashable = ObjectHashable<any Plugin>

我遇到了同样的错误:

要求指定为“T”:“AnyObject”[其中T = 任何插件]

我的理解是,虽然Plugin协议被限制为类类型,但any Plugin事实并非如此。但是,我不知道下一步该怎么做。

更新:

如果我不使用通用的 for ObjectHashable,它就会起作用:

public struct PluginHashable: Hashable {
  
  public let plugin: Plugin
  
  public init(plugin: Plugin) {
    self.plugin = plugin
  }
  
  public static func ==(lhs: Self, rhs: Self) -> Bool {
    return ObjectIdentifier(lhs.plugin) == ObjectIdentifier(rhs.plugin)
  }
  
  public func hash(into hasher: inout Hasher) {
    hasher.combine(ObjectIdentifier(plugin))
  }
}

但是,这个解决方案仅适用于Plugin协议,因此并不理想。我更希望有一个适用于所有类似情况的解决方案。

swift
  • 1 个回答
  • 49 Views
Martin Hope
VIVEK ROBIN KUJUR
Asked: 2025-04-29 12:02:44 +0800 CST

鼠标点击时切换和添加元素类的问题

  • 4

我在尝试在鼠标点击事件发生时切换并向元素添加类时遇到了问题。同样,我有多个“li”元素。我想将“class = subdrop active”添加到选定的锚点标签,并将“class = active”添加到后续的 li 标签。我不确定我是否正确处理了类操作。有人能建议一下正确的方法吗?

<li class="submenu">
  <a href="javascript:void(0);">
    <i class="ti ti-layout-dashboard"></i>
    <span>Admin Profile</span>
    <span class="menu-arrow"></span>
  </a>
  <ul>
    <li>
      <a href="<?php echo base_url('admin_dashboard'); ?>">Dashboard</a>
    </li>
    <li>
      <a href="<?php echo base_url('admin_profile'); ?>">Profile</a>
    </li>
    <li>
      <a href="#">Settings</a>
    </li>
    <li>
      <a href="#">Contacts</a>
    </li>
  </ul>
</li>

尝试在选定的 li 点击上获取以下结果

<li class="submenu">
 <a href="javascript:void(0);" class="subdrop active"><i class="ti ti-layout-dashboard"></i><span>Admin Profile</span><span class="menu-arrow"></span>
</a>
<ul>
  <li><a href="<?php echo base_url('admin_dashboard'); ?>" class="active">Dashboard</a></li>
  <li><a href="<?php echo base_url('admin_profile'); ?>">Profile</a></li>
  <li><a href="#">Settings</a></li>
  <li><a href="#">Contacts</a></li>
</ul>
</li>
javascript
  • 1 个回答
  • 39 Views
Martin Hope
Rohan Bari
Asked: 2025-04-29 12:01:32 +0800 CST

为什么在单个语句中调用两个函数不会影响值?[重复]

  • 6
这个问题已经有答案了:
C 语言中函数调用前的参数评估顺序 (7 个答案)
昨天关闭。

在此代码中:

// Stack using LinkedList //

#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node* next;
};

struct Node* top = NULL;

short isEmpty(void) {
    if (top == NULL) {
        printf("error: The stack is empty.\n");
        return 1;
    }
    
    return 0;
}

void push(int value) {
    struct Node* newNode = (void*)malloc(sizeof(struct Node));
    if (!newNode) {
        printf("error: Heap overflow!\n");
        exit(1);
    }
    
    newNode->data = value;
    newNode->next = top;
    top = newNode;
}

int pop(void) {
    if (isEmpty()) {
        exit(1);
    }
    
    struct Node* ref = top;
    int val = top->data;
    top = top->next;
    free(ref);
    
    return val;
}

int peek(void) {
    if (isEmpty()) {
        exit(1);
    }
    
    return top->data;
}

void display(void) {
    if (isEmpty()) {
        exit(1);
    }
    
    while (top) {
        printf("%d\n", top->data);
        top = top->next;
    }
}

int main(void) {
    push(10);
    push(20);
    push(30);
    push(40);
    
    printf("Peek: %d\n", peek());
    int val = pop();
    printf("Popped: %d, now Peek: %d\n", val, peek());
    push(50);
    display();
    
    return 0;
}

看看这些行:

int val = pop();
printf("Popped: %d, now Peek: %d\n", val, peek());

返回:Popped: 40, now Peek: 30

正如预期的那样。但是,当这样写时:

printf("Popped: %d, now Peek: %d\n", pop(), peek());

它产生以下输出:Popped: 40, now Peek: 40

这是Godbolt。

有人能告诉我为什么会这样吗?

c
  • 1 个回答
  • 71 Views
Martin Hope
Fady Hany
Asked: 2025-04-29 11:01:13 +0800 CST

VB.NET 中数组的分配[重复]

  • 5
这个问题已经有答案了:
数组、堆、栈和值类型 (8 个答案)
vb.net 数组是否仅包含对堆栈上分配的值类型变量的引用? (2 个答案)
昨天关闭。

我对 C# 了解不多,据我所知,C# 和 VB 之间的区别几乎仅在于语法,我的问题是我看到了这个 问题并且看到了答案(只有一个答案),说实话我不明白问题和答案之间有什么关系:)

所以(据我所知)在 C# 中数组元素是在堆中(数组内部)分配的。

书中的段落有误吗?或者我遗漏了什么?

在此处输入图片描述

.net
  • 1 个回答
  • 81 Views
Martin Hope
yazandaoudd
Asked: 2025-04-29 10:48:26 +0800 CST

如何使用 Appwrite 会话而不是 JWT 对自定义 API 网关的前端请求进行身份验证?

  • 5

我正在构建一个全栈移动应用程序,使用 Appwrite 进行身份验证和后端服务。前端与一个自定义 API 网关通信,该网关将请求代理到各个微服务。

目前,我正在使用 Appwrite 的 account.createJWT() 来验证用户身份,但 JWT 令牌每 15 分钟就会过期一次。频繁刷新令牌对于我的应用程序来说不可扩展,尤其是在用户群增长的情况下。因此,我正在尝试使用会话验证来代替 JWT。

我面临的问题是:如何使用 Appwrite 会话正确地验证对 API 网关的前端请求?

环境详情:

Backend API gateway is built with FastAPI

Appwrite version: cloud

Frontend framework: React Native 

我的问题是:

What is the correct way to validate Appwrite user sessions from a backend service (API gateway) without using the frontend SDKs?

Is it possible to securely authenticate frontend requests to a custom backend using only Appwrite sessions (without using short-lived JWTs)?

If not, what would be the best scalable approach for authenticating requests in this setup?

任何建议、推荐流程或示例都将不胜感激!

以下是我尝试过的方法:

I retrieve the user session on the frontend (account.get() gives me session info).

I send the session ID (or the Appwrite cookie) along with API requests to my gateway.

On the backend (in the API gateway), I try to validate the session by using the Appwrite Server SDK (account.getSession(sessionId)).

However, sometimes I get errors like:
Unauthorized: User is missing "account" scope.
authentication
  • 1 个回答
  • 33 Views
Martin Hope
Abdul Khadar
Asked: 2025-04-29 09:52:58 +0800 CST

Azure Policy 要求在创建资源时添加标签

  • 5

我启用了 Azure 策略 [需要资源标签],它正在按预期验证资源创建时的标签,但它也会评估现有资源并显示不合规。

定义

{
  "properties": {
    "displayName": "Require a tag on resources",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Enforces existence of a tag. Does not apply to resource groups.",
    "metadata": {
      "version": "1.0.1",
      "category": "Tags"
    },
    "version": "1.0.1",
    "parameters": {
      "tagName": {
        "type": "String",
        "metadata": {
          "displayName": "Tag Name",
          "description": "Name of the tag, such as 'environment'"
        }
      }
    },
    "policyRule": {
      "if": {
        "field": "[concat('tags[', parameters('tagName'), ']')]",
        "exists": "false"
      },
      "then": {
        "effect": "deny"
      }
    },
    "versions": [
      "1.0.1"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/871b6d14-10aa-478d-b590-94f262ecfa99",
  "type": "Microsoft.Authorization/policyDefinitions",
  "name": "871b6d14-10aa-478d-b590-94f262ecfa99"
}

我已经检查过它对现有资源和新资源都有效。是否有可能只对新资源进行评估?

  • 1 个回答
  • 52 Views
Martin Hope
Dorkhan C.
Asked: 2025-04-29 08:15:33 +0800 CST

如何计算至少有一个单元格的数字大于 0 的列数?

  • 8
年 一个 b c
2017 0 1 3
2018 0 3 0
2019 0 0 0

鉴于上面的表格,有什么 Excel 公式可以帮助我计算出有多少列至少有一个单元格大于 1?我希望有一个公式,即使有 1000 列也能用。

在这种情况下,答案应该是 2(b 列和 c 列)。

我尝试使用 COUNTIFS 和 SUM 的不同组合,但尚未找到正确的组合。到目前为止,我已经尝试过

=SUM(--(MAX(B2:B4)>1), --(MAX(C2:C4)>1), --(MAX(D2:D4)>1))

这是可行的,但是对于 1000 列来说就不可行了。

excel
  • 3 个回答
  • 97 Views
Martin Hope
Olivia McGregor
Asked: 2025-04-29 07:55:05 +0800 CST

我的保证金代码一直以文本形式出现在我的网站上吗?

  • 4

我是编程新手,在正式开始创建网站之前,想先测试一下代码。然而,导致我继续操作的问题是边距代码。虽然可以正常工作,但它总是出现在我网站上的文本以及我尝试的其他代码中。有什么方法可以解决这个问题吗?

(代码)

<!DOCTYPE html>
<html>
  <head>
<style>
body {
  background-image: url("starbackground.gif");
}
</style>
</head>

<body>
    <div id= "header">
    <meta charset="UTF-8">
    <title>Testing stuff</title>
   </div>
   
  <div id= tst>
    <p><h1 style="color:Tomato;">testing stuff rn</h1></p>
    </div>

   <div id = "textfortextbox"> 
   <p><h2 style="color:White;">text OooOooh</h2></p>
</div>

    <div id = "textbox">
     margin-left:100px;
<img src="https://starchips.neocities.org/text%20box.png" width="1200" height="1000" > 

</div>

</body>
</html>

html
  • 2 个回答
  • 74 Views
Martin Hope
David
Asked: 2025-04-29 07:20:48 +0800 CST

从同一 Azure Function App 中的计时器触发器函数调用 HTTP 触发器函数时出错

  • 5

我创建了一个 Azure Function 应用。其中,我有一个 HTTPTrigger 函数“Sync”,该函数运行良好,可以通过本地 (HTTP://localhost/api/sync) 或 Azure 的 URL ( https://xxx.azurewebsites.net/api/sync )成功调用。

我希望能够继续通过 http 调用该函数,但我也想触发它每小时运行一次,因此我创建了一个 TimerTrigger 函数“ScheduledSync”,其唯一目的是通过 HTTPRequestMessage 调用“Sync”函数。

ScheduledSync 在本地调用并成功运行 HTTP 触发函数时运行良好,但一旦在 Azure 中发布,对https://xxx.azurewebsites.net/api/sync的 HTTP 请求就会失败。

我尝试过的所有方法都没用,在 ScheduledSync 函数日志中收到了未授权的 403 错误。我之前传递了函数的密钥,但后来完全取消了身份验证,但这就像 Azure 不允许函数使用完整的 Azure URL 调用自身一样,而且 localhost 在 Azure 中也不起作用。我可以从 PostMan 远程调用 ScheduledSync 正在调用的同一个 Azure 同步 URL,无需身份验证或密钥,并且它成功运行。

尝试根据这个问答进行重构,但似乎没有什么不同。

[Function("Sync")]
public async Task<HttpResponseData> Run(
    [HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestData req,
    FunctionContext _,
    CancellationToken cancellationToken)
{
... //sync code
[Function("ScheduledSync")]
public async Task RunAsync([TimerTrigger("0 0 * * * *")] TimerInfo timerInfo, CancellationToken cancellationToken)
{

...

try
{
    using var request = new HttpRequestMessage(HttpMethod.Post, uri);

    var response = await _httpClient.SendAsync(request, cancellationToken);

    ... // logging and error handling code

功能日志:

2025-04-28T22:46:00Z   [Information]   Executing 'Functions.ScheduledSync' (Reason='Timer fired at 2025-04-28T22:46:00.0027402+00:00', Id=895d3ab8-b00e-40b0-837d-a77892b125c6)
2025-04-28T22:46:00Z   [Information]   Trigger Details: ScheduleStatus: {"Last":"2025-04-28T22:45:00+00:00","Next":"2025-04-28T22:46:00+00:00","LastUpdated":"2025-04-28T22:45:00+00:00"}
2025-04-28T22:46:00Z   [Information]   Start processing HTTP request POST https://xxx.azurewebsites.net/api/Sync
2025-04-28T22:46:00Z   [Information]   Sending HTTP request POST https://xxx.azurewebsites.net/api/Sync
2025-04-28T22:46:00Z   [Information]   Received HTTP response headers after 46.0215ms - 403
2025-04-28T22:46:00Z   [Information]   End processing HTTP request after 46.2548ms - 403
2025-04-28T22:46:00Z   [Error] Scheduled Sync call failed with status Forbidden: <!DOCTYPE HTML>
<HTML>
  ....
  <h1 id="unavailable">Error 403 - Forbidden</h1>
  <p id="tryAgain">The web app you have attempted to reach has blocked your access 
  </p>
  ...
</HTML>

提前感谢您提供的任何帮助。

  • 1 个回答
  • 47 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