蹲在坟头点根烟

文章 评论 浏览 29

蹲在坟头点根烟 2025-02-20 22:32:01

缓存无效是复杂的问题。没有一种很好的方法来统治它们。据我所知,雷迪斯无法进行python函数,redis只是一个缓存引擎存储键,带有TTL的值对。如果您想使用无效的高速缓存maby django-cacheops自动化。 github上的django-cacheops

个性化我写了自己的cache invalidators/update。因此,当您的高速缓存的值更新时,我会在缓存中进行更新。当缓存击中其TTL时,Geter方法再次设置。

它是在信号中完成

@receiver(post_save, sender=Settings)
def invalidate_cache_settings(sender, instance, created, **kwargs):
    if instance.name == 'ADMIN_TIMEOUT':
        cache.set('admin_timeout', instance.value_int, 3600)

@register.simple_tag(name="admin_timeout")
def get_admin_timeout():
    admin_timeout = cache.get('admin_timeout', None)
    if admin_timeout is None:
        try:
            admin_timeout = Settings.objects.get(name='ADMIN_TIMEOUT').value_int
        except ObjectDoesNotExist:
            admin_timeout = '36000'
        cache.set('admin_timeout', admin_timeout, 3600)
    return admin_timeout
  

cache invalidation is complex problem. There is no one good way to rule them all. As far as i know redis is not capable of trrigering python functions, Redis is just a cache engine storing key, value pairs with ttl. If you want some automation with invalidating cache maby django-cacheops could be of use. django-cacheops on github

personaly I write my own cache invalidators/ updates. So when a value that you cache is update i update it in cache. when cache hits its ttl the geter method set its again.

it is done in signals for example when someone change model settings with admin_timeout:

@receiver(post_save, sender=Settings)
def invalidate_cache_settings(sender, instance, created, **kwargs):
    if instance.name == 'ADMIN_TIMEOUT':
        cache.set('admin_timeout', instance.value_int, 3600)

then in custom tag

@register.simple_tag(name="admin_timeout")
def get_admin_timeout():
    admin_timeout = cache.get('admin_timeout', None)
    if admin_timeout is None:
        try:
            admin_timeout = Settings.objects.get(name='ADMIN_TIMEOUT').value_int
        except ObjectDoesNotExist:
            admin_timeout = '36000'
        cache.set('admin_timeout', admin_timeout, 3600)
    return admin_timeout
  

如何更新redis -django

蹲在坟头点根烟 2025-02-20 12:29:16

以下给出了多个日期范围的多个用户负面的。

使用下面的数据 -

WITH input_table AS (
select '2022-07-06' as date1,'John Doe' as user, -100 as balance union all
select '2022-07-05','John Doe',-100 union all
select '2022-07-04','John Doe',-100 union all
select '2022-07-03','John Doe',-100 union all
select '2022-07-02','John Doe',-100 union all
select '2022-07-01','John Doe',20   union all
select '2022-06-30','John Doe',-300 union all
select '2022-06-30','John Doe',538 union all
select '2022-05-31','John Doe',-300 union all
select '2022-05-30','John Doe',-538 union all
select '2022-05-29','John Doe',300 union all
select '2022-07-03','Jack',-100 union all
select '2022-07-02','Jack',-100 union all
select '2022-07-01','Jack',20   union all
select '2022-06-30','Jack',-300 union all
select '2022-06-30','Jack',538
),

查询 -

cte_1 as 
( select user, date1, 
lag(date1) over (partition by user order by date1 desc) as new_date1,
balance 
from input_table where balance>0)
select c.user, c.date1 as Negative_balance_since_date, 
(select count(*) from input_table t 
where t.balance<0 
and t.date1 > c.date1 
and (c.new_date1 is null or t.date1 < c.new_date1) 
and t.user = c.user)  as Number_of_days_since_negative_Balance
from cte_1 c;

给出以下输出 -

”在此处输入图像描述

Following gives negative for multiple user of multiple date-ranges.

