送你一个梦

文章 评论 浏览 29

送你一个梦 2025-02-20 22:23:14

实际上,有一个软件包: apicheck 。它比打印新闻要慢,但可能更健壮和测试(并且具有更多功能):

library(apicheck) # hughjonesd/apicheck

when_fun_exists("base::list2DF", report = "brief")
#> [1] "4.0.0"

在2022-07-26上创建的 reprex软件包(v2.0.1)

Actually, there's a package for that: apicheck. It's slower than printing the news, but probably more robust and tested (and it has much more functionalities as well):

library(apicheck) # hughjonesd/apicheck

when_fun_exists("base::list2DF", report = "brief")
#> [1] "4.0.0"

Created on 2022-07-26 by the reprex package (v2.0.1)

是否有一个函数可以知道何时发布函数?

送你一个梦 2025-02-20 22:15:36

如果您想使用 mutablStateFlow 方法,另一个选项也是覆盖 onPagestarted ,并做类似的事情,

class CustomWebViewClient(): WebViewClient() {
    private val _onPageFinished = MutableStateFlow(false)
    val onPageFinished = _onPageFinished.asStateFlow()
    override fun onPageStarted(
        view: WebView?,
        url: String?,
        favicon: Bitmap?,
    ) {
        _onPageFinished.update { false }
    }

    override fun onPageFinished(view: WebView?, url: String?) {
        _onPageFinished.update { true }
    }
}

class MainViewModel : ViewModel() {
    init {
        val client = CustomWebViewClient()
        viewModelScope.launch {
            client.onPageFinished.collect {
                if (it) {
                    // Do stuff when page is loaded
                } else {
                    // Do stuff when page starts loading
                }
            }
        }
    }
}

尽管最终使用FOLLOWS为此是有点过分的夸张,并且使用lambda方法Mieszko Koinma建议的可能更为直接。

If you want to use the MutablStateFlow approach, another option is to also override onPageStarted as well and do something like

class CustomWebViewClient(): WebViewClient() {
    private val _onPageFinished = MutableStateFlow(false)
    val onPageFinished = _onPageFinished.asStateFlow()
    override fun onPageStarted(
        view: WebView?,
        url: String?,
        favicon: Bitmap?,
    ) {
        _onPageFinished.update { false }
    }

    override fun onPageFinished(view: WebView?, url: String?) {
        _onPageFinished.update { true }
    }
}

class MainViewModel : ViewModel() {
    init {
        val client = CustomWebViewClient()
        viewModelScope.launch {
            client.onPageFinished.collect {
                if (it) {
                    // Do stuff when page is loaded
                } else {
                    // Do stuff when page starts loading
                }
            }
        }
    }
}

Though ultimately using flows for this is kinda overkill and using the lambda approach suggested by Mieszko Koźma is probably more straight forward.

如何以最短的方式创建自定义事件?

送你一个梦 2025-02-20 14:16:30

Linux系统上的clang不会发生您描述的行为,但是可以在 Godbolt编译器资源管理器

它看起来像 size_t 是该编译器的内置类型。

编译器接受此内置即可重新定义

typedef unsigned long long size_t;

只要定义是其他任何东西, 。如 jonathan leffler ,C11和后来允许您定义 typedef 以上的时间(而不是用于变量修饰的类型),则可以定义A typedef ) 。

The behavior you describe does not happen with clang on linux systems, but it does with the x64 version of MSVC as can be verified on the Godbolt compiler explorer.

It looks like size_t is a built-in type for this compiler.

The compiler accepts this built-in to be redefined as long as the definition is

typedef unsigned long long size_t;

Anything else causes an error. As commented by Jonathan Leffler, C11 and later allows you to define a typedef more than once as long as the definitions are the same (and not for a variably-modified type).

为什么我可以在不定义的情况下使用size_t?

送你一个梦 2025-02-20 06:51:10
  1. 您永远不会运行创建的函数,
  2. 应将条件反转
  3. 文件 + 2629800000将返回字符串,但如果是数字
const testFolder = './whitelisted/';
const fs = require('fs').promises; // fixed lib import

fs.readdirSync(testFolder).forEach(file => {
  console.log(file);
  // converted file to number, changed >= to <=
  if (+file + 2629800000 <= Date.now()) {
    const deleteFile = async (filePath) => {
        try {
          await fsPromises.unlink(filePath);
          console.log('Successfully removed file!');
        } catch (err) {
          console.log(err);
        }
      };
    deleteFile(file) // runned function
  }
});
  1. You never run the function you created
  2. The condition should be reversed
  3. file + 2629800000 will return a string, but should a number
