甜点

文章 评论 浏览 28

甜点 2025-02-16 08:03:05

不要使用 livedata 作为返回类型。
使用:

fun readDrinkData() : MutableList<Sum>

而不是:

fun readDrinkData() : LiveData<MutableList<Sum>>

如果您想在房间型号中使用复杂的对象,则必须为这些类型添加一个房间交换器。阅读以下内容:使用ROOM 。例如,您可以使用 gson 将它们转换为 json-string

class MyModel (
    var key: String,
    var value: String,
)

class MySuperModel (
    var name: String,
    var data: MyModel,
)
object Converters {
    @TypeConverter
    fun fromJsonString(String srtJson): MyModel {
        return Gson().fromJson(srtJson, MyModel.class);
    }

    @TypeConverter
    fun toJsonString(MyModel data): String {
        return Gson().toJson(data);
    }
}

然后,您必须将转换器添加到数据库中:

@Database(entities = {MySuperModel.class})
@TypeConverters({Converters.class})
class MyDatabase : RoomDatabase

Don't use LiveData as the return type.
Use:

fun readDrinkData() : MutableList<Sum>

Instead of:

fun readDrinkData() : LiveData<MutableList<Sum>>

In case you want to use complex objects in your room models, You have to add a Room-Converter for those types. Read this: Referencing complex data using Room.
For example you can use GSON to convert them to a json-string

class MyModel (
    var key: String,
    var value: String,
)

class MySuperModel (
    var name: String,
    var data: MyModel,
)
object Converters {
    @TypeConverter
    fun fromJsonString(String srtJson): MyModel {
        return Gson().fromJson(srtJson, MyModel.class);
    }

    @TypeConverter
    fun toJsonString(MyModel data): String {
        return Gson().toJson(data);
    }
}

Then you have to add your converters to your database:

@Database(entities = {MySuperModel.class})
@TypeConverters({Converters.class})
class MyDatabase : RoomDatabase

房间“不确定如何将光标转换为此方法的返回类型”

甜点 2025-02-16 04:40:50

您可以使用使它们连接。

You can use WCONCAT to concatenate them.

Concat在Codesys中的两个Wstrings

甜点 2025-02-15 19:56:09

