停顿的约定

文章 评论 浏览 28

停顿的约定 2025-02-20 21:26:42

这是因为 tokencontractAddress上的功能是由 finalToken (用户调用)调用。

如果您想从用户作为功能的一部分中提取令牌,则用户需要发送2次单独的交易。

  1. 第一次交易到 tokencontractAddress 直接调用其 and code> anderve()函数,传递 finalToken 地址为spender。

  2. 以及您的 finalToken 合同的第二个。

您还需要进行更改以调用 safetransfrom()在代码中 - 不是 safetransfer() - 将用户地址作为令牌发送者传递。

IERC20 tokennew = IERC20(address(tokenContractAddress));
// user is the token sender, `to` is the recipient
tokennew.safeTransferFrom(msg.sender, to, amount);

It's because the safeTransfer() function on tokenContractAddress is called by FinalToken (which is called by the user).

If you want to pull tokens from the user as a part of your function, the user needs to send 2 separate transactions.

  1. First transaction to the tokenContractAddress contract directly, invoking its approve() function, passing FinalToken address as the spender.

  2. And the second to your FinalToken contract as they are doing in your example already.

You also need to make a change to call safeTransferFrom() in your code - not safeTransfer() - passing the user address as the token sender.

IERC20 tokennew = IERC20(address(tokenContractAddress));
// user is the token sender, `to` is the recipient
tokennew.safeTransferFrom(msg.sender, to, amount);

IERC20 SAFETRANSFER第二令牌问题

停顿的约定 2025-02-19 15:13:49

// no设计的关键字 是一种非常难闻的气味;并且选项1和2不会没有 async


我们

static async Task MethodAsync(int i) { WriteLine($"<{i}"); await Task.Delay(100); WriteLine($"{i}>"); }

static IEnumerable<Task> GetTasks()
{
    for(int i=0 ; i<5;i++ )
    {
        yield return MethodAsync(i);  
    }
}

可以使用 foreach 依次执行并等待此任务:

var tasks = GetTasks();

foreach (var t in tasks) // Please note it is the enumeration which starts the tasks one by one
{
    await t;
}

这是

<0
0>
<1
1>
<2
2>
<3
3>
<4
4>

为了说明它是foreach - 不是等待 - 启动任务,让我们直接使用枚举器:

var tasks = GetTasks();

var enumerator = tasks.GetEnumerator();

var b = true;
while (b)
{
  Console.WriteLine("Moving to next");
  b = enumerator.MoveNext();
  Console.WriteLine("Moved");
  if(b)
  {
    await enumerator.Current;
    Console.WriteLine("After await");
  }
}

此打印:

Moving to next
<0
Moved
0>
After await
Moving to next
<1
Moved
1>
After await
Moving to next
<2
Moved
2>
After await
Moving to next
<3
Moved
3>
After await
Moving to next
<4
Moved
4>
After await
Moving to next
Moved

重要的是要注意 getTasks 在此处负责。

通过以下实现,到getTasks()返回时,将已经启动(或计划在其中很多)开始任务。

static IEnumerable<Task> GetTasks()
{
    List<Task> tasks = new ();
    for(int i=0 ; i<5;i++ )
    {
        tasks.Add(MethodAsync(i)); 
    }
    return tasks;
}

在这种情况下,foreach只会顺序等待(在这种情况下,这是没有用的)。

结果

var tasks = GetTasks();

foreach (var t in tasks) 
{
    await t;
}

将是这样的事情:

<0
<1
<2
<3
<4
1>
4>
3>
0>
2>

// no ``async`` keyword by design is a very bad smell; and options 1 and 2 won't compile without async.


Having

