欢烬

文章 评论 浏览 30

欢烬 2025-02-10 17:53:58

您是绝对正确的,背景中有些事情正在发生:

  • h1 元素的HTML默认值是
h1 {
    display: block;
    font-size: 2em;
    margin-block-start: 0.67em;
    margin-block-end: 0.67em;
    margin-inline-start: 0px;
    margin-inline-end: 0px;
    font-weight: bold;
}

在最近的Windows Firefox和Edge中进行了一些测试之后,似乎在两个浏览器中,都有一些 H1 默认值被我不清楚

:-webkit-any(article, aside, nav, section) h1 {
    font-size: 1.5em;
    margin-block-start: 0.83em;
    margin-block-end: 0.83em;
}

为什么浏览器(用户代理CSS内部文件)插入此代码的原因对我来说尚不清楚。可能是因为根据某些W3财团规范,这是第一个节内的第一个 H1

  • 当未设置元素(或< body> )的行高时没错,不是 恰好 mdn'Line-Height:values' 1.1 1.1 1.2 (或 110%和 120%,具体取决于浏览器)。


  • 使用 em 用于任何大小值的单元(如上 h1 默认情况下使用 font-size ),>直接父级的字体大小将用于计算子元素字体大小。

在这种情况下, H1字体大小的最终计算值:30px * 1.5em = 45px times 110%或120%将产生A 49.5px和54px 之间的字体大小。

您的计算 H1字体大小51.2px 在这两个值中整齐地位于。最终计算的元素高度取决于 font-family @ahaworth描绘的领先空间

我知道,对吧?我们开发人员讨厌“排序”计算...

为了规避上述模糊性,您可能需要为CSS body 中的整个文档设置默认行高,因为所有元素都继承这个值。通常使用 1.2 1.3 之间的值。对于 a11y (可访问性),建议至少 1.5 的默认行高。我经常使用 20/16 = 1.25

请注意,大​​多数字体 - 家庭由于字体特定的间距而在高度上略有不同。因此,必须设置足够高的默认车身线路高度以适合文档中最高的字体。这样,您可以控制CSS计算中的元素高度,因为元素高度(当CSS中未设置)是基于 line-height 字体大小

You are absolutely right, there's is something going on in the background:

  • The HTML default for a h1 element is
h1 {
    display: block;
    font-size: 2em;
    margin-block-start: 0.67em;
    margin-block-end: 0.67em;
    margin-inline-start: 0px;
    margin-inline-end: 0px;
    font-weight: bold;
}

After some testing in most recent Windows Firefox and Edge, it appears that in both browsers some h1 default values get overridden with

:-webkit-any(article, aside, nav, section) h1 {
    font-size: 1.5em;
    margin-block-start: 0.83em;
    margin-block-end: 0.83em;
}

Why this code is inserted by the browsers (user agent CSS internal files) is unclear to me. Probably because it is the first h1 inside the first section, as per some W3 Consortium specification.

  • When a line-height for an element (or <body>) is not set the default line height will roughly be (that's right, not exactly MDN 'line-height: Values' ) a value between 1.1 and 1.2 (or 110% and 120%, depending on browser).

  • When using the em unit for any size value (as h1 above does by default with font-size), the font-size of the direct parent will be used to calculate the child element font size.

In this case the final computed value for h1 font-size: 30px * 1.5em = 45px times roughly 110% or 120% will yield a font size between 49.5px and 54px.

Your computed h1 font-size 51.2px lies neatly within those two values. The final computed element height depends on font-family leading space as @AHaworth depicted.

I know, right? We developers hate 'sortof' calculations...

To circumvent the vagueness above, you might want to set a default line height for the entire document in CSS body as all elements inherit this value. Often values between 1.2 and 1.3 are used. For a11y (accessibility) a default line height of at least 1.5 is advised. I often use 20/16 = 1.25.

Be aware that most font-families slightly differ in height because of font specific spacing. Therefore it is imperative to set a high enough default body line-height to fit the tallest font in your document. This way you have control over element heights in your CSS calculations as element heights (when not set in CSS) are based on line-height not font-size.

嗨,谁能告诉我此&lt; h1&gt;标签高度?

欢烬 2025-02-10 10:35:58

APISIX支持通过TLS扩展服务器名称指示(SNI)加载多个SSL证书。您可以使用apisix admin API进行 ssl 创建Apisix中的SSL对象。作为

单个域的多个证书:

如果要为单个域配置多个证书,则
实例,支持两个
ecc
和RSA键交换算法,然后只配置额外的证书(
第一证书和私钥仍应放入 cert )和
certs

  • certs :PEM编码的证书数组。
  • :PEM编码的私钥数组。

apisix 将证书和私钥与SSL密钥相同的索引配对
一对。因此 certs的长度必须相同。

因此,要使用RSA&amp;配置Apache Apisix ECC的同一域双证书,您必须做类似的事情:

curl -X PUT "127.0.0.1:9180/apisix/admin/ssls/1" \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -d 
'{
    "cert": "certificate",
    "key": "key",
    "snis": [...],
    "certs": [...], <- extra certificates
    "keys": [...],  <- extra keys
}'