Using below as data -

WITH input_table AS (
select '2022-07-06' as date1,'John Doe' as user, -100 as balance union all
select '2022-07-05','John Doe',-100 union all
select '2022-07-04','John Doe',-100 union all
select '2022-07-03','John Doe',-100 union all
select '2022-07-02','John Doe',-100 union all
select '2022-07-01','John Doe',20   union all
select '2022-06-30','John Doe',-300 union all
select '2022-06-30','John Doe',538 union all
select '2022-05-31','John Doe',-300 union all
select '2022-05-30','John Doe',-538 union all
select '2022-05-29','John Doe',300 union all
select '2022-07-03','Jack',-100 union all
select '2022-07-02','Jack',-100 union all
select '2022-07-01','Jack',20   union all
select '2022-06-30','Jack',-300 union all
select '2022-06-30','Jack',538
),

Query -

cte_1 as 
( select user, date1, 
lag(date1) over (partition by user order by date1 desc) as new_date1,
balance 
from input_table where balance>0)
select c.user, c.date1 as Negative_balance_since_date, 
(select count(*) from input_table t 
where t.balance<0 
and t.date1 > c.date1 
and (c.new_date1 is null or t.date1 < c.new_date1) 
and t.user = c.user)  as Number_of_days_since_negative_Balance
from cte_1 c;

Gives following output -

enter image description here

如何查询用户级别的负余额衰老报告

蹲在坟头点根烟 2025-02-20 07:50:41

因此,我可以在Kotlin的Gradle中对其进行调整

plugins {
    id ("com.google.protobuf") version ("0.8.12")
}
protobuf {
    protoc {
        artifact = if (osdetector.os == "osx") {
            ("com.google.protobuf:protoc:3.14.0:osx-x86_64")
        } else {
            ("com.google.protobuf:protoc:3.14.0")
        }
    }
   generateProtoTasks {
        all().forEach {
            it.builtins {
                create("java") {
                    option("lite")
                }
            }
        }
    }
}

以这种方式配置Proto DataStore的Gradle

So I could adjust it in Gradle in kotlin

plugins {
    id ("com.google.protobuf") version ("0.8.12")
}
protobuf {
    protoc {
        artifact = if (osdetector.os == "osx") {
            ("com.google.protobuf:protoc:3.14.0:osx-x86_64")
        } else {
            ("com.google.protobuf:protoc:3.14.0")
        }
    }
   generateProtoTasks {
        all().forEach {
            it.builtins {
                create("java") {
                    option("lite")
                }
            }
        }
    }
}

In this way configure the gradle for proto DataStore

我该如何从Groggy到Kotlin DSL Protobuf

蹲在坟头点根烟 2025-02-19 21:48:17
CREATE TYPE vehicle_type AS ENUM ('car', 'truck', 'motorcycle');
-- add column with default
ALTER TABLE tbl ADD COLUMN v_type vehicle_type NOT NULL DEFAULT 'car';

在此处阅读手册。

em>“您只希望以下3个条目之一出现” ,也不会使其无效。

枚举占据4个字节。 To keep the disk footprint to a minimum, you could alternatively use a

ALTER TABLE tbl
  ADD column v_type2 "char" NOT NULL DEFAULT 'c'
, ADD CONSTRAINT v_type_allowed CHECK (v_type2 IN ('c', 't', 'm'));

效力:小,快速。
缺点:特定于Postgres的,不那么可读。

db&lt;&gt;

;

  • gt href =“ https://dba.stackexchange.com/a/166167/3684”>单字节“ char”类型在PostgreSQL中如何工作?
CREATE TYPE vehicle_type AS ENUM ('car', 'truck', 'motorcycle');
-- add column with default
ALTER TABLE tbl ADD COLUMN v_type vehicle_type NOT NULL DEFAULT 'car';

Read the manual here.

Since " you only want one of the following 3 entries to ever possibly appear", also make it NOT NULL.

