故人如初

文章 评论 浏览 28

故人如初 2025-02-20 20:03:07

问题在于参数的范围延伸超出条件范围,因此捕获其在顶级创建的闭合。

例如,简化您的原始代码,例如:

public static void Usage(string area, string operation, Dictionary<string, string> parameters)
{
    Func<Dictionary<string, string>> function = null;

    if (parameters != null)
    {
        function = new Func<Dictionary<string, string>>(() =>
        {
            return parameters;
        });
    }
}

... C#1.0等效看起来像这样:

   <>c__DisplayClass5_0 <>c__DisplayClass5_ = new <>c__DisplayClass5_0 ();
   <>c__DisplayClass5_.parameters = parameters;
   Func<Dictionary<string, string>> function = null;
   if (<>c__DisplayClass5_.parameters != null)
   {
        function = new Func<Dictionary<string, string>> (<>c__DisplayClass5_.<Usage>b__0);
   }

您可以看到创建闭合并设置其属性,以便在功能中任何地方需要的情况下可以使用它。为了避免在未满足条件时发生这种情况,请在条件下在本地创建一个单独的变量范围。

public static void Usage(string area, string operation, Dictionary<string, string> parameters)
{
    Func<Dictionary<string, string>> function = null;

    if (parameters != null)
    {
        var capturable = parameters;
        function = new Func<Dictionary<string, string>>(() =>
        {
            return capturable;
        });
    }
}

这将您的C#1.0等效代码更改为:

   Func<Dictionary<string, string>> function = null;
   if (parameters != null)
   {
        <>c__DisplayClass5_0 <>c__DisplayClass5_ = new <>c__DisplayClass5_0 ();
        <>c__DisplayClass5_.capturable = parameters;
        function = new Func<Dictionary<string, string>> (<>c__DisplayClass5_.<Usage>b__0);
   }

The problem is that the scope of parameters extends beyond the scope of your conditional, so the closure that captures it is created at the top level.

Simplifying your original code to this, for example:

public static void Usage(string area, string operation, Dictionary<string, string> parameters)
{
    Func<Dictionary<string, string>> function = null;

    if (parameters != null)
    {
        function = new Func<Dictionary<string, string>>(() =>
        {
            return parameters;
        });
    }
}

... the C# 1.0 equivalent looks like this:

   <>c__DisplayClass5_0 <>c__DisplayClass5_ = new <>c__DisplayClass5_0 ();
   <>c__DisplayClass5_.parameters = parameters;
   Func<Dictionary<string, string>> function = null;
   if (<>c__DisplayClass5_.parameters != null)
   {
        function = new Func<Dictionary<string, string>> (<>c__DisplayClass5_.<Usage>b__0);
   }

You can see that the closure is created, and its property is set, so that it can be used if needed anywhere in the function. To avoid this happening when your condition is not met, create a separate variable scoped locally to your if condition.

public static void Usage(string area, string operation, Dictionary<string, string> parameters)
{
    Func<Dictionary<string, string>> function = null;

    if (parameters != null)
    {
        var capturable = parameters;
        function = new Func<Dictionary<string, string>>(() =>
        {
            return capturable;
        });
    }
}

That changes your C# 1.0-equivalent code to:

   Func<Dictionary<string, string>> function = null;
   if (parameters != null)
   {
        <>c__DisplayClass5_0 <>c__DisplayClass5_ = new <>c__DisplayClass5_0 ();
        <>c__DisplayClass5_.capturable = parameters;
        function = new Func<Dictionary<string, string>> (<>c__DisplayClass5_.<Usage>b__0);
   }

即使此func&lt;&gt;变量是空的吗?

故人如初 2025-02-20 13:42:37

如果您想在同一张表上加入两次,这可能会有所帮助

SELECT a.QUANTITY, a.START, a.[END], isnull(b.serial,c.serial) serial,isnull(c1.name,c2.name) color, isnull(m.name,n.name) material
FROM reserved_coils a 
LEFT JOIN coils b ON a.number = b.serial
LEFT JOIN coils_in_transport c ON a.number = c.serial
LEFT JOIN material m ON b.material = m.id
LEFT JOIN material n ON c.material = n.id
LEFT JOIN color c1 on b.color=c1.id
LEFT JOIN color c2 on c.color=c2.id
where isnull(b.status,c.status) = 2