APISIX supports loading multiple SSL certificates by TLS extension Server Name Indication (SNI). You can use the APISIX Admin API for SSL to create SSL objects in APISIX. And as the documentation quotes:

Multiple certificates for a single domain:

If you want to configure multiple certificates for a single domain, for
instance, supporting both the
ECC
and RSA key-exchange algorithm, then just configure the extra certificates (the
first certificate and private key should be still put in cert and key) and
private keys by certs and keys.

  • certs: PEM-encoded certificate array.
  • keys: PEM-encoded private key array.

APISIX will pair the certificate and private key with the same indices as an SSL key
pair. So the length of certs and keys must be the same.

So to configure Apache APISIX with RSA & ECC dual certificates for the same domain, you would have to do something like this:

curl -X PUT "127.0.0.1:9180/apisix/admin/ssls/1" \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -d 
'{
    "cert": "certificate",
    "key": "key",
    "snis": [...],
    "certs": [...], <- extra certificates
    "keys": [...],  <- extra keys
}'

如何使用RSA&amp;配置Apache Apisix同一域的ECC双证书?

欢烬 2025-02-10 05:06:57

我是Unix哲学的忠实拥护者“做一件事,做得很好”。捕获用户输入并验证它是两个单独的步骤:

  • get_input 提示用户输入,直到
  • 使用 valivator 函数可以将输入验证,该功能可以传递给> get_input

可以将其保持与(python 3.8+,WALRUS Operator)一样简单:

def get_input(
    prompt="Enter a value: ",
    validator=lambda x: True,
    error_message="Invalid input. Please try again.",
):
    while not validator(value := input(prompt)):
        print(error_message)
    return value

def is_positive_int(value):
    try:
        return int(value) >= 0
    except ValueError:
        return False

if __name__ == "__main__":
    val = get_input("Give a positive number: ", is_positive_int)
    print(f"OK, thanks for {val}")

样本运行:

Give a positive number: -5
Invalid input. Please try again.
Give a positive number: asdf
Invalid input. Please try again.
Give a positive number:
Invalid input. Please try again.
Give a positive number: 42
OK, thanks for 42

in Python&lt; 3.8您可以使用 get_input 这样:

def get_input(
    prompt="Enter a value: ",
    validator=lambda x: True,
    error_message="Invalid input. Please try again.",
):
    while True:
        value = input(prompt)
        if validator(value):
            return value
        print(error_message)

您还可以处理键盘Interrupt 并在终止应用程序之前打印友好的退出消息。如果需要,可以使用计数器来限制允许的重试。

I am a big fan of Unix philosophy "Do one thing and do it well". Capturing user input and validating it are two separate steps:

  • prompting the user for input with get_input until the input is ok
  • validating using a validator function that can be passed to get_input

It can be kept as simple as (Python 3.8+, with the walrus operator):

def get_input(
    prompt="Enter a value: ",
    validator=lambda x: True,
    error_message="Invalid input. Please try again.",
):
    while not validator(value := input(prompt)):
        print(error_message)
    return value

