别在捏我脸啦

文章 评论 浏览 30

别在捏我脸啦 2025-02-20 14:56:43

您可以使用char(60)类型。这是与二进制旁边提出的(64)。参考:用于使用哪种数据类型哈希密码字段和多少长度?

如果您的哈希没有编码为base64或十六进制或其他,请使用 bytea

You can use CHAR(60) type. This is suggested alongside BINARY(64). Reference: What data type to use for hashed password field and what length?

If your hash is not encoded as Base64 or hex or whatever, use BYTEA.

yugabytedb中模仿二进制的数据类型(64)

别在捏我脸啦 2025-02-20 13:36:34

您可以使用以下功能在更简单的更新操作中更新投票集合。

假设投票集合文档strcture是:

{ 
  _id: ObjectId("62c59379ed72ad7e8e85a8d7"),
  user_id: 12,
  post_id: "Complex Update",
  vote_value: 1    // this can be 0, 1 (upvote) or -1 (downvote) values only.
}

更新操作逻辑和函数:

如果不存在文档 - >

  • 创建新文档,其中三个文档字段( fote_value 将为 1 -1 )。

如果存在文档 - >

  • 如果upvote& amp;现有的投票值== 1,已经投票,发送消息“不能再次投票”。没有更新。
  • 如果upvote& amp;现有投票值== -1,将投票值更新为0(零)。
  • 如果upvote& amp;现有投票值== 0,将投票价值更新为1
  • 。现有投票值== 1,将投票值更新为0(零)。
  • 如果降级& amp;现有的投票值== -1,已经被投票,发送消息“不能再次投票”。没有更新。
  • 如果降级& amp;现有投票值== 0,将投票值更新为-1。

该函数的输入是三个变量: userId postid fotevalue (值是 1 for UpVote和 -1 用于下调的投票)。请注意,如果 POST_ID user_id (一起)不存在 post_id (请注意使用 UPSERT 标志)。

function updateVote(postid, userid, votevalue) {

  // Validate for input values...
  // Validate for votevalue == 1 or -1 
  // Convert votevalue to an integer, if required

  var result = db.test.findOneAndUpdate( 
    { post_id: postid, user_id: userid },
    [
        { 
            $set: { 
                vote_value: { $ifNull: [ "$vote_value", 0 ] } 
            } 
        },
        { 
            $set: { 
                vote_value: {
                    $switch: {
                        branches: [
                            { case: { $and: [ { $eq: [ votevalue, 1 ] }, { $eq: [ "$vote_value", -1 ] } ] }, then: 0 },
                            { case: { $and: [ { $eq: [ votevalue, 1 ] }, { $eq: [ "$vote_value", 0 ] } ] }, then: 1 },
                            { case: { $and: [ { $eq: [ votevalue, -1 ] }, { $eq: [ "$vote_value", 0 ] } ] }, then: -1 },
                            { case: { $and: [ { $eq: [ votevalue, -1 ] }, { $eq: [ "$vote_value", 1 ] } ] }, then: 0 },
                        ],
                        default: "$vote_value"
                    }
                }
            }
        },
    ], 
    { 
        projection: { vote_value: 1 }, 
        upsert: true 
    }
  )

  if (result === null) {
      return "created new document";
  }

  if (votevalue === 1 && result.vote_value === 1) {
      return "cannot upvote again";
  }
  else if (votevalue === -1 && result.vote_value === -1) {
      return "cannot downvote again";
  }
  else {
      return "voted successfully";
  }

}

注意:

  • JavaScript功能代码适用于 Mongosh (或 mongo shell)。
  • 这需要MongoDB v4.2或更高(使用聚合管道的更新)。

You can use the following functionality to update the votes collection in a simpler update operation.

Assume that the votes collection document strcture is, for example:

{ 
  _id: ObjectId("62c59379ed72ad7e8e85a8d7"),
  user_id: 12,
  post_id: "Complex Update",
  vote_value: 1    // this can be 0, 1 (upvote) or -1 (downvote) values only.
}

The update operation logic and function:

If the document not exists ->

  • create new document, with the three document fields (vote_value will be 1 or -1).

