文章 评论 浏览 27

2025-02-21 02:06:55
df.reset_index(drop=True)

drop 属性指定是否应删除先前使用的索引列。

df.reset_index(drop=True)

The drop attribute specifies whether the previously used index column should be removed.

如何更改索引值从0开始

2025-02-21 01:12:11

类名称为 zafg3t-1 gawepq 等是动态生成的,并且在大量时间后会更改即使是下次您访问站点 farresh。


搜索 框中单击您需要诱导 webdriverwait 对于 emeltage_be_be_clickable() ,您可以使用以下任何一个 定位器策略

  • 使用 css_selector

      driver.get('https://coinmarketcap.com/')
    WebDriverWait(驱动程序,20).until(ec.element_to_be_clickable(((by.css_selector
    WebDriverWait(驱动程序,20).until(ec.element_to_be_clickable(((by.css_selector
     
  • 使用 xpath

      driver.get('https://coinmarketcap.com/')
    webdriverwait(驱动程序,20).until(ec.element_to_be_clickable(((by.xpath,“ // div [@class ='cmc-cookie-policy-banner__close'close'close'close']))。
    WebDriverWait(驱动程序,20).until(ec.element_to_be_clickable(((by.xpath,“ // div [text()='search']”))。
     
  • 注意:您必须添加以下导入:

     来自selenium.webdriver.support.ui导入webdriverwait
    从selenium.webdriver.common.通过进口
    从selenium.webdriver.support进口预期_conditions作为ec
     
  • 浏览器快照:

“

Classnames like zafg3t-1, gaWePq, etc are dynamic generated and would change after a considerable amount of time and even may be the next time you access the site afresh.


Solution

To click within the Search box you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    driver.get('https://coinmarketcap.com/')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.cmc-cookie-policy-banner__close"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div[data-text='Use to trigger search']"))).click()
    
  • Using XPATH:

    driver.get('https://coinmarketcap.com/')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='cmc-cookie-policy-banner__close']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[text()='Search']"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • Browser Snapshot:

coinmarketcap

通过className查找元素,然后单击JavaScript渲染网站中的元素使用Python Selenium

2025-02-21 01:10:49

生成的逻辑ID(例如 testlambdafunction67ca3bed )是稳定的(除非更改构造ID或构造树),因此通常可以在 env.json 另外,您可以将所有env var放在参数键:

// env.json
{
  "Parameters": {
    "TABLE_NAME": "localtable",
    "BUCKET_NAME": "testBucket",
    "STAGE": "dev"
  }
}

The generated Logical IDs like TestLambdaFunction67CA3BED are stable (unless you change the Construct ID or construct tree), so are generally fine to use in env.json Alternatively, you can place all the env vars under a Parameters key:

// env.json
{
  "Parameters": {
    "TABLE_NAME": "localtable",
    "BUCKET_NAME": "testBucket",
    "STAGE": "dev"
  }
}

我如何最好使用CDK&最好地完成本地环境变量。山姆?

2025-02-20 18:41:03

tl; dr

char 类型是遗产,本质上是损坏的,并且大多数字符失败。请参阅 char 失败 inideOne.com live代码。请参阅我的评论在这里

使用代码点与单个字符一起工作时的整数数字。

"hello

tl;dr

The char type is legacy, essentially broken, and fails with most characters. See char fail in live code at Ideone.com. See my Comments here and here on this page.

Use code point integer numbers when working with individual characters.

"hello????"
.codePoints()
.mapToObj( Character :: toString )
.toArray( String[]::new )

See this code run live at Ideone.com.

[h, e, l, l, o, ????]

Code points

A code point is the number assigned permanently to each character identified by Unicode.

int[] codePoints = "hello".codePoints().toArray() ; 

[104, 101, 108, 108, 111]

Get the character for each of those code points.

List< String > lettersOfHello = 
    Arrays
    .stream( codePoints )
    .mapToObj( Character :: toString )
    .toList() 
;

See this code run live at Ideone.com.

[h, e, l, l, o]

如何将字符串转换为字符数组-Java 8

2025-02-20 09:55:48

解决方案非常简单。 pil.image 可以使用文件实例打开,因此我刚刚使用 f_object.file 进行打开,然后将其保存在Bytesio实例中,并具有优化和压缩。

正确工作代码:

# imports
from pathlib import Path

from django.core.files.uploadedfile import InMemoryUploadedFile
from PIL import Image


# some service class
...
    def _convert_to_webp(self, f_object: InMemoryUploadedFile):
        suffix = Path(f_object._name).suffix
        if suffix == ".webp":
            return f_object._name, f_object
        
        new_file_name = str(Path(f_object._name).with_suffix('.webp'))
        image = Image.open(f_object.file)
        thumb_io = io.BytesIO()
        image.save(thumb_io, 'webp', optimize=True, quality=95)
    
        new_f_object = InMemoryUploadedFile(
            thumb_io,
            f_object.field_name,
            new_file_name,
            f_object.content_type,
            f_object.size,
            f_object.charset,
            f_object.content_type_extra
        )
        
        return new_file_name, new_f_object

95%被选择为平衡参数。质量非常不好,质量= 80 质量= 90

The solution was pretty simple. PIL.Image can be opened using file instance, so I just opened it using f_object.file and then saved it in BytesIO instance with optimization and compression.

Correctly working code:

# imports
from pathlib import Path

from django.core.files.uploadedfile import InMemoryUploadedFile
from PIL import Image


# some service class
...
    def _convert_to_webp(self, f_object: InMemoryUploadedFile):
        suffix = Path(f_object._name).suffix
        if suffix == ".webp":
            return f_object._name, f_object
        
        new_file_name = str(Path(f_object._name).with_suffix('.webp'))
        image = Image.open(f_object.file)
        thumb_io = io.BytesIO()
        image.save(thumb_io, 'webp', optimize=True, quality=95)
    
        new_f_object = InMemoryUploadedFile(
            thumb_io,
            f_object.field_name,
            new_file_name,
            f_object.content_type,
            f_object.size,
            f_object.charset,
            f_object.content_type_extra
        )
        
        return new_file_name, new_f_object

95% was chosen as balanced parameter. There was very bad quality with quality=80 or quality=90.

Django将图像转换为WebP

2025-02-20 05:42:12

Kafka恰好是Kafka-streams功能,尽管它也可以与常规消费者和生产商一起使用。

完全只能在您的应用程序仅与Kafka交互的情况下实现:没有XA和其他类型的技术分布式交易,可以使Kafka消费者能够在确切的一方面与其他一些存储(例如REDIS)进行交互方式。

在分布式世界中,我们必须承认这是不可取的,因为它引入了锁定,争夺和指数下降的效果。如果我们不需要进入分布式世界,那么我们不需要卡夫卡,而且很多事情变得更加容易。

KAFKA中的交易本来可以在一个仅与Kafka交互的应用程序中使用,它可以保证您的应用程序将从某些主题分区中读取,2)在其他主题分区中写入一些结果,3)提交阅读与1相关的偏移,或者没有做任何事情。如果以这样的方式将几个应用程序背靠背并通过Kafka进行交互,那么如果您非常小心,您 可以准确地实现一次。如果您的消费者需要4)与REDIS互动5)与其他一些存储互动或在某处做一些副作用(例如发送电子邮件左右),那么通常无法执行步骤1,2,3,4, 5在原子上作为分布式应用程序的一部分。您 can 使用其他存储技术(是的,Kafka本质上是存储)实现此类方法,但是它们不能分发,并且您的应用程序也无法分发。从本质上讲,这就是帽定理告诉我们的。

这也是为什么确切的一致性本质上是Kafka-streams的内容:Kafka流只是Kafka消费者/生产者客户端的智能包装器,以免您构建仅与Kafka交互的应用程序。

您还可以通过其他数据处理框架(例如Spark Streaming或Flink)实现准确的流媒体流处理。

在实践中,通常不必为交易而不是在消费者中脱颖而出要简单得多。您可以保证,最大的消费者组的一个消费者在任何时间点都连接到每个分区,因此重复始终会在您的应用程序的同一实例中发生(直到它重新计算),并且取决于您的配置,复制通常仅在一个Kafka消费者缓冲区中发生,因此您无需在消费者中存储太多状态即可删除。如果您使用某种仅能增加的事件ID(本质上是Kafka偏移量是BTW的,这不是巧合),那么您只需要保持应用程序的每个实例的状态-ID您已成功处理的每个分区。

Kafka exactly-once is essentially a Kafka-Streams feature, although it can be used with regular consumer and producers as well.

Exactly once can only be achieved in a context where your applications are only interacting with Kafka: there is no XA nor other kind of distributed transactions across technologies that would enable a Kafka consumer interact with some other storage (like Redis) in an exactly-once manner.

In a distributed world, we have to acknowledge that is not desirable, since it introduce locking, contention, and exponentially degrading performance under load. If we don't need to be in a distributed world, then we don't need Kafka and many things become easier.

Transactions in Kafka are meant to be used within one application that is only interacting with Kafka, it lets you guarantee that the app will 1) read from some topic partitions, 2) write some result in some other topic partitions and 3) commit the read offsets related to 1, or do none of those things. If several apps are put back-to-back and interacting through Kafka in such manner, then you could achieve exactly once if you're very careful. If your consumer needs to 4) interact with Redis 5) interact with some other storage or do some side effect somewhere (like sending an email or so), then there is in general no way to perform steps 1,2,3,4,5 atomically as part of a distributed application. You can achieve this kind of things with other storage technologies (yes, Kafka is essentially a storage), but they cannot be distributed and your application cannot either. That's essentially what the CAP theorem tells us.

That's also why exactly-once is essentially a Kafka-streams stuff: Kafka Stream is just a smart wrapper around the Kafka consumer/producer clients that lest you build applications that interact only with Kafka.

You can also achieve exactly-once streaming processing with other data-processing framework, like Spark Streaming or Flink.

In practice it's often much simpler to not bother with transactions and just de-duplicate in the consumer. You have the guarantee that at max one consumer of the consumer group is connected to each partition at any point in time, so duplicates will always happen in the same instance of your app (until it re-scales), and, depending on your config, the duplication should typically only happen within one single Kafka consumer buffer, so you don't need to store much state in your consumer to de-duplicate. If you use some kind of event-ids that can only increase for example (which is essentially what the Kafka offset is BTW, and it's no coincidence), then you just need to keep in the state of each instance of your app the maximum event-id per partition that you've successfully processed.

kafka |确切的一方面消费者不止一次消耗消息

2025-02-19 14:33:09

这比任何事物都更像是个人意见,但是业务部门中的每个元素都应代表与其他元素不同的东西,并实现一个单一的目的。因此,如果身份验证和交付业务元素有不同的目的(例如,即使是指同一数据库对象),我对您的方法没有任何问题。

对于您的最后一句话,有过滤器和拦截器可以在任何交互之前,甚至在服务本身或DTO对象中验证对象。因此,除非您使用某种不可修复的字段过滤器和验证器对象,否则除非明确对其进行编码,否则您不应遇到所需的字段问题。

This is more of a personal opinion than anything, but each element in the business unit should represent something different than other elements, and serve a single purpose. So, if the Authentication and Delivery business elements serve different purposes (even if they refer to the same database object, for instance) I don't see any problem with your approach.

For your last sentence, there are filters and interceptors to validate objects in requests previous to any interaction, or even in the service itself, or the DTO object. So unless you are using some sort of unmodifiable field filter and validator object, you shouldn't run into required field issues unless you explicitly code it.

共享两个不同的DTO以使用客户端模块(库)以不同的微服务以不同的方式表示相同对象是正确的吗?

2025-02-19 08:20:36

没有办法在注释中指定自定义逻辑,因此您必须将其留在运行时处理注释的代码,但是,您也不能将 null 作为标记值。

告诉您的注释处理工具需要自定义处理的唯一方法是选择专用标记类型作为默认值。这可能是一种类型,否则将永远不会作为常规注释值(例如 void.class )出现的类型,或者您仅创建仅作为标记的类。

要显示类似的现实生活示例,代码>注释具有预期元素,表示要投掷的预期类型。默认值应该表明预期不例外,不能是 null ,也不能以 throwable 层次结构外的类型,因为该值必须符合声明的类型班级扩展可投掷&gt; 。因此,默认值是一个专用类型 test。无 在处理注释时,框架从未被抛弃和治疗。

对于您的情况,您必须确定合适的标记类型或创建专用类型并调整处理代码以检查该类型。例如

public final class UseFieldType {
    private UseFieldType() {}
}

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface YourAnnotation {
    Class<?> className() default UseFieldType.class;
}
class YourCodeUsedAtRuntime {
    public static Optional<Class<?>> getAnnotationValue(Field f) {
       YourAnnotation a = f.getAnnotation(YourAnnotation.class);
       if(a == null) return Optional.empty();

       Class<?> type = a.className();
       if(type == UseFieldType.class) type = f.getType();
       return Optional.of(type);
    }
}
class Example {
    @YourAnnotation String string;
    @YourAnnotation(className = Pattern.class) String regEx;
    String none;

    public static void main(String[] args) {
        for(Field f: Example.class.getDeclaredFields()) {
            System.out.println(f.getName() + ": "
                + YourCodeUsedAtRuntime.getAnnotationValue(f)
                      .map(Class::getName).orElse("No annotation"));
        }
    }
}
string: java.lang.String
regEx: java.util.regex.Pattern
none: No annotation

There is no way to specify a custom logic in an annotation, so you have to leave it to the code processing the annotation at runtime, however, you can’t use null as a marker value either.

The only way to tell your annotation processing tool that custom processing is required, is by choosing a dedicated marker type as default value. This might be a type that would otherwise never occur as a regular annotation value, e.g. void.class, or you create a class solely for serving as the marker.

To show a similar real life example, JUnit’s @Test annotation has an expected element denoting an expected type to be thrown. The default, supposed to express that no exception is expected, can’t be null nor a type outside the Throwable hierarchy as the value must conform to the declared type Class<? extends Throwable>. Therefore, the default value is a dedicated type Test.None that is never thrown and treated specially by the framework when processing the annotation.

For your case, you have to decide for a suitable marker type or create a dedicated type and adapt the processing code to check for the type. E.g.

public final class UseFieldType {
    private UseFieldType() {}
}

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface YourAnnotation {
    Class<?> className() default UseFieldType.class;
}
class YourCodeUsedAtRuntime {
    public static Optional<Class<?>> getAnnotationValue(Field f) {
       YourAnnotation a = f.getAnnotation(YourAnnotation.class);
       if(a == null) return Optional.empty();

       Class<?> type = a.className();
       if(type == UseFieldType.class) type = f.getType();
       return Optional.of(type);
    }
}
class Example {
    @YourAnnotation String string;
    @YourAnnotation(className = Pattern.class) String regEx;
    String none;

    public static void main(String[] args) {
        for(Field f: Example.class.getDeclaredFields()) {
            System.out.println(f.getName() + ": "
                + YourCodeUsedAtRuntime.getAnnotationValue(f)
                      .map(Class::getName).orElse("No annotation"));
        }
    }
}
string: java.lang.String
regEx: java.util.regex.Pattern
none: No annotation

如何将默认值设置为注释变量作为变量注释的类类型?

2025-02-19 07:10:56

使用 React-mark.js 您可以简单地:

<Marker mark="hello">
  Hello World
</Marker>

链接:

With react-mark.js you can simply:

<Marker mark="hello">
  Hello World
</Marker>

Links:

使用ReactJ突出显示文本

2025-02-19 06:55:40

这在这里:

var distance = countDownDate - now;
var percentremains = (distance / countDownDate);

没有意义。 <代码>距离将是销售结束之间的一定数毫秒。但是 CountDowndate 转换为数字,将是销售结束时的Unix时间戳 - 类似于 1656727199000 。例如,如果有2天的销售结束,则结果计算为 1000 * 60 * 60 * 60 * 24 * 2 (毫秒),除以 1656727199000 。但是剩下的数字不应取决于它是哪个确切的时间戳。例如,在2200年,此计算从销售结束开始2天,将产生较低的 percenemains

您需要的是在某个地方添加它:

销售设置为持续4天

,然后将其分解为您的计算。

下面是一种可能的方法。我也自由使用了更精确的变量名称。

const saleStartTimestamp = new Date("Jun 27, 2022 20:59:59").getTime();
const saleEndTimestamp = new Date("Jul 01, 2022 20:59:59").getTime();

const timeoutId = setInterval(function() {
  const now = new Date().getTime();
  const millisecondsBetweenNowAndSaleEnd = saleEndTimestamp - now;
  const totalMillisecondsOfSale = saleEndTimestamp - saleStartTimestamp;
  const proportionOfSaleTimeLeft = millisecondsBetweenNowAndSaleEnd / totalMillisecondsOfSale;
  
  const productsAvailableAtStart = 1000;
  const productsLeft = Math.floor(proportionOfSaleTimeLeft * productsAvailableAtStart);
  console.log('productsLeft', productsLeft);

  // populate DOM, etc
}, 1000);

This here:

var distance = countDownDate - now;
var percentremains = (distance / countDownDate);

doesn't make sense. The distance will be some number of milliseconds between now and when the sale ends. But the countDownDate, converted to a number, will be the unix timestamp of when the sale ends - something like 1656727199000. If there are, say, 2 days between now and when the sale ends, the resulting calculation is 1000 * 60 * 60 * 24 * 2 (milliseconds) divided by 1656727199000. But the number left should not depend on which exact timestamp it is. For example, in the year 2200, this calculation 2 days from the end of a sale would produce a far lower percentremains.

What you need is to add this in as a variable somewhere:

and the sale is set to last 4 days

and then factor it into your calculations.

One possible approach is below. I've also taken the liberty of using more precise variable names.

const saleStartTimestamp = new Date("Jun 27, 2022 20:59:59").getTime();
const saleEndTimestamp = new Date("Jul 01, 2022 20:59:59").getTime();

const timeoutId = setInterval(function() {
  const now = new Date().getTime();
  const millisecondsBetweenNowAndSaleEnd = saleEndTimestamp - now;
  const totalMillisecondsOfSale = saleEndTimestamp - saleStartTimestamp;
  const proportionOfSaleTimeLeft = millisecondsBetweenNowAndSaleEnd / totalMillisecondsOfSale;
  
  const productsAvailableAtStart = 1000;
  const productsLeft = Math.floor(proportionOfSaleTimeLeft * productsAvailableAtStart);
  console.log('productsLeft', productsLeft);

  // populate DOM, etc
}, 1000);

调整JS倒数计时器以显示剩余的产品数

2025-02-19 01:38:56

与Tomcat 4.4相比,Tomcat 9将产生JSP的不同Java代码。 Tomcat 9将为最小匹配所需的JDK生成 - 因此,您将不幸地使用旧的JDK编译器编译Tomcat 8代码。其中,显然:仿制药。其中Java 1.4知道 MAP ,新版本知道 map&lt; string,long&gt;

JSP无非是用于从JSP生成Java Servlet的编译器的输入,然后将其交给所讨论的Java编译器。

如果您的代码仅由JSP组成 ,则最好不要修复JSP。否则,请考虑重新编译整个应用程序:您现在也采用了较新的Servlet规范,可能会错过一些必需的东西。我并不100%相信它们都是真正的二进制倒数兼容。

tomcat 9 use

Tomcat 9 will generate different Java code from a JSP than Tomcat 4.4 would. And Tomcat 9 will generate for the JDK that it requires as minimal match - so you'll be out of luck with compiling the Tomcat 8 code with an old JDK compiler. Among it, obviously: Generics. Where Java 1.4 knew of Map, newer versions know of Map<String,Long>.

JSPs are nothing else than input for a compiler that generates Java Servlets from the JSP, and in turn hands it to the Java compiler in question.

If your code is only made up of JSPs, you're better off fixing the JSPs. Otherwise, consider recompiling the whole application: You're now also on a newer servlet specification and might miss some required things. I'm not 100% confident that they're all truly binary backward-compatible.

Tomcat 9 uses:

尝试部署为Tomcat编写的应用程序4.4 J2SE 1.4使用Tomcat 9

2025-02-19 01:35:58

扭转条件:

select a.* 
  from ( select distinct position from job) a
 where position not in (
         select position
           from job
          where salary < 400 or salary > 700
       )

您可能还想阅读所有操作员的工作方式。您的查询错误地假设所有职位都是相同的(否则所有职位都无法正常工作)。

或者,使用全部两次:

select a.* 
  from (
    select distinct position 
       from job
           ) a
where 400 >=  ALL (
              select salary
                 from job
                where position = a.position
           )
  and 700 <=  ALL (
              select salary
                 from job
                where position = a.position
           )

Reverse the condition:

select a.* 
  from ( select distinct position from job) a
 where position not in (
         select position
           from job
          where salary < 400 or salary > 700
       )

You also might want to read about how ALL operator works like. Your query incorrectly assumes all positions are the same (otherwise ALL will not work).

Alternatively, use ALL twice:

select a.* 
  from (
    select distinct position 
       from job
           ) a
where 400 >=  ALL (
              select salary
                 from job
                where position = a.position
           )
  and 700 <=  ALL (
              select salary
                 from job
                where position = a.position
           )

SQL中的所有操作员

2025-02-18 17:52:14

仅使用显示的样本,请尝试以下 JQ 代码。使用 tostream 在此处函数在此处获取所需值要求。

jq -c '[.[] | tostream | if .[1] != null then .[1] else empty end]' Input_file

With your shown samples only, please try following jq code. Using tostream function here to get the required values from requirement.

jq -c '[.[] | tostream | if .[1] != null then .[1] else empty end]' Input_file

如果在JQ数组中的字符串,请获取值,如果对象或字符串

2025-02-18 05:51:40

为此,您可以在 Navigator 中使用剪贴板 API。

<script>
    function myFunction() {
        let userInput = document.querySelector("#userInput");
        let url = document.querySelector("#url");
        
        let output = "https://www.amazon.it/dp/" + userInput.value + "/ref=nosim?tag=altpe-21";
        url.innerHTML = output;

        navigator.permissions.query({name: "clipboard-write"}).then(result => {
            if (result.state == "granted" || result.state == "prompt") {
                 navigator.clipboard.writeText(output);
            }
        });

    }
</script>

You can use the Clipboard API in the navigator for this purpose.

<script>
    function myFunction() {
        let userInput = document.querySelector("#userInput");
        let url = document.querySelector("#url");
        
        let output = "https://www.amazon.it/dp/" + userInput.value + "/ref=nosim?tag=altpe-21";
        url.innerHTML = output;

        navigator.permissions.query({name: "clipboard-write"}).then(result => {
            if (result.state == "granted" || result.state == "prompt") {
                 navigator.clipboard.writeText(output);
            }
        });

    }
</script>

复制到剪贴板HTML

2025-02-18 03:06:58

我认为这将起作用,但作为临时解决方法。

while True:
    try:
        driver.get('https://katalon.com/')
        break
    except:
        continue

I think this will work but as a temporary workaround.

while True:
    try:
        driver.get('https://katalon.com/')
        break
    except:
        continue

Selenium / Seleniumwire未知错误:无法确定未知错误的加载状态:意外命令响应

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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