def is_positive_int(value):
    try:
        return int(value) >= 0
    except ValueError:
        return False

if __name__ == "__main__":
    val = get_input("Give a positive number: ", is_positive_int)
    print(f"OK, thanks for {val}")

Sample run:

Give a positive number: -5
Invalid input. Please try again.
Give a positive number: asdf
Invalid input. Please try again.
Give a positive number:
Invalid input. Please try again.
Give a positive number: 42
OK, thanks for 42

In Python < 3.8 you could use get_input like this:

def get_input(
    prompt="Enter a value: ",
    validator=lambda x: True,
    error_message="Invalid input. Please try again.",
):
    while True:
        value = input(prompt)
        if validator(value):
            return value
        print(error_message)

You might also handle KeyboardInterrupt and print a friendly exit message before terminating the application. A counter can be used to limit the allowed retries if desired.

询问用户输入,直到他们给出有效的响应

欢烬 2025-02-10 03:54:29

您的问题重点是修复“在没有明确参数的情况下反复称呼它”时解决行为。
您还应该问自己,当带有参数的称为时,您想发生什么:

>>> CONSTANT = ['the']
>>> my_func(CONSTANT)
['the', 'a']
>>> CONSTANT  # oops??
['the', 'a']

如果需要,请参见Henryr的答案( = none ,检查 none 内部)。

但是,如果您不打算突变参数,只需将其用作列表的起点,就可以简单地复制它

def myFunc(starting_list=[]):
    starting_list = list(starting_list)
    starting_list.append("a")
    print(starting_list)

:但是我想那只是一个玩具的例子)

通常,在Python中突变您的论点是不好的。完全期望突变对象的唯一函数是对象的方法。突变一个可选的参数甚至更罕见 - 仅在某些调用中才发生的副作用确实是最好的接口吗?

  • 如果您从“输出参数”的C习惯中做到这一点,那是完全不必要的 - 您可以随时返回多个值作为元组。

  • 如果您这样做是为了有效地构建一个长列表而没有构建中间列表,请考虑将其写入生成器,并在调用它时使用 result_list.extend(myfunc())。这样,您的通话惯例仍然非常干净。

可选的防御步骤,如果您想强制执行功能车体,则不应突变:

  • 使用不变的默认值: starting_list =()。有时需要更改代码,但使用 list()也接受元组,例如返回[*starter_list,“ a”]] 。
  • 添加键入注释并运行类型的检查器。

PS一种模式,其中经常完成的可选arg 是递归函数中隐藏的“备忘录” arg:

def depth_first_walk_graph(graph, node, _visited=None):
    if _visited is None:
        _visited = set()  # create memo once in top-level call

    if node in _visited:
        return
    _visited.add(node)
    for neighbour in graph[node]:
        depth_first_walk_graph(graph, neighbour, _visited)

Your question focuses on fixing the behavior when "it is called repeatedly without an explicit argument".
You should also ask yourself what you want to happen when called with an argument:

>>> CONSTANT = ['the']
>>> my_func(CONSTANT)
['the', 'a']
>>> CONSTANT  # oops??
['the', 'a']

If that's desired, see HenryR's answer (=None, check is None inside).

But if you didn't intend to mutate the argument, just use it as starting point for a list, you can simply copy it:

def myFunc(starting_list=[]):
    starting_list = list(starting_list)
    starting_list.append("a")
    print(starting_list)

(or in this simple case just print starting_list + ["a"] but I guess that was just a toy example)

In general, mutating your arguments is bad style in Python. The only functions that are fully expected to mutate an object are methods of the object. It's even rarer to mutate an optional argument — is a side effect that happens only in some calls really the best interface?

  • If you do it from the C habit of "output arguments", that's completely unnecessary - you can always return multiple values as a tuple.

  • If you do this to efficiently build a long list of results without building intermediate lists, consider writing it as a generator and using result_list.extend(myFunc()) when you are calling it. This way your calling conventions remains very clean.

Optional defensive steps if you feel like enforcing the function body shouldn't mutate:

  • Use immutable defaults: starting_list=(). Sometimes needs code changes but copying with list() accepts tuples too, as would e.g. return [*starting_list, "a"].
  • Add a type annotation and run a type checker.