An enum occupies 4 bytes. To keep the disk footprint to a minimum, you could alternatively use a "char" field instead which occupies 1 byte;

ALTER TABLE tbl
  ADD column v_type2 "char" NOT NULL DEFAULT 'c'
, ADD CONSTRAINT v_type_allowed CHECK (v_type2 IN ('c', 't', 'm'));

Upsides: small, fast.
Downsides: Postgres-specific, less readable.

db<>fiddle here

See:

有没有办法将PostgreSQL列定义为枚举?

蹲在坟头点根烟 2025-02-19 20:14:52

我发现使用“如果 name ==' main ':”并将所有功能保留在“ main()”中:“作为功能处理程序,所有功能都顺利运行。
我仍在尝试弄清楚为什么这起作用。

I found that using "if name == 'main':" and keeping all the functions in "main():" as a function handler everything ran smoothly.
I'm still trying to figure out why this works.

电报机器人在第三次功能后不响应

蹲在坟头点根烟 2025-02-19 20:04:46

https://github.com/exceljs/exceljs/exceljs/exceljs/issues/issues/433
排标题看起来像这样:

const rowHeader = [
  { key: 'xxx' },
  { key: 'adsff' },
  { key: 'ff' },
  { key: 'ffff' },
  { key: 'sdfasdf' },
  { key: 'fasdfads' },
  { key: 'fasdfasdf' },
  { key: 'fasdfadf' },
  { key: 'fasdfawsdft' },
];
const imageId2 = workbook.addImage({
            base64: myBase64Image,
            extension: 'png',
          });
          worksheet.addImage(imageId2, 'A1:D3');
          worksheet.mergeCells('A1:D3');
          worksheet.addRow({});
          const col: string[] = [];
    
          rowHeader.forEach(header => {
            col.push(header.key);
          });
          const columnHeaders: string[] = Object.values(col);
          worksheet.getRow(5).values = columnHeaders;
          worksheet.getRow(5).font = {
            name: 'Arial Black',
            bold: true,
          };
          worksheet.columns = rowHeader;
          worksheet.addRows(dataTableRows);
    
          workbook.xlsx.writeBuffer().then(data => {
            const blob = new Blob([data], {
              type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
            });
            const a = window.document.createElement('a');
            const downloadUrl = window.URL.createObjectURL(blob);
            a.href = downloadUrl;
            a.download = `${fileName}.xlsx`;
            document.body.appendChild(a);
            a.click();
            document.body.removeChild(a);
            window.URL.revokeObjectURL(downloadUrl);
          });

https://github.com/exceljs/exceljs/issues/433
row headers looks like this:

const rowHeader = [
  { key: 'xxx' },
  { key: 'adsff' },
  { key: 'ff' },
  { key: 'ffff' },
  { key: 'sdfasdf' },
  { key: 'fasdfads' },
  { key: 'fasdfasdf' },
  { key: 'fasdfadf' },
  { key: 'fasdfawsdft' },
];
const imageId2 = workbook.addImage({
            base64: myBase64Image,
            extension: 'png',
          });
          worksheet.addImage(imageId2, 'A1:D3');
          worksheet.mergeCells('A1:D3');
          worksheet.addRow({});
          const col: string[] = [];
    
          rowHeader.forEach(header => {
            col.push(header.key);
          });
          const columnHeaders: string[] = Object.values(col);
          worksheet.getRow(5).values = columnHeaders;
          worksheet.getRow(5).font = {
            name: 'Arial Black',
            bold: true,
          };
          worksheet.columns = rowHeader;
          worksheet.addRows(dataTableRows);
    
          workbook.xlsx.writeBuffer().then(data => {
            const blob = new Blob([data], {
              type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
            });
            const a = window.document.createElement('a');
            const downloadUrl = window.URL.createObjectURL(blob);
            a.href = downloadUrl;
            a.download = `${fileName}.xlsx`;
            document.body.appendChild(a);
            a.click();
            document.body.removeChild(a);
            window.URL.revokeObjectURL(downloadUrl);
          });

