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
Irina
Asked: 2025-04-28 11:25:52 +0800 CST

sql alchemy 为 sql lite 生成整数而不是 int

  • 6

Python Sql Alchemy 使用 VARCHAR 而不是 INTEGER 为 sql lite 生成表,因此选择按字母顺序排列的 sql lite

给定由 SQL Alchemy 生成的 Sql Lite 中的 City 表:

class City(Base):
__tablename__ = "city"
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
city_name: Mapped[str] = mapped_column(String, index=True)

它生成: 在此处输入图片描述

数据:

15470   Paris
100567  Paris

询问:

select(City).where(City.city_name == city_name.upper()).order_by(City.id).limit(1)

SELECT city.id, city.city_name 
FROM city 
WHERE city.city_name = :city_name_1 ORDER BY city.id
LIMIT :param_1

返回城市 ID 为 100567,而不是 15470。

我是否也需要提供带有 SQL 插入的示例?

python
  • 1 个回答
  • 37 Views
Martin Hope
Mauro
Asked: 2025-04-28 11:25:32 +0800 CST

Image->Picture->Assign(Bitmap) 和 Image->Picture->Bitmap = Bitmap 之间真的有区别吗?

  • 7

我很难理解这两种说法之间是否真的有区别:

Image->Picture->Bitmap = bitmap;  // bitmap is a TBitmap object
Image->Picture->Assign(bitmap);

VCL 帮助清楚地说明了通过以下方式进行分配=:

注意:在分配 Bitmap 属性时,TPicture 会分配另一个 TBitmap 对象的属性。它不会获取指定值的所有权。

这意味着第一个语句不会将位图复制到 中,而只是接管Image->Picture->Bitmap的地址。bitmapImage->Picture->Bitmap

为什么我删除了位图Image->Picture->Bitmap对象后,图片仍然正确显示在屏幕上?

c++
  • 1 个回答
  • 113 Views
Martin Hope
theguywiththefuzzyhat
Asked: 2025-04-28 11:19:46 +0800 CST

如何使用 datetime.timedelta 修改时间,然后使用 datetime.date.strftime 格式化它?

  • 5

我可以使用timedelta找到下周日的日期(如果今天是周日,则为今天的日期),代码如下:

print(datetime.date.today() + datetime.timedelta(7 - int(time.strftime("%u"))))

我可以使用strftime获取今天的日期,并按照我想要的方式对其进行格式化:

print(datetime.date.today().strftime("%d.%m.%Y"))

但我实在想不出如何让这两个程序一起运行,才能让我按自己想要的格式显示下周日的日期。我单独运行这两个程序得到的结果是

2025-05-04
27.04.2025

但我想要的是 05.04.2025。我知道可以把2025-05-04传入str()然后格式化,但感觉很笨重。我希望找到在这种情况下如何使用strftime的方法,因为我很确定我想要做的事情正是它的初衷。

python
  • 1 个回答
  • 33 Views
Martin Hope
ok akkx
Asked: 2025-04-28 11:14:29 +0800 CST

为什么在以 base.__init__() 形式调用 __init__ 时需要显式地将自身作为参数?

  • 6

我知道有两种从派生类调用超类构造函数的方法:super().__init__()和base.__init__(self)。为什么第二种方法需要我明确提供self参数?

以下代码片段展示了其中的区别:

class base:
    def __init__(self,/):
        print("initializing")

class der(base):
    def __init__(self):
        super().__init__()  #no error
        base.__init__(self) #no error
        base.__init__() #error, self required

obj = der()

第三次构造函数调用抛出此错误:

File "demo.py", line 11, in <module>
    obj = der()
          ^^^^^
  File "demo.py", line 9, in __init__
    base.__init__() #error, should be: base.__init__(self)
    ^^^^^^^^^^^^^^^
TypeError: base.__init__() missing 1 required positional argument: 'self'

我希望base.__init__()能够工作,因为super().__init__()不需要明确的self。

python
  • 1 个回答
  • 48 Views
