Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

Remove your **/var/lib/dpkg/lock** file and force package reconfiguration.

***sudo rm /var/lib/dpkg/lock
sudo dpkg --configure -a***
It should work after this.
3 years ago
**yield** is just like **return** - it returns whatever you tell it to (as a generator). The difference is that the next time you call the generator, execution starts from the last call to the **yield** statement. Unlike return, the stack frame is not cleaned up when a yield occurs, however, control is transferred back to the caller, so its state will resume the next time the function is called.

In the case of your code, the function **get_child_candidates** is acting like an iterator so that when you extend your list, it adds one element at a time to the new list.

**list.extend** calls an iterator until it's exhausted. In the case of the code sample you posted, it would be much clearer to just return a tuple and append that to the list.
3 years ago
It's boilerplate code that protects users from accidentally invoking the script when they didn't intend to. Here are some common problems when the guard is omitted from a script:

If you import the guardless script in another script (e.g. import my_script_without_a_name_eq_main_guard), then the second script will trigger the first to run at import time and using the second script's command-line arguments. This is almost always a mistake.

If you have a custom class in the guardless script and save it to a pickle file, then unpickling it in another script will trigger an import of the guardless script, with the same problems outlined in the previous bullet.
3 years ago
For deleting the remote branch:

***git push origin --delete ***
For deleting the local branch, you have three ways:

***1: git branch -D

2: git branch --delete --force # Same as -D

3: git branch --delete # Error on unmerge***
3 years ago
One use for metaclasses is adding new properties and methods to an instance automatically.

For example, if you look at Django models, their definition looks a bit confusing. It looks as if you are only defining class properties:

***class Person(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)***
However, at runtime the Person objects are filled with all sorts of useful methods.
3 years ago
An **abstract class** is a class that is only partially implemented by the programmer. It may contain one or more abstract methods. An abstract method is simply a function definition that serves to tell the programmer that the method must be implemented in a child class.

An **interface** is similar to an abstract class; indeed interfaces occupy the same namespace as classes and abstract classes. For that reason, you cannot define an interface with the same name as a class. An interface is a fully abstract class; none of its methods are implemented and instead of a class sub-classing from it, it is said to implement that interface.
3 years ago
The difference is syntax. Underneath the textual exterior, they are identical. This is why sass and scss files can import each other. Actually, Sass has four syntax parsers: scss, sass, CSS, and less. All of these convert a different syntax into an Abstract Syntax Tree which is further processed into CSS output or even onto one of the other formats via the sass-convert tool.

Use the syntax you like the best, both are fully supported and you can change between them later if you change your mind.
3 years ago
The underscore character **'_'** as in **_()** is an alias to the **gettext()** function.
3 years ago
In most basic terms,
***for (let i = 0; i < 5; i++) {
// i accessible
}
// i not accessible ***
***for (var i = 0; i < 5; i++) {
// i accessible
}
// i accessible ***
3 years ago
An important reason is to add one and only one variable as the "Root" of your namespace...

***var MyNamespace = {}
MyNamespace.foo= function() {

}
or

var MyNamespace = {
foo: function() {
},
...
}***
There are many techniques for namespacing. It's become more important with the plethora of JavaScript modules available.
3 years ago
For sin specifically, using Taylor expansion would give you:

***sin(x) := x - x^3/3! + x^5/5! - x^7/7! + ... (1)***

you would keep adding terms until either the difference between them is lower than an accepted tolerance level or just for a finite amount of steps (faster, but less precise). An example would be something like:

***float sin(float x)
{
float res=0, pow=x, fact=1;
for(int i=0; i<5; ++i)
{
res+=pow/fact;
pow*=-1*x*x;
fact*=(2*(i+1))*(2*(i+1)+1);
}

return res;
}***
Note: (1) works because of the aproximation sin(x)=x for small angles. For bigger angles you need to calculate more and more terms to get acceptable results. You can use a while argument and continue for a certain accuracy:

***double sin (double x){
int i = 1;
double cur = x;
double acc = 1;
double fact= 1;
double pow = x;
while (fabs(acc) > .00000001 && i < 100){
fact *= ((2*i)*(2*i+1));
pow *= -1 * x*x;
acc = pow / fact;
cur += acc;
i++;
}
return cur;
}***
3 years ago
***public void CopyStream(Stream stream, string destPath)
{
using (var fileStream = new FileStream(destPath, FileMode.Create, FileAccess.Write))
{
stream.CopyTo(fileStream);
}
}***
3 years ago