If the document exists ->

  • if upvote && existing vote value == 1, already upvoted, send message "cannot upvote again". No update happens.
  • if upvote && existing vote value == -1, update vote value to 0 (zero).
  • if upvote && existing vote value == 0, update vote value to 1.
  • if downvote && existing vote value == 1, update vote value to 0 (zero).
  • if downvote && existing vote value == -1, already downvoted, send message "cannot downvote again". No update happens.
  • if downvote && existing vote value == 0, update vote value to -1.

The input to the function are the three variables: userid, postid and the votevalue (values are 1 for upvote and -1 for down vote). Note the update creates new document if the post_id and theuser_id (together) do not exist in the collection (note the use of the upsert flag).

function updateVote(postid, userid, votevalue) {

  // Validate for input values...
  // Validate for votevalue == 1 or -1 
  // Convert votevalue to an integer, if required

  var result = db.test.findOneAndUpdate( 
    { post_id: postid, user_id: userid },
    [
        { 
            $set: { 
                vote_value: { $ifNull: [ "$vote_value", 0 ] } 
            } 
        },
        { 
            $set: { 
                vote_value: {
                    $switch: {
                        branches: [
                            { case: { $and: [ { $eq: [ votevalue, 1 ] }, { $eq: [ "$vote_value", -1 ] } ] }, then: 0 },
                            { case: { $and: [ { $eq: [ votevalue, 1 ] }, { $eq: [ "$vote_value", 0 ] } ] }, then: 1 },
                            { case: { $and: [ { $eq: [ votevalue, -1 ] }, { $eq: [ "$vote_value", 0 ] } ] }, then: -1 },
                            { case: { $and: [ { $eq: [ votevalue, -1 ] }, { $eq: [ "$vote_value", 1 ] } ] }, then: 0 },
                        ],
                        default: "$vote_value"
                    }
                }
            }
        },
    ], 
    { 
        projection: { vote_value: 1 }, 
        upsert: true 
    }
  )

  if (result === null) {
      return "created new document";
  }

  if (votevalue === 1 && result.vote_value === 1) {
      return "cannot upvote again";
  }
  else if (votevalue === -1 && result.vote_value === -1) {
      return "cannot downvote again";
  }
  else {
      return "voted successfully";
  }

}

NOTES:

  • The JavaScript function code is for the mongosh (or mongo shell).
  • This requires MongoDB v4.2 or higher (uses Updates with Aggregation Pipeline).

单个“ upvote”在我的提要中的帖子行动需要4个mongodb查询。可以做得更好吗?似乎很低效率

别在捏我脸啦 2025-02-20 06:50:36

Promise.All 的想法是将作为参数作为...承诺的数组?无论如何,这应该起作用(测试)。

import fetch from 'node-fetch';
import DomParser from 'dom-parser';
var parser = new DomParser();

const urlsData = ['http://www.ynet.co.il/Integration/StoryRss2.xml', 'http://www.ynet.co.il/Integration/StoryRss544.xml'];

var total = [];

Promise.all(urlsData.map(u => fetch(u)
    .then(response => response.text())
    .then(str => parser.parseFromString(str, "text/xml"))
    .then(data => total.push(...data.getElementsByTagName('item'))))
).then(() => {
    console.log(total)
})

The idea of Promise.all is to get as argument an array of ... promises? Anyhow this should work (tested).

import fetch from 'node-fetch';
import DomParser from 'dom-parser';
var parser = new DomParser();

const urlsData = ['http://www.ynet.co.il/Integration/StoryRss2.xml', 'http://www.ynet.co.il/Integration/StoryRss544.xml'];

var total = [];

Promise.all(urlsData.map(u => fetch(u)
    .then(response => response.text())
    .then(str => parser.parseFromString(str, "text/xml"))
    .then(data => total.push(...data.getElementsByTagName('item'))))
).then(() => {
    console.log(total)
})

如何将RSS频道项目的列表合并到一个页面中,而不是一个页面中的每个频道?

别在捏我脸啦 2025-02-19 13:33:22

