increment

Increment matrix structure in MongoDb

陌路散爱 提交于 2019-12-05 12:24:11
I would like to have a matrix structure (a NxN integer matrix) and I want to increment values in it. Which is the right approach to model a matrix in MongoDb and to increment theirValues? Andrew Orsich Lets consider we have: 1 2 3 4 5 6 7 8 9 You can store matrix as embedded array in mongodb in different ways: 1.Represent matrix as one-dimensional array and store like this: { _id: "1", matrix: [1,2,3,4,5,6,7,8,9], width: 3, // or store just size in case of NxN height: 3, } Then to increment third element of matrix you will need following update: db.matrix.update({_id: 1}, { $inc : { "matrix.2"

C# increment ToString

邮差的信 提交于 2019-12-05 10:44:08
I add an unexpected behaviour from C#/WPF private void ButtonUp_Click(object sender, RoutedEventArgs e) { int quant; if( int.TryParse(Qnt.Text, out quant)) { string s = ((quant++).ToString()); Qnt.Text = s; } } So, if I get quant as 1, quant will be incremented to 2. But the s string will be 1. Is this a question of precedence? EDIT: I re-wrote this as: quant++; Qnt.Text = quant.ToString(); and now this works as I expected. You are using the post -increment operator. This evalutates to the original value, and then increments. To do what you want in a one-liner you can use the pre -increment

Variable is incremented twice in node.js http callback function

ⅰ亾dé卋堺 提交于 2019-12-05 09:19:39
I was playing around with node.js and something strange happens when you run this code: var http = require("http"); var i = 0; function onRequest(request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.write("You're number " + i++); response.end(); } http.createServer(onRequest).listen(8888); I would expect it to behave like a page views counter, but with each refresh of the browser tab i get the result of what seems to be i=i+2 instead of a simple increment. Could someone explain this behavior to me? Your browser is hitting your server for favicon.ico as well.

Generate vector of a repeated string with incremental suffix number

大兔子大兔子 提交于 2019-12-05 08:09:32
I would like to generate a vector based on repeating the string "FST" but with a number at the end which increments: "Fst1" "Fst2" "Fst3" "Fst4" ... "Fst100" An alternative to paste is sprintf , which can be a bit more convenient if, for instance, you wanted to "pad" your digits with leading zeroes. Here's an example: sprintf("Fst%d", 1:10) ## No padding # [1] "Fst1" "Fst2" "Fst3" "Fst4" "Fst5" # [6] "Fst6" "Fst7" "Fst8" "Fst9" "Fst10" sprintf("Fst%02d", 1:10) ## Pads anything less than two digits with zero # [1] "Fst01" "Fst02" "Fst03" "Fst04" "Fst05" # [6] "Fst06" "Fst07" "Fst08" "Fst09"

Javascript increment while assigning

℡╲_俬逩灬. 提交于 2019-12-05 07:50:53
I was having a conversation about the prefix increment operator, and we seem to have run into a disagreement. When running this code: var x = 0; x = ++x; is the second line equivalent to: x = (x = x + 1) OR x = (x + 1) It is hard to tell the difference because the results are identical (both result in x having a value of 1) I believe that the value is not saved to the original variable when the left hand side of the assignment is the variable itself. My counterpart disagrees and thinks the value is saved to the original variable whenever the ++ operator is used. Which one of us is right? It is

css increment nth-child attribute values

依然范特西╮ 提交于 2019-12-05 05:34:38
Is there a way to increment attribute values using n in nth-child(n) to output the result of: div:nth-child(1){ top: -5px; } div:nth-child(2){ top: -10px; } div:nth-child(3){ top: -15px; } div:nth-child(4){ top: -20px; } div:nth-child(5){ top: -25px; } You could if you use a preprocessor like sass . An example: div { $var: 5; @for $i from 1 through 5 { &:nth-child(#{$i}) { top: -#{$var}px; $var: $var + 5; } } } A demo: http://sassmeister.com/gist/7d7a8ed86e857be02d1a Another way to achieve this: div { $list: 1 2 3 4 5; @each $i in $list { &:nth-child(#{$i}) { top: -5px * $i; } } } A demo:

Why is x++-+-++x legal but x+++-+++x isn't?

久未见 提交于 2019-12-05 02:18:22
I'm wondering why in C# the following is fine: int y = x++-+-++x; But int y = x+++-+++x; Isn't? Why is there a bias against the +? The other two answers are correct; I will add to them that this illustrates some basic principles of lexical analysis: The lexical analyzer is short-sighted -- it has minimal "look-ahead" The lexical analyzer is greedy -- it tries to make the longest token it can right now . The lexical analyzer does not backtrack trying to find alternate solutions when one fails. These principles imply that +++x will be lexed as ++ + x and not + ++ x . The parser will then parse +

Pointer incrementing in C++

假如想象 提交于 2019-12-05 00:17:09
问题 What does this mean: that a pointer increment points to the address of the next base type of the pointer? For example: p1++; // p1 is a pointer to an int Does this statement mean that the address pointed to by p1 should change to the address of the next int or it should just be incremented by 2 (assuming an int is 2 bytes), in which case the particular address may not contain an int ? I mean, if p1 is, say, 0x442012, will p1++ be 0x442014 (which may be part of the address of a double) or will

Lambda parameter conflicting with class field on accessing field in later scope

本小妞迷上赌 提交于 2019-12-04 23:59:05
I've got a weak imagination when it comes to names, so I often find myself re-using identifiers in my code. This caused me to run into this specific problem. Here's some example code: public delegate void TestDelegate(int test); public class Test { private int test; private void method(int aaa) { TestDelegate del = test => aaa++; test++; } public static void Main() { } } Here are the compilation errors (output by ideone ): prog.cs(11,3): error CS0135: `test' conflicts with a declaration in a child block prog.cs(9,22): (Location of the symbol related to previous error) Compilation failed: 1

Difference between ++ and +=1 in javascript

南笙酒味 提交于 2019-12-04 22:47:16
Could somebody explain why the following functions give different results. The first does not seem to work, but the second does. I'm puzzled because I thought +=1 and ++ did the same thing. (I'm not intending to actually use this code, it's just to demonstrate the difference). /*function 1*/ function incrementIfZero1(base,element) { if (element == 0) { return base++; } else { return base; } }; /*function 2*/ function incrementIfZero2(base,element) { if (element == 0) { return base+=1; } else { return base; } }; incrementIfZero1(1,0) /* -> 1*/ incrementIfZero2(1,0) /* -> 2*/ Any help is very