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
Daryl Clark
Asked: 2025-04-30 06:03:20 +0800 CST

使用 Graph API 根据 lastModifiedDateTime 过滤 SharePoint 列表项

  • 5

我正在尝试过滤 SharePoint 项目列表,以便仅获取过去一天内修改过的项目。根据以下 Graph API 文档,我应该可以使用

$filter=lastModifiedDateTime ge {24 小时前}

查询参数

https://learn.microsoft.com/en-us/graph/api/listitem-list?view=graph-rest-1.0

https://learn.microsoft.com/en-us/graph/api/resources/listitem?view=graph-rest-1.0

我使用的示例 URL 是:

https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items?$filter=lastModifiedDateTime ge 2025-04-28T00:00:00Z

我收到了来自微软的“无效请求”,但没有任何实际原因。

如果我不添加过滤器,我就可以毫无问题地退回所有商品。

  • 2 个回答
  • 45 Views
Martin Hope
ysap
Asked: 2025-04-30 05:15:36 +0800 CST

如何更改图例中的线条和标记样式?

  • 6

我的脚本生成了一个由数十条线和线段组成的复合图。我尝试为该图添加一个自定义图例,该图例仅包含其中三条线,但我似乎无法控制该图例中线条和标记的样式。

情节如下:

在此处输入图片描述

在图例中,我希望Line1风格 为'b.-',Line2风格 为'r-o',Line3风格 为'g-o'。

有没有办法用一定数量的标签和特定的线条样式来定义图例?

matlab
  • 1 个回答
  • 30 Views
Martin Hope
hugo
Asked: 2025-04-30 04:50:34 +0800 CST

Python pg8000 查询参数...在“$2”处或附近出现语法错误

  • 5

你好...我正在尝试向查询添加一个参数,但出现此错误:

"errorMessage": "{'S': 'ERROR', 'V': 'ERROR', 'C': '42601', 'M': 'syntax error at or near \”$2\"', 'P': '3793', 'F': 'scan.l', 'L': '1146', 'R': 'scanner_yyerror'}"

这有效:

import pg8000

account_id = 1234

sql = “”"
    SELECT *
    FROM samples
    WHERE account_id = %s
    AND delete_date IS NULL
    ORDER BY date DESC
“”"

cursor.execute(sql, (account_id,))

但事实并非如此:

import pg8000

account_id = 1234

start_date = query_string_params['start-date'] if 'start-date' in query_string_params else None

// start_date format is: '2025-02-04'

filters = “"
if start_date is not None:
   filters = filters + f" AND DATE(sample_date) >= '{start_date}'"

sql = “”"
    SELECT *
    FROM samples
    WHERE account_id = %s
    AND delete_date IS NULL
    %s
    ORDER BY date DESC
“”"

cursor.execute(sql, (account_id, filters))

知道我做错了什么吗?

python
  • 1 个回答
  • 42 Views
Martin Hope
Abhijit Sarkar
Asked: 2025-04-30 04:34:21 +0800 CST

从哈希图中获取排序顺序时 PriorityQueue Comparator 的行为很奇怪

  • 3

在学习LeetCode 675时,我遇到了一种PriorityQueue Comparator无法解释的奇怪行为。

为了简洁起见,我将陈述问题陈述的要点;感兴趣的人可以在 LeetCode 上阅读全文。

给定一个名为 的 mxn 矩阵forest,其中某些单元格被指定为trees。问题是找到按树​​高升序访问(截断)所有树单元格所需的最少步数。

为了解决这个问题,我找到了所有的树,并按高度升序排列。然后,我使用启发式函数运行 A* 搜索,计算每棵树到下一棵树的最小距离:distance from source + Manhattan distance from the goal

切断所有树的最小步数是所有 A* 距离的总和。如果 A* 搜索在任何时候未能返回路径,我就中止搜索。