Martin Hope
chickentaco
Asked: 2025-04-28 10:34:55 +0800 CST

ASP.NET 中的 Quartz - 核心表是什么以及我可以放弃什么?

  • 5

我目前正在考虑在一个 ASP.NET 项目中使用 Quartz 来安排任务。基本上,该应用允许用户创建可推送到设备的菜单。目前,他们只能选择在当前时间点推送菜单,但我想实现一个选项,将推送安排在以后的日期进行(例如,周二在 COB、周末、每周一早上 7 点重复执行的任务等等)。

我已经设法通过将作业存储在内存中来实现这一点,但是,这显然不是最佳做法,我想将这些作业存储在数据库中 - 这就是我目前有点卡住的地方......

我们有一个现有的数据库(在 SQL Server 中),我们也将在其中添加必要的表,但是 GitHub 上用于 Quartz 的脚本包含大量表……我想我的问题是,我实际需要创建的表的最小数量是多少?哪些表可以省略?我可以根据我的具体情况创建自己的表吗(如果可以,如何创建)?

总之:

  • 在我的 ASP.NET 项目中使用 Quarts 来安排稍后执行的任务
  • 这些作业有参数(设备 ID 等)
  • 目前已实现并正在内存中存储,但希望将这些作业/触发器存储在数据库中
  • Quartz 的脚本非常大,并且创建了大量的表
  • 我实际需要的绝对最小/必要表格是什么?

如果您需要我提供更多详细信息,请随时询问:)

已实现内存调度 - 有效。目前正在寻找创建表前关于 Quartz DB 的信息。

c#
  • 1 个回答
  • 49 Views
Martin Hope
David Wohlferd
Asked: 2025-04-28 09:49:55 +0800 CST

Vector64.ExtractMostSignificantBits 不使用 pext 指令有什么原因吗?

  • 6

令我惊讶的是,与 Vector256 不同,Vector64 中的 ExtractMostSignificantBits 函数并没有使用内部函数来完成工作。使用内部函数后,以下 36 行代码如下:

mov      qword ptr [rsp+0x80], r12
movzx    rdx, byte  ptr [rsp+0x80]
shr      edx, 7
movzx    r8, byte  ptr [rsp+0x81]
shr      r8d, 7
add      r8d, r8d
or       edx, r8d
movzx    r8, byte  ptr [rsp+0x82]
shr      r8d, 7
shl      r8d, 2
or       r8d, edx
mov      edx, r8d
movzx    r8, byte  ptr [rsp+0x83]
shr      r8d, 7
shl      r8d, 3
or       r8d, edx
mov      edx, r8d
movzx    r8, byte  ptr [rsp+0x84]
shr      r8d, 7
shl      r8d, 4
or       r8d, edx
mov      edx, r8d
movzx    r8, byte  ptr [rsp+0x85]
shr      r8d, 7
shl      r8d, 5
or       r8d, edx
mov      edx, r8d
movzx    r8, byte  ptr [rsp+0x86]
shr      r8d, 7
shl      r8d, 6
or       r8d, edx
mov      edx, r8d
movzx    r8, byte  ptr [rsp+0x87]
shr      r8d, 7
shl      r8d, 7
or       r8d, edx

分为这4个:

mov      qword ptr [rsp+0x70], rcx
mov      r10, qword ptr [rsp+0x70]
mov      r15, 0x8080808080808080
pext     r10, r10, r15

似乎你可以用这样的方法将它卷入Vector64.cs :