If you want left join twice on same table, this might help

SELECT a.QUANTITY, a.START, a.[END], isnull(b.serial,c.serial) serial,isnull(c1.name,c2.name) color, isnull(m.name,n.name) material
FROM reserved_coils a 
LEFT JOIN coils b ON a.number = b.serial
LEFT JOIN coils_in_transport c ON a.number = c.serial
LEFT JOIN material m ON b.material = m.id
LEFT JOIN material n ON c.material = n.id
LEFT JOIN color c1 on b.color=c1.id
LEFT JOIN color c2 on c.color=c2.id
where isnull(b.status,c.status) = 2

DB<>Fiddle

SQL查询不返回预期值

故人如初 2025-02-20 00:47:06

我们通过Kadena团队通过方向尝试的第三件事是我们尚未提供权限的功能:fold db。

(let*(qry(lambda(k obj)true));;
(f(lambda(x)[(在'firstName x),(在'bx)])))(fold-db people(qry)(f)))

这实际上是最正确的答案最初的扫描,对于新用户而言,将几乎无法理解,而没有协议经验。

我们建议一个简单的句子 - &gt;

“对于多种条件,请使用fold-db函数。”

在文档中。

这欺骗了我们,因为我们习惯于使用SQL语法,以至于我们没有想象像这样的功能不错,我们陷入了试图找出条件逻辑的方式。

The third thing we tried via direction from the Kadena team was a function we had yet to purview: Fold DB.

(let* ((qry (lambda (k obj) true)) ;;
(f (lambda(x) [(at 'firstName x), (at 'b x)])) ) (fold-db people (qry) (f)) )

This actually is the most correct answer but it was not obvious from the initial scan and would be near inscrutable for a new user to put together with no pact experience.

We suggest a simple sentence ->

"For multiple conditions use fold-db function."

In the documentation.

This fooled us because we are so used to using SQL syntax that we didn't imagine that there was a nice function like this lying around and we got stuck in our ways trying to figure out conditional logic.

如何使用PACT智能合约语言中的多个子句选择一行

故人如初 2025-02-19 23:36:29
 public class Master
 {
   public List<Table1> T1 { get; set; }
   public List<Table2> T2 { get; set; }
 }
 
public class Table1
{
  public string sample1 { get; set; }
  public string sample2 { get; set; }
}

public class Table2
{
  public string sample1 { get; set; }
  public string sample2 { get; set; }
}

        <--Controller-->
        Master master  = new Master();
        var getSamples = _db.dbSamples.Where(y => y.sample == "sample1");
        var table1List = new List<Table1>();
        var table2List = new List<Table2>();
        var masterData= new Master();
            foreach (var item in getSamples)
              {
                var data = new Table1();
                data.A = item.A;
                data.B = item.B;
                table1List.add(data);
              }
        master.T1 = table1List;
        var getSamples1 = _db.dbSamples.Where(y => y.sample == "sample2");
           foreach (var item in getSamples1)
              {
                var data2 = new Table2();
                data2.A = item.A;
                data2.B = item.B;
                table2List.add(data2);
              }
        master.T2 = table2List;
        return View(master);

我认为您要做的就是这样。如果不是这样,请详细说明这个问题。

更新的代码。相应地更改变量名称。

 public class Master
 {
   public List<Table1> T1 { get; set; }
   public List<Table2> T2 { get; set; }
 }
 
public class Table1
{
  public string sample1 { get; set; }
  public string sample2 { get; set; }
}

public class Table2
{
  public string sample1 { get; set; }
  public string sample2 { get; set; }
}

        <--Controller-->
        Master master  = new Master();
        var getSamples = _db.dbSamples.Where(y => y.sample == "sample1");
        var table1List = new List<Table1>();
        var table2List = new List<Table2>();
        var masterData= new Master();
            foreach (var item in getSamples)
              {
                var data = new Table1();
                data.A = item.A;
                data.B = item.B;
                table1List.add(data);
              }
        master.T1 = table1List;
        var getSamples1 = _db.dbSamples.Where(y => y.sample == "sample2");
           foreach (var item in getSamples1)
              {
                var data2 = new Table2();
                data2.A = item.A;
                data2.B = item.B;
                table2List.add(data2);
              }
        master.T2 = table2List;
        return View(master);

