<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2.1" -->
<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/"
	>

<channel>
	<title>A Developer E-pistle</title>
	<link>http://blog.marcomagdy.com</link>
	<description>by Marco Magdy</description>
	<pubDate>Sun, 14 Sep 2008 18:16:08 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>
	<language>en</language>
			<item>
		<title>Getting Around Dynamic Casting To Achieve Better Design And Performance</title>
		<link>http://blog.marcomagdy.com/archive/2008/09/02/getting-around-dynamic-casting-to-achieve-better-design-and-performance/</link>
		<comments>http://blog.marcomagdy.com/archive/2008/09/02/getting-around-dynamic-casting-to-achieve-better-design-and-performance/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 03:19:35 +0000</pubDate>
		<dc:creator>Marco Magdy</dc:creator>
		
		<category><![CDATA[C\C++]]></category>

		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://blog.marcomagdy.com/archive/2008/09/03/getting-around-dynamic-casting-to-achieve-better-design-and-performance/</guid>
		<description><![CDATA[Using dynamic casts to determine an execution path in your code is not the best to write your logic.
I realized this fact while looking at Google&#8217;s style guide for C++
Do not use RTTI, except in unit-tests. If you find yourself in need of writing code that behaves differently based on the class of an object, [...]]]></description>
			<content:encoded><![CDATA[<p>Using dynamic casts to determine an execution path in your code is not the best to write your logic.</p>
<p>I realized this fact while looking at <a href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Run-Time_Type_Information__RTTI_" target="_blank">Google&#8217;s style guide for C++</a></p>
<blockquote><p>Do not use RTTI, except in unit-tests. If you find yourself in need of writing code that behaves differently based on the class of an object, consider one of the alternatives to querying the type. </p>
<p>Virtual methods are the preferred way of executing different code paths depending on a specific subclass type. This puts the work within the object itself. </p>
<p>If the work belongs outside the object and instead in some processing code, consider a double-dispatch solution, such as the Visitor design pattern. This allows a facility outside the object itself to determine the type of class using the built-in type system. </p>
<p>If you think you truly cannot use those ideas, you may use RTTI. But think twice about it. <img src='http://blog.marcomagdy.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> Then think twice again. Do not hand-implement an RTTI-like workaround. The arguments against RTTI apply just as much to workarounds like class hierarchies with type tags.</p>
</blockquote>
<p>That was an eye-opener to me. I didn&#8217;t know what <a href="http://en.wikipedia.org/wiki/Double_dispatch" target="_blank">double-dispatch</a> is all about. Turns out that it&#8217;s the heart of the <a href="http://www.dofactory.com/Patterns/PatternVisitor.aspx" target="_blank">Visitor&#8217;s Pattern</a> (although the example at <a href="http://dofactory.com" target="_blank">dofactory.com</a> is not ideal because they do not provide overloads for the visit() function and they cast all types to the base).</p>
<p>&#160;</p>
<p><strong>Double-Dispatch is the ability to dynamically select a method according to the run-time type of the caller (single dispatch) and the run-time type of the argument as well.</strong></p>
<p>&#160;</p>
<p>To close out, remember before you use dynamic casting in your code to think if there is a better way to achieve the same results using <em>function overloads</em>, <em>virtual functions</em> or <em>double dispatch</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcomagdy.com/archive/2008/09/02/getting-around-dynamic-casting-to-achieve-better-design-and-performance/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Parsing SQL Statements With Regex</title>
		<link>http://blog.marcomagdy.com/archive/2008/08/05/getting-around-sql-escaped-apostrophes-with-in-a-regex/</link>
		<comments>http://blog.marcomagdy.com/archive/2008/08/05/getting-around-sql-escaped-apostrophes-with-in-a-regex/#comments</comments>
		<pubDate>Tue, 05 Aug 2008 13:41:11 +0000</pubDate>
		<dc:creator>Marco Magdy</dc:creator>
		
		<category><![CDATA[Regular Expressions]]></category>

		<guid isPermaLink="false">http://blog.marcomagdy.com/archive/2008/08/05/getting-around-sql-escaped-apostrophes-with-in-a-regex/</guid>
		<description><![CDATA[I was trying to parse a SQL script the other day with regular expressions to extract some values of some columns. The script looked something like this:
NSERT INTO wp_posts (ID, post_author, post_date, post_content, post_title) VALUES (5, 1, &#8216;2008-02-03 20:06:31&#8242;, &#8216;marco&#8217;&#8217;s long text&#8217;, &#8216;hello world&#8217;);

so I had a regular expression that would capture anything between two [...]]]></description>
			<content:encoded><![CDATA[<p>I was trying to parse a SQL script the other day with regular expressions to extract some values of some columns. The script looked something like this:</p>
<blockquote><p>NSERT INTO wp_posts (ID, post_author, post_date, post_content, post_title) VALUES (5, 1, &#8216;2008-02-03 20:06:31&#8242;, &#8216;marco&#8217;&#8217;s long text&#8217;, &#8216;hello world&#8217;);</p>
</blockquote>
<p><font color="#666666">so I had a regular expression that would capture anything between two apostrophes </font></p>
<blockquote><p><font color="#666666">&#8216;(?&lt;text&gt;[^&#8217;]+)&#8217;</font></p>
</blockquote>
<p><font color="#666666">The problem is escaped apostrophes in the text itself. Like in the example above <em>marco&#8217;&#8217;s long text</em> it would stop at the first apostrophe.</font></p>
<p><font color="#666666">So, in short,&#160; to get around that, I did a simple ORing like this:</font></p>
<blockquote><p><font color="#666666">&#8216;(?&lt;text&gt;([^&#8217;]|[&#8217;]{2})+)&#8217;</font></p>
</blockquote>
<p><font color="#666666">Seems very simple, but it took me a while to see the light.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcomagdy.com/archive/2008/08/05/getting-around-sql-escaped-apostrophes-with-in-a-regex/feed/</wfw:commentRss>
		</item>
		<item>
		<title>My Favorite Geek Quotes</title>
		<link>http://blog.marcomagdy.com/archive/2008/07/06/my-favorite-geek-quotes/</link>
		<comments>http://blog.marcomagdy.com/archive/2008/07/06/my-favorite-geek-quotes/#comments</comments>
		<pubDate>Sun, 06 Jul 2008 05:07:54 +0000</pubDate>
		<dc:creator>Marco Magdy</dc:creator>
		
		<category><![CDATA[geek stuff]]></category>

		<guid isPermaLink="false">http://blog.marcomagdy.com/archive/2008/07/06/my-favorite-geek-quotes/</guid>
		<description><![CDATA[I think any of those would be cool to have on a T-shirt.

I would love to change the world, but they won&#8217;t give me the source code 
There are 10 types of people, those who understand binary, and those who don&#8217;t 
There is no place like 127.0.0.1 
Oh, please, Give me a &#60;br/&#62; 
I&#8217;m not [...]]]></description>
			<content:encoded><![CDATA[<p>I think any of those would be cool to have on a T-shirt.
<ul>
<li>I would love to change the world, but they won&#8217;t give me the source code </li>
<li>There are 10 types of people, those who understand binary, and those who don&#8217;t </li>
<li>There is no place like 127.0.0.1 </li>
<li>Oh, please, Give me a &lt;br/&gt; </li>
<li>I&#8217;m not married, I&#8217;m only loosely coupled </li>
<li>To understand recursion, you must first understand recursion </li>
<li>Girls are like Internet domain names, the ones I like are already taken </li>
<li>How many people can read hex if only you and dead people can read hex? </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcomagdy.com/archive/2008/07/06/my-favorite-geek-quotes/feed/</wfw:commentRss>
		</item>
		<item>
		<title>jscalendar shows at the top of the screen in IE7</title>
		<link>http://blog.marcomagdy.com/archive/2008/06/17/jscalendar-shows-at-the-top-of-the-screen-in-ie7/</link>
		<comments>http://blog.marcomagdy.com/archive/2008/06/17/jscalendar-shows-at-the-top-of-the-screen-in-ie7/#comments</comments>
		<pubDate>Tue, 17 Jun 2008 05:32:19 +0000</pubDate>
		<dc:creator>Marco Magdy</dc:creator>
		
		<category><![CDATA[Web]]></category>

		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://blog.marcomagdy.com/archive/2008/06/17/jscalendar-shows-at-the-top-of-the-screen-in-ie7/</guid>
		<description><![CDATA[jscalendar v1.0 has a bug that makes the calendar displays at the top of the screen in IE7.
Here is a patch that fixes it.
reference: http://drupal.org/node/118926
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.dynarch.com/projects/calendar/">jscalendar</a> v1.0 has a bug that makes the calendar displays at the top of the screen in IE7.</p>
<p><a href="http://blog.marcomagdy.com/wp-content/uploads/2008/06/jscalendar-1.0-patch.zip" title="jscalendar ie7 patch">Here is a patch</a> that fixes it.</p>
<p>reference: <a href="http://drupal.org/node/118926" target="_blank">http://drupal.org/node/118926</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcomagdy.com/archive/2008/06/17/jscalendar-shows-at-the-top-of-the-screen-in-ie7/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Platform-Independent Bitwise Rotation function</title>
		<link>http://blog.marcomagdy.com/archive/2008/02/26/platform-independent-bitwise-rotating-function/</link>
		<comments>http://blog.marcomagdy.com/archive/2008/02/26/platform-independent-bitwise-rotating-function/#comments</comments>
		<pubDate>Tue, 26 Feb 2008 05:02:26 +0000</pubDate>
		<dc:creator>Marco Magdy</dc:creator>
		
		<category><![CDATA[C\C++]]></category>

		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://blog.marcomagdy.com/archive/2008/02/26/platform-independent-bitwise-rotating-function/</guid>
		<description><![CDATA[A simple macro to rotate the bits of an unsigned 32-bit value. using shift-left and shift-right we can achieve rotate-left and rotate-right.
#define rotlFixed(x,n) (((x) &#60;&#60; (n)) &#124; ((x) &#62;&#62; (32 - (n)))) 
#define rotrFixed(x,n) (((x) &#62;&#62; (n)) &#124; ((x) &#60;&#60; (32 - (n))))
The macro above can be trivially converted to a function and used in [...]]]></description>
			<content:encoded><![CDATA[<p>A simple macro to rotate the bits of an unsigned 32-bit value. using shift-left and shift-right we can achieve rotate-left and rotate-right.</p>
<p><code>#define rotlFixed(x,n) (((x) &lt;&lt; (n)) | ((x) &gt;&gt; (32 - (n)))) </code></p>
<p><code>#define rotrFixed(x,n) (((x) &gt;&gt; (n)) | ((x) &lt;&lt; (32 - (n))))</code></p>
<p>The macro above can be trivially converted to a function and used in C# for example<em>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcomagdy.com/archive/2008/02/26/platform-independent-bitwise-rotating-function/feed/</wfw:commentRss>
		</item>
		<item>
		<title>JavaScript font detector</title>
		<link>http://blog.marcomagdy.com/archive/2008/02/24/javascript-font-detector/</link>
		<comments>http://blog.marcomagdy.com/archive/2008/02/24/javascript-font-detector/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 02:37:26 +0000</pubDate>
		<dc:creator>Marco Magdy</dc:creator>
		
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://blog.marcomagdy.com/archive/2008/02/24/javascript-font-detector/</guid>
		<description><![CDATA[I found this little JavaScript utility that tests for the existence of a specific font on the client machine.     I thought it would be very handy to use for my church&#8217;s website (coming soon) which will probably have some content written in the Coptic language.
Most probably we will be using Athanasuis [...]]]></description>
			<content:encoded><![CDATA[<p>I found this little <a href="http://www.lalit.org/lab/fontdetect.php" target="_blank">JavaScript utility</a> that tests for the existence of a specific font on the client machine.     <br />I thought it would be very handy to use for <a href="http://www.stmarystmina.org" target="_blank">my church&#8217;s website</a> (coming soon) which will probably have some content written in the Coptic language.</p>
<p>Most probably we will be using <a href="/wp-content/uploads/2008/02/Athanasuis-Plain.zip">Athanasuis font</a>.</p>
<p>Anyways, I want to save the script <a href="/wp-content/uploads/2008/02/font-detector.zip">here</a> in case the original site goes down or something.</p>
<p>The script is released under <a href="http://www.apache.org/licenses/LICENSE-2.0.html">Apache License, Version 2.0</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcomagdy.com/archive/2008/02/24/javascript-font-detector/feed/</wfw:commentRss>
		</item>
		<item>
		<title>You Suck At Photoshop</title>
		<link>http://blog.marcomagdy.com/archive/2008/02/23/you-suck-at-photoshop/</link>
		<comments>http://blog.marcomagdy.com/archive/2008/02/23/you-suck-at-photoshop/#comments</comments>
		<pubDate>Sun, 24 Feb 2008 03:33:13 +0000</pubDate>
		<dc:creator>Marco Magdy</dc:creator>
		
		<category><![CDATA[geek stuff]]></category>

		<guid isPermaLink="false">http://blog.marcomagdy.com/archive/2008/02/23/you-suck-at-photoshop/</guid>
		<description><![CDATA[I stumbled on this series of youtube episodes at digg.com and I think they are amazing.
if you have a few minutes check them out. each episode is like 5 minutes long.
Here is episode #2 but definitely check out the other episodes as well in the related videos section.
]]></description>
			<content:encoded><![CDATA[<p>I stumbled on this series of youtube episodes at digg.com and I think they are amazing.</p>
<p>if you have a few minutes check them out. each episode is like 5 minutes long.</p>
<p>Here is <a href="http://www.youtube.com/watch?v=VXeZ0s8DXZ0" target="_blank">episode #2</a> but definitely check out the other episodes as well in the related videos section.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcomagdy.com/archive/2008/02/23/you-suck-at-photoshop/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Shuffling Analysis</title>
		<link>http://blog.marcomagdy.com/archive/2007/12/15/shuffling-analysis/</link>
		<comments>http://blog.marcomagdy.com/archive/2007/12/15/shuffling-analysis/#comments</comments>
		<pubDate>Sat, 15 Dec 2007 05:49:20 +0000</pubDate>
		<dc:creator>Marco Magdy</dc:creator>
		
		<category><![CDATA[Algorithms]]></category>

		<guid isPermaLink="false">http://blog.marcomagdy.com/archive/2007/12/15/shuffling-analysis/</guid>
		<description><![CDATA[This post is in regard to Jeff  Atwood&#8217;s post on Shuffling  and The  Danger of Naïveté.
In his second post he used an example of shuffling three-card deck 600,000 times to explain how naive solutions can be dangerous. The post is extremely well written. I enjoyed every bit of it. However I had [...]]]></description>
			<content:encoded><![CDATA[<p>This post is in regard to <a href="http://www.codinghorror.com/blog/">Jeff  Atwood&#8217;s</a> post on <a href="http://www.codinghorror.com/blog/archives/001008.html?r=31644" target="_blank">Shuffling</a>  and <a href="http://www.codinghorror.com/blog/archives/001015.html" target="_blank">The  Danger of Naïveté.</a></p>
<p>In his second post he used an example of shuffling three-card deck 600,000 times to explain how naive solutions can be dangerous. The post is extremely well written. I enjoyed every bit of it. However I had two questions that I couldn&#8217;t find an answer for in Jeff&#8217;s post. <strong>Why exactly 3 permutations (out of the 6 possible ones) are biased? and why those 3 specifically are biased and not any other permutations?</strong></p>
<p>I spent sometime thinking about it and using a pencil and a paper I was able to get some answers.<br />
First here is the naive method: (I reversed the loop to be as similar as possible to the correct method)</p>
<pre>for (int i = cards.Length - 1; i &gt;= 0; i--)
{
    int n = random.Next(cards.Length);
    Swap(ref cards[i], ref cards[n]);
}</pre>
<p>And here is the correct one (<a href="http://en.wikipedia.org/wiki/Knuth_shuffle" target="_blank">Knuth  Shuffle</a>)</p>
<pre>for (int i = cards.Length - 1; i &gt; 0; i--)
{
    int n = rand.Next(i + 1);
    Swap(ref cards[i], ref cards[n]);
}</pre>
<p>Now let&#8217;s agree on some facts real quick. For a three-card deck:</p>
<ol>
<li>There are exactly 6 <strong>unique</strong> possible permutations for that   deck (3!)</li>
<li>Using the Naive shuffling method, there are 27 possible sequences of random-numbers   on any given run (3<sup>3</sup>)</li>
</ol>
<p>The answer to the first question above, is that 27 mod 6 is equal to 3. What that means is there are 3 extra sequences of random numbers that have to map to 1 (or 2 or 3) of the 6 unique permutations of the deck.</p>
<p>To answer the second question we have to note something first about using swapping to perform a shuffle, take a look at the state of the deck at each iteration given the following random numbers:</p>
<table cellpadding="2" cellspacing="2" width="100%">
<tr>
<td>
<table border="1" cellpadding="2" cellspacing="2" width="16%">
<tr>
<th align="center">Step</th>
<th>Random Number</th>
<th>Deck</th>
</tr>
<tr>
<td>0</td>
<td>N/A</td>
<td>123</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>132</td>
</tr>
<tr>
<td>2</td>
<td>3</td>
<td>123</td>
</tr>
<tr>
<td>3</td>
<td>3</td>
<td>321</td>
</tr>
</table>
</td>
<td>
<table border="1" cellpadding="2" cellspacing="2" width="16%">
<tr>
<th align="center">Step</th>
<th>Random Number</th>
<th>Deck</th>
</tr>
<tr>
<td>0</td>
<td>N/A</td>
<td>123</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>321</td>
</tr>
<tr>
<td>2</td>
<td>1</td>
<td>231</td>
</tr>
<tr>
<td>3</td>
<td>2</td>
<td>321</td>
</tr>
</table>
</td>
</tr>
</table>
<p>Notice how the two different sequences of random-numbers resulted in the same permutation of the deck. Now remember there are 27 possible sequences and only 6 unique permutations. if we divide 27/6 we get 4 (with remainder 3) which means there are at least 4 paths (or sequences) for every unique permutation of the deck, the 3 extra possible sequence lead to 3 of the unique permutations giving them an advantage over the other 3.</p>
<p>so basically we have 6 permutations of the deck, 3 of them have 4 random-number sequences that lead to them, and the other 3 have <strong>5</strong> sequences that lead to them.</p>
<p>In this particular example if you follow the algorithm above and try the following random-number sequences you will get the same deck permutation for all 5.</p>
<ul>
<li> 1,1,2</li>
<li>3,1,3</li>
<li> 2,2,2</li>
<li> 1,3,1</li>
<li> 2,3,3</li>
</ul>
<h3>Conclusion</h3>
<p>The problem with the Naive shuffling method is swapping! The fact that swapping elements in 2 (or more) different sequences can lead to the same deck permutation is a subtle problem.</p>
<p>The Knuth shuffle algorithm avoids that problem by ensuring N! possible random sequences where N is the number of elements in a deck (or any container).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcomagdy.com/archive/2007/12/15/shuffling-analysis/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Function Pointers</title>
		<link>http://blog.marcomagdy.com/archive/2007/11/15/function-pointers/</link>
		<comments>http://blog.marcomagdy.com/archive/2007/11/15/function-pointers/#comments</comments>
		<pubDate>Fri, 16 Nov 2007 02:19:59 +0000</pubDate>
		<dc:creator>Marco Magdy</dc:creator>
		
		<category><![CDATA[C\C++]]></category>

		<guid isPermaLink="false">http://blog.marcomagdy.com/archive/2007/11/15/function-pointers/</guid>
		<description><![CDATA[Declaring function pointers in C\C++ has a somewhat strange syntax, specially when you want to specify a function pointer as the return type of another function.
so here is a brief explanation:
To declare a pointer to an int called pNumber:
int *pNumber;
To declare a pointer to a function called pFunc (that has a string parameter and returns [...]]]></description>
			<content:encoded><![CDATA[<p>Declaring function pointers in C\C++ has a somewhat strange syntax, specially when you want to specify a function pointer as the return type of another function.<br />
so here is a brief explanation:</p>
<p>To declare a pointer to an int called <em>pNumber</em>:</p>
<p><em><font color="#800080">int *</font><font color="#800000">pNumber</font>;</em></p>
<p>To declare a pointer to a function called <em>pFunc</em> (that has a <em>string </em>parameter and returns an <em>int</em>):</p>
<p><em><font color="#800080">int (*</font><font color="#800000"> pFunc</font><font color="#800080">)(string);</font></em></p>
<p><font color="#000000">in red is the variable name, in purple is the type.</font></p>
<p>To declare a function that returns a pointer to a function:</p>
<p><font color="#800080"><em>int (*</em></font> <em><font color="#800000">GetFuncPointer(void) </font><font color="#800080">)(string);</font></em></p>
<p>in red is a normal function declaration, in purple is the return type of that function<font color="#800080">.</font><br />
S o basically <em><font color="#800080">int(*)(string)</font></em> is the <strong>type </strong>of the function pointer.</p>
<p>If we want to declare a function that takes a function pointer as a parameter then we would write something like this:</p>
<p><em><font color="#800000">void RegisterCallBack(</font> <font color="#800080">int(*)(string) </font><font color="#800000">);</font></em> <font color="#339933"><em>/* unnamed parameter */</em></font></p>
<p>or</p>
<p><em><font color="#800000">void RegisterCallBack(</font> <font color="#800080">int(*myCallback)(string) </font><font color="#800000">);</font></em> <em><font color="#339933">/* named parameter */</font></em></p>
<p>A prettier way to use function pointers is to use <em>typedef</em> to declare an alias. The<em> typedef</em> syntax is exactly the same as declaring a regular variable (or a function pointer).</p>
<p><em><font color="#0000ff">typedef</font> <font color="#800080">int(*</font><font color="#800000">FunctionPointer</font><font color="#800080">)(string);</font></em></p>
<p>now we can use FunctionPointer like this:</p>
<p><em>FunctionPointer GetFuncPointer(void);</em></p>
<p><a href="http://boredzo.org/pointers/#function_pointers">Click For More Information&#8230;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcomagdy.com/archive/2007/11/15/function-pointers/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Mr. Compiler, would you please inline this function?</title>
		<link>http://blog.marcomagdy.com/archive/2007/11/05/mr-compiler-would-you-please-inline-my-function/</link>
		<comments>http://blog.marcomagdy.com/archive/2007/11/05/mr-compiler-would-you-please-inline-my-function/#comments</comments>
		<pubDate>Mon, 05 Nov 2007 17:32:59 +0000</pubDate>
		<dc:creator>Marco Magdy</dc:creator>
		
		<category><![CDATA[C\C++]]></category>

		<guid isPermaLink="false">http://blog.marcomagdy.com/archive/2007/11/05/mr-compiler-would-you-please-inline-my-function/</guid>
		<description><![CDATA[I&#8217;ve always read that marking a function inline doesn&#8217;t guarantee that the compiler will actually inline it, but it&#8217;s merely a hint to the compiler to “try its best” to do it. Which have always raised the question in my head, how do I know if Mr. Compiler agreed to inline my function? Do I [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve always read that marking a function <em>inline </em>doesn&#8217;t guarantee that the compiler will actually inline it, but it&#8217;s merely a hint to the compiler to “try its best” to do it. Which have always raised the question in my head, how do I know if Mr. Compiler <em>agreed </em>to inline my function? Do I have to look at the generated assembly code? There has to be an easier way!</p>
<p>So I invested 15 minutes researching that issue and found out that Mr. Compiler is friendly enough to let you know if it was <em><strong>not </strong></em>possible to fulfill your request to inline a certain function by issuing a warning.</p>
<p>For Microsoft’s VC8 compiler <a href="http://msdn2.microsoft.com/en-us/library/yd3056cz%28VS.80%29.aspx" title="warning C41710" target="_blank">warning C4710</a> is turned off by default, you can turn it on by doing any of the following (depends on your choice):</p>
<ol>
<li> <code>#pragma warning (default : 4710)</code></li>
<li><code>#pragma warning (custom_warning_level : 4710)</code></li>
</ol>
<p>For GCC  the <a href="http://gcc.gnu.org/onlinedocs/gcc-4.2.2/gcc/Warning-Options.html" target="_blank">-Winline switch</a> can be used to achieve the same thing.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcomagdy.com/archive/2007/11/05/mr-compiler-would-you-please-inline-my-function/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Installing nVidia drivers on debian linux</title>
		<link>http://blog.marcomagdy.com/archive/2007/11/02/installing-nvidia-drivers-on-debian-linux/</link>
		<comments>http://blog.marcomagdy.com/archive/2007/11/02/installing-nvidia-drivers-on-debian-linux/#comments</comments>
		<pubDate>Fri, 02 Nov 2007 23:02:28 +0000</pubDate>
		<dc:creator>Marco Magdy</dc:creator>
		
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://blog.marcomagdy.com/archive/2007/11/02/installing-nvidia-drivers-on-debian-linux/</guid>
		<description><![CDATA[Since I forget the steps every single time I try to install or upgrade linux I&#8217;ll write them down.

download the drivers from www.nvidia.com (usually a file with .run extension)
download the kernel header files &#8212; apt-get install linux-headers-$(uname -r)
execute the command &#8212; sh path to the nvidia driver here

There is another method I found, that seems [...]]]></description>
			<content:encoded><![CDATA[<p>Since I forget the steps every single time I try to install or upgrade linux I&#8217;ll write them down.</p>
<ol>
<li>download the drivers from www.nvidia.com (usually a file with .run extension)</li>
<li>download the kernel header files &#8212; apt-get install linux-headers-$(uname -r)</li>
<li>execute the command &#8212; sh <em>path to the nvidia driver here</em></li>
</ol>
<p>There is another method I found, that seems to work for a lot of people:</p>
<ol>
<li>apt-get install module-assistant</li>
<li>m-a prepare</li>
<li>m-a auto-install nvidia</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcomagdy.com/archive/2007/11/02/installing-nvidia-drivers-on-debian-linux/feed/</wfw:commentRss>
		</item>
		<item>
		<title>&#8216;Developers&#8217; Anagrams !!!</title>
		<link>http://blog.marcomagdy.com/archive/2007/08/07/developers-anagrams/</link>
		<comments>http://blog.marcomagdy.com/archive/2007/08/07/developers-anagrams/#comments</comments>
		<pubDate>Wed, 08 Aug 2007 03:47:43 +0000</pubDate>
		<dc:creator>Marco Magdy</dc:creator>
		
		<category><![CDATA[geek stuff]]></category>

		<guid isPermaLink="false">http://blog.marcomagdy.com/archive/2007/08/07/developers-anagrams/</guid>
		<description><![CDATA[I&#8217;m a big fan of anagrams, they are very interesting to me, they are mysterious, funny and sometimes true..
quoting a phrase on my favorite anagram generator site &#8220;All the life&#8217;s wisdom can be found in anagrams.  Anagrams never lie.&#8221;
here are a few interesting anagrams for the word developers:

Peeve Lords (that&#8217;s us for the customers)
Deep [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a big fan of anagrams, they are very interesting to me, they are mysterious, funny and sometimes true..</p>
<p>quoting a phrase on <a href="http://wordsmith.org/anagram/index.html" title="Internet Anagram Server" target="_blank">my favorite anagram generator site</a> <em>&#8220;All the life&#8217;s wisdom can be found in anagrams.  Anagrams never lie.&#8221;</em></p>
<p>here are a few interesting anagrams for the word <em>developers</em>:</p>
<ul>
<li>Peeve Lords (that&#8217;s us for the customers)</li>
<li>Deep Solver</li>
<li>Speed Lover (for the performance obsessed ones)</li>
<li>Deep Lovers</li>
</ul>
<p>Anagrams are amazing..</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcomagdy.com/archive/2007/08/07/developers-anagrams/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The typename Keyword</title>
		<link>http://blog.marcomagdy.com/archive/2007/08/02/the-typename-keyword/</link>
		<comments>http://blog.marcomagdy.com/archive/2007/08/02/the-typename-keyword/#comments</comments>
		<pubDate>Thu, 02 Aug 2007 17:14:27 +0000</pubDate>
		<dc:creator>Marco Magdy</dc:creator>
		
		<category><![CDATA[C\C++]]></category>

		<guid isPermaLink="false">http://blog.marcomagdy.com/archive/2007/08/02/the-typename-keyword/</guid>
		<description><![CDATA[Indicates that the name following represents a parameterized type placeholder that will be replaced by a user-specified actual type.
consider the following example:
template&#60;class T&#62; class A
{
T::x(y); // ambiguous: calling a function or constructing an object?
// without &#8216;typename&#8217; this will be interpreted as a function call
typedef char C;
A::C d;
}
The statement A::C d; is ill-formed. The class A [...]]]></description>
			<content:encoded><![CDATA[<p>Indicates that the name following represents a parameterized type placeholder that will be replaced by a user-specified actual type.</p>
<p>consider the following example:<br />
<em>template&lt;class T&gt; class A<br />
{<br />
T::x(y); // ambiguous: calling a function or constructing an object?<br />
// without &#8216;typename&#8217; this will be interpreted as a function call<br />
typedef char C;<br />
A::C d;<br />
}</em></p>
<p>The statement A::C d; is ill-formed. The class A also refers to A&lt;T&gt; and thus depends on a template parameter. You must add the keyword typename to the beginning of this declaration:</p>
<p>typename A::C d;</p>
<p>You can also use the keyword typename in place of the keyword class in template parameter declarations.</p>
<p>typename was introduced after the keyword class to solve the problems shown above, but both keywords are equivalent in declaring template parameters.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcomagdy.com/archive/2007/08/02/the-typename-keyword/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Persisting SessionID Across Multiple Requests</title>
		<link>http://blog.marcomagdy.com/archive/2007/07/19/persisting-sessionid-across-multiple-requests/</link>
		<comments>http://blog.marcomagdy.com/archive/2007/07/19/persisting-sessionid-across-multiple-requests/#comments</comments>
		<pubDate>Thu, 19 Jul 2007 05:25:22 +0000</pubDate>
		<dc:creator>Marco Magdy</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://blog.marcomagdy.com/archive/2007/07/19/persisting-sessionid-across-multiple-requests/</guid>
		<description><![CDATA[Today we had a problem while working on Darden&#8217;s project.
We were using the SessionID as a unique key to store some information about the behavior of the user surfing the site.
The SessionID was getting changed with every page request.
The trivial solution was adding a global.asax file to the project.
]]></description>
			<content:encoded><![CDATA[<p>Today we had a problem while working on <a href="http://www.darden.com" target="_blank" class="snap_shot">Darden</a>&#8217;s project.</p>
<p>We were using the SessionID as a unique key to store some information about the behavior of the user surfing the site.</p>
<p>The SessionID was getting changed with every page request.</p>
<p>The trivial solution was adding a <em>global.asax</em> file to the project.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcomagdy.com/archive/2007/07/19/persisting-sessionid-across-multiple-requests/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Regex for U.S and Canadian Zip Codes</title>
		<link>http://blog.marcomagdy.com/archive/2007/07/18/regex-for-us-and-canadian-zip-codes/</link>
		<comments>http://blog.marcomagdy.com/archive/2007/07/18/regex-for-us-and-canadian-zip-codes/#comments</comments>
		<pubDate>Wed, 18 Jul 2007 15:14:50 +0000</pubDate>
		<dc:creator>Marco Magdy</dc:creator>
		
		<category><![CDATA[Regular Expressions]]></category>

		<category><![CDATA[C#]]></category>

		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://blog.marcomagdy.com/archive/2007/07/18/regex-for-us-and-canadian-zip-codes/</guid>
		<description><![CDATA[for my future references, below is a regular expression for validating U.S and Canadian zip codes.
^\d{5}(?:-\d{4})?$&#124;^[a-zA-Z]\d[a-zA-Z]\s?\d[a-zA-Z]\d$
more details on the format of Canadian zip codes
]]></description>
			<content:encoded><![CDATA[<p>for my future references, below is a regular expression for validating U.S and Canadian zip codes.</p>
<p>^\d{5}(?:-\d{4})?$|^[a-zA-Z]\d[a-zA-Z]\s?\d[a-zA-Z]\d$</p>
<p><a href="http://en.wikipedia.org/wiki/Canadian_postal_code" target="_blank" class="snap_shot">more details on the format of Canadian zip codes</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcomagdy.com/archive/2007/07/18/regex-for-us-and-canadian-zip-codes/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to type a unicode character under MS Windows</title>
		<link>http://blog.marcomagdy.com/archive/2007/07/15/how-to-type-a-unicode-character-under-ms-windows/</link>
		<comments>http://blog.marcomagdy.com/archive/2007/07/15/how-to-type-a-unicode-character-under-ms-windows/#comments</comments>
		<pubDate>Sun, 15 Jul 2007 05:26:21 +0000</pubDate>
		<dc:creator>Marco Magdy</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.marcomagdy.com/archive/2007/07/15/how-to-type-a-unicode-character-under-ms-windows/</guid>
		<description><![CDATA[
Press and hold down the Alt key.
Press the + (plus) key on the numeric keypad.
Type the hexadecimal Unicode value.
Release the Alt key.

Note that this method will only work if you have the following registry key set to the correct value..
under HKEY_Current_User/Control Panel/Input Method, set EnableHexNumpad  to 1
Use the Character Map to find the hexadecimal [...]]]></description>
			<content:encoded><![CDATA[<ol>
<li>Press and hold down the <code>Alt</code> key.</li>
<li>Press the <code>+</code> (plus) key on the <em>numeric keypad</em>.</li>
<li>Type the hexadecimal Unicode value.</li>
<li>Release the <code>Alt</code> key.</li>
</ol>
<p>Note that this method will only work if you have the following registry key set to the correct value..<br />
under <code>HKEY_Current_User/Control Panel/Input Method</code>, set <code>EnableHexNumpad </code> to <code>1</code></p>
<p>Use the <em>Character Map</em> to find the hexadecimal Unicode values for different characters.</p>
<p>Also, it&#8217;s worth noting that if you are using <em>MS Word</em> you can simply type in the Unicode hex value first and then press <em>Alt+x. </em>The hex number will be replaced by it&#8217;s equivalent Unicode character automagically.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcomagdy.com/archive/2007/07/15/how-to-type-a-unicode-character-under-ms-windows/feed/</wfw:commentRss>
		</item>
		<item>
		<title>C# Numeric Literals Suffixes</title>
		<link>http://blog.marcomagdy.com/archive/2007/07/10/c-numeric-literals-suffixes/</link>
		<comments>http://blog.marcomagdy.com/archive/2007/07/10/c-numeric-literals-suffixes/#comments</comments>
		<pubDate>Wed, 11 Jul 2007 03:18:48 +0000</pubDate>
		<dc:creator>Marco Magdy</dc:creator>
		
		<category><![CDATA[C#]]></category>

		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://blog.marcomagdy.com/archive/2007/07/10/c-numeric-literals-suffixes/</guid>
		<description><![CDATA[The suffixes in the table below are useful because they tell the compiler what type a numeric literal is and how it should be treated. The default type of a numeric literal is integer (int) of course, but if you want to specify decimal or long, how would you do that? (please don&#8217;t cast it, it&#8217;s ugly)
Consider having [...]]]></description>
			<content:encoded><![CDATA[<p>The suffixes in the table below are useful because they tell the compiler what type a numeric literal is and how it should be treated. The default type of a numeric literal is integer (int) of course, but if you want to specify decimal or long, how would you do that? (please don&#8217;t cast it, it&#8217;s ugly)</p>
<p>Consider having an overloaded method, one overload takes a parameter of type long, another of type int, now if you want to pass in the number &#8216;15&#8242; for example, these suffixes will help you choose which overload to actually invoke by appending a letter (or two) to the numeric literal.</p>
<table border="1" cellPadding="1" cellSpacing="1">
<tr>
<th>Type</th>
<th>  Suffix</th>
<th>  Example</th>
</tr>
<tr>
<td>  uint</td>
<td>  U or u</td>
<td>  100U</td>
</tr>
<tr>
<td>  long</td>
<td>  L or l</td>
<td>  100L</td>
</tr>
<tr>
<td>  ulong</td>
<td>  UL or ul</td>
<td>  100UL</td>
</tr>
<tr>
<td>  float</td>
<td>  F or f</td>
<td>  123.45F</td>
</tr>
<tr>
<td>  decimal</td>
<td>  M or m</td>
<td>  123.45M</td>
</tr>
</table>
<p>Note that the suffixes are case-insensitive.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcomagdy.com/archive/2007/07/10/c-numeric-literals-suffixes/feed/</wfw:commentRss>
		</item>
		<item>
		<title>DateTime &#038; Number Format String Cheat Sheet</title>
		<link>http://blog.marcomagdy.com/archive/2007/07/05/datetime-number-format-string-cheat-sheet/</link>
		<comments>http://blog.marcomagdy.com/archive/2007/07/05/datetime-number-format-string-cheat-sheet/#comments</comments>
		<pubDate>Thu, 05 Jul 2007 18:08:40 +0000</pubDate>
		<dc:creator>Marco Magdy</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://blog.marcomagdy.com/archive/2007/07/05/datetime-number-format-string-cheat-sheet/</guid>
		<description><![CDATA[I don&#8217;t know why I haven&#8217;t spent the time to create something handy like this!
If you are a .net developer (specially an asp.net one) you certainly will see the benefit of this cheat sheet. Personally I have wasted my time before trying to format an integer to print in a certain way and of course [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know why I haven&#8217;t spent the time to create something handy like <a href="http://blog.marcomagdy.com/wp-content/uploads/2007/07/formatting-cheat-sheet.pdf" title="cheat sheet">this</a>!</p>
<p>If you are a .net developer (specially an asp.net one) you certainly will see the benefit of this <a href="http://blog.marcomagdy.com/wp-content/uploads/2007/07/formatting-cheat-sheet.pdf" title="cheat sheet">cheat sheet</a>. Personally I have wasted my time before trying to format an integer to print in a certain way and of course i didn&#8217;t have the correct format-specifier right off the top of my head so i had to hunt down the information on Microsoft&#8217;s slow-and-poorly-searchable msdn which is certainly something i try to avoid!</p>
<p>reference: <a href="http://weblogs.asp.net/scottgu/" class="snap_shot">Scott Gutherie&#8217;s blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcomagdy.com/archive/2007/07/05/datetime-number-format-string-cheat-sheet/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Consolas - A font for programmers!</title>
		<link>http://blog.marcomagdy.com/archive/2007/07/03/consolas-a-font-for-programmers/</link>
		<comments>http://blog.marcomagdy.com/archive/2007/07/03/consolas-a-font-for-programmers/#comments</comments>
		<pubDate>Tue, 03 Jul 2007 04:24:33 +0000</pubDate>
		<dc:creator>Marco Magdy</dc:creator>
		
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://blog.marcomagdy.com/archive/2007/07/03/consolas-a-font-for-programmers/</guid>
		<description><![CDATA[I stumbled upon this font called Consolas which is recommended and created by Microsoft to use with Visual Studio 2005 (I&#8217;m not sure why just 2005), It&#8217;s a very good font for writing scripts, code, HTML, etc..

It&#8217;s monospaced (i.e. fixed width)
The characters &#8216;0&#8242; and &#8216;o&#8217; are very distinguishable (which helps avoid a common mistake)
It&#8217;s compact, [...]]]></description>
			<content:encoded><![CDATA[<p>I stumbled upon this font called <a href="http://www.microsoft.com/downloads/details.aspx?familyid=22e69ae4-7e40-4807-8a86-b3d36fab68d3&amp;displaylang=en" title="Consolas Font Pack for Microsoft Visual Studio" target="_blank">Consolas</a> which is recommended and created by Microsoft to use with Visual Studio 2005 (I&#8217;m not sure why just 2005), It&#8217;s a very good font for writing scripts, code, HTML, etc..</p>
<ul>
<li>It&#8217;s monospaced (i.e. fixed width)</li>
<li>The characters &#8216;0&#8242; and &#8216;o&#8217; are very distinguishable (which helps avoid a common mistake)</li>
<li>It&#8217;s compact, compared to <em>Courier New</em></li>
<li>It looks very pleasant</li>
</ul>
<p>Make sure you have the <em>ClearType</em> effect turned on (Control Panel-&gt;Display-&gt;Appearance-&gt;Effects)</p>
<p>I&#8217;m glad I found this font, and that&#8217;s why I&#8217;m sharing it, It&#8217;s way better than <em>Courier New</em> which used to be my favorite actually.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcomagdy.com/archive/2007/07/03/consolas-a-font-for-programmers/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Subsonic DAL</title>
		<link>http://blog.marcomagdy.com/archive/2007/06/30/subsonic-dal/</link>
		<comments>http://blog.marcomagdy.com/archive/2007/06/30/subsonic-dal/#comments</comments>
		<pubDate>Sat, 30 Jun 2007 18:32:31 +0000</pubDate>
		<dc:creator>Marco Magdy</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://blog.marcomagdy.com/archive/2007/06/30/subsonic-dal/</guid>
		<description><![CDATA[Subsonic is my favorite library for creating data access layers in asp.net.

It creates properties to the related entities/tables in the database, some people like to call this feature Deep Properties!
no need to create CRUD stored procedures for every table in the db
you can do queries on the fly, WHERE clauses, ORDER BY clauses and aggregate [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.subsonicproject.com/" title="SubSonic Homepage" class="snap_shots">Subsonic</a> is my favorite library for creating data access layers in asp.net.</p>
<ul>
<li>It creates properties to the related entities/tables in the database, some people like to call this feature <em>Deep Properties!</em></li>
<li>no need to create CRUD stored procedures for every table in the db</li>
<li>you can do queries on the fly, <em>WHERE</em> clauses, <em>ORDER BY</em> clauses and aggregate functions</li>
<li>It&#8217;s open-source and free</li>
<li>the classes are generated using a tool, no more tedious DAL writing</li>
<li>for your convenience you get &#8220;Scaffolding forms&#8221;.</li>
<li>it uses <strong>parameterized</strong> dynamic sql, which makes all those great features above possible</li>
<li>It has providers for MS Sql Server and MySQL</li>
</ul>
<p>If you are an asp.net developer you should give it a try, or at least check it out, it&#8217;ll be worth your while.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcomagdy.com/archive/2007/06/30/subsonic-dal/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
