Find common elements in matrices

My goal is to get a list of setnteceIds in order of the most repeated.

In my database I have stems (words):

|  Stem   |   SentenceId    |
| Hello   | (2,46,62)       |
| Good    | (1,123,45)      |
| Morning | (23,2436,12312) |

My steps

  1. Get all Prayer ID

    (6, 86),(6),(4),(3, 86),(...)
  2. Create an empty object, and every time you see a number, increase its value (or set it to 1 if it has not been seen before)

     {2: 1, 3: 4, 4: 1, 6: 11, 85: 1, 86: 5, 87: 1, 89: 1}

  3. Sort the object by the attribute and place it in a relevance matrix.

     ("6", "86", "3", "89", "87", "85", "4", "2")

Full Code:

getAllStatementIdFromStem = async (stems: string()) => {
    const ids: { (key: number): number } = {};
    await this.getBulkStem(stems).toArray((stems: Stem()) =>{ statements }) =>
        statements.forEach((statementId: number) => {
          typeof ids(statementId) === "undefined"
            ? (ids(statementId) = 1)
            : ids(statementId)++;
    return Object.entries(ids)
      .sort((a, b) => a(1) - b(1))
      .map(x => x(0));

Could I be doing something more effectively? I feel that I am taking too many additional steps.

What is the common practice of how many screenshots should be taken during tests?

We have a large set of tests and we send our screenshots to AWS for use in debugging if a test fails. I wonder what is the common practice for how many screenshots to take during each test case.

nt.number theory – Maximum common divisor as a nonlinear combination $ ax + by + alpha xy $ and asks about the related function

There is this well-known elementary theorem:

Each pair of integers $ to $ Y $ b $ has a common divisor $ d $ Shape $ d = ax + for $. In addition, each common divisor of $ to $ Y $ b $ divide this $ d $.

Then, the greatest common divisor can be represented linearly as a function of $ to $ Y $ b $.

But, it seems to me that also an interesting question is when the greatest common divisor can be represented as follows $ ax + for + alpha xy $, where $ alpha in mathbb Z $ It is something constant.

It seems obvious that for some $ alpha $ the greatest common divisor $ d $ will not be expressible in the form $ ax + for + alpha xy $ but for some other $ alpha $ It will be expressible.

At least, $ d $ is expressible as $ ax + for + alpha xy $ Yes $ alpha = 0 $ but surely for some $ a, b in mathbb Z $ the chose $ alpha = 0 $ It's not the only one.

Assume that by $ (a, b) in mathbb Z times mathbb Z $ set $ ((a, b)) $ it is the set of all $ alpha $ such that $ d = ax + for + alpha xy $so, for example, if for some $ (a, b) $ we have that $ d = ax + for + alpha_r xy $ for $ r = 1, …, $ then $ alpha_r in beta ((a, b)) $.

Yes $ text {noe} ( beta ((a, b))) $ of note the number of elements in the set $ ((a, b)) $ so I would like to know at least some information about the function $ (a, b) to text {noe} ( beta ((a, b))) $ And what is generally known about that function, for example, some properties of it or some rules that govern its behavior?

Use 2 cameras to get the common area between them in the middle

I am configuring 2 cameras with a LIDAR. I want to get the distance and the image. Then the cameras are equidistant from the lidar. How can I use your 2 images to do it? Please help

design patterns: how could you reuse common JS modules between several projects?

In my company, we are developing quite simple React Native applications and sometimes only for mobile devices. Most of them have similar logic, such as the flow of & # 39; login by phone & # 39 ;, some payments, etc., and also some similar UI components.
What we want to do is take all those modules with a similar logic, which is basically reducer + actions + selectors + sagas, and move them somewhere, from which we can reuse them in our new projects. The same with the components of the user interface.

So, my questions are: does this make sense? How would one do that? I am thinking of a monorepo with a package for each module. Does this approach fit our needs?

Microservices: what is the best way to share common functionality or reuse existing code in the microservices architecture?

I'm curious to know what is the best practice or way to share functionalities or common codes among microservices. For example, there is a microservice responsible for operations related to user entity. Yes now X The microservice needs some data related to user entity, then how can this be achieved? Coding of some logic related to user in X It is not a good idea, as it will create redundancy.

What I know so far is that

  1. We can use a facade design pattern, in which we can package common functionalities in some library (JAR type) and share this between different microservices, but then it will create a restriction on the technology that can be used for microservices. For example, JAR can be used primarily with Java projects.
  2. We can use some queue system to send messages from one microservice to another. But I am not sure exactly how we can achieve this and how much this is reliable and compatible.
  3. We can directly use HTTP REST calls between microservices for communication. But again, this will add latency in response time, which is bad.

So what is the best form of internal microservice communication?

Design: Is it a common pattern to create / update / archive as a process?

Traditionally we are supposed to try to create, read, update, delete as separate concepts. However, I have noticed that the following pattern seems more useful for certain contexts (create, update, delete), (read).

For example:

In the context where what is allowed for a new object can be virtually indistinguishable from an existing object for many properties

  • Create or update. By combining create and update in one step, a lot of reuse is created. This dramatically simplifies the back-end code in two parts: if an ID is not provided, create a new object (relatively empty), if an ID is provided, try to obtain it. Then perform the update. The front-end is also simplified and, from the perspective of user interaction, news and updates (editions) are automatically consistent.

  • In some cases, "Delete" is actually "File" and acts more as a property update than as a separate request, that is, converting an "is_archived" flag to True. In this context, it becomes a subset of Update.

What I'm already aware of

  • REST does not need to be used for internal APIs
  • Most things are not really REST

The goal is not so much to have an all-in-one endpoint as mentioned here: RESTful API versus One Do-All Endpoint

But rather combine similar concerns and make it more composable. For example, adding a property in this pattern means adding it in one place.

The net effect is that instead of having 3 back-end routes and 3 front-end components (6 in total), there are 1 of teach (2 in total), with only marginal differences when necessary.

Read operations seem significantly different because
* In general, it is assumed that the object always exists
* He usually reads several objects or does other things with him.
* Often, different permissions and context assumptions

Here it is a bit. Is it better to have Create and Edit actions separately or combine Create and Edit into one?
And there was a discussion about compensation.

The key distinction is that I am not only asking for the background API, but rather the way a person thinks in the context of both of them Front and Back end, the context of archived Also be part of it. (And in the context of modern frames)

Suppose that 𝑎, 𝑏, 𝑚 and 𝑛 are natural numbers, 𝑎> 1, and suppose that 𝑎, 𝑏 do not have a common factor. Show that: (𝑎𝑛 + 𝑏𝑛) | (𝑎𝑚 + 𝑏𝑚) → 𝑛 | 𝑚

Let 𝑎, 𝑏, 𝑚 and 𝑛 be natural numbers, 𝑎> 1, and assume that 𝑎, 𝑏
They have no common factor.

Test it:


PS: this question is from the book "A trip in mathematics"

Complexity of time: algorithm to find the lowest common ancestor of all the deepest leaves

This is the statement of the problem I found today.

Given a binary tree, find the lowest common ancestor of all the deepest leaves.

I came up with a correct algorithm, but I would like to confirm the execution time of this approach.

The algorithm is as follows:

  1. Go through the tree and find the deepest level of the tree, dmax.
  2. Go through the tree and find all the leaves in depth dmax.
  3. Given the LCA (A, B, C) = LCA (LCA (A, B), C), traverse all the nodes found in step 2 and calculate LCA.

The subroutine for LCA (A, B) it is simple. From A, go to the root and store each visited node in a hashset. So, starting at yes, go up until you find a node contained in the hashset.

I know that the first two steps of the algorithm are both In), where n corresponds to the number of nodes in the tree. However, I am not sure about the last step.

LCA (A, B) The subroutine has a linear complexity. But how many nodes, in the worst case, can be found in step 2?

Intuitively, I would say that it has to be much less than n nodes.

Is there a common or typical icon for an external link to a company's website?

I am building a website directory that lists thousands of companies. Each company has an external website and several social sites, such as Facebook, Twitter and Instagram. I have a good set of square icons that represent each of the social sites.

For the link to the company's website, I have a text link that says "visit our website". However, that doesn't look as good as the icons.

Is there a common or typical icon that represents a link to a company's website?