I assume that what you are trying to do is this. If it is not, please elaborate on the question.

Updated code. Change variable names accordingly.

如何将值从多个列表传递给ViewModel

故人如初 2025-02-18 16:29:54

已经有很多解释来解释它是如何发生以及如何修复它的,但是您也应该遵循最佳实践避免 nullpointerexpiption

参见:
最佳实践

我会补充一点,非常重要,可以很好地利用 final 修饰符。
使用“最终”

修饰符:

  1. 使用 final 修饰符来执行良好的初始化。
  2. 避免在方法中返回null,例如适用时返回空收集。
  3. 使用注释 @Nullable
  4. 快速失败,并使用断言在整个应用程序不应为null时避免通过整个应用程序传播Null对象。
  5. 首先使用已知对象的平等: if(“ nownobject” .equals(unknownobject)
  6. peave valueof()而不是 toString()
  7. 使用null SAFE 方法 stringutils.isempty(null)
  8. 使用Java 8可选作为方法中的返回值,可选类为表示可选值而不是null引用提供了解决方案。

A lot of explanations are already present to explain how it happens and how to fix it, but you should also follow best practices to avoid NullPointerExceptions at all.

See also:
A good list of best practices

I would add, very important, make a good use of the final modifier.
Using the "final" modifier whenever applicable in Java

Summary:

  1. Use the final modifier to enforce good initialization.
  2. Avoid returning null in methods, for example returning empty collections when applicable.
  3. Use annotations @NotNull and @Nullable
  4. Fail fast and use asserts to avoid propagation of null objects through the whole application when they shouldn't be null.
  5. Use equals with a known object first: if("knownObject".equals(unknownObject)
  6. Prefer valueOf() over toString().
  7. Use null safe StringUtils methods StringUtils.isEmpty(null).
  8. Use Java 8 Optional as return value in methods, Optional class provide a solution for representing optional values instead of null references.

什么是NullPoInterException,我该如何修复?

故人如初 2025-02-18 12:41:05

在Linux中,访问音频设备都是通过文件系统完成的。因此,如果将必要的文件(/dev/audio?)安装到容器中,并授予合适的特权,那么您应该很好。

In Linux accessing the audio devices is all done via the filesystem. So if you mount the necessary files (/dev/audio?) into the container and give suitable privileges you should be good to go.

容器化的JAR(Java)如何访问默认系统混音器?

故人如初 2025-02-18 09:33:23

您可以组合两个 seq

c(seq(min(variable), 0, length.out=3), 
  seq(0, max(variable), length.out=3)[-1])
#[1] -73.0 -36.5   0.0  58.0 116.0

这仅在 min(variable)&lt; = 0 max(variable)&gt; = 0 时,才能按预期工作。

You can combine two seq.

c(seq(min(variable), 0, length.out=3), 
  seq(0, max(variable), length.out=3)[-1])
#[1] -73.0 -36.5   0.0  58.0 116.0

This will only work as expected when min(variable) <= 0 and max(variable) >= 0.

如何以零作为中点创建一个从min到最大的数字序列?

故人如初 2025-02-17 16:00:19

更新,

因为您需要以相同的方式对待每个“行” ,您可以通过在每个递归呼叫中移动矩阵中的位置来递归地添加每个嵌套数组的总数:

public static int arrSum(int[] arr, int pos) {
    if (pos == arr.length) { // base case
        return 0;
    }
    
    return arr[pos] + arrSum(arr, pos + 1); // recursive case
}

您的条件逻辑可以是像这样刷新:

public static int arrSum(int[] arr, int pos) {

    if (pos == arr.length) { // base case
        return 0;
    }
    
    if (pos == 0) {
        return 10 * arr[pos] + arrSum(arr, pos + 1);
    }
    if (pos == 1) {
        return 50 * arr[pos] + arrSum(arr, pos + 1);
    }
    if (pos == 2) {
        return 22 * arr[pos] + arrSum(arr, pos + 1);
    }
    if (pos == 3) {
        return 7 * arr[pos] + arrSum(arr, pos + 1);
    }
    if (pos == 4) {
        return 45 * arr[pos] + arrSum(arr, pos + 1);
    }
    
    return arr[pos] + arrSum(arr, pos + 1);
}

的问题的初始版本有关

此部分与您不需要为 n 的每个硬编码值重复冗余条件逻辑

。而且,不需要将数组的每个元素乘以 10 ,我们也可以乘以 10 总和。

这就是计算数组总和的递归方法的方式:

public static int arrSum(int[] arr, int pos) {
    if (pos == arr.length) { // base case
        return 0;
    }
    
    return arr[pos] + arrSum(arr, pos + 1); // recursive case
}

您可以如何计算嵌套数组元素的总和(逻辑几乎相同):

public static int matrixSum(int[][] matrix, int pos) {
    if (pos == matrix.length) { // base case
        return 0;
    }
    
    return arrSum(matrix[pos], 0) + matrixSum(matrix, pos + 1); // recursive case
}

main()

public static void main(String[] args) {
    int[][] matrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
    System.out.println(matrixSum(matrix, 0) * 10);
}

输出:

450 // sum of numbers from 1 to 9 equels 45, and * 10 = 450

sidenote:在Java中没有 2d-arrays (因此,此术语不正确)。我们可以创建一个由其他数组组成的数组。

Update

Since you need every "row" to be treated in the same way you can recursively add up the total calculated for every nested array by moving position in the matrix with every recursive call:

public static int arrSum(int[] arr, int pos) {
    if (pos == arr.length) { // base case
        return 0;
    }
    
    return arr[pos] + arrSum(arr, pos + 1); // recursive case
}

Your condition logic can be brushed up like that:

public static int arrSum(int[] arr, int pos) {

    if (pos == arr.length) { // base case
        return 0;
    }
    
    if (pos == 0) {
        return 10 * arr[pos] + arrSum(arr, pos + 1);
    }
    if (pos == 1) {
        return 50 * arr[pos] + arrSum(arr, pos + 1);
    }
    if (pos == 2) {
        return 22 * arr[pos] + arrSum(arr, pos + 1);
    }
    if (pos == 3) {
        return 7 * arr[pos] + arrSum(arr, pos + 1);
    }
    if (pos == 4) {
        return 45 * arr[pos] + arrSum(arr, pos + 1);
    }
    
    return arr[pos] + arrSum(arr, pos + 1);
}

This part is related to the Initial version of the Question

You don't need redundant conditional logic repeated for every hard-coded value of n.

As well as there's no need to multiply each element of the array by 10, instead we can multiply by 10 the overall sum.

That's how your recursive method that calculates the array sum can be fixed:

public static int arrSum(int[] arr, int pos) {
    if (pos == arr.length) { // base case
        return 0;
    }
    
    return arr[pos] + arrSum(arr, pos + 1); // recursive case
}

And that how you can calculate the sum of the elements of a nested array (the logic is almost the same):

public static int matrixSum(int[][] matrix, int pos) {
    if (pos == matrix.length) { // base case
        return 0;
    }
    
    return arrSum(matrix[pos], 0) + matrixSum(matrix, pos + 1); // recursive case
}

main()

public static void main(String[] args) {
    int[][] matrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
    System.out.println(matrixSum(matrix, 0) * 10);
}

Output:

450 // sum of numbers from 1 to 9 equels 45, and * 10 = 450

Sidenote: in Java there's no 2d-arrays (so this term isn't correct accurate). We can create a nested array - an array that is composed of other arrays.

将嵌套数组中的元素乘以某些值,然后将结果添加在一起

故人如初 2025-02-17 03:27:24

要列出搜索结果列表,在服务器上运行的代码必须解析URL并执行搜索。

http://www.w3schools.com 不关注查询字符串。 (它具有搜索表格,但它使用JS进行处理,而不是使用常规表格提交)。

https://duckduckgo.com do 请注意查询字符串,因此

<form method=get action="https://duckduckgo.com/" target="_blank">
  <input type=text name=q value="">
  <input type=submit value="go">
</form>

……可以工作。

您不能让任意的第三方页面注意查询字符串。

To present a list of search results, code running on the server has to parse the URL and perform the search.

http://www.w3schools.com doesn't pay any attention to the query string. (It has a search form, but it processes it with JS and not with a regular form submission).

https://duckduckgo.com does pay attention to the query string, so

<form method=get action="https://duckduckgo.com/" target="_blank">
  <input type=text name=q value="">
  <input type=submit value="go">
</form>

… would work.

You can't make an arbitrary third-party page pay attention to the query string.

HTML搜索表格将查询提交到外部站点,并查看结果

故人如初 2025-02-17 03:09:01

首先,问题不是愚蠢。

其次,对于解决方案,在成功使用电话号码登录后,鉴于该帐户刚刚创建(新用户)后,您现在可以显示表单以获取用户的姓名和其他详细信息。

在此表格的提交时,将名称保存到 updateProfile 的Firebase身份验证用户对象。然后将其他数据保存到使用用户UID作为文档ID的Firestore文档中,最好在用户收集中。

在页面加载上,您可以检查用户是否签名(如果为firm),请检查用户是否在Firestore中有数据(如果为false),请向用户显示上述表单,否则请按照需要继续使用应用程序。

First, the question is not dumb.

Secondly, for a solution, after signing in with phone number successfully, given that the account was just created (a new user), you can now show a form to obtain the user's name and other details.

On submit of this form, save the name to firebase authentication user object with updateProfile. Then save other data to a Firestore document with the user's uid as document id and preferably on the users collection.

On page load, you can check if the user is signed in, if true, check if the user has data in Firestore, if false, show the user the above form, else, continue app usage as you want.

他们的任何功能是否像IngupWitheMailandPassword一样在firebase中签名? (对于网络)我想用他的信誉进行用户注册

故人如初 2025-02-17 02:54:37

您可以创建一个为您完成此工作的函数:

document.getElementById("leg_type2")
  .addEventListener("click", function () { toggle(2); });

document.getElementById("leg_type3")
  .addEventListener("click", function () { toggle(3); });

function toggle(index) {
  const { children } = Group1;

  for (let i = 0; i < children.length; i++) {
    if (i !== index) {
      children[i].visible = false;
      children[i].scale.set(0,0,0);
    }
  }

  children[index].visible = true;
  children[index].scale.set(1, 1, 1);
}

You can create a function that does this work for you:

document.getElementById("leg_type2")
  .addEventListener("click", function () { toggle(2); });

document.getElementById("leg_type3")
  .addEventListener("click", function () { toggle(3); });

function toggle(index) {
  const { children } = Group1;

  for (let i = 0; i < children.length; i++) {
    if (i !== index) {
      children[i].visible = false;
      children[i].scale.set(0,0,0);
    }
  }

  children[index].visible = true;
  children[index].scale.set(1, 1, 1);
}

关于button.addeventlistener

故人如初 2025-02-16 20:47:42

欢迎来到社区。

是的,您可以保存训练有素的模型并稍后再用。有几种方法可以这样做,我将在这里向您介绍其中几个。但是,请注意您用来构建模型并使用该库的方法的库。

  1. pickel:泡菜是python中序列化对象的标准方式。

    导入泡菜

    pickle.dump(型号,open(fileName,'wb'))

    loaded_model = pickle.load(open(fileName,'rb'))

  2. joblib:joblib是Scipy生态系统的一部分,并提供用于管道python作业的实用程序。

    导入Joblib

    joblib.dump(模型,文件名)

    loaded_model = joblib.load(filename)

  3. 最后,如他人所建议的您使用诸如TensorFlow之类的库来构建和训练模型,请注意,它们具有广泛的方法来使用构建模型并保存/加载它。请检查以下信息:

tensorflow保存和加载模型

Welcome to the community.

Yes, you may save the trained model and reuse it later. There are several ways to do so and I will introduce you to a couple of them here. However, please note which library you used to build your model and use a method for that library.

  1. Pickel: Pickle is the standard way of serializing objects in Python.

    import pickle

    pickle.dump(model, open(filename, 'wb'))

    loaded_model = pickle.load(open(filename, 'rb'))

  2. Joblib: Joblib is part of the SciPy ecosystem and provides utilities for pipelining Python jobs.

    import joblib

    joblib.dump(model, filename)

    loaded_model = joblib.load(filename)

  3. Finally, as suggested by others, if you used libraries such as Tensorflow to build and train your models, please note that they have extensive ways to work with the built model and save/load it. Please check the following information:

Tensorflow Save and Load model

保存和重用ML模型

故人如初 2025-02-16 19:48:25

首先,您不必使用Fluid ViewHelper来创建页脚。只需在邮政和一些字段中使用HTML形式即可。表格的作用应包含PowerMail表单的URL。如果字段使用正确的名称,则PowerMail将预填充输入字段。

此处记录了更多信息:

First of all, you don't have to use Fluid ViewHelpers for creating your footer form. Simply use a HTML-Form with POST and some fields. The action of the form should contain the URL of the powermail form. If the fields are using correct names, powermail will prefill the input fields.

More information how to prefill fields in powermail is documented here: https://github.com/einpraegsam/powermail/blob/develop/Documentation/ForAdministrators/BestPractice/PrefillField.md

Typo3 PowerMail:从另一页插入从形式插入PowerMail输入字段

故人如初 2025-02-16 17:23:43

它之所以不让我移动这本书的原因是,为了运行宏,已经打开了工作簿,并且在使用时无法移动打开的文件。

The reason it is not letting me move the book is that in order to run the macro, the workbook has been opened, and an opened file cannot be moved while being used.

为什么可以将“宏观启用的宏观”工作簿移至带有“ name as”的另一个文件夹VBA中的方法?

故人如初 2025-02-16 02:21:56

建议

在您当前脚本中发现的问题:

在评论之后的脚本中 //现在,让我们放回电子表格 ,ID 125130 的第一个实例已被找到因此, 125130 ID的行长的下一个重复将保持不变,从而导致错误 “异常:数据中的列数与该范围内的列数不符数据有13个,但范围有14个。

也许您可以在下面尝试此脚本,我认为它具有更简单的实现:

提出的脚本

function test2() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = ss.getSheetByName("UTSheet");
  const range = sheet.getDataRange();
  let values = range.getValues();
  let output = []; //Container of row data with unique IDs
  let colA = [...values.map(x => x[0])];

  values.forEach(row => {
    if (output.map(x => x[0]).includes(row[0])) //if an ID already exists in the output variable, it will be ignored
      return;
    row.push(colA.filter(x => x == row[0]).length) //adds the ID's total count (if it has duplicates Or 1 if none) at the end of each row of data of that current ID in the loop
    output.push(row); //put the first ID instance data with total count in the "output" variable
  });

  sheet.getRange(15, 1, output.length, output[0].length).setValues(output);
}