public static uint ExtractMostSignificantBits<T>(this Vector64<T> vector)
{
    if (Bmi2.X64.IsSupported)
    {
        ulong mask = 0;

        if (typeof(T) == typeof(byte) || typeof(T) == typeof(sbyte))
            mask = 0x8080808080808080;
        else if (typeof(T) == typeof(short) || typeof(T) == typeof(ushort))
            mask = 0x8000800080008000;
        else if (typeof(T) == typeof(int) || typeof(T) == typeof(uint) || typeof(T) == typeof(float))
            mask = 0x8000000080000000;
        else if (typeof(T) == typeof(long) || typeof(T) == typeof(ulong) || typeof(T) == typeof(double))
            mask = 0x8000000000000000;
        else if (typeof(T) == typeof(nint) || typeof(T) == typeof(nuint))
            if (IntPtr.Size == 4)
                mask = 0x8000000080000000;
            else
                mask = 0x8000000000000000;

        ulong u = vector._00;

        ulong retval = Bmi2.X64.ParallelBitExtract(u, mask);

        return (uint)retval;
    }

    // Fall back to the old code
    uint result = 0;
    for (int index = 0; index < Vector64<T>.Count; index++)
    {
        uint value = Scalar<T>.ExtractMostSignificantBit(vector.GetElementUnsafe(index));
        result |= (value << index);
    }

    return result;
}

BMI2 已经不算“新”了,早在 2013 年左右就已推出。而且,考虑到 JIT 编译,这样做成本也不高。

我已经编写了一些测试代码(可根据要求提供),它产生的结果与现有代码相同,只是速度快了两倍多(如果对 Vector64.GetElementUnsafe 进行一些改进,速度可能会更快)。

我是不是忽略了什么细微差别或特殊情况,导致使用内在函数不可接受?还是有人只是忽略了这一点?

c#
  • 1 个回答
  • 85 Views
Martin Hope
Abdul Khadar
Asked: 2025-04-28 09:49:26 +0800 CST

Azure SQL 数据库备份 PITR 和 LTR

  • 5

我对 Azure SQL 数据库备份 PITR 和 LTR 的工作原理非常困惑。我从备份中观察到以下几点:

  1. PITR——每天发生的最早时间点保留。例如:
  2. PITR 配置为 7 天

例 1:

2025-4-28 - current Day,
2025-4-27,
2025-4-26,
2025-4-25,
2025-4-24,
2025-4-23,
2025-4-22,
2025-4-21 - Earliest PITR restore point

例 2:

2025-4-29 - current Day,
2025-4-28,
2025-4-27,
2025-4-26,
2025-4-25,
2025-4-24,
2025-4-23,
2025-4-22 - Earliest PITR restore point

那么,我们也能恢复 2025-4-20 吗?还是只能从(最早的 PITR 还原点)2025-4-21 恢复到当前日期(2025-4-28)?

请有人向我解释一下这实际上是如何运作的。

还有 LTR?

  • 1 个回答
  • 71 Views
Martin Hope
SRobertJames
Asked: 2025-04-28 09:35:56 +0800 CST

如何在 Python 中存储 ID,而不必支付每个整数 28 字节的费用?

  • 6

我的 Python 代码将数百万个 ID 存储在各种数据结构中,以实现一个经典算法。运行时间还不错,但内存占用却很糟糕。

这些 id 是ints。我猜想,由于 Python 的 int 类型起始于 28 个字节,并且会不断增长,因此代价非常大。由于它们只是不透明的 id,而不是真正的数学对象,所以我只用 4 个字节就可以了。

有没有一种方法可以在 Python 中存储 ID,而不用占用全部 28 个字节?例如,我是否需要将它们同时作为字典的键和值?

注意:像 BumPy 这样的常见解决方案在这里不起作用,因为它不是一个连续的数组。它是将键和值放入一个字典中,或者放入字典的字典中,等等。

我也乐意接受其他对 int 占用内存较少的 Python 解释器。

python
  • 1 个回答
  • 167 Views
Martin Hope
kesarling
Asked: 2025-04-28 09:14:20 +0800 CST

如何将 Sender 对象从可变引用移到字符串和 Sender 对象元组的向量?

  • 4

这并不能解决我的问题。建议的答案是用Nones 替换值。我确实需要减小向量的大小。

口粮:

use tokio::sync::mpsc;