const testFolder = './whitelisted/';
const fs = require('fs').promises; // fixed lib import

fs.readdirSync(testFolder).forEach(file => {
  console.log(file);
  // converted file to number, changed >= to <=
  if (+file + 2629800000 <= Date.now()) {
    const deleteFile = async (filePath) => {
        try {
          await fsPromises.unlink(filePath);
          console.log('Successfully removed file!');
        } catch (err) {
          console.log(err);
        }
      };
    deleteFile(file) // runned function
  }
});

如果文件大于30天,则删除时间盖章的文件

送你一个梦 2025-02-20 05:02:15

您需要用自我对象引用文件名。同样,ClassName只能访问类成员,因此Self.FileName无法使用。

class MYDATA:
    def __init__(self,filename):
        self.filename = filename
        
        # get the main axis of the file.
        self.values = self.get_values_from_file()
      
    def get_values_from_file(self):
        values = []
        with open(self.filename, 'r') as file:
            for line in file:
                pos = list(map(float, line.split(',')))
                values.append(pos)
        return values

mydataobj = MYDATA(r'my_data_file.csv')
print(mydataobj .get_values_from_file())

You need to refer filename with self object. Also classname can only access class members, so self.filename wouldn't have worked.

class MYDATA:
    def __init__(self,filename):
        self.filename = filename
        
        # get the main axis of the file.
        self.values = self.get_values_from_file()
      
    def get_values_from_file(self):
        values = []
        with open(self.filename, 'r') as file:
            for line in file:
                pos = list(map(float, line.split(',')))
                values.append(pos)
        return values

mydataobj = MYDATA(r'my_data_file.csv')
print(mydataobj .get_values_from_file())

python从文件中读取数据到类

送你一个梦 2025-02-20 03:33:08

之所以发生这种情况,是因为您已经在数据库中拥有一些模型的数据,因此您需要首先删除数据。

您可以简单地从Django Shell中删除表中的所有对象:

转到命令提示符,

1. python manage.py shell
2. from main.models import Name
3. Name.objects.all().delete()
(main being the app name here)

此对象将删除教程表中的所有对象,然后进行makemigrations和magrate迁移,并且可以正常工作。

或者,如果它仍然不起作用,则可以尝试以下方法:

1. delete the migrations file (folder) of the app and makemigrations and migrate again.
2. change the database of your project (but you can loss all of the site data by this.)

This is happening because you already have some data of the model in the database so you need to delete the data first.

You can simply delete all the objects in the table from django shell:

go to command prompt

1. python manage.py shell
2. from main.models import Name
3. Name.objects.all().delete()
(main being the app name here)

This will delete all the objects in the Tutorial table and then makemigrations and migrate and it should work just fine.

or if it still don't work you can try these approaches:

1. delete the migrations file (folder) of the app and makemigrations and migrate again.
2. change the database of your project (but you can loss all of the site data by this.)