static async Task MethodAsync(int i) { WriteLine(
quot;<{i}"); await Task.Delay(100); WriteLine(
quot;{i}>"); }

static IEnumerable<Task> GetTasks()
{
    for(int i=0 ; i<5;i++ )
    {
        yield return MethodAsync(i);  
    }
}

we can execute and await this tasks sequentially with a foreach:

var tasks = GetTasks();

foreach (var t in tasks) // Please note it is the enumeration which starts the tasks one by one
{
    await t;
}

This prints

<0
0>
<1
1>
<2
2>
<3
3>
<4
4>

To illustrate that it's the foreach - not await - that starts the tasks let's use enumerators directly:

var tasks = GetTasks();

var enumerator = tasks.GetEnumerator();

var b = true;
while (b)
{
  Console.WriteLine("Moving to next");
  b = enumerator.MoveNext();
  Console.WriteLine("Moved");
  if(b)
  {
    await enumerator.Current;
    Console.WriteLine("After await");
  }
}

This prints:

Moving to next
<0
Moved
0>
After await
Moving to next
<1
Moved
1>
After await
Moving to next
<2
Moved
2>
After await
Moving to next
<3
Moved
3>
After await
Moving to next
<4
Moved
4>
After await
Moving to next
Moved

It's important to note that GetTasks is in charge here.

With the following implementation the tasks will already be started (or scheduled to start if there are a lot of them) by the time GetTasks() returns.

static IEnumerable<Task> GetTasks()
{
    List<Task> tasks = new ();
    for(int i=0 ; i<5;i++ )
    {
        tasks.Add(MethodAsync(i)); 
    }
    return tasks;
}

In this case foreach will only wait sequentially (which in not that useful).

With

var tasks = GetTasks();

foreach (var t in tasks) 
{
    await t;
}

the result will something like this:

<0
<1
<2
<3
<4
1>
4>
3>
0>
2>

在C#10中同时或顺序运行任务收集

停顿的约定 2025-02-19 10:16:29

递归CTE非常好。但是,如果您想构建一个较大的层次结构(例如200k+),则使用temp表中的没有羞耻感。

这是我用于大型和缓慢移动的层次结构的脱衣/修改版本。

示例

Create Table #YourTable ([Employee] varchar(50),[Manager] varchar(50))
Insert Into #YourTable Values 
 ('Jack',null)
,('Luna','Jack')
,('Japan','Jack')
,('Alice','Luna')
,('Alex','Luna')
,('Jessica','Alex')


Select *
      ,Lvl=1
      ,Path=convert(varchar(500),Employee)
 Into  #TempBld 
 From  #YourTable 
 Where Manager is null

Declare @Cnt int=1
While @Cnt<=30  -- Set Max Level -- You can be a little generous here.
    Begin
        Insert Into #TempBld 
        Select A.*
              ,Lvl =B.Lvl+1
              ,Path=B.Path+' - '+A.Employee
         From  #YourTable A
         Join  #TempBld B on (B.Lvl=@Cnt and A.Manager=B.Employee)
        Set @Cnt=@Cnt+1
    End

Select * from #TempBld Order by Path

结果

Lvl Employee    Manager   Path
1   Jack        NULL      Jack
2   Japan       Jack      Jack - Japan
2   Luna        Jack      Jack - Luna
3   Alex        Luna      Jack - Luna - Alex
4   Jessica     Alex      Jack - Luna - Alex - Jessica
3   Alice       Luna      Jack - Luna - Alice

Recursive CTEs are great to a point. However, if you are looking to build a large hierarchy (like 200K+), there is NO shame in using TEMP tables.

Here is a stripped down/modified version I've used for my LARGE and SLOW MOVING hierarchies.

Example

Create Table #YourTable ([Employee] varchar(50),[Manager] varchar(50))
Insert Into #YourTable Values 
 ('Jack',null)
,('Luna','Jack')
,('Japan','Jack')
,('Alice','Luna')
,('Alex','Luna')
,('Jessica','Alex')


Select *
      ,Lvl=1
      ,Path=convert(varchar(500),Employee)
 Into  #TempBld 
 From  #YourTable 
 Where Manager is null

Declare @Cnt int=1
While @Cnt<=30  -- Set Max Level -- You can be a little generous here.
    Begin
        Insert Into #TempBld 
        Select A.*
              ,Lvl =B.Lvl+1
              ,Path=B.Path+' - '+A.Employee
         From  #YourTable A
         Join  #TempBld B on (B.Lvl=@Cnt and A.Manager=B.Employee)
        Set @Cnt=@Cnt+1
    End

Select * from #TempBld Order by Path

Results

Lvl Employee    Manager   Path
1   Jack        NULL      Jack
2   Japan       Jack      Jack - Japan
2   Luna        Jack      Jack - Luna
3   Alex        Luna      Jack - Luna - Alex
4   Jessica     Alex      Jack - Luna - Alex - Jessica
3   Alice       Luna      Jack - Luna - Alice

递归查询SQL运行太慢吗?如何改进?

停顿的约定 2025-02-19 08:38:47

Lightdm和Kwallet船的弹药似乎没有通过登录而通过补充群体。为了解决这个问题,我还在 sudo usermod -ag docker $ user docker ,

auth optional pam_kwallet.so
auth optional pam_kwallet5.so

发表

#auth optional pam_kwallet.so
#auth optional pam_kwallet5.so

在重新启动<之前,我必须在 /etc/pam.d/lightdm.d/lightdm 中 评论。 /strong>,让Docker-Group实际产生效果。

错误: https://bugs.launchpad.net/lightdm/lightdm/lightdm/+blightdm/++bug/+bug/178141418 在这里: https://bugzilla.redhat.com/show_bug.cgi.cgi.cgi.cgi?id=158149555814955

lightdm and kwallet ship with a bug that seems to not pass the supplementary groups at login. To solve this, I also, beside sudo usermod -aG docker $USER, had to comment out

auth optional pam_kwallet.so
auth optional pam_kwallet5.so

to

#auth optional pam_kwallet.so
#auth optional pam_kwallet5.so

in /etc/pam.d/lightdm before rebooting, for the docker-group to actually have effect.

bug: https://bugs.launchpad.net/lightdm/+bug/1781418 and here: https://bugzilla.redhat.com/show_bug.cgi?id=1581495

如何修复Docker:获得许可的问题

停顿的约定 2025-02-19 02:41:47

感谢 @RenéKling's

答案 服务器:

import socket

HOST = "127.0.0.1"
PORT = 6000

s= socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.bind((HOST, PORT))

while True:
    message, addr = s.recvfrom(1024)
    print(f"Connected by {addr}")

Godot:

extends Node2D
tool

export(bool) var btn =false setget set_btn

var socket = PacketPeerUDP.new()


func set_btn(new_val):
    socket.set_dest_address("127.0.0.1", 6000)
    socket.put_packet("Time to stop".to_ascii())

figured it out thanks to @René Kling 's answer

just incase someone wants the complete version

python server:

import socket

HOST = "127.0.0.1"
PORT = 6000

s= socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.bind((HOST, PORT))

while True:
    message, addr = s.recvfrom(1024)
    print(f"Connected by {addr}")

Godot:

extends Node2D
tool

export(bool) var btn =false setget set_btn

var socket = PacketPeerUDP.new()


func set_btn(new_val):
    socket.set_dest_address("127.0.0.1", 6000)
    socket.put_packet("Time to stop".to_ascii())

将Python本地服务器与Godot连接

停顿的约定 2025-02-18 19:48:42

我确实在一夜之间找到了一个分辨率,感谢您的帮助和建议&lt;我提出了解决并引起了很多问题,但这些是解决方案。我确实做一些默认时间不准确,但这并不重要。我确实在IF语句以及第二个IF语句中嵌套了最高最低点以重置该值。

这是绘图的最后“逻辑”。这在任何时间范围内都没有运行时错误,也没有以前的会话值中的野生线图。

var float Asiahigh  = na
var float Asialow   = na
bgColorAsia         = color.new(color.red,85)
rangeColorAsia      = activeAsia ? color.new(color.red,0): color.new(color.red,100)  

AsiaLookback= nz(ta.barssince(ta.change(activeAsia))) + 1

if activeAsia
    
    Asiahigh := nz(ta.highest(high,AsiaLookback))
    Asialow  := nz(ta.lowest(low,AsiaLookback))

if not activeAsia
    Asiahigh := close[1]
    Asialow := close[1]

其余代码的大部分都保持不变,但要清理一点。

I did find a resolution overnight thanks for your help and suggestions< I ened up solving and causing a whole bunch of problems but these are the resolutions. I do realzie some of my default times are not accurate but that isn't terribly important. I did nest the highest lowest in a if statement as well as a second if statement to reset the values.

this was the final "logic" for the plotting. this didn't have runtime errors on any time frame and didn't have wild line plots from previous sessions values.

var float Asiahigh  = na
var float Asialow   = na
bgColorAsia         = color.new(color.red,85)
rangeColorAsia      = activeAsia ? color.new(color.red,0): color.new(color.red,100)  

AsiaLookback= nz(ta.barssince(ta.change(activeAsia))) + 1

if activeAsia
    
    Asiahigh := nz(ta.highest(high,AsiaLookback))
    Asialow  := nz(ta.lowest(low,AsiaLookback))

if not activeAsia
    Asiahigh := close[1]
    Asialow := close[1]

most of the rest of the code was left the same but clean up a bit.

建立高/低的会话指示器

停顿的约定 2025-02-18 14:36:24

请在这里看看:

@withmockuser 和相关的注释可能很有用在这里,您不需要做丑陋的嘲笑安全环境工作。

Please have a look here: https://docs.spring.io/spring-security/site/docs/4.2.x/reference/html/test-method.html

@WithMockUser and related annotations might be useful here and you won't need to do ugly mocking security context stuff.

模拟弹簧安全单元测试WebTestclient

停顿的约定 2025-02-18 10:45:02

我在我的项目中使用它,它运行良好

    ngOnInit(): void {
        this.spinner.show().then();
        this.coursService.getCoursOfMySchool(user.school.idSchool).subscribe(value => {
            this.courses = value
            this.spinner.hide().then()
          });

  }

I use this in my project and it work well

    ngOnInit(): void {
        this.spinner.show().then();
        this.coursService.getCoursOfMySchool(user.school.idSchool).subscribe(value => {
            this.courses = value
            this.spinner.hide().then()
          });

  }

ngxspinner hide功能不隐藏

停顿的约定 2025-02-18 09:58:00

我找到了一个解决方案,我必须修改build.js文件以添加node_modules/highcharts-export-server-server目录中的“ {{version}}/modules/pattern-fill.js”,执行节点build.js生成服务并重新启动服务

I found a solution, I had to modify the build.js file to add "{{version}}/modules/pattern-fill.js" in the node_modules/highcharts-export-server directory, execute node build.js to re-generate the service and restart the service

HighCharts:模式填充不使用导出服务器

停顿的约定 2025-02-18 06:07:27

我自己问这个问题。 :)发现/最初是由Guido提出的在这里

替代建议:使用'/'怎么样?相反
'*'的意思是“关键字参数”,而'/'不是一个新字符。

然后他的建议 won

呵呵。如果这是真的,我的“/”提案将获胜:

  def foo(pos_only, /,pos_or_kw, *,kw_only):...
 

我认为涵盖此内容的非常相关的文件是 pep 570
回顾部分看起来不错。

回顾

用例将确定在函数定义中使用哪些参数:

  def f(pos1,pos2, /,pos_or_kwd, *,kwd1,kwd2):
 

作为指导:

如果名称无关紧要或没有意义,则使用仅位置,并且只有几个参数总是以相同的顺序传递。
当名称具有含义时,使用关键字 - 通过使用名称明确说明函数定义更易于理解。


如果函数以/结束,

def foo(p1, p2, /)

则意味着所有功能参数均为位置。

I asked this question myself. :) Found out that / was originally proposed by Guido in here.