#[tokio::main]
async fn main() {

    // Pits the singers against each other...
    // Please do not get confused by the type of the sender used in here.
    // This still will showcase the same problem.
    fn pit(singers: &mut Vec<(String, mpsc::Sender<String>)>) {
        use rand::Rng;
        let mut rng = rand::thread_rng();
        let i1 = rng.gen_range(0..singers.len());
        let i2 = rng.gen_range(0..singers.len());
        // This will add dunsel "singers" to the vector who will get
        // pitted against one another. The actual code makes sure that
        // there are at least 2 singers in queue. What is does not do - 
        // and neither should it - is check if they are dummy objects.
        // Rust did not like me using singers[i1].take().unwrap() and
        // complained about iterators not being implemented for Sender?
        let (dunsel, _) = mpsc::channel::<String>(1);
        let s1 = std::mem::replace(&mut singers[i1], (String::new(), dunsel.clone()));
        let s2 = std::mem::replace(&mut singers[i2], (String::new(), dunsel.clone()));
        // returns s1, s2... not needed for MRE
    }

    let mut v = vec![];
    let (tx, _) = mpsc::channel::<String>(256); // receiver is not needed for MRE
    for name in vec!["name1".to_string(), "name2".to_string(), "name3".to_string()] {
        // In the actual code, the singer clients are sent this tx
        // and they send their transmitter channels via this tx, which
        // is then pushed to the vector. Here, it just accepts `String`s
        // So, tx is of the type mpsc::Sender<mpsc::Sender<String>>!!
        v.push((name.clone(), tx.clone()));
    }
    tokio::spawn(async move {
        let mut v = v;
        pit(&mut v); 
    });
}
rust
  • 1 个回答
  • 52 Views
Martin Hope
Alex Urrutia
Asked: 2025-04-28 09:06:46 +0800 CST

我的自定义 UIview 类中的主视图边框位于另一个视图之上

  • 3

我的问题的屏幕截图

我遇到了一个问题:我自定义的 UIview 类的主视图边框覆盖了该类中的 rankbadgeview。我怎么也想不出原因。我试过把 rankbadgeview 子视图连同其中的 uilabel 一起放到最上面,但仍然不行。谁能帮我看看这个问题?

class LeaderboardCircleView: UIView {
    private let mainLabel = UILabel()
    let rankBadgeView = UIView()
    private let rankLabel = UILabel()
    private let scoreLabel = UILabel()
    
    init(mainText: String, rankText: String, backgroundColor: UIColor, score: Int) {
        super.init(frame: .zero)
        setupViews()
        configure(mainText: mainText, rankText: rankText, backgroundColor: backgroundColor, score: score)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }


    private func updateScoreLabelWith(score: Int) {
        let trophyAttachment = NSTextAttachment()
        trophyAttachment.image = UIImage(systemName: "trophy.fill")?.withTintColor(.systemYellow, renderingMode: .alwaysOriginal)
        trophyAttachment.bounds = CGRect(x: 0, y: -2, width: 16, height: 16)
        
        let trophyString = NSAttributedString(attachment: trophyAttachment)
        let scoreString = NSAttributedString(string: " \(score) pts", attributes: [
            .font: AppStyle.shared.headerFont(size: 12),
            .foregroundColor: UIColor.darkGray
        ])
        
        let fullScoreText = NSMutableAttributedString()
        fullScoreText.append(trophyString)
        fullScoreText.append(scoreString)
        
        scoreLabel.attributedText = fullScoreText
    }

    
    private func setupViews() {
        layer.borderWidth = 2
        layer.borderColor = AppStyle.shared.primaryColor?.cgColor
        translatesAutoresizingMaskIntoConstraints = false
        clipsToBounds = false
        
        mainLabel.translatesAutoresizingMaskIntoConstraints = false
        mainLabel.textAlignment = .center
        mainLabel.adjustsFontSizeToFitWidth = true
        mainLabel.minimumScaleFactor = 0.5
        mainLabel.numberOfLines = 2
        mainLabel.font = AppStyle.shared.headerFont(size: 18)
        mainLabel.textColor = .white
        addSubview(mainLabel)
        
        rankBadgeView.translatesAutoresizingMaskIntoConstraints = false
        rankBadgeView.clipsToBounds = true
        rankBadgeView.backgroundColor = AppStyle.shared.primaryColor
        rankBadgeView.layer.zPosition = 1  // Sends it behind the border

        addSubview(rankBadgeView)
        
        rankLabel.translatesAutoresizingMaskIntoConstraints = false
        rankLabel.textAlignment = .center
        rankLabel.font = AppStyle.shared.headerFont(size: 12)
        rankLabel.textColor = .white
        rankBadgeView.addSubview(rankLabel)
        
        scoreLabel.translatesAutoresizingMaskIntoConstraints = false
        scoreLabel.textAlignment = .center
        scoreLabel.adjustsFontSizeToFitWidth = true
        scoreLabel.minimumScaleFactor = 0.5
        scoreLabel.numberOfLines = 1
        addSubview(scoreLabel)
        
        NSLayoutConstraint.activate([
            mainLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 10),
            mainLabel.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -10),
            mainLabel.centerXAnchor.constraint(equalTo: centerXAnchor),
            mainLabel.centerYAnchor.constraint(equalTo: centerYAnchor),
            
            rankBadgeView.centerXAnchor.constraint(equalTo: centerXAnchor),
            rankBadgeView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: 12),
            rankBadgeView.widthAnchor.constraint(equalToConstant: 30),
            rankBadgeView.heightAnchor.constraint(equalToConstant: 30),
            
