Skip to content

Instantly share code, notes, and snippets.

@DarrenCook
DarrenCook / future_test.cpp
Last active August 29, 2015 14:05
Using std::future for data flow from one producer to multiple consumers. See http://stackoverflow.com/a/25339704/841830
/**
* This is the full example code for the StackOverflow answer here: http://stackoverflow.com/a/25339704/841830
*
* @copyright Darren Cook, 2014. MIT License.
*/
#include <stdio.h>
#include <iostream>
#include <future>
#include <random>
@DarrenCook
DarrenCook / test.R
Created August 8, 2012 03:59
R: Strange ccf result with xts data
library(xts)
tmp1=dget("tmp1.txt")
tmp2=dget("tmp2.txt")
ccf(drop(tmp1),drop(tmp2)) #Weird?
tmp2=tail(tmp2,50)
tmp1=tail(tmp1,50)
ccf(drop(tmp1),drop(tmp2)) #Plausible
@DarrenCook
DarrenCook / random_example1.cpp
Created March 1, 2012 00:34
Show usage of C++ random (tr1 or C++11)
#include <iostream>
#include <boost/tr1/random.hpp>
//#include <tr1/random.hpp> //If your compiler supports it
//#include <random> //If using c++11; then the "tr1::" prefixes can be removed.
using namespace std;
//Random number generator can be global. Use a mutex if program is multi-threaded.
tr1::mt19937 random_generator;
@DarrenCook
DarrenCook / example6c.variaion3.cpp
Created February 15, 2012 03:05
Use two io_services, with strand for timer, but not for PrintNum
#include <boost/asio.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/bind.hpp>
#include <iostream>
boost::mutex global_stream_lock;
void WorkerThread( boost::shared_ptr< boost::asio::io_service > io_service )
@DarrenCook
DarrenCook / example6c.variation2.cpp
Created February 15, 2012 02:29
Use strand for timer, but not for PrintNum
#include <boost/asio.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/bind.hpp>
#include <iostream>
boost::mutex global_stream_lock;
void WorkerThread( boost::shared_ptr< boost::asio::io_service > io_service )
@DarrenCook
DarrenCook / example6c.variation1.cpp
Created February 15, 2012 02:15
asio: Use strand for PrintNum, but not for the TimerHandler
#include <boost/asio.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/bind.hpp>
#include <iostream>
boost::mutex global_stream_lock;
void WorkerThread( boost::shared_ptr< boost::asio::io_service > io_service )