Alternative proposal: how about using '/' ? It's kind of the opposite
of '*' which means "keyword argument", and '/' is not a new character.

Then his proposal won.

Heh. If that's true, my '/' proposal wins:

 def foo(pos_only, /, pos_or_kw, *, kw_only): ...

I think the very relevant document covering this is PEP 570.
Where recap section looks nice.

Recap

The use case will determine which parameters to use in the function definition:

 def f(pos1, pos2, /, pos_or_kwd, *, kwd1, kwd2):

As guidance:

Use positional-only if names do not matter or have no meaning, and there are only a few arguments which will always be passed in the same order.
Use keyword-only when names have meaning and the function definition is more understandable by being explicit with names.


If the function ends with /

def foo(p1, p2, /)

This means all functional arguments are positional.

当help()列表方法签名时,斜线是什么意思?

停顿的约定 2025-02-17 17:18:24

console.log(contactsres) in getserversideprops

从getServersideProps调用API(等待fetch( your_path ))

console.log(contactsRes) in getServerSideProps

Or

call your api from getServerSideProps (await fetch(your_path))

NextJS getServersideProps()从不调用API

停顿的约定 2025-02-17 10:47:33

您可以使用 itertools.permutations()获取每个数字的数字,然后使用 map() str() int()< / code>将生成的数字转换为所需数字:

import itertools

n = 3
for item in itertools.permutations(range(1, n + 1), n):
    result = int(''.join(map(str, item)))
    print(result)

此输出(仅显示前三行 /最后三行):

123
132
213
231
312
321

You can use itertools.permutations() to get the digits of each number, and then use map() with str() and int() to turn the generated digits into the desired numbers:

import itertools

n = 3
for item in itertools.permutations(range(1, n + 1), n):
    result = int(''.join(map(str, item)))
    print(result)

This outputs (only first three / last three lines shown):

123
132
213
231
312
321

用指定数字制作所有数字,Python

停顿的约定 2025-02-17 05:29:35

定义一个块函数,然后通过列表重新迭代

def chunk_list(lst, chunk_size):
    for j in range(0, len(lst), chunk_size):
        yield lst[j:j + chunk_size]

,将其使用如下:

import pandas as pd
d = {'col1':[2,4,5,6],'col2':[8,8,6,1],'col3':[1,2,3,4],'col4':[4,4,4,4]}

df = pd.DataFrame(d,index=['Item1','Item2','Item1','Item2'])

for chunk in chunk_list(df.columns, 2):
    diff = "diff" + chunk[0]+ chunk[1]
    df[diff] = df[chunk[0]] - df[chunk[1]]

define a chunk function which iterate through a list