我设置了null = true and black = true,但仍然获取“ django.db.utils.integrityerror :( 1048,columt; massenger_name; null; smassenger_name;

送你一个梦 2025-02-19 11:57:02

自从被接受的答案以来,男高音已更改了网站,使代码不返回任何结果。因此, get_gif_url 函数现在看起来像这样:

import requests
import re
import json

def get_gif_url(view_url):
    # Get the gif data from the embed page
    embed_url = re.sub(r'/view/[^/?]+-(\d+)', r'/embed/\1', view_url)
    page_content = requests.get(embed_url).text
    gif_info = re.search(r'<script id="gif-json"[^>]+>(.+?)</script>', page_content)
    if not gif_info:
        return None
    
    # Parse the JSON data
    gif_info = json.loads(gif_info.group(1))
    return gif_info['media_formats']['gif']['url']

Tenor has changed their site since the accepted answer, making the code not return any results. Because of this reason, the get_gif_url function would now look like this:

import requests
import re
import json

def get_gif_url(view_url):
    # Get the gif data from the embed page
    embed_url = re.sub(r'/view/[^/?]+-(\d+)', r'/embed/\1', view_url)
    page_content = requests.get(embed_url).text
    gif_info = re.search(r'<script id="gif-json"[^>]+>(.+?)</script>', page_content)
    if not gif_info:
        return None
    
    # Parse the JSON data
    gif_info = json.loads(gif_info.group(1))
    return gif_info['media_formats']['gif']['url']

带有discord.py的男高音链接

送你一个梦 2025-02-19 10:06:10

在Oracle 19中,您可以使用 JSON_MERGEPATCH

UPDATE jsontable j
SET   jsoncol = JSON_MERGEPATCH(
                  jsoncol,
                  (
                    SELECT JSON_OBJECT(
                             KEY 'Company'
                             VALUE JSON_ARRAYAGG(
                                     CASE id
                                     WHEN 999
                                     THEN JSON_MERGEPATCH(
                                            json,
                                            '{"Name":"DEF"}'
                                          )
                                     ELSE json
                                     END
                                     FORMAT JSON
                                     RETURNING CLOB
                                   )
                             FORMAT JSON
                             RETURNING CLOB
                             )
                    FROM   jsontable jt
                           CROSS APPLY JSON_TABLE(
                             jt.jsoncol,
                             '$.Company[*]'
                             COLUMNS(
                               json VARCHAR2(4000) FORMAT JSON PATH '

对于示例数据:

CREATE TABLE jsontable (
  jsoncol CLOB CHECK (jsoncol IS JSON)
);

INSERT INTO jsontable (jsoncol)
VALUES ('{
  "Company": [
    {
      "Info": {
        "Address": "123"
      },
      "Name": "ABC",
      "Id": 999
    },
    {
      "Info": {
        "Address": "456"
      },
      "Name": "XYZ",
      "Id": 888
    }
  ]
}');

然后,在更新之后,该表包含:

jsoncol
{“ company”:[{“ info”:{“ address”:“ 123”},“ name”:“ def”:“ def”,“ id”:999},{ “ info”:{“ address”:“ 456”},“名称”:“ xyz”,“ id”:888}]}

db&lt;&gt; fiddle 在这里

, id NUMBER PATH '$.Id' ) ) WHERE jt.ROWID = j.ROWID ) )

对于示例数据:


然后,在更新之后,该表包含:

jsoncol
{“ company”:[{“ info”:{“ address”:“ 123”},“ name”:“ def”:“ def”,“ id”:999},{ “ info”:{“ address”:“ 456”},“名称”:“ xyz”,“ id”:888}]}

db&lt;&gt; fiddle 在这里

From Oracle 19, you can use JSON_MERGEPATCH:

UPDATE jsontable j
SET   jsoncol = JSON_MERGEPATCH(
                  jsoncol,
                  (
                    SELECT JSON_OBJECT(
                             KEY 'Company'
                             VALUE JSON_ARRAYAGG(
                                     CASE id
                                     WHEN 999
                                     THEN JSON_MERGEPATCH(
                                            json,
                                            '{"Name":"DEF"}'
                                          )
                                     ELSE json
                                     END
                                     FORMAT JSON
                                     RETURNING CLOB
                                   )
                             FORMAT JSON
                             RETURNING CLOB
                             )
                    FROM   jsontable jt
                           CROSS APPLY JSON_TABLE(
                             jt.jsoncol,
                             '$.Company[*]'
                             COLUMNS(
                               json VARCHAR2(4000) FORMAT JSON PATH '

Which, for the sample data:

CREATE TABLE jsontable (
  jsoncol CLOB CHECK (jsoncol IS JSON)
);

INSERT INTO jsontable (jsoncol)
VALUES ('{
  "Company": [
    {
      "Info": {
        "Address": "123"
      },
      "Name": "ABC",
      "Id": 999
    },
    {
      "Info": {
        "Address": "456"
      },
      "Name": "XYZ",
      "Id": 888
    }
  ]
}');

Then after the UPDATE, the table contains:

JSONCOL
{"Company":[{"Info":{"Address":"123"},"Name":"DEF","Id":999},{"Info":{"Address":"456"},"Name":"XYZ","Id":888}]}

db<>fiddle here

, id NUMBER PATH '$.Id' ) ) WHERE jt.ROWID = j.ROWID ) )

Which, for the sample data:


Then after the UPDATE, the table contains:

JSONCOL
{"Company":[{"Info":{"Address":"123"},"Name":"DEF","Id":999},{"Info":{"Address":"456"},"Name":"XYZ","Id":888}]}

db<>fiddle here

在Oracle SQL中更新JSON数据

送你一个梦 2025-02-18 23:57:44

要打印client_id,您可以在会话中存储该“ ID”,然后以这种方式从会话中打印您的搜索值保留​​保留并在所有视图中获取数据概念视图::您可以在AppServiceProvider中注册,请浏览此信息链接

https://laravel.com/laravel.com/docs/docs/9 .x/views#sharing-data-with-all-views

To print client_id you can store that "id" in session and print from the session by this way your search value keep remains and to get data in all views there is the concept View::share you can register that in AppServiceProvider please go through this link

https://laravel.com/docs/9.x/views#sharing-data-with-all-views

Laravel 9-从一个控制器传递每个视图的数据

送你一个梦 2025-02-18 20:02:47

我的简短建议:

obervable1.pipe(
  switchMap(obs1-result => forkJoin(of(obs1-result), observable2)),
  map([obs1-result, obs2-result] => isEditing ? obs1-result : obs2-result
).subscribe();

请在此处查看示例:工作示例

My brief suggestion:

obervable1.pipe(
  switchMap(obs1-result => forkJoin(of(obs1-result), observable2)),
  map([obs1-result, obs2-result] => isEditing ? obs1-result : obs2-result
).subscribe();

Please have a look at the example here: working example

如何有条件执行可观察的? (取决于班级中的可变状态)

送你一个梦 2025-02-18 12:49:32

Spark在连接方面取得了许多进步。

其中之一是:

当任何联接方的运行时统计信息都小于广播哈希(Hash Join Join)阈值时,AQE转换式 - 合并连接到广播哈希。这并不像计划广播哈希(Hash)首先加入那样有效,但是比继续进行排序连接要好,因为我们可以保存两个加入侧面的排序,并在本地读取Shuffle Files以节省网络流量(如果spark.sql.Adaptive.localshufflereader.enabled为true)

https://spark.apache.org/docs/3.1.1/sql-performance-tuning.html#converting-converting-converting-sort-merge-join-join-join-join-to-broadcast-join

Spark has made many improvements around joins.

One of them is :

AQE converts sort-merge join to broadcast hash join when the runtime statistics of any join side is smaller than the broadcast hash join threshold. This is not as efficient as planning a broadcast hash join in the first place, but it’s better than keep doing the sort-merge join, as we can save the sorting of both the join sides, and read shuffle files locally to save network traffic(if spark.sql.adaptive.localShuffleReader.enabled is true)

https://spark.apache.org/docs/3.1.1/sql-performance-tuning.html#converting-sort-merge-join-to-broadcast-join

从Spark 2.4.0到Spark 3.1.1迁移导致SortMergeJoin更改为BroadcasthashJoin

送你一个梦 2025-02-18 08:24:31

初始化Spring Boot Project Intellij Idey时,它要求选择依赖关系

while initialize the spring boot project IntelliJ idea it is asking to select the dependency

初始化Spring Boot Project Intellij Idey时,它要求选择依赖关系

送你一个梦 2025-02-18 05:22:34

受Bittickler关于如何使其适用于非“容器”类型的评论的启发,这是适用于 double s的最小示例:

class dranged {
    double start, stop, step, cur;
    int index;

public:
    dranged(double start, double stop, double step) :
        start(start), stop(stop), step(step),
        cur(start), index(0) {}

    auto begin() { return *this; }
    auto end() { return *this; }

    double operator*() const { return cur; }

    auto& operator++() {
        index += 1;
        cur = start + step * index;
        return *this;
    }

    bool operator!=(const dranged &rhs) const {
        return cur < rhs.stop;
    }
};

请注意,请注意使用&lt; 在!= 中,操作员维护正确的不变性,但是显然假设 spep 是正面的,并且在任何地方都不适合更一般的范围。我已经使用了整数索引来防止浮点错误的传播,但否则旨在简单。

这可以用作:

double sum() {
    double accum = 0;
    for (auto val : dranged(0, 6.28, 0.1)) {
        accum += val;
    }
    return accum;
}

GCC和Clang产生非常合理的代码使用优化时(即 -os 或以上 -O1 for GCC或 -O2 for clang)。

Inspired by BitTickler's comment about how to make it work for non-"container" types, here's a minimal example of something that works for doubles:

class dranged {
    double start, stop, step, cur;
    int index;

public:
    dranged(double start, double stop, double step) :
        start(start), stop(stop), step(step),
        cur(start), index(0) {}

    auto begin() { return *this; }
    auto end() { return *this; }

    double operator*() const { return cur; }

    auto& operator++() {
        index += 1;
        cur = start + step * index;
        return *this;
    }

    bool operator!=(const dranged &rhs) const {
        return cur < rhs.stop;
    }
};

Note that the use of < in the != operator maintains the correct invariant, but obviously assumes step is positive and wouldn't be appropriate everywhere a more general range would be. I've used an integer index to prevent propagation of floating point error, but have aimed for simplicity otherwise.

This can be used as:

double sum() {
    double accum = 0;
    for (auto val : dranged(0, 6.28, 0.1)) {
        accum += val;
    }
    return accum;
}

GCC and Clang both produce very reasonable code when compiled with optimisations (i.e. either -Os or above -O1 for GCC or -O2 for Clang).

如何使我的自定义类型与“基于范围的循环”一起使用。

送你一个梦 2025-02-17 09:11:38

这是一个权限问题,如果您使用Linux/Mac,您只需在命令之前将sudo作为前缀写

It's a permission issue, you can just write sudo as a prefix before your command if you are using linux/Mac

节点:事件:505投掷ER; //未经治疗&#x27;错误&#x27;事件错误:听EACCES:允许拒绝4000;

送你一个梦 2025-02-17 08:54:59

@simbathesailor/simbathesailor/lives-what-what-what-what-what-c​​ode 就像魅力一样的工作呢

  1. 使用 npm / YARN - dev - no-save

  2. 添加导入:< /p>

      import {usewhatchanged}来自'@simbathesailor/use-use-what-whanged';
     
  3. 调用:

      //(保证使用效率DEP与使用whatchanged同步)
    令deps = [a,b,c,d]
    
    使用(deps,'a,b,c,d');
    useeffect(()=&gt; {
      //您的效果
    },deps);
     

在控制台中创建此漂亮的图表:

image loaded from github

有两个常见的罪魁祸首:

  1. 某些对象像这样传递:
// Being used like:
export function App() {
  return <MyComponent fetchOptions={{
    urlThing: '/foo',
    headerThing: 'FOO-BAR'
  })
}
export const MyComponent = ({fetchOptions}) => {
  const [someData, setSomeData] = useState()
  useEffect(() => {
    window.fetch(fetchOptions).then((data) => {
      setSomeData(data)
    })

  }, [fetchOptions])

  return <div>hello {someData.firstName}</div>
}

在对象情况下的修复,如果可以的话,请在组件渲染之外划分一个静态对象:

const fetchSomeDataOptions = {
  urlThing: '/foo',
  headerThing: 'FOO-BAR'
}
export function App() {
  return <MyComponent fetchOptions={fetchSomeDataOptions} />
}

您也可以包裹在usememo中:

export function App() {
  return <MyComponent fetchOptions={
    useMemo(
      () => {
        return {
          urlThing: '/foo',
          headerThing: 'FOO-BAR',
          variableThing: hash(someTimestamp)
        }
      },
      [hash, someTimestamp]
    )
  } />
}

同样的概念在一定程度上适用于功能,除非您最终可以闭合。

@simbathesailor/use-what-changed works like a charm!

  1. Install with npm/yarn and --dev or --no-save

  2. Add import:

    import { useWhatChanged } from '@simbathesailor/use-what-changed';
    
  3. Call it:

    // (guarantee useEffect deps are in sync with useWhatChanged)
    let deps = [a, b, c, d]
    
    useWhatChanged(deps, 'a, b, c, d');
    useEffect(() => {
      // your effect
    }, deps);
    

Creates this nice chart in the console:

image loaded from github

There are two common culprits:

  1. Some Object being pass in like this:
// Being used like:
export function App() {
  return <MyComponent fetchOptions={{
    urlThing: '/foo',
    headerThing: 'FOO-BAR'
  })
}
export const MyComponent = ({fetchOptions}) => {
  const [someData, setSomeData] = useState()
  useEffect(() => {
    window.fetch(fetchOptions).then((data) => {
      setSomeData(data)
    })

  }, [fetchOptions])

  return <div>hello {someData.firstName}</div>
}

The fix in the object case, if you can, break-out a static object outside the component render:

const fetchSomeDataOptions = {
  urlThing: '/foo',
  headerThing: 'FOO-BAR'
}
export function App() {
  return <MyComponent fetchOptions={fetchSomeDataOptions} />
}

You can also wrap in useMemo:

export function App() {
  return <MyComponent fetchOptions={
    useMemo(
      () => {
        return {
          urlThing: '/foo',
          headerThing: 'FOO-BAR',
          variableThing: hash(someTimestamp)
        }
      },
      [hash, someTimestamp]
    )
  } />
}

The same concept applies to functions to an extent, except you can end up with stale closures.

确定哪种依赖性阵列变量导致使用效果挂钩发射

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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