trying to remove item from vector and this error came out: C2676 binary '==' - vector

for (Node &i : myNodes){
if (CheckCollisionPointCircle(Vector2{ (float)(GetMouseX()),(float)(GetMouseY()) }, Vector2{ (float)(i.X),(float)(i.Y) }, i.radient)) {
auto index = std::find(myNodes.begin(), myNodes.end(), i);
myNodes.erase(index);
}
}
trying to remove a Node from vector of nodes if the CheckCollisionPointCircle() returns true

for (auto iter = myNodes.begin(); iter != myNodes.end();) {
if (CheckCollisionPointCircle(Vector2{ (float)(GetMouseX()),(float)(GetMouseY()) }, Vector2{ (float)(iter->X),(float)(iter->Y) }, iter->radient)) {
iter = myNodes.erase(iter);
}
else {
++iter;
}
}

Related

Dart sort / compare nullable datetime

I'm trying to compare list of music with releaseDate. But I can retrieve music without releaseDate and when I want to sort them, I got an error.
How can I sort / compare nullable datetime and put null releaseDate to the end?
_followedMusic.sort((a, b) {
if (a.releaseDate != null && b.releaseDate != null)
return a.releaseDate.compareTo(b.releaseDate);
else
// return ??
});
Thank you
If you take a look at the documentation for compareTo:
Returns a value like a Comparator when comparing this to other. That is, it returns a negative integer if this is ordered before other, a positive integer if this is ordered after other, and zero if this and other are ordered together.
https://api.dart.dev/stable/2.10.0/dart-core/Comparable/compareTo.html
So your compareTo should just result in returning the values -1, 0 or 1 according to if the compared object should be before, the same position or after the current object.
So in your case if you want your null entries to be at the start of the sorted list, you can do something like this:
void main() {
final list = ['b', null, 'c', 'a', null];
list.sort((s1, s2) {
if (s1 == null && s2 == null) {
return 0;
} else if (s1 == null) {
return -1;
} else if (s2 == null) {
return 1;
} else {
return s1.compareTo(s2);
}
});
print(list); // [null, null, a, b, c]
}
Or if you want the null at the end:
void main() {
final list = ['b', null, 'c', 'a', null];
list.sort((s1, s2) {
if (s1 == null && s2 == null) {
return 0;
} else if (s1 == null) {
return 1;
} else if (s2 == null) {
return -1;
} else {
return s1.compareTo(s2);
}
});
print(list); // [a, b, c, null, null]
}
Or, as #lrn suggests, make the last example in a more short and efficient way (but maybe not as readable :) ):
void main() {
final list = ['b', null, 'c', 'a', null];
list.sort((s1, s2) => s1 == null
? s2 == null
? 0
: 1
: s2 == null
? -1
: s1.compareTo(s2));
print(list); // [a, b, c, null, null]
}
what about _followdMusic.map((date) => return date ?? 1900.01.01).toList().sort(...)
the date is pseudo code, not sure how to write it. This way you put all unknown dates at one of the ends of the list.
The answer of #julemand101 also can be used with the extension function.
extension DateEx on DateTime? {
int compareToWithNull(DateTime? date2) {
if (this == null && date2 == null) {
return 0;
} else if (this == null) {
return -1;
} else if (date2 == null) {
return 1;
} else {
return this!.compareTo(date2);
}
}
}

The IN operator is provided with too many operands; number of operands: 119 dynamodb

Try to use IN operation in dynamodb but get following error. Could anyone help me with alternative solution ?
var params = {
TableName : "table_name",
FilterExpression : "id IN ("+Object.keys(profileIdObject).toString()+ ")",
ExpressionAttributeValues : profileIdObject
};
ERROR ::
{
"message": "Invalid FilterExpression: The IN operator is provided with too many operands; number of operands: 119",
"code": "ValidationException",
"time": "2018-02-13T08:48:02.597Z",
"statusCode": 400,
"retryable": false,
"retryDelay": 25.08276239472692
}
According to docs:
The maximum number of operands for the IN comparator is 100
Found here: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-expression-parameters
You will need to perform the query/scan in multiple batches, in your case with 100 of Object.keys(profileIdObject).toString() in the first batch and 19 in the second batch. Then coalesce the results.
According to dynamodb documentation, the maximum number of operands for the IN comparator is 100
So you can split into many operations like :
FilterExpression : "id IN (1,2,3, ....) OR id IN (101,102,103,...) ..."
Using this function :
let getFilterExp = function (x) {
let arr = []
let currentIndex = 0
let counter = 0
let max = 99
arr[currentIndex] = {}
for (let y in x) {
if (counter < max) {
arr[currentIndex][y] = x[y]
counter++
}
else {
currentIndex++
arr[currentIndex] = {}
arr[currentIndex][y] = x[y]
counter = 0
}
}
let exp = ''
for (let i = 0; i < arr.length; i++) {
if (i == 0) {
exp += "id IN (" + Object.keys(arr[i]).toString() + ")"
}
else {
exp += " OR id IN (" + Object.keys(arr[i]).toString() + ") "
}
}
return exp
}
Where x is the profileIdObject in your case
let filterExp = getFilterExp(profileIdObject )

How can I manipulate a nested QJsonObject/QJsonArray structure in c++ with minimal code?