P.S. One pattern where mutating an optional arg is frequently done is a hidden "memo" arg in recursive functions:

def depth_first_walk_graph(graph, node, _visited=None):
    if _visited is None:
        _visited = set()  # create memo once in top-level call

    if node in _visited:
        return
    _visited.add(node)
    for neighbour in graph[node]:
        depth_first_walk_graph(graph, neighbour, _visited)

我如何避免由Python引起的问题(例如,可变的默认参数“记住”旧数据)?

欢烬 2025-02-10 02:48:12

我自己解决了问题。

我写道:

                class UnionC(ctypes.Union):
                    _fields_ = [
                        ('cdata', ctypes.c_char),
                        ('idata', ctypes.c_short),
                        ('ldata', ctypes.c_long),
                        ('fdata', ctypes.c_float),
                        ('dfdata', ctypes.c_double),
                    ]

我删除了:

union = UnionC()
union.ldata[0] = value

这些更改为我解决了问题。我很确定上面的两行引起了问题。

I managed to solve the issue myself.

I wrote:

                class UnionC(ctypes.Union):
                    _fields_ = [
                        ('cdata', ctypes.c_char),
                        ('idata', ctypes.c_short),
                        ('ldata', ctypes.c_long),
                        ('fdata', ctypes.c_float),
                        ('dfdata', ctypes.c_double),
                    ]

And I removed :

union = UnionC()
union.ldata[0] = value

These changes solved the problem for me. I'm pretty sure the line two lines above were causing the issue.

attributeError:Unionc对象没有属性

欢烬 2025-02-09 17:01:36

那不是您创建R串的方式。它应该是r'c:\ some \ path',而不是“ r'+”'c:\ some \ path'。 r在最左边的报价前面走出引号。您是第一次做正确的事情,但是当您串联变量以构建最终文件路径时,您使用了R-strings错误,并且会遇到不是有效的文件路径的东西。

That’s not how you create r-strings. Instead of ‘r’+”’C:\SOME\PATH’”, it should be r’C:\SOME\PATH’. The r goes outside the quotes, in front of the leftmost quote. You did it right the first time but as you concatenated variables to build up the final file path, you used r-strings incorrectly, and wound up with something that isn’t a valid file path.

python中的无效论点

欢烬 2025-02-09 01:12:44