演示

”在此处输入图像说明”

执行没有异常错误

”在此处输入图像说明”

Suggestion

Issue found in your current script:

In the script after the comment // now let put back into spreadsheet, the first instance of the id 125130 has already been found thus, the next duplicate of 125130 id's row length will remain unchanged, causing the error "Exception: The number of columns in the data does not match the number of columns in the range. The data has 13 but the range has 14." as other data row lengths are changed to 14 except for one in the values array.

Perhaps you can try this script below, which I think has a simpler implementation:

Proposed Script

function test2() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = ss.getSheetByName("UTSheet");
  const range = sheet.getDataRange();
  let values = range.getValues();
  let output = []; //Container of row data with unique IDs
  let colA = [...values.map(x => x[0])];

  values.forEach(row => {
    if (output.map(x => x[0]).includes(row[0])) //if an ID already exists in the output variable, it will be ignored
      return;
    row.push(colA.filter(x => x == row[0]).length) //adds the ID's total count (if it has duplicates Or 1 if none) at the end of each row of data of that current ID in the loop
    output.push(row); //put the first ID instance data with total count in the "output" variable
  });

  sheet.getRange(15, 1, output.length, output[0].length).setValues(output);
}

Demonstration

enter image description here

Execution without exception error

enter image description here

可以弄清楚为什么代码不能应用于较大范围

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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