只有第3层开关能够显示直接连接到它们的设备的IP地址。您的 sg-1008d 只是一个不受管理的开关,它将无法显示连接到其的设备的MAC或IP地址。您将能够通过运行网络工具(例如或通过查看路由器的连接设备列表。但这不会向您显示设备在开关中连接的端口。

Only layer 3 switches have the ability to display the IP address of the devices directly connected to them. Your SG-1008D is just an unmanaged switch and it will not be able to display the MAC or the IP address of the devices connected to it. You will be able to identify the MAC and IP address of the devices connected to the switch by running network tools such as Angry IP Scanner or by looking into the connected devices list of the router. But that will not show you the ports where the devices are connected to in the switch.

需要揭示通过Edgemax路由器4连接到开关的设备的IP地址

别在捏我脸啦 2025-02-19 07:46:37

使用“导入pexpect”而不是“导入序列”

use "import pexpect" instead of "import serial"

如何解决运行PEXPECT-SERIAL示例的问题

别在捏我脸啦 2025-02-19 06:27:04

修复程序

您必须将Express Server作为静态保存的静态文件JF作为静态文件

(在生产中避免,因为它们可能会在重新部署上删除,因此应避免使用图像)。

为此,假设图像存在于 public/images 中,则应添加以下行

app.use(express.static('public'))

public/images/1.png 应该在http:/ /localhost:8000/images/1.png

为什么需要这?

Essential,Express仅服务于您在路由中默认情况下生成的响应。因此,您需要要求Express将“公共”中的文件作为静态文件(按原样)提供。

Note - Express在静态目录中查找文件,因此静态目录的名称不是URL的一部分。

参考

https://expressjs.coms.com/en/en/starter/static-files.html a>

The Fix

You'll have to make express server the images as static files jf you are saving the image locally

(which you should avoid in production as they might be deleted on redeployments).

To do this, assuming the images are present in public/images, you should add the following lines

app.use(express.static('public'))

Then, public/images/1.png should be available at http://localhost:8000/images/1.png

Why is this needed?

Essential, express just serves the responses you generate in routes by default. So you need to ask express to serve the files inside "public" as static files (which are served as is).

NOTE - Express looks up the files relative to the static directory, so the name of the static directory is not part of the URL.

Reference

https://expressjs.com/en/starter/static-files.html

如何从Express API和Mongo DB获取图像

别在捏我脸啦 2025-02-18 23:18:22

使用TSCONFIG和您共享的示例,Typescript(v4.7.3) will 识别 iseralized 作为 boolean |未定义

Typescript在v2.0中实现了严格的null检查(请参阅发行说明)。如果使用中的版本低于v2.0,则该规则将被忽略。

您使用的编辑器可能无法以构建脚本中定义的方式解析tsconfig。编辑还可能错误地解决了TSCONFIG。

验证打字稿版本为v2.0或以上,请确保正确解决了TSCONFIG,并使用TSC编译项目(编辑器可能是错误的)。

With the tsconfig and the example you shared, typescript (v4.7.3) will recognize isGeneralized as boolean | undefined.

Typescript implemented strict null checks in v2.0 (see release notes). If the version in use is below v2.0, the rule will be ignored.

The editor you are using may not resolve the tsconfig the way it is defined in the build scripts. There is also a possibility that the editor has just resolved the tsconfig incorrectly.

Verify the the typescript version to be or above v2.0, make sure the tsconfig is resolved correctly, and compile the project with tsc (the editor might be wrong).

当不确定的工会中,TS未能像未定义一样键入

别在捏我脸啦 2025-02-18 15:23:13

使用两个INT的滴定方法是一种实例方法,您正在尝试不先创建对象实例的情况。

为什么编译器应该接受?我高度怀疑,在任何先前的JDK中,其行为都不同。

The doSomething method which takes two ints is an instance method and you are trying to call it without creating an instance of the object first.

Why should the compiler accept that? I highly doubt, that in any prior JDK it behaved differently.

foo(int,int)被挑选在foo(int ...)上

别在捏我脸啦 2025-02-18 04:39:04
Create the configmap from a file.
Just create a sample file like ui.properties
example:
cat ui.properties
1. name=x
2. rollno=y
    
Command to create a configmap from above file
kubectl create configmap ui-configmap --from-file=ui.properties

Verify the data.
kubectl get configmap ui-configmap  -o yaml

apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: <>
  name: ui-configmap
  namespace: default
data:
  name: x
  role: y
Create the configmap from a file.
Just create a sample file like ui.properties
example:
cat ui.properties
1. name=x
2. rollno=y
    
Command to create a configmap from above file
kubectl create configmap ui-configmap --from-file=ui.properties

Verify the data.
kubectl get configmap ui-configmap  -o yaml

apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: <>
  name: ui-configmap
  namespace: default
data:
  name: x
  role: y

YAML代码可以创建具有特定文件(.js/.sh)的ConfigMap

别在捏我脸啦 2025-02-18 00:25:51

Typescript旨在通过 声明合并 a>:

您可能还熟悉创建功能的JavaScript练习,然后通过将属性添加到功能中进一步扩展功能。 Typescript使用声明合并以类型安全的方式构建这样的定义。

声明合并的声明让我们说某物既是功能又是一个名称空间(内部模块):

function f() { }
namespace f {
    export var someValue = 3;
}

这可以保留键入,并让我们同时编写 f() f.somevalue 。在编写 .d.t.ts 为现有JavaScript代码的文件时,请使用 neclare

declare function f(): void;
declare namespace f {
    export var someValue: number;
}

将属性添加到功能中通常是一个令人困惑或意外的模式,因此请避免它,但是,使用或转换较旧的JS代码时可能有必要。这是将内部模块(名称空间)与外部混合的唯一时间之一。

TypeScript is designed to handle this case through declaration merging:

you may also be familiar with JavaScript practice of creating a function and then extending the function further by adding properties onto the function. TypeScript uses declaration merging to build up definitions like this in a type-safe way.

Declaration merging lets us say that something is both a function and a namespace (internal module):

function f() { }
namespace f {
    export var someValue = 3;
}

This preserves typing and lets us write both f() and f.someValue. When writing a .d.ts file for existing JavaScript code, use declare:

declare function f(): void;
declare namespace f {
    export var someValue: number;
}

Adding properties to functions is often a confusing or unexpected pattern in TypeScript, so try to avoid it, but it can be necessary when using or converting older JS code. This is one of the only times it would be appropriate to mix internal modules (namespaces) with external.

在打字稿中构建具有属性的功能对象

别在捏我脸啦 2025-02-17 22:35:38

函数或库无法实现所需的输出,因此始终有一种通过逻辑来实现结果的方法。

print('abc')
a="\n"*10

x= input(a+'Enter here :')

print(x)

Functions or libraries are not available to fulfill the desired output then there is always a way to achieve the result by logic.

print('abc')
a="\n"*10

x= input(a+'Enter here :')

print(x)

在Python的底行输入

别在捏我脸啦 2025-02-17 05:20:08

=SUMPRODUCT(--(MMULT(--ISNUMBER(SEARCH({"Red","Green","Blue"},A1:A6)),ROW($ZZ$1:INDEX($ZZ:$ZZ,COLUMNS({"Red","Green","Blue"})))^0)>0))

所有版本 将更改为定界符,以使其成为本地设置中的水平数组。

而且,不确定这一点,但是在较旧的版本中,这可能需要使用CTRL换档 - 输入编辑模式时输入。

All Versions:

=SUMPRODUCT(--(MMULT(--ISNUMBER(SEARCH({"Red","Green","Blue"},A1:A6)),ROW($ZZ$1:INDEX($ZZ:$ZZ,COLUMNS({"Red","Green","Blue"})))^0)>0))

Realize that for me {"Red","Green","Blue"} creates a horizontal array. Change the , to the delimiter to make it a horizontal array in your local settings.

And, not sure about this one, but in older version this may require the use of Ctrl-Shift-Enter instead of Enter when exiting edit mode.

enter image description here

有什么方法可以使用Countif()而不过分陈述?

别在捏我脸啦 2025-02-17 03:57:06

您可以使用 row_number()来标识所需的行。然后,过滤行很容易。例如:

select *
from (
  select t.*,
    row_number() over(
      partition by study_spec_no, status
      order by version_no desc
    ) as rn
  from t
  where status in ('New', 'Released')
) x
where rn = 1

edit

如果要使用谓词注释排除行,则不是null或version_description nes null 您可以 and 它到<<<代码>其中括号中的子句,如以下内容

  where status in ('New', 'Released')
    and (notes is not null OR version_description is not null)

You can use ROW_NUMBER() to identify the rows you want. Then, filtering out rows is easy. For example:

select *
from (
  select t.*,
    row_number() over(
      partition by study_spec_no, status
      order by version_no desc
    ) as rn
  from t
  where status in ('New', 'Released')
) x
where rn = 1

EDIT

If you want to exclude rows using the predicate notes is not null OR version_description is not null you can AND it to the WHERE clause in parenthesis, as in:

  where status in ('New', 'Released')
    and (notes is not null OR version_description is not null)

过滤列的最新行,返回两个行

别在捏我脸啦 2025-02-17 02:57:44

您没有从 uisearchbardelegate 中实现任何方法,因为您的 searchclients 函数未正确命名。您将需要将其重命名为实际上从委托协议实现了该函数。

func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String)