class Solution {
  private final int[][] dx = new int[][] {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

  public int cutOffTree(List<List<Integer>> forest) {
    int[] curr = new int[] {0, 0};
    int dist = 0;

    for (int[] next : getTreesSortedByHeight(forest)) {
      int d = minDist(forest, curr, next);
      if (d < 0) {
        return -1;
      }
      curr = next;
      dist += d;
    }

    return dist;
  }

  private List<int[]> getTreesSortedByHeight(List<List<Integer>> forest) {
    List<int[]> trees = new ArrayList<>();
    for (int row = 0; row < forest.size(); row++) {
      for (int col = 0; col < forest.get(0).size(); col++) {
        if (forest.get(row).get(col) > 1) {
          trees.add(new int[] {row, col});
        }
      }
    }
    trees.sort(Comparator.comparingInt(a -> forest.get(a[0]).get(a[1])));
    return trees;
  }

  int minDist(List<List<Integer>> forest, int[] start, int[] goal) {
    int m = forest.size();
    int n = forest.get(0).size();
    Map<Integer, Integer> costs = new HashMap<>();
    costs.put(start[0] * n + start[1], manhattanDist(start[0], start[1], goal));
    // GOTCHA: Fetching the distance from the cost map using the coordinates doesn't work!
    Queue<int[]> heap = new PriorityQueue<>(Comparator.comparingInt(a -> a[0]));
    heap.offer(new int[] {0, 0, start[0], start[1]}); // [cost, distance, row, column]

    while (!heap.isEmpty()) {
      int[] curr = heap.poll();
      int dist = curr[1];
      int row = curr[2];
      int col = curr[3];

      if (row == goal[0] && col == goal[1]) {
        return dist;
      }
      for (int[] d : dx) {
        int r = row + d[0];
        int c = col + d[1];
        if (r >= 0 && r < m && c >= 0 && c < n && forest.get(r).get(c) > 0) {
          int cost = dist + 1 + manhattanDist(r, c, goal);
          if (cost < costs.getOrDefault(r * n + c, Integer.MAX_VALUE)) {
            costs.put(r * n + c, cost);
            heap.offer(new int[] {cost, dist + 1, r, c});
          }
        }
      }
    }
    return -1;
  }

  private int manhattanDist(int row, int col, int[] goal) {
    return Math.abs(goal[0] - row) + Math.abs(goal[1] - col);
  }
}

请注意,每个堆条目都包含启发式成本。从逻辑上讲,这是不必要的,因为条目还包含单元格坐标(行和列),我们可以使用这些坐标从地图中获取距离costs,如下所示:

Queue<int[]> heap = new PriorityQueue<>(Comparator.comparingInt(a -> costs.get(a[1] * n + a[2]);
  • 在没有成本的情况下,堆条目由[距离,行,列]组成。

但这不起作用,并且其中一个测试用例失败了。这个测试用例太大了,所以我觉得没有必要贴在这里,毕竟不太可能有人有时间去调试它。

我想知道为什么会出现这种奇怪的现象。

编辑: 根据评论中的要求添加了完整的代码。

java
  • 1 个回答
  • 78 Views
Martin Hope
Simon
Asked: 2025-04-30 03:49:22 +0800 CST

如何通过表达式过滤 Polars DataFrame 中的所有列?

  • 7

我有这个示例 Polars DataFrame:

import polars as pl 

df = pl.DataFrame({
    "id": [1, 2, 3, 4, 5],
    "variable1": [15, None, 5, 10, 20],
    "variable2": [40, 30, 50, 10, None],
}) 

我尝试使用方法过滤数据框的所有列pl.all(),也尝试使用pl.any_horizontal() == Condition。但是我收到以下错误:

ComputeError: The predicate passed to 'LazyFrame.filter' expanded to multiple expressions: 

    col("id").is_not_null(),
    col("variable1").is_not_null(),
    col("variable2").is_not_null(),
This is ambiguous. Try to combine the predicates with the 'all' or `any' expression.

以下是我尝试解决这个问题的尝试。

# Attempt 1:
(
    df
    .filter(
        pl.all().is_not_null()
    )
)
# Attempt 2:
(
    df
    .filter(
        pl.any_horizontal().is_not_null()
    )
)

所需的输出,但它不适用于更大的 DataFrames:

(
    df
    .filter(
        pl.col("variable1").is_not_null(),
        pl.col("variable2").is_not_null()
    )
)

如何以可扩展的方式过滤所有列而无需单独指定每一列?

python
  • 3 个回答
  • 52 Views
Martin Hope
Varelion
Asked: 2025-04-30 03:39:43 +0800 CST

为什么这不能写入目录“输出”?

  • 5

我正在尝试使用节点、路径和 fs 将文件写入现有目录。

它应该如何工作:

  1. 初始化模拟数据。
  2. 循环模拟数据。
  3. 将模拟字符串写入现有目录“输出”
  4. 结束程序。

工作原理:

  1. 初始化模拟数据。
  2. 循环模拟数据。
  3. 尝试写入现有目录。
  4. 产量误差:

错误:

throw new Error(`Error writing: ${err.message}`);
                                ^

Error: Error writing: ENOENT: no such file or directory, open 'C:\Users\username\test\cheerio\output\55-207-0-228_2025-04-29_15:27:51.txt'
    at C:\Users\username\test\cheerio\components\WriteFile.js:31:11
    at node:fs:2385:7
    at FSReqCallback.oncomplete (node:fs:188:23)

存储库

我正在使用这个存储库。处理 node:fs writefile 的函数位于/component/WriteFile.js;它在这里被调用,就在这些行中。

项目树

这是项目结构:

project-root/
├── components/             
├── node_modules/            
├── output/                  // Target for file write. 
├── .gitignore               
├── index.js               
├── LICENSE                 
├── package-lock.json        
├── package.json            
└── README.md                

WriteFile 代码片段

为了方便起见,这里发布相关代码。WriteFile.js

const fs = require('node:fs');
const path = require('path');

const makeFile = async (fileName, { contentString, ip }) => {
    const now = new Date();
    const dateString =
        now.getFullYear() +
        '-' +
        String(now.getMonth() + 1).padStart(2, '0') +
        '-' +
        String(now.getDate()).padStart(2, '0') +
        '_' +
        String(now.getHours()).padStart(2, '0') +
        ':' +
        String(now.getMinutes()).padStart(2, '0') +
        ':' +
        String(now.getSeconds()).padStart(2, '0');

    contentString = `DATE: ${dateString}\nFor ip: ${ip}\n${contentString}`;

    const filepath = path.join(
        __dirname,
        '..',
        'output',
        `${fileName}_${dateString}.txt`
    );

    try {
        await fs.writeFile(filepath, contentString, 'utf16le', (err) => {
            if (err) {
                throw new Error(`Error writing: ${err.message}`);
            }
        });
        return 'Success';
    } catch (error) {
        console.error('\nError:\n', error.message, '\n');
    } finally {
        // Code that will run regardless of try/catch result
        // Remember, don't have a return in finally.
        console.log('Final completed.');
    }
};

module.exports = { makeFile };

调用时间:

调用地址为:

async function main() {
    let start = performance.now();
    let elapse;
    i = 0;
    for (const ip of ipList) {
        i++;
        if (i > 3) {
            break;
        }
        const sleep = (ms) =>
            new Promise((resolve) => {
                setTimeout(resolve, ms);
            });
        await sleep(500);

        await makeFile(ip.replaceAll('.', '-'), {
            contentString: 'Mockdata',
            ip: ip
        });
    }
    elapse = performance.now() - start;
    console.log('Total time elapsed: ', elapse / 1000);
}
javascript
  • 1 个回答
  • 33 Views
Martin Hope
user2580203
Asked: 2025-04-30 03:23:29 +0800 CST

在 Delphi TPrintDialog 中,可以通过编程设置打印机名称和纸张尺寸吗?

  • 5

使用 Delphi VCL。当用户开始打印作业时,我会显示 TPrintDialog。

理想情况下,打印对话框应该显示用户上次使用的打印机名称、纸张尺寸和方向(我已保存)。但是,虽然我可以将方向传递给打印机并使其显示在对话框中,但我找不到让对话框显示默认打印机和纸张尺寸以外的任何内容的方法。

我可以设计一个看起来像打印对话框的自定义对话框,并以这种方式传递参数,但似乎应该有一种方法将这些参数传递给 TPrintDialog。

谢谢。

斯科特

好的,我不确定从 StackOverflow 的角度来看我是否正确地执行了此操作,如果没有,请原谅。

在 Remy 的帮助下,我已经解决了 VCL 工作的问题,但现在我仍停留在 FMX MacOS 版本上。

使用页面方向,我可以成功设置和获取方向,但它不会影响页面设置对话框中的方向或页面的实际打印方式。

以下是我所拥有的:

function getOrientation: string;
var
FPrintInfo: NSPrintInfo;
orientation: integer;
begin
result:='';
FPrintInfo := TNSPrintInfo.Wrap(TNSPrintInfo.OCClass.sharedPrintInfo);
FPrintInfo.retain;
PMGetOrientation(FPrintInfo.PMPageFormat, @orientation);
FPrintInfo.release;
if (orientation=1) or (orientation=3) then result:='portrait';
if (orientation=2) or (orientation=4) then result:='landscape';
end;

procedure setOrientation (const toSetS:string);
var
FPrintInfo: NSPrintInfo;
orientation: integer;
begin
if toSetS='portrait' then orientation:=1 else orientation:=2;
FPrintInfo := TNSPrintInfo.Wrap(TNSPrintInfo.OCClass.sharedPrintInfo);
FPrintInfo.retain;
PMSetOrientation(FPrintInfo.PMPageFormat,orientation,true);
FPrintInfo.release;
end;

谢谢。

delphi
  • 1 个回答
  • 56 Views
Martin Hope
Jose Cabrera Zuniga
Asked: 2025-04-30 02:52:36 +0800 CST

仅使用命令和有效的 SSL 证书配置 Traefik 使用不同的 SSL 端口

  • 5

Traefik 示例发布于:

https://github.com/bluepuma77/traefik-best-practice/blob/main/docker-traefik-dashboard-letsencrypt/docker-compose.yml

a) 如何修改此代码以不使用 Letsecnrypt 并仅使用一些有效的 SSL 证书,同时仅使用命令(即命令:部分下)?

b) 如何强制 Traefik 监听“安全”主机端口 8443 并转发到其安全端口 443?

提前致谢

docker
  • 1 个回答
  • 18 Views
Martin Hope
f1sherb0y
Asked: 2025-04-30 02:51:53 +0800 CST

Dafny 验证器无法证明多重集的结果

  • 6

我正在与 Dafny 合作,试图了解规范(特别是修改和确保多集)如何影响验证。

我有一个方法do_nothing,用于修改数组 a,但确保其元素的多集保持不变。该方法的主体为空。

method do_nothing(a: array<int>)
  modifies a
  ensures multiset(a[..]) == multiset(old(a[..]))
{
  // nothing is done
}

method test()
{
  var a := new int[6] [2, -3, 4, 1, 1, 7];
  assert a[..] == [2, -3, 4, 1, 1, 7]; // Verifies
  assert a[0] !=0 ;                    // Verifies

  do_nothing(a);

  assert a[0] != 0; // <-- Verification Error: This assertion cannot be proved
}

我的期望:

a由于其中根本没有 0 ,并且 dafny 同意do_nothing确保multiset(a[..]) == multiset(old(a[..]))。因此,断言 a[0] != 0 应该成立并验证成功。

问题:

Dafny 无法验证最终断言 assert a[0] != 0;

functional-programming
  • 2 个回答
  • 26 Views
Martin Hope
user1785730
Asked: 2025-04-30 02:36:30 +0800 CST

如何创建 glfwKeyCallback

  • 5

我一直在尝试遵循这个教程。这是我的回调:

(def cb (proxy [java.lang.Object GLFWKeyCallbackI] []
          (invoke [window keycode _ action _]
            (when (and (= keycode GLFW/GLFW_KEY_ESCAPE)
                       (= action GLFW/GLFW_PRESS))
              (GLFW/glfwSetWindowShouldClose window true)))))

在这里我注册它:

(GLFW/glfwSetKeyCallback window cb)

这给了我这个错误:

Execution error (UnsupportedOperationException) at lwjgl_intro.core.proxy$java.lang.Object$GLFWKeyCallbackI$84f3fd50/address (REPL:-1).
address

我的完整代码在这里。

为什么我会收到这个错误?

编辑:这是上面链接的教程中的代码片段:

    glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> {
        if ( key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE )
            glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop
    });
clojure
  • 1 个回答
  • 31 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