<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Marius Bancila's Blog</title>
	<atom:link href="http://mariusbancila.ro/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://mariusbancila.ro/blog</link>
	<description>Sharing my opinions and ideas!</description>
	<lastBuildDate>Wed, 10 Mar 2010 10:20:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Questionaire on concurrency</title>
		<link>http://mariusbancila.ro/blog/2010/03/10/questionaire-on-concurrency/</link>
		<comments>http://mariusbancila.ro/blog/2010/03/10/questionaire-on-concurrency/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 10:20:48 +0000</pubDate>
		<dc:creator>mariusbancila</dc:creator>
				<category><![CDATA[Parallel Programming]]></category>
		<category><![CDATA[concurrency]]></category>
		<category><![CDATA[multithreads]]></category>
		<category><![CDATA[parallel]]></category>
		<category><![CDATA[survey]]></category>

		<guid isPermaLink="false">http://mariusbancila.ro/blog/?p=473</guid>
		<description><![CDATA[I think application development faces two challenges nowadays: 64-bit and multi-core/many-core hardware. Switching from 32 to 64 bit is just another step in the evolution of processors. There was a time when we switched from 8 to 16, and then from 16 to 32. There are problems that arise every time, but probably in 10-20 [...]]]></description>
			<content:encoded><![CDATA[<p>I think application development faces two challenges nowadays: 64-bit and multi-core/many-core hardware. Switching from 32 to 64 bit is just another step in the evolution of processors. There was a time when we switched from 8 to 16, and then from 16 to 32. There are problems that arise every time, but probably in 10-20 years we will have 128 bit platforms. On the other hand, multi-core/many-core is a different shift not only in development but also thinking. We either run one core or multiple core processors. My working stations has 8 cores (4 physical and 4 virtualized) and so does my laptop. Still, I don&#8217;t see an 8 times improvement of the applications running on these machines; yet I know 8 times I not what I should expect. But not even 4 times. For instance, the time for building from scratch the application I&#8217;ve working on with Visual Studio 2008 dropped from 20 minutes to 8 minutes; that&#8217;s a 2.5 improvement. I know that having N cores doesn&#8217;t mean that applications can run N times faster, because not everything can run in several threads, and then we have problems with resource access, synchronization and others. All these prevent applications run N times faster. But the problem is that we are not thinking in parallel. We are still used to program in a single thread; and when I say that I mean not only most developers are not used to do parallelization for boosting performance of some routines, but also many operations are run in the main (UI) thread, making that GUI freeze.</p>
<p>Therefore I would like to get some feedback from people working in applications development to get an idea about awareness, issues, solutions regarding concurrency. Please take several minutes to answer the questions in this survey.</p>
<p>I&#8217;d like to quote James Reinders, lead evangelist and Director of Marketing and Business Development for Intel Software Development Products, who said that:</p>
<blockquote><p>I am still confident that software development in 2016 will not be kind to programmers who have not learned to &#8220;Think Parallel.&#8221;</p></blockquote>
<blockquote><p>The &#8220;not parallel&#8221; era we are now exiting will appear to be a very primitive time in the history of computers when people look back in a hundred years. The world works in parallel, and it is time for computer programs to do the same.</p></blockquote>
<blockquote><p>Doing one thing at a time is &#8220;so yesterday.&#8221;</p></blockquote>
<p>The questionnaire bellow is also available <a href="https://spreadsheets.google.com/viewform?hl=en&#038;formkey=dE5mRlc2ejhXMVpaSUtPZmkzaHZkanc6MA" target="_blank">here</a>.</p>
<p><iframe src="https://spreadsheets.google.com/embeddedform?formkey=dE5mRlc2ejhXMVpaSUtPZmkzaHZkanc6MA" width="700" height="3400" frameborder="0" marginheight="0" marginwidth="0">Loading&#8230;</iframe></p>
<p>Thank you for answering the questionnaire.</p>
]]></content:encoded>
			<wfw:commentRss>http://mariusbancila.ro/blog/2010/03/10/questionaire-on-concurrency/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Helpers For Multithreading in C++</title>
		<link>http://mariusbancila.ro/blog/2010/02/01/helpers-for-multithreading-cpp/</link>
		<comments>http://mariusbancila.ro/blog/2010/02/01/helpers-for-multithreading-cpp/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 20:32:17 +0000</pubDate>
		<dc:creator>mariusbancila</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Parallel Programming]]></category>
		<category><![CDATA[C++ multithreads threads concurrency]]></category>

		<guid isPermaLink="false">http://mariusbancila.ro/blog/?p=466</guid>
		<description><![CDATA[On of the most important challenges nowadays in programming is concurrency. If we don&#8217;t learn to write programs that are able to run on multiple cores the progress in hardware will be pointless. But when you run multiple threads for various processing you might face the situation when you have to write over and over [...]]]></description>
			<content:encoded><![CDATA[<p>On of the most important challenges nowadays in programming is concurrency. If we don&#8217;t learn to write programs that are able to run on multiple cores the progress in hardware will be pointless. But when you run multiple threads for various processing you might face the situation when you have to write over and over again same or similar code for creating the threads, setting up the parameters for the threads, joining the threads, checking the result, cleaning-up, etc.</p>
<p>In this post I will show how you can create some helpers in C++ to simplify this process. This is not going to be a full solution, neither a solution that fits all needs, but can be a start.</p>
<p>What I would like to have is a helper class that will take care of:</p>
<ul>
<li>finding how many threads can run (considering each available core can run a thread)</li>
<li>creating and starting the threads</li>
<li>joining the threads</li>
<li>checking the result of the threads execution</li>
<li>cleaning up</li>
</ul>
<p>The class show bellow does just that.</p>
<pre class="prettyprint">
#include < windows.h >

class ThreadHelper
{
	LPVOID* m_Params;
	int m_ThreadsNo;

private:
	int GetProcessorsCount()
	{
		SYSTEM_INFO info;
		::GetSystemInfo(&amp;info);
		return info.dwNumberOfProcessors;
	}

public:
	ThreadHelper()
	{
		m_ThreadsNo = GetProcessorsCount();

		m_Params = new LPVOID[m_ThreadsNo];
		for(int i = 0; i < m_ThreadsNo; ++i)
			m_Params[i] = NULL;
	}

	ThreadHelper(int threadsNo)
	{
		if(threadsNo < 1)
			m_ThreadsNo = GetProcessorsCount();
		else
			m_ThreadsNo = threadsNo;

		m_Params = new LPVOID[m_ThreadsNo];
		for(int i = 0; i < m_ThreadsNo; ++i)
			m_Params[i] = NULL;
	}

	~ThreadHelper()
	{
		delete [] m_Params;
	}

	int GetThreadsNo() const {return m_ThreadsNo;}
	bool SetThreadParams(int threadIndex, LPVOID lpData)
	{
		if(threadIndex >= 0 &#038;&#038; threadIndex < m_ThreadsNo)
		{
			m_Params[threadIndex] = lpData;
			return true;
		}

		return false;
	}

	bool Run(LPTHREAD_START_ROUTINE threadProc, BOOL startImmediatelly, DWORD timeout = INFINITE)
	{
		bool success = false;

		HANDLE* hThreads = new HANDLE[m_ThreadsNo];
		DWORD* dwThreadIds = new DWORD[m_ThreadsNo];

		bool allThreadsOK = true;

		// create the threads
		for(int i = 0; i < m_ThreadsNo &amp;&amp; allThreadsOK; ++i)
		{
			hThreads[i] = ::CreateThread(
				NULL,
				0,
				threadProc,
				m_Params[i],
				startImmediatelly ? 0 : CREATE_SUSPENDED,
				&amp;dwThreadIds[i]);

			if(hThreads[i] == NULL)
			{
				for(int j = 0; j < i; ++j)
				{
					::CloseHandle(hThreads[j]);
				}

				allThreadsOK = false;
			}
		}

		if(allThreadsOK)
		{
			// start the threads if they were suspended first
			if(!startImmediatelly)
			{
				for(int i = 0; i < m_ThreadsNo; ++i)
				{
					::ResumeThread(hThreads[i]);
				}
			}

			// wait for all threads
			DWORD joinret = ::WaitForMultipleObjects(
				m_ThreadsNo,
				hThreads,
				TRUE,
				timeout);

			if(joinret == WAIT_FAILED)
			{

			}
			else if(joinret = WAIT_TIMEOUT)
			{

			}
			else if(joinret >= WAIT_OBJECT_0 &amp;&amp; joinret < WAIT_OBJECT_0 + m_ThreadsNo)
			{
				success = true;
			}
			else if(joinret >= WAIT_ABANDONED_0 &amp;&amp; joinret < WAIT_ABANDONED_0 + m_ThreadsNo)
			{

			}

			// close the thread handles
			for(int i = 0; i < m_ThreadsNo; ++i)
			{
				::CloseHandle(hThreads[i]);
			}
		}

		delete [] hThreads;
		delete [] dwThreadIds;

		return success;
	}
};
</pre>
<p>This helper class contains:</p>
<ul>
<li>one parameter-less constructor that identifies the number of available processors and sets the threads count equal to the processors count</li>
<li>one constructor that takes the number of threads that should be created</li>
<li>one method (SetThreadParams) for setting the parameters for each thread that will be created</li>
<li>one method (Run) that creates and runs the thread, waits for them and checks the result of the execution</li>
</ul>
<p>As you can see the Run() method is simplistic. It does not handle for instance timed out or abandoned thread executions. Also it joins all threads, waiting until all of them finished execution. A more flexible method could wait only until the first thread finishes and then maybe closes the other threads. But as I said, this is a sample and not a complete solution.</p>
<p>Having this helper set up, I will start several threads to find the prime numbers in a sequence and print them in the console. </p>
<p>The following function computes whether a number is prime/</p>
<pre class="prettyprint">
#include < cmath >

bool IsPrime(int number)
{
	const int max = static_cast< int >(
		std::sqrt(static_cast< double >(number))) + 1;

	for (int i=2; i!=max; ++i)
	{
		if (number % i == 0) return false;
	}

	return true;
}
</pre>
<p>The thread procedure will run through a sub-sequence of a vector of integers and verify if each element is prime. I will use the following structure to pass the sequence bounds to the thread procedure:</p>
<pre class="prettyprint">
struct vector_bounds
{
	std::vector< int >::const_iterator begin;
	std::vector< int >::const_iterator end;
};
</pre>
<p>The thread procedure could look like this:</p>
<pre class="prettyprint">
static CRITICAL_SECTION cs;

DWORD WINAPI FindPrimes(LPVOID lpData)
{
	vector_bounds* bounds = static_cast< vector_bounds* >(lpData);
	if(bounds == NULL)
		return 1;

	for(std::vector< int >::const_iterator cit = bounds->begin;
		cit != bounds->end; ++cit)
	{
		if(IsPrime(*cit))
		{
			EnterCriticalSection(&amp;cs);

			std::cout << *cit << std::endl;

			LeaveCriticalSection(&amp;cs);
		}
	}

	return 0;
};
</pre>
<p>To print to the console a locking mechanism is necessary, otherwise prints from two different threads could collide. The critical section will be initialized before the threads are started.</p>
<p>What remains to be done is generating a sequence of integers, setting up the parameters with the sequence bounds for each thread and run the threads using the helper.</p>
<pre class="prettyprint">
int main()
{
	// generate some random numbers
	srand((unsigned long)time(NULL));
	std::vector< int > numbers;
	std::generate_n(std::back_inserter(numbers), 1000, rand);

	// create the thread helper
	ThreadHelper helper(4);
	int threads = helper.GetThreadsNo();

	// create the parameters for the threads
	std::vector< vector_bounds > params;
	std::vector< int >::const_iterator begin = numbers.begin();
	size_t partitionsize = numbers.size()/threads;

	for(int i = 0; i < threads; ++i)
	{
		vector_bounds bound;
		bound.begin = begin;
		bound.end = (i == threads - 1) ? numbers.end() : begin + partitionsize;
		params.push_back(bound);

		begin = bound.end;
	}

	for(int i = 0; i < threads; ++i)
		helper.SetThreadParams(i, &amp;params[i]);

	// run the threads
	InitializeCriticalSection(&amp;cs);

	std::cout << "start running..." << std::endl;

	bool success = helper.Run(FindPrimes, FALSE);

	std::cout << "finished " << (success? "successfully" : "failed") << std::endl;

	DeleteCriticalSection(&amp;cs);

	return 0;
}
</pre>
<p>Having this threads helper class, what I need to do when running some processing in several threads is:</p>
<ul>
<li>setup thread parameters (if the case)</li>
<li>write the thread procedure</li>
<li>create a ThreadHelper object and initialize it</li>
<li>run the threads and collect the results</li>
</ul>
<p>The helper class prevents writing same code over and over again and helps focusing on the most important tasks: writing the thread procedure. As I said earlier it is not a full solution, nor one that fits all scenarios, but you can develop it to suit your needs.</p>
]]></content:encoded>
			<wfw:commentRss>http://mariusbancila.ro/blog/2010/02/01/helpers-for-multithreading-cpp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows 7 Quotes Problem</title>
		<link>http://mariusbancila.ro/blog/2010/01/15/windows-7-quotes-problem/</link>
		<comments>http://mariusbancila.ro/blog/2010/01/15/windows-7-quotes-problem/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 08:44:45 +0000</pubDate>
		<dc:creator>mariusbancila</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[keyboard]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[win7]]></category>

		<guid isPermaLink="false">http://mariusbancila.ro/blog/?p=463</guid>
		<description><![CDATA[For several months, after I installed Windows 7 at home I had a very annoying problem: whenever I was writing double quotes (&#8220;) or single quotes (&#8216;) in some text editors and all browsers, the quotes did not appear. Only after I was typing another character, then both the opening and the closing quotes were [...]]]></description>
			<content:encoded><![CDATA[<p>For several months, after I installed Windows 7 at home I had a very annoying problem: whenever I was writing double quotes (&#8220;) or single quotes (&#8216;) in some text editors and all browsers, the quotes did not appear. Only after I was typing another character, then both the opening and the closing quotes were shown, followed by the character (like &#8220;&#8221;X or &#8221;X, instead of &#8220;X&#8221; or &#8216;X&#8217;). And when pressing some characters, like A or I, instead of getting &#8220;&#8221;A or &#8220;&#8221;I what was showing up was an Ä or Ï with two points on top. To get &#8220;X&#8221;, I had to type quote followed by space followed by X and then quote again. Really annoying.</p>
<p>The curious thing was that my environment was similar to the one I had at the office: Windows 7 Ultimate, Visual Studio 2008 SP1, Office 2007, same browsers, etc. So I had to rule out a problem with Visual Studio. It must have been some weird setting in Windows 7, though I had done identical installations at home and at the office. Well, it turned out I didn&#8217;t have identical setups: at home I had both Romanian and English keyboard layouts, and for English I had both &#8220;US&#8221; and &#8220;United States-International&#8221;, the later being the default input language for the English layout.</p>
<img alt="Keyboard input" src="/blog/wp-content/uploads/2010/01/keyboardinput.png" title="Keyboard input" width="431" height="491" />
<p>Changing the default input language to <strong>English (United States) &#8211; US</strong> (as shown in the image above) solved this problem (without restarting Windows, only the applications where the problem occurred).</p>
<p>You can find this from Control Panel > Change Keyboard or other input methods > Keyboard and Languages > Change keyboards. </p>
]]></content:encoded>
			<wfw:commentRss>http://mariusbancila.ro/blog/2010/01/15/windows-7-quotes-problem/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Weasel Implementation in C#</title>
		<link>http://mariusbancila.ro/blog/2010/01/11/weasel-implementation-in-csharp/</link>
		<comments>http://mariusbancila.ro/blog/2010/01/11/weasel-implementation-in-csharp/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 10:08:13 +0000</pubDate>
		<dc:creator>mariusbancila</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[dawkins]]></category>
		<category><![CDATA[evolution]]></category>
		<category><![CDATA[simulation]]></category>
		<category><![CDATA[weasel]]></category>

		<guid isPermaLink="false">http://mariusbancila.ro/blog/?p=455</guid>
		<description><![CDATA[In the book The Blind Watchmaker, Richard Dawkins explains how evolution happens through accumulated small random variations (or mutations) filtered by the natural selection, as opposed to the mainstream misinterpretation that evolution happens in big leaps. He proposes a computer program, called weasel, to demonstrate how the accumulated small improvements (mutations that bring a benefit [...]]]></description>
			<content:encoded><![CDATA[<p>In the book <a href="http://en.wikipedia.org/wiki/The_Blind_Watchmaker" target="_blank">The Blind Watchmaker</a>, <a href="http://en.wikipedia.org/wiki/Richard_Dawkins" target="_blank">Richard Dawkins</a> explains how evolution happens through accumulated small random variations (or mutations) filtered by the natural selection, as opposed to the mainstream misinterpretation that evolution happens in big leaps. He proposes a computer program, called <a href="http://en.wikipedia.org/wiki/Weasel_program" target="_blank">weasel</a>, to demonstrate how the accumulated small improvements (mutations that bring a benefit to the individual so that it is &#8220;chosen&#8221; by the natural selection) produce faster results.</p>
<blockquote><p>
I don&#8217;t know who it was first pointed out that, given enough time, a monkey bashing away at random on a typewriter could produce all the works of Shakespeare. The operative phrase is, of course, given enough time. Let us limit the task facing our monkey somewhat. Suppose that he has to produce, not the complete works of Shakespeare but just the short sentence &#8216;Methinks it is like a weasel&#8217;, and we shall make it relatively easy by giving him a typewriter with a restricted keyboard, one with just the 26 (capital) letters, and a space bar. How long will he take to write this one little sentence?</p>
<p>[...]</p>
<p>We again use our computer monkey, but with a crucial difference in its program. It again begins by choosing a random sequence of 28 letters, just as before &#8230; it duplicates it repeatedly, but with a certain chance of random error – &#8216;mutation&#8217; – in the copying. The computer examines the mutant nonsense phrases, the &#8216;progeny&#8217; of the original phrase, and chooses the one which, however slightly, most resembles the target phrase, METHINKS IT IS LIKE A WEASEL.
</p></blockquote>
<p>The phrase &#8220;METHINKS IT IS LIKE A WEASEL&#8221; is from Hamlet:</p>
<blockquote><p>
<strong>Hamlet</strong>: Do you see yonder cloud that&#8217;s almost in shape of a camel?<br />
<strong>Polonius</strong>: By the mass, and &#8217;tis like a camel, indeed.<br />
<strong>Hamlet</strong>: Methinks it is like a weasel.
</p></blockquote>
<p>The algorithm as described on Wikipedia, is as follows: </p>
<ol>
<li>Start with a random string of 28 characters.</li>
<li>Make 100 copies of this string, with a 5% chance per character of that character being replaced with a random character.</li>
<li>Compare each new string with the target &#8220;METHINKS IT IS LIKE A WEASEL&#8221;, and give each a score (the number of letters in the string that are correct and in the correct position).</li>
<li>If any of the new strings has a perfect score (28), halt.</li>
<li>Otherwise, take the highest scoring string, and go to step 2.</li>
</ol>
<p>A character is an upper case letter or space, the number of copies per iteration could be 100 and the mutation rate 5%.  </p>
<p>The following C# code is an implementation of the algorithm.</p>
<pre class="prettyprint">
class Weasel1
{
   private const string ALLOWED_CHARS = "ABCDEFGHIJKLMNOPQRSTUVXYWZ ";
   private const string TARGET = "METHINKS IT IS LIKE A WEASEL";
   Random rand = new Random();

   private int Fitness(string candidate)
   {
      int score = 0;
      for (int i = 0; i < candidate.Length; ++i)
      {
         if (candidate[i] == TARGET[i])
            score++;
      }

      return score;
   }

   private string Mutate(string parent)
   {
      StringBuilder builder = new StringBuilder();
      for (int i = 0; i < parent.Length; ++i)
      {
         bool mutate = rand.Next(20) == 10;
         builder.Append(
            mutate ?
            ALLOWED_CHARS[rand.Next(ALLOWED_CHARS.Length)] : parent
            [i]);
      }
      return builder.ToString();
   }

   public void Run(int copies)
   {
      StringBuilder builder = new StringBuilder();
      for (int i = 0; i < TARGET.Length; ++i)
      {
         builder.Append(ALLOWED_CHARS[rand.Next(ALLOWED_CHARS.Length)]);
      }
      string parent = builder.ToString();

      int step = 1;
      Console.WriteLine("{0:D3} {1}", step, parent);

      do
      {
         step++;

         string[] children = new string[copies];
         for (int i = 0; i < copies; ++i)
         {
            children[i] = Mutate(parent);
         }

         int indexMax = 0;
         int scoreMax = 0;
         for (int i = 0; i < copies; ++i)
         {
            int score = Fitness(children[i]);

            if (score > scoreMax)
            {
               scoreMax = score;
               indexMax = i;
            }
         }

         parent = children[indexMax];

         Console.WriteLine("{0:D3} {1}", step, parent);

      } while (parent != TARGET);
   }
}

class Program
{
   static void Main(string[] args)
   {
      Weasel1 weasel = new Weasel1();
      weasel.Run(100);
   }
}
</pre>
<p>Function Fitness() computes how similar an offspring is to the parent, function Mutate() makes a copy of the parent with a 5% chance for each character to mutate. Function Run() runs the algorithm until the target string is reached. A possible output of the program is shown below. Different runs require different number of iterations (even more than 100).</p>
<pre class="prettyprint">
001 E PVBQVRYRNQSRBCDLOCFOGEIB J
002 E PVBQVRYRNQSRBCDLOCFOWEIB J
003 E PVIQVRYRNQSRBCDLOCFOWEIB J
004 EEPLIQVUYRNQSRBCDLOCFOWEIB J
005 EEPLIQVU RNQSRBCDLOCFOWEIB J
006 EEPHIQLU RNQSRBCDLOCFKWEIB J
007 EEPHIQLU RNQSRHCDKOCFKWEIB J
008 EEPHIQLU RNQSSHCDKOCFKWEIB J
009 EEPHIQLU RNQSS CDKOCFKWEIB J
010 EEPHIQLU RNQSS CDKOCWKWEKB L
011 EEPHIQLU RNQSS CDKOCOKWEKB L
012 EEPHIQLU RN SS CDKOGOKWEKB L
013 EEPHIQLU RN SS LDKOGOKWEKB L
014 EEPHIQLU RT SS LDKOGOKWEKB L
015 EEPHIQLU RT SS LDKOGOKWEKBEL
016 EEPHIQLU RT SS LPKOGOKWEKBEL
017 EEPHIQLU RT SS LPKOGOKWEKSEL
018 EEPHIQLU IT SS LPKOGOKWEKSEL
019 EEPHIQLU IT SS LIKOGOKWEKSEL
020 EEPHIQLU IT SS LIKOGOKWEKSEL
021 EEKHIQLS IT SS LIKOGOKWEKSEL
022 EEKHIQLS IT SS LIKOGOKWEKSEL
023 EEKHIQLS IT SS LIKO OKWEKSEL
024 EEKHIQLS IT SS LIKO OFWEKSEL
025 EEKHIQLS IT ES LIKO OFWENSEL
026 EEKHINLS IT ES LIKO OFWENSEL
027 EEKHINLS IT ES LIKO O WENSEL
028 EEKHINLS IT ES LIKO O WECSEL
029 EEKHINLS IT BS LIKO O WEHSEL
030 EEKHINLS IT QS LIKO O WEASEL
031 EETHINSS IT QS LIKO O WEASEL
032 EETHINSS IT QS LIKO O WEASEL
033 EETHINSS IT IS LIKO O WEASEL
034 EETHINSS IT IS LIKO O WEASEL
035 EETHINBS IT IS LIKO O WEASEL
036 XETHINBS IT IS LIKO O WEASEL
037 XETHINBS IT IS LIKO O WEASEL
038 XETHINBS IT IS LIKO O WEASEL
039 XETHINBS IT IS LIKO O WEASEL
040 XETHINBS IT IS LIKK O WEASEL
041 XETHINBS IT IS LIKK O WEASEL
042 XETHINBS IT IS LIKK O WEASEL
043 XETHINKS IT IS LIKK O WEASEL
044 XETHINKS IT IS LIKK   WEASEL
045 XETHINKS IT IS LIKK   WEASEL
046 XETHINKS IT IS LIKK   WEASEL
047 XETHINKS IT IS LIKE   WEASEL
048 XETHINKS IT IS LIKE   WEASEL
049 METHINKS IT IS LIKE   WEASEL
050 METHINKS IT IS LIKE   WEASEL
051 METHINKS IT IS LIKE A WEASEL
</pre>
<p>We can change this algorithm to randomize the chance of mutation. The changes to the code are small (basically function Mutate changes to take not only the parent string but only the chance for the mutation rate), but this increases the number of iterations needed to reach the target string.</p>
<pre class="prettyprint">
class Weasel2
{
   const string TARGET = "METHINKS IT IS LIKE A WEASEL";
   const string ALLOWED_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
   Random rand = new Random();

   private double Fitness(string candidate)
   {
      int score = 0;
      for (int i = 0; i < candidate.Length; ++i)
      {
         if (candidate[i] == TARGET[i])
            score++;
      }

      return score;
   }

   private string Mutate(string parent, double rate)
   {
      StringBuilder builder = new StringBuilder();
      foreach(char c in parent)
      {
         builder.Append(
            rand.NextDouble() < rate ?
            c:
            ALLOWED_CHARS[rand.Next(ALLOWED_CHARS.Length)]);
      }

      return builder.ToString();
   }

   public void Run(int copies)
   {
      StringBuilder builder = new StringBuilder();
      for (int i = 0; i < TARGET.Length; ++i)
      {
         builder.Append(ALLOWED_CHARS[rand.Next(ALLOWED_CHARS.Length)]);
      }
      string parent = builder.ToString();

      int step = 1;
      Console.WriteLine("{0:D4} {1}", step, parent);

      do
      {
         string[] children = new string[copies];
         for(int i = 0; i < copies; ++i)
         {
            children[i] = Mutate(parent, rand.NextDouble());
         }

         int indexMax = 0;
         double scoreMax = 0;
         for (int i = 0; i < copies; ++i)
         {
            double score = Fitness(children[i]);

            if (score > scoreMax)
            {
               scoreMax = score;
               indexMax = i;
            }
         }

         parent = children[indexMax];

         Console.WriteLine("{0:D4} {1}", step, parent);
         step++;

      } while (parent != TARGET);
   }
}
</pre>
<p>Here is the output, but because of the bigger number of iterations, only every 20th iteration is shown:</p>
<pre class="prettyprint">
0001 BXZZBDJSZTVYFWRSGNKYEULISWRK
0020 MSTCFNBSTITVIS L KPLEDBRASEC
0040 METCINQSDITVIS LIKW A IRISEW
0060 METLINKSOITJIS LJKW A IGASEW
0080 METLINKSOITJIS LJKX A WEAUEL
0100 METLINKSTKTXIS LIKK A WEAOEL
0120 METHINKS KTXIS LIKH A WEAOEL
0140 METHINKSDKTXIS LIKA A WEASEL
0160 METHINKSEGTXIS LIKA A WEASEL
0180 METHINKSEGTEIS LIKE A WEASEL
0200 METHIMKSEGTMIS LIKE A WEASEL
0220 METHIMKSTITNIS LIKE A WEASEL
0240 METHIAKSTIT IS LIKE A WEASEL
0260 METHIPKSTIT IS LIKE A WEASEL
0280 METHJKKSTOT IS LRKE A WEASEL
0300 METHYQKSCOT IS LRKE A WEASEL
0320 METHFPKSCOT IS LRKE A WEASEL
0340 METHFPKSCGT IS LRKE A WEASES
0360 METHINKS XT IS LMOE A WEAIEL
0380 METHINKS YT IS LMZE A WEAIEL
0400 METHINKS IT IS LMHE A WEAIEL
0420 METHINKS IT IS LEDE A WEANEL
0440 METHINKS IT IS LIPE A WEANYL
0460 METHINKS IT IS LIPE A WEAOYL
0480 METHINKS IT IS LIWE A WEARWL
0500 METHINKS IT IS LIWEDA WEAFWT
0520 METVINKS IT IS LILE A WEABBG
0540 METVINKS IT IS LIJE A WEABTG
0560 METHINKS IT IS LIJE A WEAMRV
0580 METHINKS IT IS LIZE A WEAMRV
0600 METHINKS IT IS LIZE A WEA OV
0620 METHINKS IT IS LIZE A WEAHE
0640 METHINKS IT IS LIJE A WEAHEH
0660 METHINKS IT IS LIFE A WEAHEH
0680 M THINKS IT IS LINE I WXAHEL
0700 MQTHINKS IT IS LIAE I WXASEL
0720 MZTHIRKS IT IS LIKE T WXASEL
0740 METHINKR IT IS LIKE T WRASEL
0760 METOINKI IT IS LIKE T WRASEL
0780 METMINKM IT IS LIKE A WQASEL
0800 METMINKS IT IS LIKE A WQASEL
0820 METJIXKS IT IS LIKE A WQASEL
0840 METJILKS IT IS LIKE A WUASEL
0860 METJIPKS IP IS LIKE A WAASEL
0880 METJIPKS IW IS LIKE A WLASEL
0900 METIIBKS QT IS LIKE A SEASEL
0920 METIIPKS PT IS LIKE A SEASEL
0940 METKINKS PT IS LIKE A TEASEL
0960 METKINKS BT IS LIKE A QEASEL
0980 METWINKS IT IS LIKE A QEASEL
1000 METOINKS IT IS LIKE ANQEASEL
1020 METUINKS IT IS LIKE AHTEASEL
1040 METUINKS IT IS LIKE AMWEASEO
1060 METQINKS IT IS LIKE AMWEASEO
1080 MZTYINKS IT ISULIKE AKWEASEL
1100 MZTYINKS IT ISULIKE APWEADEL
1120 MJTHINKS IT ISULIKE AEWEAQEL
1140 MJTHINKS IT ISULIKE AFWEAUEL
1160 MJTHINKS IT ISCLIKP AVWEABEL
1180 MJTHINKS IT IS LIKP AVWEAGEG
1200 MNTHINKS IT IS LIKM AVWEACE
1220 MNTHINKS IT IS LIKM AQWEACEL
1240 MNTHINKS IT IS LIKMXAKWEAAEL
1260 MNTHINKS CT IS LIKMGAPWEASEL
1280 MPTHINKS IX IS EIK GA WEASEL
1300 METHINKS IX IS LIK RA WEASEL
1320 METHINKS IZ IS LIKEWA WEASEL
1340 METHINKS IZ ISILIKEWA WEASEL
1360 METHINKS IJ ISILIKE A WEASEL
1380 METHINKS IM ISELIKE A WEASEL
1400 METHINKS IM ISELIKE A WEASEL
1420 METHINKS IU ISELIKE A WEASEL
1440 METHINKS IY ISELIKE A WEASEL
1460 METHINKS IT ISVLIKE A WEASEL
1480 METHINKS IT ISCLIKE A WEASEL
1500 METHINKS IT ISCLIKF A WEASEL
1520 METHINKS IT ISTLIKF A WEASEL
1540 METXINKS IT ISOLIKF A WEASEL
1560 MZTXINKS IT ISOLIKC A WEASEL
1580 MATXINKS IT IS LIKC A WEASEL
1600 MATXINKS IT IS LIKE A WEDSEL
1620 METHINKSGITVIC LIKE A WEASEL
1640 METHINKSGITQIC LIKE A WEASEL
1660 METHINLSAITQIC LIKE A WEASEL
1680 METHINLSAITQIH LIKE A WEASEL
1700 METHINGS ITAIH LIKE A WEASEL
1720 METHINGS ITRIS LIKE W WEASEL
1740 METHINVS IT IS LIJE A WEASEL
1760 METHINVS IT IS LIGE A WEASEL
1780 METHINVS IT IS LIGE A WEASEL
1800 METHINVS IT IS LI E A WEASYL
1820 METHIN S IT IS LIKE A WTASYT
1840 METHINQS IT IS LIKE A STASYT
1860 METHINWA IT IS LIKE A IFASES
1880 METHINKA IT IS LIKE A IFASEJ
1900 METHINKA IT YS LIKE O IEAAEL
1920 METHINKU IT YS LIKE O WEAAEL
1940 METHOJKM IT JS LIKE O WEAPEL
1960 METHOJKF IT IS LIKE  RWEATEL
1980 METHFGKF IT IS LIKE ARWBATEL
2000 METHYNKG IT IS LIKE ARWEALEL
2020 METHUNKD IT IS LIKE AAWEAWEL
2040 METHIWKN IT IS LIKE AYWEADEL
2060 METHIUKN IT IS LIKE AKWEAQEL
2080 METHIUKN IT IS LIKE A WEAQEL
2100 METHIAKN IT IS LIKE N WEAQEL
2120 METHINKK IT IS LIKE N WEEQEL
2140 METHDNKQ IT IS LIKE A WEBSEL
2160 METHDNKQ IT IS LIKE A WEBSEL
2180 METHDNKQ IT IS LIKE A WEBSEL
2200 METHMNKQ IT IS LIKE A WEBSEL
2220 MEKHBNKX IT IS LIKE A WEBSEL
2240 MEBHQNKS IT IS LIKE A WEBSEL
2260 METHQNKS IT IS LIKEZA WEFSEL
2280 METHGNKS IT IS LIKEZA WESSEL
2300 METHGNKS IT IS LIKEZA WEWSEL
2320 METHLNKS IT IP BIKE A WEOSEL
2340 METHYNKS IT IB SIKE A WEQSEL
2360 METHINKS ITQIJ LIKE A WEQSEL
2380 METHINKS ITIIJ LIKE A WEYSTL
2400 METQINKS ITIIJ LIKE A WEASGL
2420 METHINKS ITIIJJLIKE A WEASGL
2440 METHINKS ITQIWJLIKE A WEAS L
2460 METHINKS ITZIWJLIKE A WEASCL
2480 METHINKS IT IDLLIZE A UEASCL
2500 METHINKS IT ID LIZE A IEASZL
2520 METHINKS IT ID LIZE A IEASZL
2540 METHINKS IT IB LIZE A XEASOL
2560 METHINKS IT IB LIAE A  EASOL
2580 METHINKS IT IBVLICE A  EASEL
2600 METHINKS IT IBVLIKE A  EASEL
2620 METHINKS IT IKDLIKE A  EASEL
2640 METHINKS IT IKNLIKE A HEASEL
2660 METHINKS IT IKNLIKE A HIASEL
2680 METHINKS IT IZNLIKE A HIASEL
2700 METHINKS IT IZNLIKE A WOASEL
2720 METHINKS IT ISNLIKE A WOASEL
2740 METHINKS IT ISNLIKE M WSASEL
2760 METHINKS IT ISVLIKE M WXASEL
2780 METHINKS IT IS LIKE S WEASEL
2785 METHINKS IT IS LIKE A WEASEL
</pre>
<p>Notice that matching letters are not immutable. A letter, even if it matches one in the target string can change at any time.</p>
<p>You can find similar implementations in several programming languages on the <a href="http://rosettacode.org/wiki/Evolutionary_algorithm" target="_blank">Rosetta Code website</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://mariusbancila.ro/blog/2010/01/11/weasel-implementation-in-csharp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>More God Modes in Windows 7</title>
		<link>http://mariusbancila.ro/blog/2010/01/08/more-god-modes-in-windows-7/</link>
		<comments>http://mariusbancila.ro/blog/2010/01/08/more-god-modes-in-windows-7/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 21:37:05 +0000</pubDate>
		<dc:creator>mariusbancila</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[godmode]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[win7]]></category>

		<guid isPermaLink="false">http://mariusbancila.ro/blog/?p=451</guid>
		<description><![CDATA[In my previous post I wrote about a feature called &#8220;god mode&#8221; available in Windows 7 and Vista. By creating a folder with a specific name you get one entry point to all the commands available in Control Panel. It was reported that several such shortcuts exits. Below is an image with the 16 folders [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://mariusbancila.ro/blog/2010/01/06/playing-god-in-windows-7/">previous post</a> I wrote about a feature called &#8220;god mode&#8221; available in Windows 7 and Vista. By creating a folder with a specific name you get one entry point to all the commands available in Control Panel. It was <a href="http://www.tomshardware.com/news/GodMode-Windows-7-Secret-Shortcuts,9373.html" target="_blank">reported</a> that several such shortcuts exits. Below is an image with the 16 folders that are god modes.</p>
<div class="wp-caption alignnone" style="width: 723px"><img alt="" src="/blog/wp-content/uploads/2010/01/godmode5.png" title="All 16 god modes" width="713" height="558" /><p class="wp-caption-text">All 16 god modes</p></div>
<p>You can create them all by making and running (from the desired parent folder) a .cmd or .bat file with the following content:</p>
<pre class="prettyprint">
mkdir ControlPanel.{ED7BA470-8E54-465E-825C-99712043E01C}
mkdir LocationSensor.{00C6D95F-329C-409a-81D7-C46C66EA7F33}
mkdir BiometricDevice.{0142e4d0-fb7a-11dc-ba4a-000ffe7ab428}
mkdir PowerOptions.{025A5937-A6BE-4686-A844-36FE4BEC8B6D}
mkdir TaskbarIcons.{05d7b0f4-2121-4eff-bf6b-ed3f69b894d9}
mkdir Credentials.{1206F5F1-0569-412C-8FEC-3204630DFB70}
mkdir InstallFromNetwork.{15eae92e-f17a-4431-9f28-805e482dafd4}
mkdir DefaultPrograms.{17cd9488-1228-4b2f-88ce-4298e93e0966}
mkdir PublicKeys.{1D2680C9-0E2A-469d-B787-065558BC7D43}
mkdir WifiNetworks.{1FA9085F-25A2-489B-85D4-86326EEDCD87}
mkdir Network.{208D2C60-3AEA-1069-A2D7-08002B30309D}
mkdir Computer.{20D04FE0-3AEA-1069-A2D8-08002B30309D}
mkdir Printers.{2227A280-3AEA-1069-A2DE-08002B30309D}
mkdir workplaceConnetions.{241D7C96-F8BF-4F85-B01F-E2B043341A4B}
mkdir Firewall.{4026492F-2F69-46B8-B9BF-5654FC07E423}
mkdir PerformanceRatings.{78F3955E-3B90-4184-BD14-5397C15F1EFC}
</pre>
<p>(You can get the GUIDs of the folders from the above listing).</p>
<p>You can read more about this <a href="http://www.tomshardware.com/news/GodMode-Windows-7-Secret-Shortcuts,9373.html" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://mariusbancila.ro/blog/2010/01/08/more-god-modes-in-windows-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Playing God in Windows 7</title>
		<link>http://mariusbancila.ro/blog/2010/01/06/playing-god-in-windows-7/</link>
		<comments>http://mariusbancila.ro/blog/2010/01/06/playing-god-in-windows-7/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 08:26:49 +0000</pubDate>
		<dc:creator>mariusbancila</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[godmode]]></category>
		<category><![CDATA[win7]]></category>

		<guid isPermaLink="false">http://mariusbancila.ro/blog/?p=446</guid>
		<description><![CDATA[There has been some buzz in the last few days about a feature in Windows 7 called &#8220;God mode&#8221;. Well, it doesn&#8217;t empower you as a God but allows you to access all the nested features available in Control Panel from a single entry point. All you have to do is creating a folder (or [...]]]></description>
			<content:encoded><![CDATA[<p>There has been some buzz in the last few days about a feature in Windows 7 called &#8220;God mode&#8221;. Well, it doesn&#8217;t empower you as a God but allows you to access all the nested features available in Control Panel from a single entry point. All you have to do is creating a folder (or renaming an existing one) with the name <em><strong>GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}</strong></em></p>
<div class="wp-caption alignnone" style="width: 521px"><img alt="" src="/blog/wp-content/uploads/2010/01/godmode1.png" title="Folder GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}" width="511" height="156" /><p class="wp-caption-text">Create a folder with the name GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}</p></div><br />
After the folder was created/renamed its icon changes to the icon used for Control Panel.<br />
<div class="wp-caption alignnone" style="width: 520px"><img alt="" src="/blog/wp-content/uploads/2010/01/godmode2.png" title="Control Panel icon" width="510" height="156" /><p class="wp-caption-text">Same icon as Control Panel</p></div><br />
When you enter the folder you find all the commands that are available in Control Panel, but in a single list with no nesting. So this could be a good place to access quick commands.<br />
<div class="wp-caption alignnone" style="width: 755px"><img alt="" src="/blog/wp-content/uploads/2010/01/godmode3.png" title="Commands available in GodMode folder" width="745" height="540" /><p class="wp-caption-text">Commands available in GodMode folder</p></div>
<p>On the other hand you can get the same from the Start menu by searching for the name. Here is an example of the commands made available when searching for &#8220;defrag&#8221;.<br />
<div class="wp-caption alignnone" style="width: 421px"><img alt="" src="/blog/wp-content/uploads/2010/01/godmode4.png" title="Commands available from Start Menu" width="411" height="475" /><p class="wp-caption-text">Start menu results for &quot;defrag&quot;</p></div><br />
Of course, in this later case, one needs to know what to search for, but in general that should not be a problem.</p>
<p>This feature also works in Windows Vista and Windows Server 2008, but it <a href="http://www.sitepoint.com/blogs/2010/01/05/windows-7-god-mode/#">is reported</a> that is crashes with Vista 64 bit.</p>
<p>This feature only works from Windows Explorer. It is not available from tools like Total Commander or FreeCommander.</p>
]]></content:encoded>
			<wfw:commentRss>http://mariusbancila.ro/blog/2010/01/06/playing-god-in-windows-7/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Great Global Warming Swindle</title>
		<link>http://mariusbancila.ro/blog/2009/12/17/the-great-global-warming-swindle/</link>
		<comments>http://mariusbancila.ro/blog/2009/12/17/the-great-global-warming-swindle/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 21:31:39 +0000</pubDate>
		<dc:creator>mariusbancila</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[warming climate hoax]]></category>

		<guid isPermaLink="false">http://mariusbancila.ro/blog/?p=437</guid>
		<description><![CDATA[Two months ago I was showing my friends a film called &#8220;The Great Global Warming Swindle.&#8221; As the title suggests, the topic of the movie is the global scale deceit about the man-made global warming. A number of important scientists argue that man has nothing to do with the rise of temperature and everything happens [...]]]></description>
			<content:encoded><![CDATA[<p>Two months ago I was showing my friends a film called &#8220;The Great Global Warming Swindle.&#8221; As the title suggests, the topic of the movie is the global scale deceit about the man-made global warming. A number of important scientists argue that man has nothing to do with the rise of temperature and everything happens of natural causes.</p>
<p><script type="text/javascript" src="http://en.sevenload.com/pl/UsTF3KX/500x314/0"></script>
<p>Link: <a href="http://en.sevenload.com/videos/UsTF3KX-The-Great-Global-Warming-Swindle"><img src="http://static.sevenload.net/img/sevenload.png" width="66" height="10" alt="The Great Global Warming Swindle" /></a></p>
<p>After a hacker broke into the computers at the University of East Anglia&#8217;s Climate Research Unit, stole and published on the internet tens of megabytes of data and emails, it seems that the premises for the greatest scandal in modern science are set, and the truth will be finally revealed. These information show that top scientists have deliberately alter data to exaggerate global warming, destroyed embarrassing data, pushed for discrediting scientists that had other views on the topics, and others. This scandal is now referred to as <a href="http://en.wikipedia.org/wiki/Climatic_Research_Unit_e-mail_hacking_incident">Climate-gate</a>.</p>
<p>I suggest that you watch the movie. It explains both what is causing the rise in temperature and why all the fuss around this phenomenon. </p>
<p>Now, the theory about man-driver temperature rise is based on two ideas: temperature variations depend on CO2 level variations, and man activity increases the CO2 in the atmosphere. Here are two charts from Wikipedia that show the variation of temperature in the last 150 years and last 1000 years.</p>
<div class="wp-caption alignnone" style="width: 610px"><a href="http://en.wikipedia.org/wiki/Temperature_record_of_the_past_1000_years"><img alt="Source: Wikipedia - Temperature record of the past 1000 years" src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/bb/Instrumental_Temperature_Record.svg/600px-Instrumental_Temperature_Record.svg.png" title="Instrumental Temperature record of the last 150 years." width="600" height="600" /></a><p class="wp-caption-text">Source: Wikipedia - Temperature record of the past 1000 years</p></div>
<div class="wp-caption alignnone" style="width: 609px"><a href="http://en.wikipedia.org/wiki/Temperature_record_of_the_past_1000_years"><img alt="Source: Wikipedia: 1000 Year Temperature Comparison" src="http://upload.wikimedia.org/wikipedia/commons/b/bb/1000_Year_Temperature_Comparison.png" title="1000 Year Temperature Comparison" width="599" height="442" /></a><p class="wp-caption-text">Source: Wikipedia: 1000 Year Temperature Comparison</p></div>
<p>You can find more charts <a href="http://www.ncdc.noaa.gov/paleo/recons.html">here</a>.</p>
<p>What these charts show is that in the last 150 years the temperature has risen and fallen. The greater rise occurred before 1940. And after 1940, when the world entered an economic boom, the temperature dropped for 3 decades. That doesn&#8217;t make any sense if the original hypothesis, that the more CO2 the greater the temperature, is true, because booming economies mean more CO2 being produced. In fact, the scientist were alarmed that a new ice age was coming. On April 28, 1975, Newsweek published an article about cooling and the effects on the planet. Here is a quote from the article:</p>
<blockquote><p>There are ominous signs that the Earth’s weather patterns have begun to change dramatically and that these changes may portend a drastic decline in food production – with serious political implications for just about every nation on Earth. The drop in food output could begin quite soon, perhaps only 10 years from now. The regions destined to feel its impact are the great wheat-producing lands of Canada and the U.S.S.R. in the North, along with a number of marginally self-sufficient tropical areas – parts of India, Pakistan, Bangladesh, Indochina and Indonesia – where the growing season is dependent upon the rains brought by the monsoon.</p></blockquote>
<p>Read the entire article <a href="http://www.denisdutton.com/cooling_world.htm">here</a>.</p>
<p>Then the question is, is there a link between CO2 and temperature? The answer is yes, but it&#8217;s mostly the other way around: the temperature is driving the CO2 level, with CO2 lagging 800-1000 years behind the temperature changes. Here are some charts of atmospheric CO2 concentration and temperature in lower atmosphere for the last 400,000 years.</p>
<div class="wp-caption alignnone" style="width: 996px"><a href="http://www.geocraft.com/WVFossils/last_400k_yrs.html"><img alt="Atmospheric CO2 Concetrations for last 400,000 years" src="http://www.geocraft.com/WVFossils/PageMill_Images/CO2_0-400k_yrs.gif" title="Atmospheric CO2 Concetrations for last 400,000 years" width="986" height="401" /></a><p class="wp-caption-text">Atmospheric CO2 Concetrations for last 400,000 years</p></div>
<div class="wp-caption alignnone" style="width: 995px"><a href="http://www.geocraft.com/WVFossils/last_400k_yrs.html"><img alt="Temperature of Lower Atmosphere for last 400,000 years" src="http://www.geocraft.com/WVFossils/PageMill_Images/Temp_0-400k_yrs.gif" title="Temperature of Lower Atmosphere for last 400,000 years" width="985" height="395" /></a><p class="wp-caption-text">Temperature of Lower Atmosphere for last 400,000 years</p></div>
<p>Here are several articles on this topic:</p>
<ul>
<li><a href="http://www.geocraft.com/WVFossils/last_400k_yrs.html">Comparison of Atmospheric Temperature with CO2 Over The Last 400,000 Years</a></li>
<li><a href="http://www.co2science.org/articles/V6/N26/EDIT.php">Ice Core Studies Prove CO2 Is Not the Powerful Climate Driver Climate Alarmists Make It Out to Be</a>
</li>
<li><a href="http://www.skepticalscience.com/co2-lags-temperature.htm">CO2 lags temperature &#8211; what does it mean?</a></li>
</ul>
<p>The rise of temperature causes a rise of atmospheric CO2 because when the ocean warm the solubility of CO2 in the water falls, which leads to more CO2 being released into the atmosphere from the oceans. The amount of CO2 released in the atmosphere by man is much less than the one released from the oceans. Why is there a lag between the rise of temperature and CO2? Because the oceans act as a big buffer, but the exact dynamics are not yet well known. However, this doesn&#8217;t mean that the greenhouse effect doesn&#8217;t exist. It does. As more CO2 is released into the atmosphere, it absorbs more radiation reflected by the earth surface, heating the atmosphere. </p>
<p>So why is temperature rising? What is driving it? Well, the answer is the sun. The more solar activity, the more solar wind and cosmic dust hit the atmosphere which influences the formation of clouds and eventually the temperature. The next images shows the correlation between solar sunspots and global temperature variations.</p>
<div class="wp-caption alignnone" style="width: 485px"><a href="http://right-mind.us/blogs/blog_0/archive/2008/02/26/58366.aspx"><img alt="Solar sunspot activity vs. Global temperatur variations" src="http://media.right-mind.us/right-mind/20081229Sunspot_Activity.jpg" title="Solar sunspot activity vs. Global temperatur variations" width="475" height="350" /></a><p class="wp-caption-text">Solar sunspot activity vs. Global temperatur variations</p></div>
<div class="wp-caption alignnone" style="width: 485px"><a href="http://right-mind.us/blogs/blog_0/archive/2008/02/26/58366.aspx"><img alt="400 years of Suspot Observations" src="http://media.right-mind.us/right-mind/20081229_390_Years_of_Sunspot_Observations.jpg" title="400 years of Suspot Observations" width="475" height="200" /></a><p class="wp-caption-text">400 years of Suspot Observations</p></div>
<div class="wp-caption alignnone" style="width: 610px"><a href="http://ossfoundation.us/projects/environment/global-warming/solar"><img alt="Temperature, Co2 &#038; Sunspots" src="http://ossfoundation.us/projects/environment/global-warming/solar/overview/image" title="Temperature, Co2 &#038; Sunspots" width="600" height="480" /></a><p class="wp-caption-text">Temperature, Co2 &#038; Sunspots</p></div>
<p>You can read more about sunspots observations here:</p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Sunspot">Wikipedia: Sunspots</a></li>
<li><a href="http://www.windows.ucar.edu/tour/link=/sun/activity/sunspot_history.html">History of Sunspot Observations</a></li>
<li><a href="http://right-mind.us/blogs/blog_0/archive/2008/02/26/58366.aspx">Solar Sunspot Activity vs. Global Temperature Variations</a></li>
<li><a href="http://www.solarcycle24.com/">Solar Cycle 24</a> &#8211; real time monitoring of the sun activity</li>
</ul>
<p>Of course, not everybody agrees that Temperature, CO2 &#038; sunspots correlate. For instance, you can read the following article that <a href="http://ossfoundation.us/projects/environment/global-warming/solar">claims the opposite</a>. It could be possible that this hypothesis is wrong, as many other theories were proved wrong over time.</p>
<p>Hopefully in the coming years (because this will take some time) the truth will be revealed. It would be silly to waste our efforts on the wrong direction. However, whatever the truth is, consuming the planet&#8217;s resource on a ever growing pace will prove catastrophic. We will never be able to kill the planet. But the planet can terminate us at any time.</p>
]]></content:encoded>
			<wfw:commentRss>http://mariusbancila.ro/blog/2009/12/17/the-great-global-warming-swindle/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>VSBuildStatus Addin Taskbar Progress on Windows 7</title>
		<link>http://mariusbancila.ro/blog/2009/12/09/vsbuildstatus-addin-taskbar-progress-on-windows-7/</link>
		<comments>http://mariusbancila.ro/blog/2009/12/09/vsbuildstatus-addin-taskbar-progress-on-windows-7/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 13:05:13 +0000</pubDate>
		<dc:creator>mariusbancila</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[addin]]></category>
		<category><![CDATA[taskbar]]></category>
		<category><![CDATA[VS2005]]></category>
		<category><![CDATA[VS2008]]></category>
		<category><![CDATA[VS2010]]></category>
		<category><![CDATA[win7]]></category>

		<guid isPermaLink="false">http://mariusbancila.ro/blog/?p=429</guid>
		<description><![CDATA[I have updated my Visual Studio addin that displays the status of a build/clean/deploy action. If you get the latest version, 1.2, and are running Visual Studio 2005, 2008 or 2010 (they are all supported) on Windows 7, the progress of the build is also displayed on the Taskbar, on the item corresponding to the [...]]]></description>
			<content:encoded><![CDATA[<p>I have updated my <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/2A2293B4-1808-44AA-B030-661F6803D8A1" target="_blank">Visual Studio addin</a> that displays the status of a build/clean/deploy action. If you get the latest version, 1.2, and are running Visual Studio 2005, 2008 or 2010 (they are all supported) on Windows 7, the progress of the build is also displayed on the Taskbar, on the item corresponding to the Visual Studio instance.</p>
<p>The following images show no progress, different progress steps, and an error during the build/clean/deploy, both for Visual Studio 2008 and Visual Studio 2010 (Beta 2). </p>
<p><img src="http://www.mariusbancila.ro/archives/addins/VSBuildStatusAddin/vsbuildstatus_noprogress.png" alt="No progress" /></p>
<p><img src="http://www.mariusbancila.ro/archives/addins/VSBuildStatusAddin/vsbuildstatus_progress1.png" alt="Build progress" /></p>
<p><img src="http://www.mariusbancila.ro/archives/addins/VSBuildStatusAddin/vsbuildstatus_progress1.png" alt="Build progress" /></p>
<p><img src="http://www.mariusbancila.ro/archives/addins/VSBuildStatusAddin/vsbuildstatus_error.png" alt="Error during build" /></p>
<p><img src="http://www.mariusbancila.ro/archives/addins/VSBuildStatusAddin/vsbuildstatusaddin_vs2010_progress.png" alt="Build progress" /></p>
<p><img src="http://www.mariusbancila.ro/archives/addins/VSBuildStatusAddin/vsbuildstatusaddin_vs2010_error.png" alt="Error during build" /></p>
<p>This was possible by using the Windows 7 Taskbar interop library available on MSDN Code Gallery <a href="http://code.msdn.microsoft.com/Windows7Taskbar/Release/ProjectReleases.aspx?ReleaseId=2246" target="_blank">here</a>.</p>
<p>You can get the latest version of the addin from the Visual Studio Gallery at this <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/2A2293B4-1808-44AA-B030-661F6803D8A1" target="_blank">link</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://mariusbancila.ro/blog/2009/12/09/vsbuildstatus-addin-taskbar-progress-on-windows-7/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Interface Implementation in C#</title>
		<link>http://mariusbancila.ro/blog/2009/12/08/interface-implementation-in-csharp/</link>
		<comments>http://mariusbancila.ro/blog/2009/12/08/interface-implementation-in-csharp/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 09:46:07 +0000</pubDate>
		<dc:creator>mariusbancila</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[interfaces]]></category>
		<category><![CDATA[OO]]></category>

		<guid isPermaLink="false">http://mariusbancila.ro/blog/?p=419</guid>
		<description><![CDATA[I recently found a piece of code that can be summarized by the following sample:

interface I
{
   void F1();
   void F2();
}

class X
{
   public void F2() { Console.WriteLine("F2"); }
}

class A : X, I
{
   public void F1() { Console.WriteLine("F1"); }
}

As you can see there is an interface I that has [...]]]></description>
			<content:encoded><![CDATA[<p>I recently found a piece of code that can be summarized by the following sample:</p>
<pre class="prettyprint">
interface I
{
   void F1();
   void F2();
}

class X
{
   public void F2() { Console.WriteLine("F2"); }
}

class A : X, I
{
   public void F1() { Console.WriteLine("F1"); }
}
</pre>
<p>As you can see there is an interface <i>I</i> that has two methods, F1 and F2. <i>A</i> is derived from <i>X</i>, that has a method F2, and also implements I, but only contains F1. I was puzzled at first, because I was expecting that <i>A</i> was <i>explictitly</i> implementing all the methods defined in the interface <i>I</i>. But F2 was implemented in <em>X</em>, its base class. After thinking a little bit it all become clear. This was a normal behavior of the compiler.</p>
<p>When a class <i>A</i> implements an interface <i>I</i> it guarantees that it supports (implements) the entire contract that the interface defines. But it does not assert that it will explicitly implement all the interface members within its explicit definition. I&#8217;m stressing on the <i>explicit</i> word here, because <i>A</i> extends (is derived from) <i>X</i>. That means <i>A</i> <i>is an</i> <i>X</i>. Everything that <i>X</i> exposes (i.e. what is visible to its derived classes) is part of <i>A</i> too. </p>
<p>In our case, F2, implemented in <i>X</i>, is also available to <i>A</i>, because <i>A</i> is an <i>X</i>. Since both F1 and F2 are members of <i>A</i>, then it means <i>A</i> fully implements <i>I</i>, which makes the code compile just fine.</p>
<p>How is this helpful? Suppose you have several interfaces that all define one ore several members with the same meaning. </p>
<pre class="prettyprint">
interface I1
{
  void F1();
  void F2();
  int ErrorCode { get; }
}

interface I2
{
  void G1();
  void G2();
  int ErrorCode { get; }
}

interface I3
{
  void H1();
  int ErrorCode { get; }
}
</pre>
<p>Instead of providing the same implementation several times, like in the following code, you can have only one implementation for the common functionality.</p>
<pre class="prettyprint">
class A : I1
{
  private int m_errorCode;

  public void F1() {}
  public void F2() {}
  public int ErrorCode { get {return m_errorCode;} }
}

class B : I2
{
  private int m_errorCode;

  public void G1() {}
  public void G2() {}
  public int ErrorCode { get {return m_errorCode;} }
}

class C : I3
{
  private int m_errorCode;

  public void H1() {}
  public int ErrorCode { get {return m_errorCode;} }
}
</pre>
<p>We can create one class that provides the implementation for ErrorCode and let the others extend it and implement the corresponding interface.</p>
<pre class="prettyprint">
class X
{
  protected int m_errorCode;

  public int ErrorCode { get {return m_errorCode;} }
}

class A : X, I1
{
  public void F1() {}
  public void F2() {}
}

class B : X, I2
{
  public void G1() {}
  public void G2() {}
}

class C : X, I3
{
  public void H1() {}
}
</pre>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://mariusbancila.ro/blog/2009/12/08/interface-implementation-in-csharp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>F# Operations on List</title>
		<link>http://mariusbancila.ro/blog/2009/12/07/fsharp-operations-on-list/</link>
		<comments>http://mariusbancila.ro/blog/2009/12/07/fsharp-operations-on-list/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 09:38:59 +0000</pubDate>
		<dc:creator>mariusbancila</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[list]]></category>

		<guid isPermaLink="false">http://mariusbancila.ro/blog/?p=412</guid>
		<description><![CDATA[In this post I want to show how you can implement common list operations: union, intersection, difference and concatenation.
Concatenation is the simplest of them all, because type List already has a function call append that does everything for you.

let concat left right =
    List.append left right

The union of two lists is a [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I want to show how you can implement common list operations: union, intersection, difference and concatenation.</p>
<p>Concatenation is the simplest of them all, because type List already has a function call append that does everything for you.</p>
<pre class="prettyprint">
let concat left right =
    List.append left right
</pre>
<p>The union of two lists is a list containing all the distinct elements from the two original lists. We can implement this operation by concatenating the two lists firsts, and the filtering the distinct elements.</p>
<pre class="prettyprint">
let union left right =
    List.append left right |> Seq.distinct |> List.ofSeq
</pre>
<p>The intersection of two lists is a list containing all the elements of the first list that also appear in the second list. We can implement this by interating through the elements of the first list and checking whether the element appears in the second list. To do this in the shortest possible time, with constant lookup time, we can use a HashSet collection. The result is an O(m+n) complexity instead of O(m*n) if you used brute force.</p>
<pre class="prettyprint">
let intersection (left:list< 'a >) (right:list< 'a >) =
    let cache = HashSet< 'a >(right, HashIdentity.Structural)
    left |> List.filter (fun n -> cache.Contains n)
</pre>
<p>The difference of two lists is a list containing all the elements from the first list that are not part of the second list. The implementation of difference is very similar to the implementation of the intersection. All that differs is the lambda used for the filtering. </p>
<pre class="prettyprint">
let difference (left:list< 'a >) (right:list< 'a >) =
    let cache = HashSet< 'a >(right, HashIdentity.Structural)
    left |> List.filter (fun n -> not (cache.Contains n))
</pre>
<p>Let&#8217;s see all these put to a use:</p>
<pre class="prettyprint">
let main() =
    let c = concat [4;3;2;1] [2;3;5]
    printfn "%A" c

    let u = union [4;3;2;1] [2;3;5]
    printfn "%A" u

    let i = intersection [4;3;2;2;1] [2;3;5]
    printfn "%A" i

    let d = difference [4;3;2;1] [2;3;5]
    printfn "%A" d

main()
</pre>
<p>This program yields the following output:</p>
<pre class="prettyprint">
[4; 3; 2; 1; 2; 3; 5]
[4; 3; 2; 1; 5]
[3; 2; 2]
[4; 1]
</pre>
<p>Notice that these operations work with unsorted lists. You don&#8217;t have to sort the lists first to apply them. </p>
<p>In order to use the HashSet, you need to add a reference to the FSharp.PowerPack.dll assembly. This sample was build with F# 1.9.7.8 for Visual Studio 2008.</p>
<p>UPDATE: You can read about similar implementations but using operators on this post by <a href="http://mixedsyntax.wordpress.com/2009/04/28/adding-ruby-and-c-operators-to-f/">Jason Kikel</a>. He also deals with repetitions, regular expression binding operator and null coalescing binding operator.</p>
]]></content:encoded>
			<wfw:commentRss>http://mariusbancila.ro/blog/2009/12/07/fsharp-operations-on-list/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