Swift中很少有nitpicks

  1. 从较小的字母开始命名属性,
var companyID = ""
var companyName = ""
var clientList = [Client]()
var filteredArray = [Client]()
let urlService = "https://fetch.php"
  1. 您可以跳过每个 self。在引用声明类型范围内的属性或功能时,您将作为前缀添加为前缀。
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    companyID = filteredArray[indexPath.row].companyID
    companyName = filteredArray[indexPath.row].name
}
  1. 当协议符合使用扩展符合时,它的清洁程度要大得多,因此代码很好地分开,并且它们不会相互混合。
extension TableViewController: UISearchBarDelegate {
    func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
        //let text: String = self.searchClients.text ?? ""

        print("search for \(searchText)")

        filteredArray = []

        if searchText == "" {
            filteredArray = clientList
        } else {
            filteredArray = clientList.filter { item in
                item.name.lowercased().contains(searchText.lowercased())
            }
        }
        print(filteredArray)
        tableView.reloadData()
    }
}

You are not implementing any method from the UISearchBarDelegate since your searchClients function is not correctly named. You will need to rename it to searchBar to actually implement the function from the delegate protocol.

func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String)

Few Nitpicks

  1. In Swift we are naming properties by starting with a lowercase letter
var companyID = ""
var companyName = ""
var clientList = [Client]()
var filteredArray = [Client]()
let urlService = "https://fetch.php"
  1. You can skip every self. you are adding as a prefix when referencing to a property or function within the scope of the declaring type.
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    companyID = filteredArray[indexPath.row].companyID
    companyName = filteredArray[indexPath.row].name
}
  1. Its much cleaner when protocol conformances are implemented using extensions so the code is nicely separated and they do not mix with each other.