def chunk_list(lst, chunk_size):
    for j in range(0, len(lst), chunk_size):
        yield lst[j:j + chunk_size]

then, use it as follows:

import pandas as pd
d = {'col1':[2,4,5,6],'col2':[8,8,6,1],'col3':[1,2,3,4],'col4':[4,4,4,4]}

df = pd.DataFrame(d,index=['Item1','Item2','Item1','Item2'])

for chunk in chunk_list(df.columns, 2):
    diff = "diff" + chunk[0]+ chunk[1]
    df[diff] = df[chunk[0]] - df[chunk[1]]

如何在熊猫中创建多个差异列?立刻

停顿的约定 2025-02-17 03:47:47

这些方向有些误导。他们告诉您要验证您的密钥在代理中,而不告诉您如何首先将其添加到代理商中。 (实际上,他们这样做了,但是在单独的页面。)您需要运行一个命令 ssh-add〜/.ssh/my_key 首先要填充代理。 (每次您启动新代理时,都需要重复此操作;用于自动填充用钥匙链中的键的代理的技术超出了此答案的范围。)

我不为代理而烦恼。相反,我将类似以下内容添加到我的SSH配置文件中。

Host github.com
    User git
    IdentityFile ~/.ssh/my_key

然后, ssh 而不是需要查找 IdentityFile 指定的文件,而不是需要查找活动代理。

(如果将密码添加到密钥中,则代理很方便,因为在将密钥添加到代理中时,您只会提示您的密码,而不是每次 ssh 尝试使用键。)

The directions are somewhat misleading. They tell you to verify that your key is in the agent without telling you how to add it to the agent in the first place. (Actually, they do, but on a separate page.) You need to run a command like ssh-add ~/.ssh/my_key first to populate the agent. (This needs to be repeated every time you start a new agent; techniques for automatically populating an agent with keys stored in a keychain are beyond the scope of this answer.)

I don't bother with an agent. Instead, I add something like the following to my SSH configuration file.

Host github.com
    User git
    IdentityFile ~/.ssh/my_key

Then, instead of needing to look in an active agent, ssh simply looks for the file specified by IdentityFile.

(If you add a passphrase to your key, the agent is convenient because you will only be prompted for the passphrase when you add the key to the agent, not every time ssh tries to use the key.)

错误致命:无法从远程存储库中读取。 ``$ ssh -add -l -e sha256`代理没有身份。

停顿的约定 2025-02-17 01:18:37

导出goproxy =直接
重新启动,似乎proxy.golang.org最近有一些困难
Hth

export GOPROXY=direct
and relaunch, seems like proxy.golang.org have some difficulties recently
HTH

我尝试安装依赖项时超时

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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