How to use a timer in C++ to force input within a given time?

#include <iostream> #include <thread> #include <chrono> #include <mutex> #include <condition_variable> using namespace std; condition_variable cv; int value; void read_value() { cin >> value; cv.notify_one(); } int main() { cout << “Please enter the input: “; thread th(read_value); mutex mtx; unique_lock<mutex> lck(mtx); while (cv.wait_for(lck, chrono::seconds(2)) == cv_status::timeout) { cout << “\nTime-Out: 2 second:”; cout << “\nPlease … Read more

Does reactive extensions support rolling buffers?

This is possible by combining the built-in Window and Throttle methods of Observable. First, let’s solve the simpler problem where we ignore the maximum count condition: public static IObservable<IList<T>> BufferUntilInactive<T>(this IObservable<T> stream, TimeSpan delay) { var closes = stream.Throttle(delay); return stream.Window(() => closes).SelectMany(window => window.ToList()); } The powerful Window method did the heavy lifting. Now … Read more

Simulate lag function in MySQL

This is my favorite MySQL hack. This is how you emulate the lag function: SET @quot=-1; select time,company,@quot lag_quote, @quot:=quote curr_quote from stocks order by company,time; lag_quote holds the value of previous row’s quote. For the first row @quot is -1. curr_quote holds the value of current row’s quote. Notes: order by clause is important … Read more