您应该使用AWS-SDK创建API终点并获取URL:

  • api代码(aws-sdk api doc)

    • 用于上传,参考 s3.getSignedurl('putobject')
    • 不要使用 s3.putobject 用于上传文档,这是一个差异概念
    • 示例:
       返回新的Promise(((解决,拒绝)=&gt; {
        令url = this.s3.getSignedUrl(“ getObject”,{
        水桶:水桶,
        钥匙:钥匙,
        到期:Expires_second
      }))
      返回分辨率(URL)
       
  • s3 bucket config (参考链接)

    • 选择您的存储桶
    • 权限选项卡&gt;跨原生资源共享(CORS)&GT;编辑
        [
          {
            “允许的人”:[
              “*”,
              “授权”
            ],,
            “允许的方法”:[
              “邮政”,
              “得到”,
              “放”,
              “删除”,
              “头”
            ],,
            “允许的人”:[
              “*”
            ],,
            “ ExposeHeaders”:[],
            “ MaxageseConds”:3000
          }  
        这是给出的
       
    • 确认您的允许的方法现有 put 方法
  • 上传文档(Postman Case)

    • 复制并粘贴从 s3.getSignedurl('putobject')
    • 获得的链接

    • 身体选项卡&gt;二进制选择您的文档
    • 标题&gt;取消选中“ content-type”,“用户代理”
    • [可选]如果您想接受选定的文件类型,请编辑 {coct:'*/*'}
      • 示例: {Accept:'Image/png'}
    • put 方法发送
  • 发送,现在您可以检查S3桶

其他有用的参考

You should use aws-sdk to create the API end point and get the url:

  • API Code (aws-sdk API Doc):

    • for upload, reference s3.getSignedUrl('putObject')
    • Don't use S3.putObject for upload document, it is a difference concept
    • Example:
      return new Promise((resolve, reject) => {
        let url = this.S3.getSignedUrl("getObject", {
        Bucket: bucket,
        Key: key,
        Expires: expires_second
      })
      return resolve(url)
      
  • S3 Bucket Config (Reference Link):

    • Select your bucket
    • Permissions Tab > Cross-origin resource sharing (CORS) > Edit
        [
          {
            "AllowedHeaders": [
              "*",
              "Authorization"
            ],
            "AllowedMethods": [
              "POST",
              "GET",
              "PUT",
              "DELETE",
              "HEAD"
            ],
            "AllowedOrigins": [
              "*"
            ],
            "ExposeHeaders": [],
            "MaxAgeSeconds": 3000
          }  
        ]
      
    • Confirm your AllowedMethods existing PUT method
  • Upload Document(Postman case)

    • Copy and paste the link which get from s3.getSignedUrl('putObject')
    • Body tab > binary > select you document
    • Headers > uncheck 'Content-Type', 'User-Agent'
    • [Optional] if u want to accept selected file type, edit { Accept: '*/*'}
      • Example: {Accept: 'image/png' }
    • Send with PUT method
  • now you may check the s3 bucket

other helpful reference:
https://medium.com/@aidan.hallett/securing-aws-s3-uploads-using-presigned-urls-aa821c13ae8d

我可以通过AWS API-GATEWAY将Form-DATA文件上传到S3吗?

甜点 2025-02-15 15:39:28

主要想法是使用〜/.ssh/config将“主机”条目分配给您的每个帐户:

Host ghuser1
  Hostname github.com
  User git
  IdentityFile ~/.ssh/key1

Host gluser1
  Hostname gitlab.com
  User git
  IdentityFile ~/.ssh/keyg1

Host gluser2
  Hostname gitlab.com
  User git
  IdentityFile ~/.ssh/keyg2

这意味着,对于克隆,您需要使用“ host

git clone ghuser1:me/MyRepo

您还可以通过以下方式测试身份验证:

ssh -Tv ghuser1
ssh -Tv gluser1
ssh -Tv gluser2

一些注释:

  • 用户 is 始终 git ,从来没有您的github或gitlab帐户用户名。
  • 需要身份验证才能确定您的帐户是否有权访问 private 存储库(您必须是添加为合作者)。
    对于公共存储库来说,这不太重要。

The main idea is to use ~/.ssh/config to assign a "Host" entry to each of your accounts:

Host ghuser1
  Hostname github.com
  User git
  IdentityFile ~/.ssh/key1

Host gluser1
  Hostname gitlab.com
  User git
  IdentityFile ~/.ssh/keyg1

Host gluser2
  Hostname gitlab.com
  User git
  IdentityFile ~/.ssh/keyg2

That means, for cloning, you will need to use that "Host" entry:

git clone ghuser1:me/MyRepo

You can also test the authentication with:

ssh -Tv ghuser1
ssh -Tv gluser1
ssh -Tv gluser2

A few notes:

  • the User is always git, never your GitHub or GitLab account username.
  • the authentication is needed in order to determine if your account has the right to access a private repository (you must be added as collaborator).
    For a public repository, this is less important.

多个GIT帐户的SSH密钥管理

甜点 2025-02-15 15:21:06

一个视图收到请求“在此URL上给我一个页面”,然后返回响应“好的 - 这是模板和某些上下文”。在您的视图中,响应由Render()函数返回,并且渲染函数希望该请求作为第一个参数 - 而是给出响应。

如果要访问视图的响应,则可以将其分配给变量而不是返回(您必须稍后将其返回或类似的内容)。

 response = render(request, "app1/figure_data_page.html", context, RequestContext(request))
 print(response)
 context['response'] = response

但是,将其作为视图参数并不是很有意义(除非您需要完全不同的视图响应),因为该视图本应生成响应本身。

A view receives a request "give me a page at this URL" and returns a response "Ok - here's a template and some context". In your view, the response is returned by the render() function, and the render function wants the request as the first argument - you're giving a response instead.

If you want to access the view's response, you could assign it to a variable rather than return it (you'd have to actually return it or something similar later).

 response = render(request, "app1/figure_data_page.html", context, RequestContext(request))
 print(response)
 context['response'] = response

But asking for it as a view argument doesn't make a great deal of sense (unless you need the response for a totally different view) as the view is supposed to generate the response itself.

Django:通过请求和响应作为视图参数

甜点 2025-02-15 11:01:31

用上面的示例简单地说

student s1 = null 在没有零安全性的情况下是有效的,这将导致其他各种问题,尤其是在处理大型项目时。

  • 因此,当您选择 null Safety 时,默认情况下,代码中的类型是不可删除的,这意味着变量不能包含 null ,除非您说他们可以。
  • 使用无效的安全性,您的运行时间 null-DENLEFERCE错误变成编辑时间分析错误。

在null Safety中,您不能像 student s1一样= null
而是使用学生? s1 = null 。这意味着您说的是编译器,您知道您知道此值可能是无效的,并且在整个程序中都要处理它。

因此,Flutter接受这一点,并通过提供诸如 ?? 之类的功能来帮助您。

总而言之,引入了无效安全性,因为
开发人员喜欢像DART这样的静态语言,因为它们使类型的检查器能够在编译时(通常在IDE中)在编译时找到错误。您越早找到一个错误,就越早可以修复它。当语言设计师谈论“固定零参考错误” 时,它们意味着丰富静态类型检查器,以便语言可以检测错误,

而DART则设计用于在最终用户的设备上运行。如果服务器应用程序失败,您通常可以在任何人注意到之前重新启动它。但是,当一个扑朔迷离的应用程序在用户的手机上崩溃时,它们就不高兴了。当您的用户不高兴时,您就不开心。

请按照以下链接深入研究无效安全概念。

To say in simple terms using your above example

Student s1 = null is valid without null safety which will lead to various other problems , Especially when you are dealing with the huge project.

  • So when you opt into null safety, types in your code are non-nullable by default, meaning that variables can’t contain null unless you say they can.
  • With null safety, your runtime null-dereference errors turn into edit-time analysis errors.

Where as in null safety , you can't have somethin like Student s1 = null,
Instead use Student? s1 = null. Meaning you are explicity saying the compiler that you are aware that this value can be null and take care of it in the entire program.

So flutter accepts that and helps you through by giving features like ! ?? ?.

To summarize , the null safety was introduced because,
Developers like statically-typed languages like Dart because they enable the type checker to find mistakes in code at compile time, usually right in the IDE. The sooner you find a bug, the sooner you can fix it. When language designers talk about “fixing null reference errors”, they mean enriching the static type checker so that the language can detect mistakes

And Dart is designed to run on an end-user’s device. If a server application fails, you can often restart it before anyone notices. But when a Flutter app crashes on a user’s phone, they are not happy. When your users aren’t happy, you aren’t happy.

Please follow the below links to dive deep into the null-safety concept.

对无效安全的好处感到困惑

甜点 2025-02-15 08:34:46

假设前8行应该施加掩码(将最后3行未触及):

修改输入文件以在前2行中包含双匹配的SSN模式:

$ cat testfile
123456789 needs to be matched (and again 123-45-6789)
123-45-6789 does, too (and again 123456789)
Mask this 123-45-6789 SSN please
Don't miss 123456789 either.
123456789 should match.
123-45-6789 should also match.
As should 123456789
And 123-45-6789
But not 1234567890
1234567890 should also not match.
And 1234567890 is right out.

一个 SED> SED 使用OP的修改版本的想法REGEX:

sed -r 's/\b([0-9]{3})(-{0,1})([0-9]{2})(-{0,1}[0-9]{4})\b/XXX\2XX\4/g' testfile

where:

  • -r - 启用扩展的正则表面支持(消除需要逃脱Parens和Braces)
  • ([0-9] {3}) - 匹配3位数字(< em> 1st捕获组)
  • ( - {0,1}) - 匹配可选 - 第二捕获组
  • <代码>([0-9] {2}) - 匹配2位数字( 3rd Capture group
  • ( - {0,1} [0-9] [0-9] {4}) - 匹配可选 - + 4位数字(第四捕获组
  • xxx \ 2xx \ 2xx \ 4 - 用 xxx ,按原样打印第二个捕获组,用 xx 替换第三捕获组,打印第四捕获组,如
  • g - 应用于行中的所有匹配项

这会生成:

XXXXX6789 needs to be matched (and again XXX-XX-6789)
XXX-XX-6789 does, too (and again XXXXX6789)
Mask this XXX-XX-6789 SSN please
Don't miss XXXXX6789 either.
XXXXX6789 should match.
XXX-XX-6789 should also match.
As should XXXXX6789
And XXX-XX-6789
But not 1234567890
1234567890 should also not match.
And 1234567890 is right out

Assuming the first 8 lines should have a mask applied (leaving the last 3 lines untouched):

Modifying input file to include dual matching SSN patterns in the first 2 lines:

$ cat testfile
123456789 needs to be matched (and again 123-45-6789)
123-45-6789 does, too (and again 123456789)
Mask this 123-45-6789 SSN please
Don't miss 123456789 either.
123456789 should match.
123-45-6789 should also match.
As should 123456789
And 123-45-6789
But not 1234567890
1234567890 should also not match.
And 1234567890 is right out.

One sed idea using a modified version of OP's regex:

sed -r 's/\b([0-9]{3})(-{0,1})([0-9]{2})(-{0,1}[0-9]{4})\b/XXX\2XX\4/g' testfile

Where:

  • -r - enable extended regex support (eliminates need to escape parens and braces)
  • ([0-9]{3}) - match 3 digits (1st capture group)
  • (-{0,1}) - match optional - (2nd capture group)
  • ([0-9]{2}) - match 2 digits (3rd capture group)
  • (-{0,1}[0-9]{4}) - match optional - + 4 digits (4th capture group)
  • XXX\2XX\4 - replace 1st capture group with XXX, print 2nd capture group as is, replace 3rd capture group with XX, print 4th capture group as is
  • g - apply to all matches in a line

This generates:

XXXXX6789 needs to be matched (and again XXX-XX-6789)
XXX-XX-6789 does, too (and again XXXXX6789)
Mask this XXX-XX-6789 SSN please
Don't miss XXXXX6789 either.
XXXXX6789 should match.
XXX-XX-6789 should also match.
As should XXXXX6789
And XXX-XX-6789
But not 1234567890
1234567890 should also not match.
And 1234567890 is right out

在脚本(bash / perl / python)中使用正则掩盖SSN

甜点 2025-02-15 05:26:47

挖掘文档我找到了以下语句:

对于新的网络接口,无论提供的顺序

如何传递给我的功能,导致错误的IP到错误的子网/AZ。

要覆盖此行为,我已经将 private_ip_list_enabled 设置为 true

这是我的工作代码:

resource "aws_network_interface" "private" {
  count = length(var.private_subnets) > 0 ?  length(var.private_subnets) : 0
  subnet_id               = element(var.private_subnets, count.index)
  private_ip_list_enabled = true
  private_ip_list         = tolist([cidrhost(element(var.private_subnets_cidr_blocks, count.index), 10)])
  description             = "Private Interface"
  source_dest_check       = false
}

胜利是我的!

Digging into the documentation I found this statement:

For a new network interface, the same primary IP address is consistently selected from a given set of addresses, regardless of the order provided.

This sorting happens before the list is passed to my functions resulting in the wrong IPs going to the wrong subnet/AZ.

To override this behaviour I've set private_ip_list_enabled to true.

Here's my working code:

resource "aws_network_interface" "private" {
  count = length(var.private_subnets) > 0 ?  length(var.private_subnets) : 0
  subnet_id               = element(var.private_subnets, count.index)
  private_ip_list_enabled = true
  private_ip_list         = tolist([cidrhost(element(var.private_subnets_cidr_blocks, count.index), 10)])
  description             = "Private Interface"
  source_dest_check       = false
}

Victory is mine!

Terraform-序列错误的对象

甜点 2025-02-15 04:44:48

一种方法是使用 sed sort 以数值方式将年份复制到每行的开始,然后在每行开始时删除年份:

sed 's/^.*[[:space:]]\([12][09][0-9][0-9]\)[[:space:]].*$/\1 &/' animals.txt \
    | sort -n | sed 's/^.....//'

带有示例 Animal.txt 的输出是:

oryx    Writing Word Macros     1999    Roman, Steven
donkey  Cisco IOS in a Nutshell 2005    Boney, James
snail   SSH, The Secure Shell   2005    Barrett, Daniel
horse   Linux in a Nutshell     2009    Sievers, Ellen
python  Programming Python      2010    Lutz, Mark
alpaca  Intermediate Perl       2012    Schwartz, Randal
robin   MySQL High Availability 2014    Bell, Charles

One way to do it is to copy the year to the start of each line with sed, sort the resulting output numerically, and then remove the year at the start of each line:

sed 's/^.*[[:space:]]\([12][09][0-9][0-9]\)[[:space:]].*$/\1 &/' animals.txt \
    | sort -n | sed 's/^.....//'

The output with the example animals.txt in the question is:

oryx    Writing Word Macros     1999    Roman, Steven
donkey  Cisco IOS in a Nutshell 2005    Boney, James
snail   SSH, The Secure Shell   2005    Barrett, Daniel
horse   Linux in a Nutshell     2009    Sievers, Ellen
python  Programming Python      2010    Lutz, Mark
alpaca  Intermediate Perl       2012    Schwartz, Randal
robin   MySQL High Availability 2014    Bell, Charles

基于bash中的特定列进行排序错误

甜点 2025-02-14 09:21:41

参数对我有用时,将用户代理传递到标题中。
另外,当使用获取方法时,我没有遇到这个问题。

app.get("/", function (req, res) {
  const userAgent = req.get('user-agent');
  const options = {
  host: 'newsapi.org',
  path: '/v2/top-headlines?country=in&apiKey=xxxxxxxx',
  headers: {
    'User-Agent': userAgent
  }
}
https.get(options, function (response) {
let data;
  response.on('data', function (chunk) {
      if (!data) {
          data = chunk;
      }
      else {
          data += chunk;
      }
  });
  response.on('end', function () {
      const newsData = JSON.parse(data);
      console.log(newsData);
    });
  });
  res.send("hello");
});

Passing the User agent in headers as parameters worked for me.
Also when using fetch method i didn't encountered this problem.

app.get("/", function (req, res) {
  const userAgent = req.get('user-agent');
  const options = {
  host: 'newsapi.org',
  path: '/v2/top-headlines?country=in&apiKey=xxxxxxxx',
  headers: {
    'User-Agent': userAgent
  }
}
https.get(options, function (response) {
let data;
  response.on('data', function (chunk) {
      if (!data) {
          data = chunk;
      }
      else {
          data += chunk;
      }
  });
  response.on('end', function () {
      const newsData = JSON.parse(data);
      console.log(newsData);
    });
  });
  res.send("hello");
});

用户代理在提出api请求时缺少错误

甜点 2025-02-13 20:34:28

您可以使用 torch.t 操作员。

a.T

输出:

tensor([[  101, 14812, 10337,  7257],
        [  101, 16890,  1830, 14541],
        [  101,  2586,  3842,  3293],
        [  101,  2586,  3842,  3297]])

You can use torch.T operator.

a.T

Output:

tensor([[  101, 14812, 10337,  7257],
        [  101, 16890,  1830, 14541],
        [  101,  2586,  3842,  3293],
        [  101,  2586,  3842,  3297]])

通过交换列和行索引重塑火炬张量

甜点 2025-02-13 20:17:50

目前不可能复制或复制一个应用程序的漏斗设置 - 一个应用程序。

It isn't currently possible to duplicate or copy a funnel setup- for one app to another app.

如何在Flurry中重复使用另一个应用程序的漏斗查询?

甜点 2025-02-13 19:04:44

如果不“块” v ,您正在迭代 vec&lt; i32&gt; 。此迭代器生成类型 i32 的项目,因此,无参考,没有终生, thread :: spawn()(特别是'static ) >要求)。

chunks_exact_mut(),但是,是在切片上定义的,并通过&amp; mut [t] 赋予迭代器,因此它具有参考。并且由于此引用引用 v ,它存在于 main()中,因此它不是'static ,并且不起作用。

如果您可以通过&amp; v 而不是 v 迭代,则可以观察到相同的问题,因为该迭代器给您&amp; i32 s(

error[E0597]: `v` does not live long enough
  --> src/main.rs:7:14
   |
7  |     for x in &v {
   |              ^^
   |              |
   |              borrowed value does not live long enough
   |              argument requires that `v` is borrowed for `'static`
...
16 | }
   | - `v` dropped here while still borrowed

;那就是我建议使用 rayon 如@finomnis所建议的。

Without "chunking" v, you're iterating over Vec<i32>. This iterator produces items of type i32, so, no references, no lifetimes, the requirements for thread::spawn() (specifically the 'static requirement) are met.

chunks_exact_mut(), however, is defined on slices and gives iterator over &mut [T], so it does have a reference. And since this reference refers v, which exists in main(), it is not 'static and does not work.

You can observe the same problem if you'll iterate over &v instead of v, since that iterator gives you &i32s (playground):

error[E0597]: `v` does not live long enough
  --> src/main.rs:7:14
   |
7  |     for x in &v {
   |              ^^
   |              |
   |              borrowed value does not live long enough
   |              argument requires that `v` is borrowed for `'static`
...
16 | }
   | - `v` dropped here while still borrowed

Other than that, I'd recommend using rayon as @Finomnis suggested.

chunks_exact_mut螺纹寿命

甜点 2025-02-13 14:55:38

多亏了@AnentRopic的提示,我能够使用以下更改使用 多处理

if __name__ == '__main__':
    list_a = generate_string(500, 10)
    list_b = generate_string(500, 10)

    pool = Pool(os.cpu_count()-2)
    res = pool.map(matching, zip(list_a, list_b))

    norm_res = matching([list_a, list_b])

Thanks to a hint from @Anentropic, I was able to use the following change with multiprocessing

if __name__ == '__main__':
    list_a = generate_string(500, 10)
    list_b = generate_string(500, 10)

    pool = Pool(os.cpu_count()-2)
    res = pool.map(matching, zip(list_a, list_b))

    norm_res = matching([list_a, list_b])

并发。未平行循环迭代

甜点 2025-02-13 06:54:45

所以,我不知道我是否对您想要什么,但是我认为您需要这样的东西吗?

LButton::
If (var = "Pressed")
{
    Click, Left, , Up
    var := "Unpressed"
}
Else
{
    Click, Left, , Down
    var := "Pressed"
}
Return

作为从AHK开始的提示,您可以使用'https://www.macrocreator.com/',在此程序中,您可以很容易地制作一个脚本,并且可以看到它在AHK中所写的内容。

像这样:

您可以导出一个AHK文件,或者只需在屏幕右侧复制脚本即可。

So, I don't know if I understand well what you want, but i think you need something like this?

LButton::
If (var = "Pressed")
{
    Click, Left, , Up
    var := "Unpressed"
}
Else
{
    Click, Left, , Down
    var := "Pressed"
}
Return

As a tip to begins with ahk, you can use 'https://www.macrocreator.com/', in this program you can make a script very easily and you can see what it writes in ahk.

Like this:
enter image description here

You can export an AHK file, or just copy the script in the right side of the screen.

与Python或AHK一起循环与LMB

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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