exceljs-在exceljs中的列标题上方添加图像

蹲在坟头点根烟 2025-02-19 04:23:34

问题是wcwidth在2020年将一个版本(0.2.1)弄乱了依赖性WCWIDTH它下载了一些版本,并且当它达到有问题的发布时,它会出现错误。

提出的一种解决方案在这里包含行的文件wcwidth!= 0.2.1,并修改pip install be pip install -r install -r sumpliont.txt -c dectraints.txts.txt

The problem is that wcwidth messed up one version (0.2.1) back in 2020 so when you pip install... and have a transient dependency on wcwidth it downloads a few versions and when it reaches this problematic release it errors out.

One solution proposed here is to exclude that version by creating a constraints.txt file containing the line wcwidth!=0.2.1 and modifying your pip install to be pip install -r requirements.txt -c constraints.txt

错误:WCWIDTH在VS代码中具有无效的轮子

蹲在坟头点根烟 2025-02-18 21:50:56

我理解的。则组件的状态 - &gt;更新Redux商店,然后阅读商店。您应该做的是:创建一个动作以更新商店,使用React-Redux派遣操作。 https://react-react-react-react-readux.js.org/api/api/connect
使用MapStateToprops读取商店状态并将其在组件中使用。

What I understood. State of Component then -> update Redux Store, then read the store. What you should do is: Create an action to update the store, use react-redux to dispatch the action. https://react-redux.js.org/api/connect.
Use mapStateToProps to read the store state and use it in your component.

RECT/REDUX更新和访问状态值

蹲在坟头点根烟 2025-02-18 07:31:07

我遇到了这个问题,这让我疯了几天。

但是我遇到了一个解决方案。

根据下面的指南,我需要将“ vite.config.js file”重命名为“ vite.config.mjs”,然后按照说明我转到package.json文件并添加了此行:

//Add this line in the very top/first object.

> "type": "module"

它应该在package.json上看起来像这样的新属性“类型”和值“模块”:

{
“名称”:“ myapp”,
“版本”:“ 1.0.0”,
“类型”:“模块”
}

解决方案来自下面的URL:
https:///vitejs.dev/guide/guide/guide/guide/troubleshooting.htmll# this-package-is-esm-仅

I had this problem and it drove me crazy for a few days.

But I came across a solution.

According to the guide below I needed to rename the "vite.config.js file" to "vite.config.mjs" then as per instructions I went to the package.json file and added this line:

//Add this line in the very top/first object.

> "type": "module"

It should look like this on package.json with the new property 'type' and value 'module':

{
"name": "myapp",
"version": "1.0.0",
"type": "module"
}

The solution came from the URL below:
https://vitejs.dev/guide/troubleshooting.html#this-package-is-esm-only

为什么Laravel Vite指令在我的项目中不起作用?

蹲在坟头点根烟 2025-02-18 03:59:23

请让客户端在开发环境中重现错误,并与您共享Dev数据库文件的副本。然后,您的开发人员可以处理有关该问题的数据。

请确保要求共享的数据不是PCI或PII,并且根据CPNA(如果客户是我们的)

Please have the client reproduce the error in their DEV environment and share the copy of the DEV database file with you. Your developers could then work with the data on the issue.

Kindly ensure the data being asked to share is not PCI or PII and in accordance to CPNA (if the client is US based)

在数据库上处理客户信息

蹲在坟头点根烟 2025-02-17 05:24:08

对于多次使用效果,请传递依赖项数组。检查有关使用效应的反应文档。您可以首先将空数组作为使用效果的第二个参数

For useEffect running multiple times, please pass in a dependency array. Check the react documentation on useEffect. You can start by giving an empty array as the second parameter to useEffect

React Hook使用效应多个问题

蹲在坟头点根烟 2025-02-17 03:12:21

这是我遇到的错误:

-django.db.utils.IntegrityError:插入或更新表“ form_blooddiscard”违反外键约束“ form_blooddiscard_status_status_master_master_id_fe293fa_fe293fa_fa_fk_master_st”
详细信息:key(status_master_id)=(3)在表“ master_statusmaster”中不存在。

如我们所见: -
详细信息:key(status_master_id)=(3)在表“ master_statusmaster”中不存在。

它告诉我,在status_master中,没有“ ID”(PK)具有“ 3”的值。

但是,在我的基本模型中: -

class BaseModel(models.Model):
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    status_master = 

models.ForeignKey(StatusMaster,on_delete=models.SET_NULL,default=3,null=True, blank=True)

有人提供了“ status_master”的默认值“ 3”,而不存在。因此,我只是删除了默认值并解决了。

This is the error I was getting:-

django.db.utils.IntegrityError: insert or update on table "Form_blooddiscard" violates foreign key constraint "Form_blooddiscard_status_master_id_ffe293fa_fk_Master_st"
DETAIL: Key (status_master_id)=(3) is not present in table "Master_statusmaster".

as we can see:-
DETAIL: Key (status_master_id)=(3) is not present in table "Master_statusmaster".

it is telling me that in status_master, there is no "id" (PK) having the value "3".

however, in my base model:-

class BaseModel(models.Model):
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    status_master = 

models.ForeignKey(StatusMaster,on_delete=models.SET_NULL,default=3,null=True, blank=True)

someone provided a default value "3" of "status_master" which does not exist. So, I simply just removed the default value and it got solved.

使用Model.Model创建一个模型后,我该如何继承另一个模型。 (碱基模型)]

蹲在坟头点根烟 2025-02-16 12:03:42

通过查看请求,您可以使用 python的请求。分析它,您有3个请求。第一个将返回带有所有文件的列表(第一个是最近的文件)。对特定文件的令牌请求,并且使用该令牌您可以请求该文件。

import requests
import json

# this URL return a list with all files
page_url = "https://arquivos.b3.com.br/api/channels/34dcaaeb-0306-4f45-a83e-4f66a23b42fa/subchannels/cc188e40-03be-408e-aa86-501926b97a76/publications?&lang=pt"

# We get the list in json format
page_request = requests.get(page_url)
page_response = json.loads(page_request.content)

# You could loop through page_response to access all files,
# this is for the latest one
latest_file = page_response[0]

# We extract the file name and the date to use in the next request
file_name = latest_file["fileName"].split("File")[0]
date = latest_file["dateTime"].split("T")[0]

# We add the extracted info in this new url to get the token
token_url = f"https://arquivos.b3.com.br/api/download/requestname?fileName={file_name}&date={date}&recaptchaToken="

token_request = requests.get(token_url)
token_response = json.loads(token_request.content)

# We extract the token value from the response
token = token_response["redirectUrl"].split("?token=")[1]

# We call this URL to get the file we want
file_url = f"https://arquivos.b3.com.br/api/download/?token={token}"

file_request = requests.get(file_url)
file_response = file_request.content

# This response is the direct CSV content, so we can just save it directly
csv_file = open(latest_file["fileName"], "wb")
csv_file.write(file_response)
csv_file.close()

您可以添加尝试,甚至可以在OOP中进行。使用该列表文件,您还可以根据日期映射并选择一个文件,而不是。

希望这有帮助:)

By looking at the requests you can use Python's requests. Analyzing it, you have 3 requests that are made. The first one will return a list with all the files (the first one is the most recent). A token request for a specific file, and with that token you can request the file.

import requests
import json

# this URL return a list with all files
page_url = "https://arquivos.b3.com.br/api/channels/34dcaaeb-0306-4f45-a83e-4f66a23b42fa/subchannels/cc188e40-03be-408e-aa86-501926b97a76/publications?&lang=pt"

# We get the list in json format
page_request = requests.get(page_url)
page_response = json.loads(page_request.content)

# You could loop through page_response to access all files,
# this is for the latest one
latest_file = page_response[0]

