Monday, July 20, 2009

Calling a member function for all STL map values (in a single line of code)


int newSize = 50;
typedef std::map<int, vector<double>> MyMap;

// call vector.resize(newSize) for all values (pair->second) of STL map
for_each(m_map.begin(), m_map.end(),
   tr1::bind(
     mem_fun_ref(&vector<double>::resize),
        tr1::bind(&MyMap::value_type::second, tr1::placeholders::_1),
        newSize));

Thursday, July 16, 2009

Sociological poll's results are clustered


Occasionally I watch some TV news programs that do polling on various political and social issues. First of all - the fact of existence of such polls is curious by itself, since it depicts how many simple minded peoples there is out there happily paying for the phone calls to poll numbers just to express their opinion. In my view all those polls are nothing more that side revenue generation options for TV/phone corps and specifically designed for it.

Anyway I've noted an interesting fact - those results have some clustering patterns - both in time and quantitative space and let me explain what I mean.
Quantitatively - results are always clustered around the following ratios:
98:2
90:10
2/3: 1/2
1/2: 1/2

I didn't done a massive statistic on it, but it's my observation. Isn't that curious?

Now regarding "time clustering" - if poll results would be very biased, i.e. huge majority in favor of a certain option (like 98:2 or 90:10) - then usually during the very first seconds (something like 30 - 40 sec's) of the poll - the minority option would be the leading one! It's seems like people supporting an option which is really not favorable in view of the majority are reacting much more actively than the average citizen.

My lecture on distributed computing


Here is my lecture on distributed computing which I presented recently to my colleagues.
(Some of the slides were taken from open materials that I've googled out.)
I think that Distributed Computing/Grid/Clouds and related technologies are going to be in the center of next technological boom/bubble cycle.
This is both because technology seems to be cheap and mature enough to crop the fruits and since it would be employed by Energy Grid / EnergyNET..

Thursday, June 25, 2009

Use Beyond Compare with Team Foundation Server in VS 2008/VS2005



VS2008 → Tools → Source Control → Visual Studio Foundation Service → Configure User Tools:
  • Compare → C:\Program Files\Beyond Compare 3\BComp.exe → %1 %2

  • Merge → C:\Program Files\Beyond Compare 3\BComp.exe → %1 %2 /savetarget=%4 /title1=%6 /title2=%7


Sunday, June 21, 2009

Addin favicon to your blog




Here is how to add Favicon to your blog:



ThreadPool.QueueUserWorkItem() could be very slow

ThreadPool.QueueUserWorkItem() could be very slow if callback being executed as a work item calls Thread.Sleep(). Consider the following example:



  1. using System;
  2. using System.Threading;
  3.  
  4. namespace Test
  5. {
  6.   class Program
  7.   {
  8.     const int waitTime = 10000;
  9.     static void Main(string[] args)
  10.     {
  11.       for (int i = 0; i < 10; i++ )
  12.         ThreadPool.QueueUserWorkItem( TestProc, i);
  13.       Console.ReadKey();
  14.     }
  15.  
  16.     static void TestProc(object stateInfo)
  17.     {
  18.       Console.WriteLine("Item number #{0} at {1}", (int)stateInfo, DateTime.Now);
  19.       Thread.Sleep(waitTime);
  20.     }
  21.   }
  22. }




The problem is that thread pool waits around 500 ms before allocating a new thread.
You may solve it by pre-specifying a minimal amount of threads in your application:
ThreadPool.SetMinThreads(20, 200);

Sand Requiem - devoted to soviet soldiers and people fallen in war that started 69 years ago...