HasAndBelongsToMany relations in Loopback - loopbackjs

I am trying to go through the example mention in the documentation for the HasAndBelongsToMany relations.
Documentation
For the Assembly and Parts example, the documentation says, it adds a function which can add part to assembly.
assembly.parts.add(part,
function(err) {
...
});
But this adds only a single part to assembly. If I have to add multiple parts, do we have a function for that? I think calling this function in a loop multiple times is not an optimal way to do.

I don't think there is a way to add multiple items at once. There seems to be a similar question here. This might help you.

Related

transition Vs custom_reaction in boost.statechart library

I've read the tutorial of boost.statechart library and its examples, and I've a question related to the transition and its action.
There are two ways to define the transition using transition<> and custom_reaction but what is the main difference between them and when to use anyone of this?
Custom reactions are more versatile. However they're also more work and more error prone.
Refer back to this section in the docs where lists limitations and concludes:
All these limitations can be overcome with custom reactions. Warning: It is easy to abuse custom reactions up to the point of invoking undefined behavior. Please study the documentation before employing them!
So you use custom reactions when you know what you are doing and require the flexibility.

Function mapping diagram

Hi this question is very broad.
SCENARIO --
I want to diagrammatically represent the functions of my class and how they call each other? The functions have a definite pattern and I want to do this to accommodate future changes such as adding a new functionality which will require to write a new function.
Eg:
function_1() ---> calls function_master()
function_2() ---> calls function_master()
If tomorrow function_3 is created then the makers should know that they need to make a call to function_master().
There are many such complex relationships.
The Real Question --> What I'm trying to achieve, does it have a name? like function mapping diagram.
I know about class diagrams. I don't want to include them. I want detailed diagram of only functions calling each other.
Can you suggest some tools so that I can make it?
It is called a function call graph.
A tool that may be used is doxygen
Imagix 4D will be of great help to you.
You may also look at wiki's link for static Analysis tools

Data structure for optimization

I am thinking about a method to handle the data more efficiently. Let me explain it:
Currently, there is a class, called Rules, it has a lot of member functions, like Rules::isForwardEligible(), Rules::isCurrentNumberEligible()....So these functions are used to check the specific situations (when other process call them), all of them return bool value.
In the body of these functions are ifs which will query the DB to compare data, finally return turn or false.
So the whole thing is like if(Rules::isCurrentNumberEligible())--->Check content in Rules::isCurrentNumberEligible()--->if(xxxx)(xxxx will be another function again, query DB), I think this kind way is not good. I want to improve it.
What I am imagining, is to use less code but query more for the information.
So I can query in the first step if(Rules::isCurrentNumberEligible()), I can set different tables for query, so the things like if(xxx){if(xx){if(xx)....}} will be less. A solutions is to build a class whose role is like a coordinator, ask him each time for different querys. Is it suitable?
I am not sure it is a good way to control this, or may be there are some good solutions aside. Please help me, thanks!
The classical algorithm for rule-based systems is the RETE algorithm. It strives to minimize the number of rules to be evaluated. The trick is that a re-evaluation of a rule does not make sense unless at least one related fact has changed.
In general, those rules should be queried first which promise maximum information gain. This helps to pin-down the respective case in as few questions as possible.
A physician in differential diagnosis would always order his/her questions from general to specific. In information theory this is called the principle of maximum entropy.

Prevent from reverse engineering C++ binary

I have read several articles on the topic as this one and implemented most of the described techniques. But I also want to add some extra un-referenced/never-used code to the binary. Ideally I want to be able to add this code to the built binary through a tool. Is there such a tool? Any ideas on how to build such a tool? Or how to generate and add to my C++ program some never-used code? Where should I put it?
In an analysis of Skype internals I read that they mess the code as much as possible. One way of achieving it is to compute each call dynamically:
if ( sin(a) == 42 ) {
do_dummy_stuff () ;
}
Should I enter into the dummy function? Or is the dummy function the never-used code?
Update: the reason I want to add never-used code to the binary is because we ship many e-books. I want the binaries of each to be little different so if one is compromised, the others not to be (at least not right away).
If I got you right, you are talking about obfuscation.
This question on Stackoverflow covers the topic. There is a lot of software that obfuscates C++ code, quick googling shows a lot of such apps, e.g. this or this.
Is there such a tool?
Yes, there is. It is called compiler with proper parameters, and to add to it a linker. Add to this combination strip, and you'll get a proper library.
On a serious note, there are no ways to prevent reverse engineering. You can only make it harder (or better annoying) for the cracker. You can take a look in this article (where developers of spyro tried all sorts of piracy protection)

How can I use ToUnicode without breaking dead key support?

A similar question has already been asked, so I'm not going to waste time re-explaining it, an existing discussion can be found here:
ToAscii/ToUnicode in a keyboard hook destroys dead keys
The reason I'm posting a new question however is that I seem to have come across a 'solution', but I'm not quite sure how to implement it.
This blog post seems to propose a solution to the problem of ToUnicode killing dead-key support:
http://www.siao2.com/2005/01/19/355870.aspx
However I'm not sure how to implement the suggested solution. A push in the right direction would be greatly appreciated.
To be clear, the part I'm referring to is this:
There are two ways to work around this:
1) You can keep calling ToUnicode with the same info until it is cleared out and then call it one more time to put the state back where it was if you had never typed anything, or
2) You can load all of the keyboard info ahead of time and then when they type information you can look up in your own info cache what the keystrokes mean, without having to call APIs later.
I'm not quite sure how to do either of those things (keyboards and internationalization are far from my strong point), so any help would be greatly appreciated.
Thanks
The first part of the answer is entirely information-free. However, the second part does make sense. ToUnicode() should have been a pure function, which merely acts as a lookup. However, it isn't. But you can call it repeatedly for all expected inputs, store those in your own lookup table and access that.
I'd recommend that Microsoft adds a lookDontTouch flag to the wFlags parameter; that would be a trivial non-breaking API fix.
If you broaden your search to include key logging, you might get some answers. The method presented in the link is extremely cumbersome compared to ToUnicode, but it works. It evolves around finding the current active keyboard layout from the registry and then manually load and parse the proper DLL.
As a note of warning, I've seen the loading part fail miserably on 64-bit Windows.