extension TableViewController: UISearchBarDelegate {
    func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
        //let text: String = self.searchClients.text ?? ""

        print("search for \(searchText)")

        filteredArray = []

        if searchText == "" {
            filteredArray = clientList
        } else {
            filteredArray = clientList.filter { item in
                item.name.lowercased().contains(searchText.lowercased())
            }
        }
        print(filteredArray)
        tableView.reloadData()
    }
}

如何在UITAITHVIEW上实现Uisearchbar?

别在捏我脸啦 2025-02-16 21:25:50

您之所以遇到的原因是因为可能无法设置环境变量(TypeScript无法知道这一点,因为它仅在编译时起作用,而在运行时不起作用),因此您需要环境变量 string 。您可以手动执行它,或使用inden-in ok ok ok 断言函数来自节点:

import {ok} from 'assert/strict';

ok(
  process.env.DB_CONNECTION,
  'DB_CONNECTION environment variable is not defined',
);

// Now `process.env.DB_CONNECTION` is guaranteed not to be `undefined`

// connect to DB
mongoose.connect(
  process.env.DB_CONNECTION,
  {
    useUnifiedTopology: true,
    useNewUrlParser: true,
    useCreateIndex: true,
  },
  () => {
    console.log('connected to db');
  }
);

The reason you are encountering this is because the environment variable might not be set (there's no way for TypeScript to know this because it only works at compile time and not during runtime), so you need to narrow the environment variable value to string. You can do it manually, or use the built-in ok assertion function from Node:

import {ok} from 'assert/strict';

ok(
  process.env.DB_CONNECTION,
  'DB_CONNECTION environment variable is not defined',
);

// Now `process.env.DB_CONNECTION` is guaranteed not to be `undefined`

// connect to DB
mongoose.connect(
  process.env.DB_CONNECTION,
  {
    useUnifiedTopology: true,
    useNewUrlParser: true,
    useCreateIndex: true,
  },
  () => {
    console.log('connected to db');
  }
);

在后端使用dotenv

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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