# We extract the file name and the date to use in the next request
file_name = latest_file["fileName"].split("File")[0]
date = latest_file["dateTime"].split("T")[0]

# We add the extracted info in this new url to get the token
token_url = f"https://arquivos.b3.com.br/api/download/requestname?fileName={file_name}&date={date}&recaptchaToken="

token_request = requests.get(token_url)
token_response = json.loads(token_request.content)

# We extract the token value from the response
token = token_response["redirectUrl"].split("?token=")[1]

# We call this URL to get the file we want
file_url = f"https://arquivos.b3.com.br/api/download/?token={token}"

file_request = requests.get(file_url)
file_response = file_request.content

# This response is the direct CSV content, so we can just save it directly
csv_file = open(latest_file["fileName"], "wb")
csv_file.write(file_response)
csv_file.close()

You can add the try and except and even make in OOP. With that list file, you can also map it and choose a file based on date and what not.

Hope this helps :)

使用硒在动态页面中下载文件

蹲在坟头点根烟 2025-02-16 08:28:20

好的,看来我有正确的答案,除非您不想要继承的属性:

if (x.hasOwnProperty('key'))

这里还有一些其他选项包含继承的属性:

if (x.key) // Quick and dirty, but it does the same thing as below.

if (x.key !== undefined)

OK, it looks like I had the right answer unless if you don't want inherited properties:

if (x.hasOwnProperty('key'))

Here are some other options to include inherited properties:

if (x.key) // Quick and dirty, but it does the same thing as below.

if (x.key !== undefined)

如何检查对象是否在JavaScript中具有特定属性?

蹲在坟头点根烟 2025-02-16 07:57:44

在您的p上定义width

header {
  height: 600px;
  background-image: url('https://images.unsplash.com/photo-1519197924294-4ba991a11128?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8d2Fyc2F3fGVufDB8fDB8fA%3D%3D&w=1000&q=80');
}

.circle {
  background: red;
  height: 100%;
  clip-path: circle(39.3% at 23% 14%);
  shape-outside: circle(39.3% at 23% 14%);
  position: relative;
}

.circle > p {
  width: 50%;
}
<header>
  <div class="circle">
    <p>
      Lorem ipsum dolor sit amet consectetur adipisicing elit. Maxime mollitia, molestiae quas vel sint commodi repudiandae consequuntur voluptatum laborum numquam blanditiis harum quisquam eius sed odit fugiat iusto fuga praesentium optio, eaque rerum! Provident
      similique accusantium nemo autem. Veritatis obcaecati tenetur iure eius earum ut molestias architecto voluptate aliquam nihil, eveniet aliquid culpa officia aut! Impedit sit sunt quaerat, odit, tenetur error, harum nesciunt ipsum debitis quas aliquid.
      Reprehenderit,
    </p>
  </div>
</header>

Define a width on your p.

header {
  height: 600px;
  background-image: url('https://images.unsplash.com/photo-1519197924294-4ba991a11128?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8d2Fyc2F3fGVufDB8fDB8fA%3D%3D&w=1000&q=80');
}

.circle {
  background: red;
  height: 100%;
  clip-path: circle(39.3% at 23% 14%);
  shape-outside: circle(39.3% at 23% 14%);
  position: relative;
}

.circle > p {
  width: 50%;
}
<header>
  <div class="circle">
    <p>
      Lorem ipsum dolor sit amet consectetur adipisicing elit. Maxime mollitia, molestiae quas vel sint commodi repudiandae consequuntur voluptatum laborum numquam blanditiis harum quisquam eius sed odit fugiat iusto fuga praesentium optio, eaque rerum! Provident
      similique accusantium nemo autem. Veritatis obcaecati tenetur iure eius earum ut molestias architecto voluptate aliquam nihil, eveniet aliquid culpa officia aut! Impedit sit sunt quaerat, odit, tenetur error, harum nesciunt ipsum debitis quas aliquid.
      Reprehenderit,
    </p>
  </div>
</header>

将文本保存在剪贴路径中

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

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