Execute statement every N iterations in Python

How about keeping a counter and resetting it to zero when you reach the wanted number? Adding and checking equality is faster than modulo. printcounter = 0 # Whatever a while loop is in Python while (…): … if (printcounter == 1000000): print(‘Progress report…’) printcounter = 0 … printcounter += 1 Although it’s quite possible … Read more

Scala streaming library differences (Reactive Streams/Iteratee/RxScala/Scalaz…)

PS: I wonder why Play Iteratees library has not been choosed by Martin Odersky for his course since Play is in the Typesafe stack. Does it mean Martin prefers RxScala over Play Iteratees? I’ll answer this. The decision of which streaming API’s to push/teach is not one that has been made just by Martin, but … Read more

does continue work in a do while?

The continue makes it jump to the evaluation at the botton so the program can evaluate if it has to continue with another iteration or exit. In this case it will exit. This is the specification: http://java.sun.com/docs/books/jls/third_edition/html/statements.html#6045 Such language questions you can search it in the Java Language Specification: http://java.sun.com/docs/books/jls/

bash script use cut command at variable and store result at another variable

The awk solution is what I would use, but if you want to understand your problems with bash, here is a revised version of your script. #!/bin/bash -vx ##config file with ip addresses like 10.10.10.1:80 file=config.txt while read line ; do ##this line is not correct, should strip :port and store to ip var ip=$( … Read more

Memory allocation when using foreach loops in C#

Foreach can cause allocations, but at least in newer versions .NET and Mono, it doesn’t if you’re dealing with the concrete System.Collections.Generic types or arrays. Older versions of these compilers (such as the version of Mono used by Unity3D until 5.5) always generate allocations. The C# compiler uses duck typing to look for a GetEnumerator() … Read more

How to give a delay in loop execution using Qt

EDIT (removed wrong solution). EDIT (to add this other option): Another way to use it would be subclass QThread since it has protected *sleep methods. QThread::usleep(unsigned long microseconds); QThread::msleep(unsigned long milliseconds); QThread::sleep(unsigned long second); Here’s the code to create your own *sleep method. #include <QThread> class Sleeper : public QThread { public: static void usleep(unsigned … Read more

Add a delay after executing each iteration with forEach loop

What you want to achieve is totally possible with Array#forEach — although in a different way you might think of it. You can not do a thing like this: var array = [‘some’, ‘array’, ‘containing’, ‘words’]; array.forEach(function (el) { console.log(el); wait(1000); // wait 1000 milliseconds }); console.log(‘Loop finished.’); … and get the output: some array … Read more