Signup/Sign In

Answers

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

Replace spawn with node-cross-spawn. For instance like this at the beginning of your app.js:
***
(function() {
var childProcess = require("child_process");
childProcess.spawn = require('cross-spawn');
})();
***
4 years ago
app.use() acts as a middleware in express apps. Unlike app.get() and app.post() or so, you actually can use app.use() without specifying the request URL. In such a case what it does is, it gets executed every time no matter what URL's been hit.
4 years ago
***
const crypto = require('crypto'),
fs = require("fs"),
http = require("http");

var privateKey = fs.readFileSync('privatekey.pem').toString();
var certificate = fs.readFileSync('certificate.pem').toString();

var credentials = crypto.createCredentials({key: privateKey, cert: certificate});

var handler = function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
};

var server = http.createServer();
server.setSecure(credentials);
server.addListener("request", handler);
server.listen(8000);
***
4 years ago
I would like to explain the concepts from the perspective of JavaScript prototype inheritance. Hopefully help to understand.

There are three options to define the scope of a directive:

scope: false: Angular default. The directive's scope is exactly the one of its parent scope (parentScope).
scope: true: Angular creates a scope for this directive. The scope prototypically inherits from parentScope.
scope: {...}: isolated scope is explained below.
Specifying scope: {...} defines an isolatedScope. An isolatedScope does not inherit properties from parentScope, although isolatedScope.$parent === parentScope. It is defined through:
***
app.directive("myDirective", function() {
return {
scope: {
... // defining scope means that 'no inheritance from parent'.
},
}
})
***
isolatedScope does not have direct access to parentScope. But sometimes the directive needs to communicate with the parentScope. They communicate through @, = and &. The topic about using symbols @, = and & are talking about scenarios using isolatedScope.

It is usually used for some common components shared by different pages, like Modals. An isolated scope prevents polluting the global scope and is easy to share among pages.
4 years ago
The provided answer is absolutely correct, but I wanted to expand for any future visitors who may want to do it a bit more dynamically -

In the view -
***


Go to edit


***
In the controller -
***
$scope.changeView = function(person){
var earl = '/editperson/' + person.id;
$location.path(earl);
}
***
Same basic concept as the accepted answer, just adding some dynamic content to it to improve a bit. If the accepted answer wants to add this I will delete my answer.
4 years ago
The server (that the POST request is sent to) needs to include the Access-Control-Allow-Headers header (etc) in its response. Putting them in your request from the client has no effect.

This is because it is up to the server to specify that it accepts cross-origin requests (and that it permits the Content-Type request header, and so on) – the client cannot decide for itself that a given server should allow CORS.
4 years ago
Yes foreign key can be null as told above by senior programmers... I would add another scenario where Foreign key will required to be null.... suppose we have tables comments, Pictures and Videos in an application which allows comments on pictures and videos. In comments table we can have two Foreign Keys PicturesId, and VideosId along with the primary Key CommentId. So when you comment on a video only VideosId would be required and pictureId would be null... and if you comment on a picture only PictureId would be required and VideosId would be null...
4 years ago
You can use the DISTINCT keyword within the COUNT aggregate function:
***
SELECT COUNT(DISTINCT column_name) AS some_alias FROM table_name
***
This will count only the distinct values for that column.
4 years ago
Postgres allows:
***
UPDATE dummy
SET customer=subquery.customer,
address=subquery.address,
partn=subquery.partn
FROM (SELECT address_id, customer, address, partn
FROM /* big hairy SQL */ ...) AS subquery
WHERE dummy.address_id=subquery.address_id;
***
This syntax is not standard SQL, but it is much more convenient for this type of query than standard SQL. I believe Oracle (at least) accepts something similar.
4 years ago
You can

1.create a table variable to hold the result set from the stored proc and then
2. insert the output of the stored proc into the table variable, and then
3. use the table variable exactly as you would any other table...
... sql ....
***
Declare @T Table ([column definitions here])
Insert @T Exec storedProcname params
Select * from @T Where ...
***
4 years ago
***
UPDATE urls
SET url = REPLACE(url, 'domain1.com/images/', 'domain2.com/otherfolder/')
***
4 years ago
Two methods are said to be overloaded if they have the same name but different signatures.
4 years ago