您可以为OnKeypress事件创建自己的验证

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)  
{  
    string str = textBox1.Text;
    if(str.All(!char.IsDigit)) {
    MessageBox.Show("You can only enter numbers");  
}

以掩盖文本框值,您需要从用户收集输入,然后将其称为字符串,例如提交按钮等事件。

string input_str = textbox1.Text;
string maskstr = "";
foreach(char c in input_str.ToCharArray()) {
if(c.IsDigit) {
maskstr += "X" ;
}
else {
maskstr += c;
}
}
return maskstr.ToString();

这应该是您的输出

Input_str : 525-754-8970
maskstr   : XXX-XXX-XXXX

You can create your own validate for onKeypress event

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)  
{  
    string str = textBox1.Text;
    if(str.All(!char.IsDigit)) {
    MessageBox.Show("You can only enter numbers");  
}

To mask a textbox value you will need to collect the input from the user then call it as a string within an event like a submit button etc.

string input_str = textbox1.Text;
string maskstr = "";
foreach(char c in input_str.ToCharArray()) {
if(c.IsDigit) {
maskstr += "X" ;
}
else {
maskstr += c;
}
}
return maskstr.ToString();

This should be your output

Input_str : 525-754-8970
maskstr   : XXX-XXX-XXXX

C#ASP.NET文本框如何验证和掩盖电话号码?

欢烬 2025-02-07 06:25:39

有什么原因是在第7行上您不会不只是初始化x?

通常,建议应始终初始化内置类型内置的本地/块范围。这是为了防止内置不确定价值的类型内置的潜在用途,并将导致不确定的行为

在您的特定示例中,尽管在下一行中,我们有 std :: cin&gt;&gt; X; 因此可以安全地省略上一行中的零初始化。

还请注意,在您的示例中,如果读取输入因某种原因失败,则在C ++ 11之前, X 仍然具有不确定的值,但从C ++ 11(&amp; onwards) x 将根据以下引用的语句具有不确定的价值。

来自 basic_istream的文档

如果提取失败(例如,如果在预期数字的位置输入字母),则将零写入值,而 failbit 设置。对于已签名的整数,如果提取导致值太大或太小而无法符合价值,则 std :: numeric_limits&lt; t&gt; :: max()或 or std :: nemeric_limert&lt; t&gt; t&gt; :: min()分别编写,并设置了FailBit标志。对于未签名的整数,如果提取导致值太大或太小而无法符合价值,则编写 std :: numeric_limits&lt; t&gt; :: max()是编写的,并且 fafs> failbit 设置标志。

似乎零启动变量是浪费时间,因为它是在下一行上重新定义的。

就像我说的那样,在您的示例中,假设您使用的是C ++ 11(''更高),则可以安全地删除零定位化。


然后用std :: cin

定义它

std :: cin 不使用“定义” IT( x )。定义仅在您写作时仅发生一次:

int x{ }; //this is a definition

即使您离开零初始化,也将是一个定义:

int x;  //this is also a definition but x is uninitialized here

Is there any reason that on line 7 you wouldn't just not initialize x?

In general, it is advised that local/block scope built in types should always be initialized. This is to prevent potential uses of uninitialized built in types which have indeterminate value and will lead to undefined behavior.

In your particular example though since in the immediate next line we have std::cin >> x; so it is safe to omit the zero initialization in the previous line.

Note also that in your example if reading input failed for some reason then prior to C++11, x still has indeterminate value but from C++11(&onwards) x will no longer has indeterminate value according to the below quoted statement.

From basic_istream's documentation:

If extraction fails (e.g. if a letter was entered where a digit is expected), zero is written to value and failbit is set. For signed integers, if extraction results in the value too large or too small to fit in value, std::numeric_limits<T>::max() or std::numeric_limits<T>::min() (respectively) is written and failbit flag is set. For unsigned integers, if extraction results in the value too large or too small to fit in value, std::numeric_limits<T>::max() is written and failbit flag is set.

It seems zero-initializing the variable is a waste of time because it's redefined on the next line.

As i said, in your example and assuming you're using C++11(& higher), you can safely leave off the zero-initialization.


then defined it with std::cin

No the use of std::cin does not "define" it(x). Definition happened only once when you wrote:

int x{ }; //this is a definition

Even if you leave the zero initialization, then also it will be a definition:

int x;  //this is also a definition but x is uninitialized here

是否有理由使用零定位化,而不是在要在使用该值之前进行更新时根本不定义变量?

欢烬 2025-02-07 06:23:23

您可以使用浏览器指纹技术,例如不仅收集用户代理,还收集其他设备详细信息,例如可用字体,安装的附加组件等,但由于违反了用户同意,因此被认为是非法的。另外,用户可以故意更改其中的一些以避免检测。

You can use browser fingerprinting techniques like collecting not only the user agent but also other device details like available fonts, installed add-ons etc but since it violates user consent, it is perceived as illegal. Also user can intentionally change some of those to avoid detection.

使用用户代理字符串或类似的东西,可以将两个完全相同的品牌和模型的设备与不同的设备检测到不同的设备?

欢烬 2025-02-06 10:00:09

因此,事实证明,您不能将Android模块添加为纯Java模块的依赖性,我认为这很有意义。

Android Studio IDE只是在提出无法做的事情,这是一种误导。

So it turns out you cannot add an Android module as a dependency to a pure java module, which I guess makes sense.

Android Studio IDE was just suggesting something that cannot be done, which is misleading.

Android:可以从另一个模块导入类

欢烬 2025-02-05 18:46:09

不幸的是,Google尚未启用对给定管理用户/域启用的列表列表(即:列表方法)的活动订阅的支持。他们唯一暴露的方法是停止现有订阅的停止方法,但它要求呼叫者已经知道与订阅相关的频道元数据。

好消息是,如果您在创建时没有存储此信息,则应该能够找到所需的参数作为事件通知的一部分。我相信他们可能会伴随着每个通知活动的标题。

Unfortunately, Google has not enabled support for a way to list (i.e: a LIST method) active subscriptions enabled for a given admin user/domain. The only method they've exposed is a STOP method to stop an existing subscription, but it requires the caller already know the channel metadata associated with the subscription.

The good news here is if you did not store this information upon creation, you should be able to find the required parameters as a part of an event notification. I believe they might be in the headers accompanying each notification event.

如何列出所有Google目录订阅频道

欢烬 2025-02-05 00:37:39

从第18版降级到16版。它对我有用。

Downgrade from version 18 to version 16.. it worked for me.

我如何解决错误&quot” gypgyp err!err!查找未从命令行或NPM配置设置的VSFind vs MSVS_Version?

欢烬 2025-02-04 16:51:48

这可以按照以下方式完成:

const filterStrings = filterArray.map(o => JSON.stringify(o));
const result = baseArray.map(o => filterStrings.includes(JSON.stringify(o)));

请查看以下可运行的代码,并查看其工作原理。

const baseArray = [
    {
        "id": 1,
        "name": "AnalyticalAdmin"
    },
    {
        "id": 2,
        "name": "Analyst"
    },
    {
        "id": 4,
        "name": "AdminReviewer"
    },
    {
        "id": 5,
        "name": "SystemAdministrator"
    },
    {
        "id": 6,
        "name": "CaseworkSTRTechLeader"
    }
];

const filterArray = [
    {
        "id": 4,
        "name": "AdminReviewer"
    }
];

const filterStrings = filterArray.map(o => JSON.stringify(o));
const result = baseArray.map(o => filterStrings.includes(JSON.stringify(o)));
console.log(result);

This could be done as follows:

const filterStrings = filterArray.map(o => JSON.stringify(o));
const result = baseArray.map(o => filterStrings.includes(JSON.stringify(o)));

Please take a look at below runnable code and see how it works.

const baseArray = [
    {
        "id": 1,
        "name": "AnalyticalAdmin"
    },
    {
        "id": 2,
        "name": "Analyst"
    },
    {
        "id": 4,
        "name": "AdminReviewer"
    },
    {
        "id": 5,
        "name": "SystemAdministrator"
    },
    {
        "id": 6,
        "name": "CaseworkSTRTechLeader"
    }
];

const filterArray = [
    {
        "id": 4,
        "name": "AdminReviewer"
    }
];

const filterStrings = filterArray.map(o => JSON.stringify(o));
const result = baseArray.map(o => filterStrings.includes(JSON.stringify(o)));
console.log(result);

通过将两个数组与对象进行比较,创建一个新的布尔值数组

欢烬 2025-02-04 11:01:25

对于此错误:

错误:无法从源加载函数定义:从函数来源:SyntaxError生成表现:无法

在功能文件夹中使用模块外的Import语句 CD(您可能已经在这里已经在这里)并在“描述”行之后的package.json文件中添加“ type”:“模块”。这对我有用

For this error:

Error: Failed to load function definition from source: Failed to generate manifest from function source: SyntaxError: Cannot use import statement outside a module

cd to the functions folder (you're probably already here) and add "type": "module" in the package.json file after the "description" line. This worked for me

firebase云错误无法从源加载功能定义

欢烬 2025-02-03 11:31:44

与较旧的Python浏览器相比,剧作家的处理方式不同...

在下拉访问中,您应该page.select_option(selector)

这也是为什么在playwright中您不能单击复选框,您应该单击一个复选框,您应该page.check(selector)(selector)
https://playwright.dev/playwright.dev/python/dev/python/docs/api/类页#页面选项

Playwright handle differently with elements than the older python browsers...

in dropdown you should page.select_option(selector)

that's also why in Playwright you can't click a check box, you should page.check(selector)
https://playwright.dev/python/docs/api/class-page#page-select-option

剧作家Python:单击未排序列表下拉列表的随机列表项目

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文