<?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>Steven Engelhardt &#187; Programming</title>
	<atom:link href="http://www.deez.info/sengelha/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.deez.info/sengelha</link>
	<description>A financial industry software developer's thoughts and insights</description>
	<lastBuildDate>Tue, 13 Apr 2010 18:28:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Implementing a Spell Checker</title>
		<link>http://www.deez.info/sengelha/2010/04/13/implementing-a-spell-checker/</link>
		<comments>http://www.deez.info/sengelha/2010/04/13/implementing-a-spell-checker/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 18:27:24 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.deez.info/sengelha/2010/04/13/implementing-a-spell-checker/</guid>
		<description><![CDATA[The following algorithms might be useful if you want to implement a spell checker (or Google-style “did you mean” feature):

Levenshtein distance 
Jaro-Winkler distance 
N-gram 

]]></description>
			<content:encoded><![CDATA[<p>The following algorithms might be useful if you want to implement a spell checker (or Google-style “did you mean” feature):</p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Levenshtein_distance">Levenshtein distance</a> </li>
<li><a href="http://en.wikipedia.org/wiki/Jaro-Winkler_distance">Jaro-Winkler distance</a> </li>
<li><a href="http://en.wikipedia.org/wiki/N-gram">N-gram</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.deez.info/sengelha/2010/04/13/implementing-a-spell-checker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reader/Writer Lock Pattern</title>
		<link>http://www.deez.info/sengelha/2010/03/14/readerwriter-lock-pattern/</link>
		<comments>http://www.deez.info/sengelha/2010/03/14/readerwriter-lock-pattern/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 20:18:29 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.deez.info/sengelha/2010/03/14/readerwriter-lock-pattern/</guid>
		<description><![CDATA[A reader-writer lock is a lock which will allow multiple concurrent readers but only one writer.&#160; A reader-writer lock can be significantly more efficient than a standard mutex if reads on your shared memory far outnumber writes.
Reader-writer locks naturally fit together with caches, as caches are only effective if reads far outnumber writes.
Here is a [...]]]></description>
			<content:encoded><![CDATA[<p>A <a href="http://en.wikipedia.org/wiki/Readers-writer_lock">reader-writer lock</a> is a lock which will allow multiple concurrent readers but only one writer.&#160; A reader-writer lock can be significantly more efficient than a standard <a href="http://en.wikipedia.org/wiki/Mutex">mutex</a> if reads on your shared memory far outnumber writes.</p>
<p>Reader-writer locks naturally fit together with <a href="http://en.wikipedia.org/wiki/Cache">cache</a>s, as caches are only effective if reads far outnumber writes.</p>
<p>Here is a general pattern for using a reader-writer lock with a cache:</p>
<ol>
<li>Acquire a reader lock. </li>
<li>Check the cache for the value. If it exists, save the value and go to step 8. </li>
<li>Upgrade the reader lock to a writer lock. </li>
<li>Check the cache for the value. If it exists, save the value and go to step 7. </li>
<li>Calculate the value (expensive, otherwise we wouldn’t cache it) </li>
<li>Insert the value into the cache. </li>
<li>Release the writer lock. </li>
<li>Release the reader lock. </li>
<li>Return the value. </li>
</ol>
<p>The reason why we have to check the cache for the value again in step (4) is because of the following possibility (assume step 4 doesn&#8217;t exist):</p>
<pre>Thread 1                         Thread 2
============================     ===============================
- Acquire reader lock            - Acquire reader lock
- Check cache for value          - Check cache for value
  with key A (not found)           with key A (not found)
- Upgrade to writer lock         - (block)
- Calculate value (expensive)
- Insert value into cache
- Release writer lock
- Release reader lock
                                 - Upgrade to writer lock
                                 - Calculate value (expensive)
                                   (<strong>We are paying this cost
                                   twice</strong>)
                                 - Insert value into cache
                                   (<strong>We are inserting two values
                                   with the same key, which may
                                   be fatal</strong>)</pre>
<p>With step 4 it becomes:</p>
<pre>Thread 1                         Thread 2
============================     ===============================
- Acquire reader lock            - Acquire reader lock
- Check cache for value          - Check cache for value
  with key A (not found)           with key A (not found)
- Upgrade to writer lock         - (block)
- Calculate value (expensive)
- Insert value into cache
- Release writer lock
- Release reader lock
                                 - Upgrade to writer lock
                                 - Check cache for value
                                   with key A (found)
                                 - Release writer lock
                                 - Release reader lock
- Return value                   - Return value</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.deez.info/sengelha/2010/03/14/readerwriter-lock-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handling Multiple QueryString Parameters With the Same Key in ASP.NET</title>
		<link>http://www.deez.info/sengelha/2009/09/23/handling-multiple-querystring-parameters-with-the-same-key-in-aspnet/</link>
		<comments>http://www.deez.info/sengelha/2009/09/23/handling-multiple-querystring-parameters-with-the-same-key-in-aspnet/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 02:23:13 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.deez.info/sengelha/2009/09/23/handling-multiple-querystring-parameters-with-the-same-key-in-aspnet/</guid>
		<description><![CDATA[When you are processing an HTTP request in ASP.NET you can retrieve the user-provided query string parameters using the HttpRequest.QueryString property.&#160; This property is an instance of the NameValueCollection class.
If the user has provided multiple parameters with the same key in the query string, HttpRequest.QueryString[key] will return all the values concatenated together with commas.&#160; If [...]]]></description>
			<content:encoded><![CDATA[<p>When you are processing an HTTP request in ASP.NET you can retrieve the user-provided query string parameters using the <a href="http://msdn.microsoft.com/en-us/library/system.web.httprequest.querystring.aspx">HttpRequest.QueryString</a> property.&#160; This property is an instance of the <a href="http://msdn.microsoft.com/en-us/library/system.collections.specialized.namevaluecollection.aspx">NameValueCollection class</a>.</p>
<p>If the user has provided multiple parameters with the same key in the query string, <code>HttpRequest.QueryString[key]</code> will return all the values concatenated together with commas.&#160; If you would rather process the values individually, use <code>HttpRequest.QueryString.GetValues(key)</code>, which will return an array of all the provided values.</p>
<p>For example:</p>
<p>URL: <a href="http://example.com?a=1&amp;a=2">http://example.com?a=1&amp;a=2</a>     <br /><code>HttpRequest.QueryString[&quot;a&quot;] = &quot;1,2&quot;</code>     <br /><code>HttpRequest.QueryString.GetValues(&quot;a&quot;) = { &quot;1&quot;, &quot;2&quot; }</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.deez.info/sengelha/2009/09/23/handling-multiple-querystring-parameters-with-the-same-key-in-aspnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pseudoloc</title>
		<link>http://www.deez.info/sengelha/2008/10/31/pseudoloc/</link>
		<comments>http://www.deez.info/sengelha/2008/10/31/pseudoloc/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 14:53:06 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Win32]]></category>

		<guid isPermaLink="false">http://www.deez.info/sengelha/?p=5504</guid>
		<description><![CDATA[I have released a pseudolocalization tool I wrote for 32-bit Windows resource DLLs here.
]]></description>
			<content:encoded><![CDATA[<p>I have released a pseudolocalization tool I wrote for 32-bit Windows resource DLLs <a href="http://www.deez.info/sengelha/code/pseudoloc/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.deez.info/sengelha/2008/10/31/pseudoloc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Balloon Tooltips</title>
		<link>http://www.deez.info/sengelha/2008/06/12/balloon-tooltips/</link>
		<comments>http://www.deez.info/sengelha/2008/06/12/balloon-tooltips/#comments</comments>
		<pubDate>Thu, 12 Jun 2008 15:17:17 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Win32]]></category>

		<guid isPermaLink="false">http://www.deez.info/sengelha/?p=5477</guid>
		<description><![CDATA[In the Windows XP login screen, the password text box will warn you with a balloon tooltip if you accidentally turn Caps Lock on:

The balloon tooltip appears to be a Windows tooltip common control with the TTS_BALLOON style.
To replicate this functionality, I decided to write a function called ShowMsgBalloon() which, given a control and the [...]]]></description>
			<content:encoded><![CDATA[<p>In the Windows XP login screen, the password text box will warn you with a balloon tooltip if you accidentally turn Caps Lock on:</p>
<p><a href="http://www.deez.info/sengelha/wp-content/uploads/2008/06/winxp-caps-lock-msg.png"><img class="alignnone size-medium wp-image-5481" title="winxp-caps-lock-msg" height="154" alt="Windows XP Caps Lock Warning Message" src="http://www.deez.info/sengelha/wp-content/uploads/2008/06/winxp-caps-lock-msg-300x154.png" width="300" /></a></p>
<p>The balloon tooltip appears to be a <a href="http://msdn.microsoft.com/en-us/library/bb760250(VS.85).aspx">Windows tooltip common control</a> with the <a href="http://msdn.microsoft.com/en-us/library/bb760248(VS.85).aspx">TTS_BALLOON style</a>.</p>
<p>To replicate this functionality, I decided to write a function called <code>ShowMsgBalloon()</code> which, given a control and the various balloon tooltip parameters, creates and shows the balloon tooltip below the control.</p>
<p>The key insight to making <code>ShowMsgBallon()</code> work as intended was to use the <a href="http://msdn.microsoft.com/en-us/library/bb760252(VS.85).aspx"><code>TTF_TRACK</code></a> option to create a tracking tooltip. This will immediately show the tooltip without requiring the user to position the mouse over the control. The main downside to using <code>TTF_TRACK</code> is that the tooltip will not move with the control if the window is moved; you need to manually move the tooltip using <code>TTM_TRACKPOSITION</code> as required. One could probably make this automatic by subclassing the tooltip&#8217;s parent control and handling <a href="http://msdn.microsoft.com/en-us/library/ms632652(VS.85).aspx"><code>WM_WINDOWPOSCHANGED</code></a> messages.</p>
<p>Here is the source code to <code>ShowMsgBalloon()</code>. When you are done with the balloon, call <a href="http://msdn.microsoft.com/en-us/library/ms632682.aspx"><code>DestroyWindow()</code></a> on the returned <code>HWND</code>. Note: you may want your application to <a href="http://msdn.microsoft.com/en-us/library/ms997646.aspx">use comctl32.dll version 6</a> as it will lead to a nicer visual style, including a close button.</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li class="li1">
<div class="de1"><span class="co2">#include &lt;windows.h&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">#include &lt;commctrl.h&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Options to ShowMsgBallon() (see dwOpts parameter). &nbsp;These are the</span></div>
</li>
<li class="li2">
<div class="de2"><span class="co1">// standard icon types for balloon tooltips.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">#define SMB_ICON_INFO &nbsp; &nbsp;(1 &lt;&lt; 0)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">#define SMB_ICON_WARNING (1 &lt;&lt; 1)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">#define SMB_ICON_ERROR &nbsp; (1 &lt;&lt; 2)</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="co1">// Given the options passed to ShowMsgBalloon(), determine what</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// parameter to send to TTM_SETTITLE for the balloon tooltip&#8217;s icon.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">static</span> DWORD</div>
</li>
<li class="li1">
<div class="de1">GetTitleIcon<span class="br0">&#40;</span>DWORD dwOpts<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>dwOpts &amp;amp; SMB_ICON_INFO<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> TTI_INFO;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span>dwOpts &amp;amp; SMB_ICON_WARNING<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> TTI_WARNING;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span>dwOpts &amp;amp; SMB_ICON_ERROR<span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> TTI_ERROR;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="co1">// Create and show a balloon tooltip immediately below the control</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// hwndCtrl with the given title, message, and options.</span></div>
</li>
<li class="li1">
<div class="de1">HWND</div>
</li>
<li class="li1">
<div class="de1">ShowMsgBalloon<span class="br0">&#40;</span>HWND hwndCtrl, LPCTSTR szTitle, LPCTSTR szMsg,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DWORD dwOpts<span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; HWND hwndRet = <span class="kw2">NULL</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; HWND hwndTT = <span class="kw2">NULL</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; TOOLINFO ti = <span class="br0">&#123;</span> <span class="nu0">0</span> <span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; RECT rc;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// Even though TTS_CLOSE is always specified, a close button will</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// only be shown if your application has a manifest that requires</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// comctl32.dll version 6.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; hwndTT = CreateWindow</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; TOOLTIPS_CLASS,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; TEXT<span class="br0">&#40;</span><span class="st0">&quot;&quot;</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; WS_POPUP | TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; CW_USEDEFAULT, CW_USEDEFAULT,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; CW_USEDEFAULT, CW_USEDEFAULT,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; hwndCtrl,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">NULL</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">NULL</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">NULL</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>hwndTT == <span class="kw2">NULL</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">goto</span> Cleanup;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// By using TTTOOLINFO_V1_SIZE rather than sizeof(TOOLINFO),</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="co1">// we don&#8217;t require users to be using comctl32 version 6.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; ti.<span class="me1">cbSize</span> = TTTOOLINFO_V1_SIZE;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; ti.<span class="me1">uFlags</span> = TTF_TRACK;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; ti.<span class="me1">hwnd</span> = hwndCtrl;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; ti.<span class="me1">lpszText</span> = const_cast&lt;lptstr&gt;<span class="br0">&#40;</span>szMsg<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!SendMessage<span class="br0">&#40;</span>hwndTT, TTM_ADDTOOL, <span class="nu0">0</span>, <span class="br0">&#40;</span>LPARAM<span class="br0">&#41;</span> &amp;amp;ti<span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">goto</span> Cleanup;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!SendMessage<span class="br0">&#40;</span>hwndTT, TTM_SETTITLE, GetTitleIcon<span class="br0">&#40;</span>dwOpts<span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#40;</span>LPARAM<span class="br0">&#41;</span> szTitle<span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">goto</span> Cleanup;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// Position the tooltip below the control</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!GetWindowRect<span class="br0">&#40;</span>hwndCtrl, &amp;amp;rc<span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">goto</span> Cleanup;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; SendMessage<span class="br0">&#40;</span>hwndTT, TTM_TRACKPOSITION, <span class="nu0">0</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MAKELONG<span class="br0">&#40;</span>rc.<span class="me1">left</span> + <span class="nu0">10</span>, rc.<span class="me1">bottom</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// Show the tooltip</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!SendMessage<span class="br0">&#40;</span>hwndTT, TTM_TRACKACTIVATE, <span class="kw2">TRUE</span>, <span class="br0">&#40;</span>LPARAM<span class="br0">&#41;</span> &amp;amp;ti<span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">goto</span> Cleanup;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; hwndRet = hwndTT;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; hwndTT = <span class="kw2">NULL</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">Cleanup:</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>hwndTT != <span class="kw2">NULL</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; ::<span class="me2">DestroyWindow</span><span class="br0">&#40;</span>hwndTT<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> hwndRet;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p><strong>Update</strong> 2008-11-01 3:08PM: If you are targeting <a href="http://msdn.microsoft.com/en-us/library/ms997646.aspx">comctl32.dll version 6</a> or later, I recommend using the <a href="http://msdn.microsoft.com/en-us/library/bb761668(VS.85).aspx">EM_SHOWBALLOONTIP message</a>.&#160; Comctl32.dll version 6 or later also automatically shows the caps lock warning balloon for edit boxes with the <a href="http://msdn.microsoft.com/en-us/library/6e36b89f(VS.80).aspx">ES_PASSWORD window style</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.deez.info/sengelha/2008/06/12/balloon-tooltips/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Escaping Strings in XPath 1.0</title>
		<link>http://www.deez.info/sengelha/2008/06/03/escaping-strings-in-xpath-10/</link>
		<comments>http://www.deez.info/sengelha/2008/06/03/escaping-strings-in-xpath-10/#comments</comments>
		<pubDate>Wed, 04 Jun 2008 00:59:03 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[XPath]]></category>

		<guid isPermaLink="false">http://www.deez.info/sengelha/?p=5476</guid>
		<description><![CDATA[
XPath is a language for selecting nodes from an XML document.  XPath is used extensively in XSLT and other XML technologies.  I also vastly prefer using XPath (e.g. with XPathNavigator) over the XML DOM when manipulating XML in a non-streaming fashion.


In XPath, strings must be delimited by either single or double quotes.  [...]]]></description>
			<content:encoded><![CDATA[<p>
<a href="http://en.wikipedia.org/wiki/XPath">XPath</a> is a language for selecting nodes from an XML document.  XPath is used extensively in <a href="http://en.wikipedia.org/wiki/XSLT">XSLT</a> and other XML technologies.  I also vastly prefer using XPath (e.g. with <a href="http://msdn.microsoft.com/en-us/library/system.xml.xpath.xpathnavigator.aspx">XPathNavigator</a>) over the XML <a href="http://en.wikipedia.org/wiki/Document_Object_Model">DOM</a> when manipulating XML in a non-streaming fashion.
</p>
<p>
In XPath, strings must be delimited by either single or double quotes.  Given a quote character used to delimit a string, one can&#8217;t represent that same quote character within the string.  This means that if you decide to use single quotes to delimit your XPath string, you couldn&#8217;t represent the string <code>O'Reilly</code>; use double quotes, and you can&#8217;t represent <code>"Hello"</code>.
</p>
<p>
However, given a quote delimiter, you can represent the <i>other</i> quote character.  We can use this observation along with the <a href="http://www.w3.org/2005/xpath-functions/#concat"><code>concat</code> XPath function</a> to devise a general quoting rule for XPath strings.  It&#8217;s easiest to show this via a series of examples:
</p>
<table border="1" style="margin-bottom: 1em;">
<tr>
<th>Original String</th>
<th>Quoted XPath String</th>
</tr>
<tr>
<td><code>a</code></td>
<td><code>'a'</code> (or <code>"a"</code>)</td>
</tr>
<tr>
<td><code>O'Reilly</code></td>
<td><code>"O'Reilly"</code></td>
</tr>
<tr>
<td><code>"Hello"</code></td>
<td><code>'"Hello"'</code></td>
</tr>
<tr>
<td><code>"Hello, Mr. O'Reilly"</code></td>
<td><code>concat('"Hello, Mr. O', "'Reilly", '"')</code></td>
</tr>
</table>
<p>
Below is a piece of C++ code which implements these quotation rules:
</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li class="li1">
<div class="de1">std::<span class="me2">string</span></div>
</li>
<li class="li1">
<div class="de1">QuoteXPathString<span class="br0">&#40;</span><span class="kw4">const</span> std::<span class="me2">string</span>&amp; xpath<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// If we don&#8217;t have any single or double-quote characters, quote the</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="co1">// expression in single quotes.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; std::<span class="me2">string</span>::<span class="me2">size_type</span> pos = xpath.<span class="me1">find_first_of</span><span class="br0">&#40;</span><span class="st0">&quot;&#8217;<span class="es0">\&quot;</span>&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>pos == std::<span class="me2">string</span>::<span class="me2">npos</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="st0">&quot;&#8217;&quot;</span> + xpath + <span class="st0">&quot;&#8217;&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="co1">// If we cannot find the alternate quotation character, quote the</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// expression in the alternate quotation character.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">char</span> chOther = <span class="br0">&#40;</span>xpath<span class="br0">&#91;</span>pos<span class="br0">&#93;</span> == <span class="st0">&#8216;&quot;&#8217;</span> ? <span class="st0">&#8216;<span class="es0">\&#8217;</span>&#8216;</span> : <span class="st0">&#8216;&quot;&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; pos = xpath.<span class="me1">find</span><span class="br0">&#40;</span>chOther, pos + <span class="nu0">1</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>pos == std::<span class="me2">string</span>::<span class="me2">npos</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> chOther + xpath + chOther;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// The string has both quotation characters. &nbsp;We need to use concat()</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// to form the string.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; std::<span class="me2">stringstream</span> ss;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; ss &lt;&lt; <span class="st0">&quot;concat(&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;&lt;&lt; chOther</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;&lt;&lt; xpath.<span class="me1">substr</span><span class="br0">&#40;</span><span class="nu0">0</span>, pos<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;&lt;&lt; chOther;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">do</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; chOther = <span class="br0">&#40;</span>xpath<span class="br0">&#91;</span>pos<span class="br0">&#93;</span> == <span class="st0">&#8216;&quot;&#8217;</span> ? <span class="st0">&#8216;<span class="es0">\&#8217;</span>&#8216;</span> : <span class="st0">&#8216;&quot;&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; std::<span class="me2">string</span>::<span class="me2">size_type</span> pos2 = xpath.<span class="me1">find</span><span class="br0">&#40;</span>chOther, pos + <span class="nu0">1</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; ss &lt;&lt; <span class="st0">&#8216;,&#8217;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;&lt; chOther</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;&lt; xpath.<span class="me1">substr</span><span class="br0">&#40;</span>pos, pos2 &#8211; pos<span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;&lt; chOther;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; pos = pos2;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">while</span> <span class="br0">&#40;</span>pos != std::<span class="me2">string</span>::<span class="me2">npos</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; ss &lt;&lt; <span class="st0">&quot;)&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">return</span> ss.<span class="me1">str</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>
Usage looks like:
</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li class="li1">
<div class="de1">std::<span class="me2">string</span> lastName = &#8230;; <span class="co1">// May come from user input</span></div>
</li>
<li class="li1">
<div class="de1">std::<span class="me2">string</span> xpath = <span class="st0">&quot;//Customer[LastName = &quot;</span> +</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; QuoteXPathString<span class="br0">&#40;</span>lastName<span class="br0">&#41;</span> + <span class="st0">&quot;]&quot;</span>;</div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.deez.info/sengelha/2008/06/03/escaping-strings-in-xpath-10/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Representing Date/Times as Strings for Non-Human Consumption</title>
		<link>http://www.deez.info/sengelha/2008/03/07/representing-datetimes-as-strings-for-non-human-consumption/</link>
		<comments>http://www.deez.info/sengelha/2008/03/07/representing-datetimes-as-strings-for-non-human-consumption/#comments</comments>
		<pubDate>Fri, 07 Mar 2008 16:46:29 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.deez.info/sengelha/2008/03/07/representing-datetimes-as-strings-for-non-human-consumption/</guid>
		<description><![CDATA[
If you ever have the need to represent a date/time (or part of a date/time) as a string for programmatic rather than human consumption (e.g. you are defining a save file format or a network protocol), please use ISO 8601 unless you have a very strong reason not to.


For more information, please read what the [...]]]></description>
			<content:encoded><![CDATA[<p>
If you ever have the need to represent a date/time (or part of a date/time) as a string for programmatic rather than human consumption (e.g. you are defining a save file format or a network protocol), please use <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO 8601</a> unless you have a very strong reason not to.
</p>
<p>
For more information, please read what the <a href="http://www.w3.org/TR/NOTE-datetime.html">W3C has to say about ISO 8601 style date and time formats</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.deez.info/sengelha/2008/03/07/representing-datetimes-as-strings-for-non-human-consumption/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t Forget to Reap your Zombies</title>
		<link>http://www.deez.info/sengelha/2008/03/07/dont-forget-to-reap-your-zombies/</link>
		<comments>http://www.deez.info/sengelha/2008/03/07/dont-forget-to-reap-your-zombies/#comments</comments>
		<pubDate>Fri, 07 Mar 2008 16:20:52 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://www.deez.info/sengelha/2008/03/07/dont-forget-to-reap-your-zombies/</guid>
		<description><![CDATA[
I recently received a bug report for my quick-and-dirty TCP debugging tool tcpconndbg where it was creating a large number of zombie processes.  The person who filed the bug, Peter Viskup, was even kind enough to send a patch.  While this is old news to anyone with extensive Unix programming experience, always remember [...]]]></description>
			<content:encoded><![CDATA[<p>
I recently received a bug report for my quick-and-dirty TCP debugging tool <a href="http://www.deez.info/sengelha/code/tcpconndbg/">tcpconndbg</a> where it was creating a large number of <a href="http://en.wikipedia.org/wiki/Zombie_process">zombie processes</a>.  The person who filed the bug, Peter Viskup, was even kind enough to send a patch.  While this is old news to anyone with extensive Unix programming experience, always remember the following:
</p>
<p>
If you create a child process using <a href="http://www.opengroup.org/onlinepubs/007908799/xsh/fork.html"><code>fork()</code></a>, you must either:
</p>
<ol>
<li>Explicitly retrieve the child process&#8217;s exit code using one of the <a href="http://www.opengroup.org/onlinepubs/009695399/functions/wait.html"><code>wait()</code></a> functions (e.g. <code>waitpid()</code>)</li>
<li>Tell the system that you aren&#8217;t interested in the child process&#8217;s exit code by using either:
<ol>
<li><a href="http://www.opengroup.org/onlinepubs/009695399/functions/sigaction.html"><code>sigaction()</code></a> with the <code>SA_NOCLDWAIT</code> parameter (preferred)</li>
<li><a href="http://www.opengroup.org/onlinepubs/000095399/functions/signal.html"><code>signal(SIGCHILD, SIG_IGN);</code></a> (for systems which do not support <code>sigaction()</code>)</li>
</ol>
</li>
</ol>
<p>
As I fixed this bug, I realized I hadn&#8217;t looked at tcpconndbg in 5 years.  My how programming style changes&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.deez.info/sengelha/2008/03/07/dont-forget-to-reap-your-zombies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Geometric Annual Return In SQL</title>
		<link>http://www.deez.info/sengelha/2008/01/30/geometric-annual-return-sql/</link>
		<comments>http://www.deez.info/sengelha/2008/01/30/geometric-annual-return-sql/#comments</comments>
		<pubDate>Wed, 30 Jan 2008 17:39:08 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Finance]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.deez.info/sengelha/2008/01/30/annualized-geometric-return-sql/</guid>
		<description><![CDATA[
Here is some quick-and-dirty SQL to calculate an geometric annual return (as a percent) from a column of monthly returns (in percents).




/* Convert the annualized number back to a percent */


SELECT &#40;T3.AnnHPR &#8211; 1&#41; * 100 AS GeomAnnRet


FROM


&#160; &#40;


&#160; /* Annualize the holding period return */


&#160; SELECT POWER&#40;T2.HPR, 12.0 / T2.NumReturns&#41; AS AnnHPR


&#160; FROM


&#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>
Here is some quick-and-dirty SQL to calculate an <a href="http://en.wikipedia.org/wiki/Return_on_investment#Average_annual_return_.28geometric.29">geometric annual return</a> (as a percent) from a column of monthly returns (in percents).
</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li class="li1">
<div class="de1"><span class="coMULTI">/* Convert the annualized number back to a percent */</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">SELECT</span> <span class="br0">&#40;</span>T3.AnnHPR &#8211; <span class="nu0">1</span><span class="br0">&#41;</span> * <span class="nu0">100</span> <span class="kw1">AS</span> GeomAnnRet</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">FROM</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#40;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="coMULTI">/* Annualize the holding period return */</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">SELECT</span> POWER<span class="br0">&#40;</span>T2.HPR, <span class="nu0">12.0</span> / T2.NumReturns<span class="br0">&#41;</span> <span class="kw1">AS</span> AnnHPR</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">FROM</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="coMULTI">/* Calculate the holding period return over the time</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; period.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; </span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp;POWER(10, SUM(LOG10(n))) is a simulated PRODUCT(n)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp;aggregate function.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; </span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp;The precision of POWER is determined by the precision</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp;of the first argument, so use a lot of decimals. */</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">SELECT</span> POWER<span class="br0">&#40;</span><span class="nu0">10.0000000000000000</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SUM<span class="br0">&#40;</span>LOG10<span class="br0">&#40;</span>T.MonthReturn<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">AS</span> HPR,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;COUNT<span class="br0">&#40;</span>*<span class="br0">&#41;</span> <span class="kw1">AS</span> NumReturns</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">FROM</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="coMULTI">/* Convert all percent returns to multipliers (1% -&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1.01) */</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw1">SELECT</span> <span class="nu0">1</span> + MonthPctReturn / <span class="nu0">100</span> <span class="kw1">AS</span> MonthReturn</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; <span class="kw1">FROM</span> &#8230;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span> <span class="kw1">AS</span> T</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#41;</span> <span class="kw1">AS</span> T2</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#41;</span> <span class="kw1">AS</span> T3&lt;/code&gt;</div>
</li>
</ol>
</div>
<p>
<b>Update</b> 2008-01-30 10:52PM: Here&#8217;s the equivalent &#8220;one-liner&#8221;:
</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">SELECT</span> <span class="nu0">100</span> * <span class="br0">&#40;</span>POWER<span class="br0">&#40;</span>POWER<span class="br0">&#40;</span><span class="nu0">10.000000000000000</span>, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SUM<span class="br0">&#40;</span>LOG10<span class="br0">&#40;</span><span class="nu0">1</span> + MonthPctReturn / <span class="nu0">100</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="nu0">12.0</span> / COUNT<span class="br0">&#40;</span>*<span class="br0">&#41;</span><span class="br0">&#41;</span> &#8211; <span class="nu0">1</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">FROM</span> &#8230;</div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.deez.info/sengelha/2008/01/30/geometric-annual-return-sql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Silverlight 1.0 Mandelbrot Set Generator</title>
		<link>http://www.deez.info/sengelha/2008/01/09/silverlight-10-mandelbrot-set-generator/</link>
		<comments>http://www.deez.info/sengelha/2008/01/09/silverlight-10-mandelbrot-set-generator/#comments</comments>
		<pubDate>Thu, 10 Jan 2008 05:40:19 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.deez.info/sengelha/2008/01/09/silverlight-10-mandelbrot-set-generator/</guid>
		<description><![CDATA[While reading the Mandelbrot set chapter in Dewdney&#8217;s The New Turing Omnibus, I realized that this would be a great test application for Microsoft&#8217;s new interactive Web application framework Silverlight.  Below is the component, its source code, and a few things I learned along the way.
Beware: the Mandelbrot set is computationally expensive and may [...]]]></description>
			<content:encoded><![CDATA[<p>While reading the Mandelbrot set chapter in Dewdney&#8217;s <a href="http://books.google.com/books?id=XW7fICYtkg8C&#038;dq=new+turing+omnibus&#038;pg=PP1&#038;ots=fWQUbonyHG&#038;sig=vJQ_A0J7V0DQMsnf2AH2LoLyMFc&#038;hl=en&#038;prev=http://www.google.com/search?hl=en&#038;q=new+turing+omnibus&#038;sa=X&#038;oi=print&#038;ct=title&#038;cad=one-book-with-thumbnail">The New Turing Omnibus</a>, I realized that this would be a great test application for Microsoft&#8217;s new interactive Web application framework <a href="http://silverlight.net/">Silverlight</a>.  Below is the component, its source code, and a few things I learned along the way.</p>
<p>Beware: the Mandelbrot set is computationally expensive and may appear to lock up your web browser.  If a &#8220;Stop running this script?&#8221; dialog pops up, please click no to allow the calculations to finish.<br />
<span id="more-5439"></span></p>
<h3>Silverlight 1.0 Mandelbrot Set Control</h3>
<p>Here is a Silverlight 1.0 control which draws the Mandelbrot set.  Left-click to zoom in on a particular region.<br />
<script type="text/javascript" src="/sengelha/wp-content/uploads/2008/01/SilverlightMandelbrot/js/Silverlight/Silverlight.js"></script><br />
<script type="text/javascript" src="/sengelha/wp-content/uploads/2008/01/SilverlightMandelbrot/js/SilverlightMandelbrot.js"></script><br />
<script type="text/javascript" src="/sengelha/wp-content/uploads/2008/01/SilverlightMandelbrot/js/SilverlightMandelbrotEvents.js"></script></p>
<div style="width:300px; height:300px;" id="SilverlightMandelbrot"></div>
<p><script type="text/javascript">  var parentElement = document.getElementById("SilverlightMandelbrot");  createSilverlightMandelbrot("/sengelha/wp-content/uploads/2008/01/SilverlightMandelbrot/xaml/mandelbrot.xaml");</script></p>
<h3>Source Code</h3>
<p>The source code to the Silverlight Mandelbrot set consists of the following pieces:</p>
<ul>
<li><a href="/sengelha/wp-content/uploads/2008/01/SilverlightMandelbrot/js/SilverlightMandelbrot.js">SilverlightMandelbrot.js</a> &mdash; The code for instantiating the Silverlight Mandelbrot control and binding it to a <code>div</code></li>
<li><a href="/sengelha/wp-content/uploads/2008/01/SilverlightMandelbrot/js/SilverlightMandelbrotEvents.js">SilverlightMandelbrotEvents.js</a> &mdash; The event handlers for the Silverlight Mandelbrot control, including the drawing code itself (performed on canvas load)</li>
<li><a href="/sengelha/wp-content/uploads/2008/01/SilverlightMandelbrot/xaml/mandelbrot.xaml">mandelbrot.xaml</a> &mdash; The XAML which defines the visual layout of the control</li>
<li><a href="/sengelha/wp-content/uploads/2008/01/SilverlightMandelbrot/js/Silverlight/Silverlight.js">Silverlight.js</a> &mdash; the Silverlight code itself</li>
</ul>
<h3>Notable Findings</h3>
<ul>
<li>Overall responsiveness is rather slow, especially on the mousemove event.  Perhaps I&#8217;m pushing Silverlight too hard too early, but this slowness makes me highly reluctant to adopt Silverlight yet.</li>
<li>I can&#8217;t figure out how to do progressive (e.g. line-by-line) rendering to give the user feedback.</li>
<li>There is no facility for directly painting an individual pixel within Silverlight.  Instead, you must draw 1 by 1 colored XAML rectangle controls.  Because individual XAML rectangles are quite heavyweight, I coalesce multiple pixels of the same color in the same row into one rectangle.</li>
<li>I wanted to use right-click to zoom out, but there doesn&#8217;t appear to be a way to capture the right click event from within Silverlight.</li>
</ul>
<h3>About the Mandelbrot Set</h3>
<p>For more information on the Mandelbrot set, see <a href="http://en.wikipedia.org/wiki/Mandelbrot_set">its Wikipedia article</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.deez.info/sengelha/2008/01/09/silverlight-10-mandelbrot-set-generator/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