Say I have a nested QJsonObject that looks like the following JSON:
var sample_set_ =
{child_sample_set_objs:[
{sample_containers:[
{"samples":[
{id:1, sample_val:42}
]}
]}
]}
or equivalently:
auto sample_set_ =
QJsonObject{
{"child_sample_set_objs",
QJsonArray{
{ QJsonObject{
{"sample_containers",
QJsonArray{
{ QJsonObject{
{"samples,
QJsonArray{
{ QJsonObject{
"id", 1,
"sample_val", 42
} }
}
}
}
} }
}
} }
}
}
}
How can I write the data to the leaf node and mutate sample_set_ without copying back all the way up the structure?
The following is what I believe I need to do and it is horrendously verbose.
Given int child_ss_idx and int sample_container_idx:
auto child_sample_set_objs = sample_set_["child_sample_set_objs"].toArray();
auto child_ss = child_sample_set_objs[child_ss_idx].toObject();
auto sample_containers = child_ss["sample_containers"].toArray();
auto sample_container = sample_containers[sample_container_idx].toObject();
auto samples = sample_container["samples"].toArray();
// the write vvvvvvvv
samples.push_back(QJsonObject{ {"sample_set_id", child_ss["id"]} });
sample_container["samples"] = samples;
sample_containers[sample_container_idx] = sample_container;
child_ss["sample_containers"] = sample_containers;
child_sample_set_objs[child_ss_idx] = child_ss;
sample_set_["child_sample_set_objs"] = child_sample_set_objs;

Highlight gridpane Column

Okay so I'm trying to highlight all the nodes in a vertical column in a gridpane when I mouse over any node in the column. So right now I'm getting the columnIndex of the node my mouse is over and then creating an array of all nodes that share that column index. Return that array to the main method and then change the background color of the nodes in the array to a color.
This is the mouse over function:
for (Node node : officeHoursGridPane.getChildren()) {
node.setOnMouseEntered((MouseEvent t) -> {
node.setStyle("-fx-background-color:#f9f3c5;");
Node source = (Node)t.getSource();
Integer colIndex = GridPane.getColumnIndex(source);
Integer rowIndex = GridPane.getRowIndex(source);
//ystem.out.println("Column #: " + colIndex + "\nRow #: " + rowIndex);
for(int c = 0; c <= colIndex; c++){
Node[] colNode = getNodeByColumnIndex(colIndex, officeHoursGridPane);
int colCount=0;
for(int v = 0; v <= colNode.length; v++){
Node vertNode = colNode[v];
vertNode.setStyle("-fx-background-color:#f9f3c5;");
}
}
});
node.setOnMouseExited((MouseEvent t) -> {
node.setStyle("-fx-background-color:#ffffff;");
});
}
This is my Node[] builder:
public Node[] getNodeByColumnIndex (final int column, GridPane gridPane) {
Node[] result = null;
ObservableList<Node> childrens = gridPane.getChildren();
int count = 0;
for (Node node : childrens) {
if(GridPane.getColumnIndex(node) == column) {
result[count] = node;
count++;
if(count > column){
break;
}
}
}
return result;
}
You should find all the nodes with the same column index in the gridpane's children:
for (Node node : officeHoursGridPane.getChildren()) {
node.setOnMouseEntered(e -> officeHoursGridPane.getChildren().forEach(c -> {
Integer targetIndex = GridPane.getColumnIndex(node);
if (GridPane.getColumnIndex(c) == targetIndex) {
c.setStyle("-fx-background-color:#f9f3c5;");
}
}));
node.setOnMouseExited(e -> officeHoursGridPane.getChildren().forEach(c -> {
Integer targetIndex = GridPane.getColumnIndex(node);
if (GridPane.getColumnIndex(c) == targetIndex) {
c.setStyle("-fx-background-color:#ffffff;");
}
}));
}
Note, that in order to not highlight extra nodes you probably should also check the row index as well.

handlebar comparison operator inside each loop

I have two type of value on handlebar page and needs to compare the first one from second.
I can print value of following code
{{articledetails.content_writer_id}}
before writing each loop on page. Now i want to compare the value like following. but i can not get the scope of articledetails.content_writer_id in below code.
{{#each contentwriterdetails}}
{{#compare this.id "==" articledetails.content_writer_id }}
I have already registered compare helper by using this code.
handlebars.registerHelper('compare', function (lvalue, operator, rvalue, options) {
var operators, result;
if (arguments.length < 3) {
throw new Error("Handlerbars Helper 'compare' needs 2 parameters");
}
if (options === undefined) {
options = rvalue;
rvalue = operator;
operator = "===";
}
operators = {
'==': function (l, r) { return l == r; },
'===': function (l, r) { return l === r; },
'!=': function (l, r) { return l != r; },
'!==': function (l, r) { return l !== r; },
'<': function (l, r) { return l < r; },
'>': function (l, r) { return l > r; },
'<=': function (l, r) { return l <= r; },
'>=': function (l, r) { return l >= r; },
'typeof': function (l, r) { return typeof l == r; }
};
if (!operators[operator]) {
throw new Error("Handlerbars Helper 'compare' doesn't know the operator " + operator);
}
result = operators[operator](lvalue, rvalue);
if (result) {
return options.fn(this);
} else {
return options.inverse(this);
}
});
and above helper is working fine as i have checked that.
Any help would be appreciated.
Use the parent's context path:
{{#each contentwriterdetails}}
{{#compare this.id "==" ../articledetails.content_writer_id }}

Resources