小编dmi*_*mi_的帖子

在C内核模块中的数组初始化中的省略号

我正在检查github上的一些代码https://github.com/umlaeute/v4l2loopback/blob/master/v4l2loopback.c并遇到了这一行,令我感到困惑.这是一些我不知道的非常酷的内核宏或gcc功能吗?怎么= -1办?

static int video_nr[MAX_DEVICES] = { [0 ... (MAX_DEVICES-1)] = -1 };
module_param_array(video_nr, int, NULL, 0444);
MODULE_PARM_DESC(video_nr, "video device numbers (-1=auto, 0=/dev/video0, etc.)");
Run Code Online (Sandbox Code Playgroud)

有问题的行是第一个,后两个用于上下文(这是使用内核宏创建cmdline可指定的参数http://lxr.free-electrons.com/source/include/linux/moduleparam.h#L103)

无论如何,数组初始化发生了什么?该语法如何工作?

c kernel

16
推荐指数
1
解决办法
2212
查看次数

如何将 SameSite cookie 属性设置为显式无 ASP NET Core

Chrome 76 将开始支持显式SameSite: None属性

https://web.dev/samesite-cookies-explained/

我发现 ASP.NET Core 的当前实现被视为SameSiteMode.None无操作并且不发送任何属性。如何向 cookie 添加自定义属性,从而SameSite: None向 cookie 文本添加显式?

将属性附加到 cookie 值不起作用,因为 HttpResponse.Cookies.Append url-encodes cookie 值。

c# asp.net asp.net-core

15
推荐指数
3
解决办法
2万
查看次数

将非常小的python Decimal转换为非科学的符号字符串

我使用Python Decimal类进行精确的浮点运算.我需要将结果编号一致地转换为标准符号数字作为字符串.但是,默认情况下,非常小的十进制数字以科学记数法呈现.

>>> from decimal import Decimal
>>> 
>>> d = Decimal("0.000001")
>>> d
Decimal('0.000001')
>>> str(d)
'0.000001'
>>> d = Decimal("0.000000001")
>>> d
Decimal('1E-9')
>>> str(d)
'1E-9'
Run Code Online (Sandbox Code Playgroud)

我怎么str(d)回来'0.000000001'

python floating-point

8
推荐指数
1
解决办法
2032
查看次数

使用 MFA Active Directory 交互式身份验证在 Python 中连接到 Azure SQL,而不使用 Microsoft.IdentityModel.Clients.ActiveDirectory dll

要使用 MFA(在 SSMS 中作为“Active Directory - Universal”)连接到 Azure SQL 数据库,Microsoft 建议并且目前只有使用 Microsoft.IdentityModel.Clients.ActiveDirectory 与 C# 连接的教程

Authentication='Active Directory Interactive';从 Python 或 Powershell设置常规 ODBC 连接字符串会导致错误

Cannot find an authentication provider for 'ActiveDirectoryInteractive'
Run Code Online (Sandbox Code Playgroud)

这似乎是因为根据https://docs.microsoft.com/en-us/azure/sql-database/active-directory-interactive-connect-azure-sql-db 上的Microsoft 示例代码,您需要明确创建自己的创建连接时的身份验证提供程序类:


        public static void Main(string[] args)
        {
            var provider = new ActiveDirectoryAuthProvider();

            SC.SqlAuthenticationProvider.SetProvider(
                SC.SqlAuthenticationMethod.ActiveDirectoryInteractive,
                //SC.SqlAuthenticationMethod.ActiveDirectoryIntegrated,  // Alternatives.
                //SC.SqlAuthenticationMethod.ActiveDirectoryPassword,
                provider);

            Program.Connection();
        }
Run Code Online (Sandbox Code Playgroud)

我想与pyodbc 连接,所以我无法实现ActiveDirectoryInteractive 提供程序。

有什么方法可以使用 OAuth 获取令牌并在连接字符串中使用它,或者在不使用 .NET 的情况下以其他方式实现 ActiveDirectoryInteractive 提供程序?

odbc azure pyodbc azure-sql-database multi-factor-authentication

6
推荐指数
2
解决办法
4906
查看次数

尝试捕获短路/直通java

我想使用try-catch块来处理两种情况:一个特定的异常,以及任何其他异常.我可以这样做吗?(一个例子)

try{
    Integer.parseInt(args[1])
}

catch (NumberFormatException e){
    // Catch a number format exception and handle the argument as a string      
}

catch (Exception e){
    // Catch all other exceptions and do something else. In this case
    // we may get an IndexOutOfBoundsException.
    // We specifically don't want to handle NumberFormatException here      
}
Run Code Online (Sandbox Code Playgroud)

NumberFormatException是否也由底部块处理?

java exception

4
推荐指数
2
解决办法
3146
查看次数

在Firefox扩展中使用XMLHttpRequest获取二进制数据

我正在尝试从我的Firefox扩展中下载一些二进制数据.当我尝试将创建的XMLHttpRequest设置为arraybuffer模式时:

oHTTP = new XMLHttpRequest();   
oHTTP.responseType = "arraybuffer";
Run Code Online (Sandbox Code Playgroud)

错误

InvalidStateErr
An attempt was made to use an object that is not, or is no longer, usable
Run Code Online (Sandbox Code Playgroud)

被扔了.

有没有其他方法可以在Firefox扩展中下载二进制数据?

javascript ajax firefox firefox-addon

4
推荐指数
1
解决办法
1429
查看次数

re.findall()在第一次运行时找到结果,但在第二次运行时找不到结果

我在网址列表上运行与ping的快速rtt比较.我想提取ip所以我可以运行whois并获取地理位置.当我在google.com和facebook.com专门开始的网址列表上运行此操作时会发生的情况是,dip匹配谷歌的正则表达式,但不是facebook,即使ping的输出都是相同的格式.下面的代码可以更好地了解发生了什么.

urls = ["google.com", "facebook.com"]
ip_regex = re.compile('[1-9]+\\.[1-9]+\\.[1-9]+\\.[1-9]+')
time_regex = re.compile(' [\.1-9]+/.*/.*/.* ms') 

for url in urls:
    output = ""
    print url

    ping = subprocess.Popen(["ping", "-c", "3", url], stdout=subprocess.PIPE)

    while ping.poll() == None:
        output += ping.stdout.read()

    output += ping.stdout.read()

    #DEBUG
    print "OUTPUT"
    print output

    ip = ip_regex.findall(output)
    print ip

    ip = ip[0]

    times = time_regex.findall(output)

    print times

    os.system('whois ' + ip + ' | egrep "Country|StateProv|City"')
Run Code Online (Sandbox Code Playgroud)

对于其他人,ip_regex在facebook(#2)上是否失败?为什么?

python regex

0
推荐指数
1
解决办法
136
查看次数