Signup/Sign In

Answers

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

When searching for an example of a C++ class that calls one of its own instance methods in a new thread, this question comes up, but we were not able to use any of these answers that way. Here's an example that does that:

Class.h
***
class DataManager
{
public:
bool hasData;
void getData();
bool dataAvailable();
};
***
Class.cpp
***
#include "DataManager.h"

void DataManager::getData()
{
// perform background data munging
hasData = true;
// be sure to notify on the main thread
}

bool DataManager::dataAvailable()
{
if (hasData)
{
return true;
}
else
{
std::thread t(&DataManager::getData, this);
t.detach(); // as opposed to .join, which runs on the current thread
}
}
***
Note that this example doesn't get into mutex or locking.
4 years ago
I had the same problem. In the jQuery documentation I found:

For cross-domain requests, setting the content type to anything other than application/x-www-form-urlencoded, multipart/form-data, or text/plain will trigger the browser to send a preflight OPTIONS request to the server.

So though the server allows cross-origin requests but does not allow Access-Control-Allow-Headers, it will throw errors. By default, the angular content type is application/json, which is trying to send a OPTION request. Try to overwrite angular default header or allow Access-Control-Allow-Headers in server end. Here is an angular sample:
***
$http.post(url, data, {
headers : {
'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'
}
});
***
4 years ago
In order to switch between different views, you could directly change the window.location (using the $location service!) in index.html file
***


edit


preview


***
Controller.js
***
function Cntrl ($scope,$location) {
$scope.changeView = function(view){
$location.path(view); // path not hash
}
}
***
4 years ago
@ allows a value defined on the directive attribute to be passed to the directive's isolate scope. The value could be a simple string value (myattr="hello") or it could be an AngularJS interpolated string with embedded expressions (myattr="my_{{helloText}}"). Think of it as "one-way" communication from the parent scope into the child directive.
& allows the directive's isolate scope to pass values into the parent scope for evaluation in the expression defined in the attribute. Note that the directive attribute is implicitly an expression and does not use double curly brace expression syntax.
= sets up a two-way binding expression between the directive's isolate scope and the parent scope. Changes in the child scope are propagated to the parent and vice-versa. Think of = as a combination of @ and &.
4 years ago
It is .shape:
***
ndarray.shape
***
Tuple of array dimensions.

Thus:
***
>>> a.shape
(2, 2)
***
4 years ago
It is .shape:
***
ndarray.shape
***
Tuple of array dimensions.

Thus:
***
>>> a.shape
(2, 2)
***
4 years ago
How about (ECMA 5.1):
***
if(Array.isArray(image_array) && image_array.length){
// array exists and is not empty
}
***
4 years ago
Use nested inline if-then statements (Ternary Operators)
***

***
for example :
***

...

***
4 years ago
Execute angular contoller function on page load
// register controller in html


// in controller
$scope.init = function () {
// check if there is query in url
// and fire search in case its value is not empty
};
4 years ago
Check out UI Bootstrap's pagination directive.
View
***


ng-model="currentPage"
total-items="todos.length"
max-size="maxSize"
boundary-links="true">



***
Controller
***
todos.controller("TodoController", function($scope) {
$scope.filteredTodos = []
,$scope.currentPage = 1
,$scope.numPerPage = 10
,$scope.maxSize = 5;

$scope.makeTodos = function() {
$scope.todos = [];
for (i=1;i<=1000;i++) {
$scope.todos.push({ text:"todo "+i, done:false});
}
};
$scope.makeTodos();

$scope.$watch("currentPage + numPerPage", function() {
var begin = (($scope.currentPage - 1) * $scope.numPerPage)
, end = begin + $scope.numPerPage;

$scope.filteredTodos = $scope.todos.slice(begin, end);
});
});
***
I have made a working plunker for reference.

Legacy Version:
View
***


data-current-page="currentPage" data-max-size="maxSize"
data-boundary-links="true">



Controller
todos.controller("TodoController", function($scope) {
$scope.filteredTodos = []
,$scope.currentPage = 1
,$scope.numPerPage = 10
,$scope.maxSize = 5;

$scope.makeTodos = function() {
$scope.todos = [];
for (i=1;i<=1000;i++) {
$scope.todos.push({ text:"todo "+i, done:false});
}
};
$scope.makeTodos();

$scope.numPages = function () {
return Math.ceil($scope.todos.length / $scope.numPerPage);
};

$scope.$watch("currentPage + numPerPage", function() {
var begin = (($scope.currentPage - 1) * $scope.numPerPage)
, end = begin + $scope.numPerPage;

$scope.filteredTodos = $scope.todos.slice(begin, end);
});
});
***
4 years ago
Try using the REPLACE function:
***
mysql> SELECT REPLACE('www.mysql.com', 'w', 'Ww');
-> 'WwWwWw.mysql.com'
***
4 years ago
You can use a User-defined function or a view instead of a procedure.

A procedure can return multiple result sets, each with its own schema. It's not suitable for using in a SELECT statement.
4 years ago