            rankLabel.centerXAnchor.constraint(equalTo: rankBadgeView.centerXAnchor),
            rankLabel.centerYAnchor.constraint(equalTo: rankBadgeView.centerYAnchor),
            
            scoreLabel.topAnchor.constraint(equalTo: rankBadgeView.bottomAnchor, constant: 4),
            scoreLabel.centerXAnchor.constraint(equalTo: centerXAnchor)
        ])
        
        bringSubviewToFront(rankBadgeView)
        rankBadgeView.bringSubviewToFront(scoreLabel)
    }
    
    private func configure(mainText: String, rankText: String, backgroundColor: UIColor, score: Int) {
        mainLabel.text = mainText
        self.backgroundColor = backgroundColor
        rankLabel.text = rankText
        
        let trophyAttachment = NSTextAttachment()
        trophyAttachment.image = UIImage(systemName: "trophy.fill")?.withTintColor(.systemYellow, renderingMode: .alwaysOriginal)
        trophyAttachment.bounds = CGRect(x: 0, y: -2, width: 16, height: 16)
        
        let trophyString = NSAttributedString(attachment: trophyAttachment)
        let scoreString = NSAttributedString(string: " \(score) pts", attributes: [
            .font: AppStyle.shared.headerFont(size: 12),
            .foregroundColor: UIColor.darkGray
        ])
        
        let fullScoreText = NSMutableAttributedString()
        fullScoreText.append(trophyString)
        fullScoreText.append(scoreString)
        
        scoreLabel.attributedText = fullScoreText
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        layer.cornerRadius = bounds.width / 2
        rankBadgeView.layer.cornerRadius = rankBadgeView.bounds.width / 2
        
        layer.shadowColor = UIColor.black.cgColor
        layer.shadowOpacity = 0.2
        layer.shadowRadius = 6.0
        layer.shadowOffset = CGSize(width: 0, height: 4)
        layer.masksToBounds = false
        
        rankBadgeView.layer.shadowColor = UIColor.black.cgColor
        rankBadgeView.layer.shadowOpacity = 0.2
        rankBadgeView.layer.shadowRadius = 4.0
        rankBadgeView.layer.shadowOffset = CGSize(width: 0, height: 2)
        rankBadgeView.layer.masksToBounds = false
    }
    
    func update(mainText: String, rankText: String, backgroundColor: UIColor, score: Int) {
        configure(mainText: mainText, rankText: rankText, backgroundColor: backgroundColor, score: score)
    }
}
  • 2 个回答
  • 53 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