<?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>Factor Mystic</title>
	<atom:link href="http://factormystic.net/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://factormystic.net/blog</link>
	<description></description>
	<lastBuildDate>Sun, 06 May 2012 05:37:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Using Reactive Extensions to smooth compass data in Windows Phone</title>
		<link>http://factormystic.net/blog/using-reactive-extensions-to-smooth-compass-data-in-windows-phone</link>
		<comments>http://factormystic.net/blog/using-reactive-extensions-to-smooth-compass-data-in-windows-phone#comments</comments>
		<pubDate>Sun, 06 May 2012 05:24:16 +0000</pubDate>
		<dc:creator>Factor Mystic</dc:creator>
				<category><![CDATA[c-sharp]]></category>
		<category><![CDATA[reactive-extensions]]></category>
		<category><![CDATA[windows-phone]]></category>

		<guid isPermaLink="false">http://factormystic.net/blog/?p=286</guid>
		<description><![CDATA[Getting Started The challenge is to take the raw compass heading data, and smooth it out over time so the UI element this data is bound to (such as an arrow) won't be jittery. You can see this jitter in the SDK example for the Compass: the CurrentValueChanged event handler is fired every 20ms and jitters [...]]]></description>
			<content:encoded><![CDATA[<h2>Getting Started</h2>
<p>The challenge is to take the raw compass heading data, and smooth it out over time so the UI element this data is bound to (such as an arrow) won't be jittery. You can see this jitter in the <a href="http://msdn.microsoft.com/en-us/library/ff431744%28v=vs.92%29.aspx#BKMK_Sensors">SDK example</a> for the Compass: the <code>CurrentValueChanged</code> event handler is fired every 20ms and jitters within the error margin for the hardware. Our task is to smooth out these data readings for a more pleasant user interface. And to make it fun, we'll be using Reactive Extensions.</p>
<p>It's quite easy to calculate a periodic average of a data stream with Reactive Extensions, and we'll tackle it in three stages:</p>
<ol>
<li>Create the <code>Observable</code></li>
<li>Segment the compass readings into chunks, and get an average</li>
<li>Capture the result and make something happen</li>
</ol>
<h2>Step 1: Create the <code>Observable</code></h2>
<p>Starting with the Compass's <a href="http://msdn.microsoft.com/en-us/library/hh239103.aspx">CurrentValueChanging</a> event, we need to convert it into an Observable. After creating a new Compass object (hereafter simply called "<code>compass</code>"), we can write this with any overload of <a href="http://msdn.microsoft.com/en-us/library/hh697809.aspx">Observable.FromEvent</a>, either by manually providing delegates to add/remove event subscriptions (as commonly listed on <a href="http://rxwiki.wikidot.com/101samples#toc6">RxWiki</a>), or by providing the event name as a string:</p>
<script src="https://gist.github.com/2607208.js"></script><noscript><p>View the code on <a href="https://gist.github.com/2607208">Gist</a>.</p></noscript>
<p>For succinctness, I'll use the latter in this post.</p>
<p>If we stop right here for a moment, we can confirm that our compass is working and that we can get readings by subscribing to the <code>Observable</code>'s stream of <code>SensorReadingEventArgs</code> events by tapping in with the <code>Subscribe</code> method and printing out the raw heading readings:</p>
<script src="https://gist.github.com/2607213.js"></script><noscript><p>View the code on <a href="https://gist.github.com/2607213">Gist</a>.</p></noscript>
<p>Running this sample will spit out an endless series of raw readings in the debug output window:</p>
<p><img class="aligncenter" title="Raw Compass Headings" src="http://i.imgur.com/TQ2zM.png" alt="" width="668" height="396" /></p>
<p>So far, so good. But, we could've done this all with a standard event handler, so let's kick it up an notch...</p>
<h2>Step 2: Break into chunks and average</h2>
<p>We want to avoid jitter in our compass readings, and a simple way to do that is to average all the individual readings over a small time period, of say, two seconds. Without Rx, you'd need to declare a period reset timer, and then keep track of a running average over the two second period, then clear it when the timer fires and so forth.</p>
<p>With Rx, it's chillingly simple; we can do it by chaining just two methods: <code>BufferWithTime</code> followed by a standard Linq <code>SelectMany</code> (well, and a <code>Select</code>). And it's all in a single statement.</p>
<script src="https://gist.github.com/2608813.js"></script><noscript><p>View the code on <a href="https://gist.github.com/2608813">Gist</a>.</p></noscript>
<p>Running this will spit out readings just like before, except now, they're clumped every two seconds, with a pause in between.</p>
<p><img class="aligncenter" title="Buffered compass headings" src="http://i.imgur.com/v2dnZ.png" alt="" width="668" height="398" /></p>
<p>Let's break it down:</p>
<p>Picking up after creating the <code>Observable</code>, we chain a call to <a href="http://msdn.microsoft.com/en-us/library/hh697736.aspx"><code>BufferWithTime</code></a>. For the specified period (two seconds, passed in with <code>TimeSpan.FromSeconds(2)</code>, <code>BufferWithTime</code> takes events and stuffs them into an <code>IList</code> of events. Then, we use <code>Select</code> to project that list of events into a list of compass headings (pulled out of the event args, <code>e.EventArgs.SensorReading.TrueHeading</code>). The <code>Subscribe</code> method, as before, allows us to debug print the compass headings to confirm.</p>
<p>Here's the full application so far:</p>
<script src="https://gist.github.com/2608127.js"></script><noscript><p>View the code on <a href="https://gist.github.com/2608127">Gist</a>.</p></noscript>
<p>Our raw compass readings are broken into two-second lists, but they're still individually jittery. However, we can instead take each list and aggregate it into a single heading value. By replacing the <code>SelectMany</code>, which gave us a list of headings, with a <code>Select</code>, we can do the averaging right inline:</p>
<script src="https://gist.github.com/2609744.js"></script><noscript><p>View the code on <a href="https://gist.github.com/2609744">Gist</a>.</p></noscript>
<p>And this gives us one average compass heading every two seconds, minus the jitter, just like we wanted:</p>
<p><img class="aligncenter" title="Average compass headings" src="http://i.imgur.com/cUa70.png" alt="" width="670" height="399" /></p>
<p>Complete program listing so far:</p>
<script src="https://gist.github.com/2609858.js"></script><noscript><p>View the code on <a href="https://gist.github.com/2609858">Gist</a>.</p></noscript>
<h2>Step 3: Making something happen</h2>
<p>We now have de-jittered compass readings coming in every two seconds. Let's hook this data up to the UI and build an actual application.</p>
<p>Taking this empty Windows Phone project, I've added the following <code>Image</code> into the default content <code>Grid</code>:</p>
<script src="https://gist.github.com/2613124.js"></script><noscript><p>View the code on <a href="https://gist.github.com/2613124">Gist</a>.</p></noscript>
<p>There's nothing special here, it's just an image with a default <code>RenderTransform</code> that sets the rotational center of the image element to the middle.</p>
<p><a href="http://factormystic.net/blog/wp-content/uploads/2012/05/screenshot.png"><img class="aligncenter size-medium wp-image-300" title="running compass application screenshot" src="http://factormystic.net/blog/wp-content/uploads/2012/05/screenshot-180x300.png" alt="" width="180" height="300" /></a></p>
<p>Pasting in the Rx code we developed above, we can swap out the debug call and instead update the <code>RenderTransform</code>'s angle property to the compass heading (actually, 360 minus the heading... we want the arrow image to rotate opposite the phone device. If we didn't do this subtraction, it'd rotate the header angle, but in the same direction we turn the phone.)</p>
<script src="https://gist.github.com/2613466.js"></script><noscript><p>View the code on <a href="https://gist.github.com/2613466">Gist</a>.</p></noscript>
<p>(Oh, and there's one other change: adding in a call to <code>ObserveOnDispatcher</code> allows us to execute the <code>Subscribe</code> delegate (eg, update the arrow rotation) on the UI thread. We didn't need to worry about that before because we were just debug printing, and not accessing any resources created on the UI thread.)</p>
<p>Running the whole program now shows the compass arrow updating once every two seconds, correctly pointing to the device's compass heading. Feel free to adjust the period from two seconds to something more useful... I found 0.5 seconds to be a good balance between update frequency and heading jitter.</p>
<p>I've posted the complete example application on github, so feel free to check it out:<br />
<a href="https://github.com/factormystic/rx-compass-smoothing"> https://github.com/factormystic/rx-compass-smoothing</a></p>
]]></content:encoded>
			<wfw:commentRss>http://factormystic.net/blog/using-reactive-extensions-to-smooth-compass-data-in-windows-phone/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Default Programs Editor 2.7</title>
		<link>http://factormystic.net/blog/default-programs-editor-2-7</link>
		<comments>http://factormystic.net/blog/default-programs-editor-2-7#comments</comments>
		<pubDate>Mon, 01 Nov 2010 03:51:50 +0000</pubDate>
		<dc:creator>Factor Mystic</dc:creator>
				<category><![CDATA[default-programs-editor]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://factormystic.net/blog/?p=279</guid>
		<description><![CDATA[The next version of Default Programs Editor has been posted, along with a total site redesign. All the important stuff is now on the root page, and I've severely dialed back on cruft to put most of your experience on a single page. And, one more note: this announcement is actually for the second release [...]]]></description>
			<content:encoded><![CDATA[<p>The next version of <strong>Default Programs Editor</strong> has been posted, along with a total site redesign. All the important stuff is now on the root page, and I've severely dialed back on cruft to put most of your experience on a single page. And, one more note: this announcement is actually for the <em>second</em> release of version 2.7. There were a couple bugs I noticed in the crash report logs that really needed to be fixed before I announced the release, so, if you happened to grab DPE in between the redesign and this post, check and see if you've got the older version. They're each got a proper version number, but "2.7" refers to the later release.</p>
<p><strong>Download</strong> now at <a href="http://defaultprogramseditor.com/">http://defaultprogramseditor.com</a><br />
<a href="http://defaultprogramseditor.com/"></a><strong>Have an idea or feature request?</strong> Put it on the feedback forum: <a href="http://defaultprogramseditor.uservoice.com/">http://defaultprogramseditor.uservoice.com</a></p>
<p><strong>Want to support Default Programs Editor?</strong> Help spread the word! Suggest Default Programs Editor to be included in Ninite (<a href="http://ninite.com/feedback">link</a>). <a href="http://defaultprogramseditor.com/donate">Donations are accepted too</a>, and thank you <strong>so much</strong> to the many people who've contributed.</p>
<p>There's some cool new stuff in 2.7, most notably <strong>context menu icon editing</strong>, <strong>'Open With' support</strong>, and built in <strong>registry backups</strong>. The latter two items were requested on the feedback forum and quite popular, so if you have a feature request, be sure go <a href="http://defaultprogramseditor.uservoice.com">there</a> and request it. There's also a myriad of great little usability tweaks like better keyboard accessibility (also a requested feature on UserVoice).</p>
<blockquote><p>Changelog:</p>
<p>Version 2.7.2675.2253 (October 29, 2010)<br />
<strong>Bugs Fixed:</strong><br />
- Fixed a minor DPI related layout bug.</p>
<p><strong>Crashes Fixed:</strong><br />
- Fixed a crash after clicking the DDE 'Edit' button when adding a new context menu item.<br />
- Viewing 'Open With' programs caused a crash when the item listed in the registry didn't exist on disk.<br />
- Fixed a crash when starting the application for some users.</p>
<p>Version 2.7.2660.1843 (October 23, 2010)<br />
<strong>New Features:</strong><br />
+ Added support for editing 'Open With' programs.<br />
+ Added support for editing context menu item icons.<br />
+ Added support for registry backups of file type information.<br />
+ Added "%1" by default when browsing for an application, and added an option to toggle it.<br />
+ "Show in folder" button added to success page when saving to a .reg file.<br />
+ Increased performance when loading long lists.<br />
+ Better support for deleting verb precedence trees.<br />
+ Increased keyboard accessibility.</p>
<p><strong>Bugs Fixed:</strong><br />
- Fixed miscellaneous layout bugs.<br />
- Fixed being stuck on the the options page after an elevated restart.<br />
- Fixed issue causing scope labels to be listed twice for context menu items.</p>
<p><strong>Crashes Fixed:</strong><br />
- Setting certain applications as context menu default could cause a crash.<br />
- Selecting multiple extensions caused a crash when switching to the context menu page in certain scenarios.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://factormystic.net/blog/default-programs-editor-2-7/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Project Euler in F#: Problem 2</title>
		<link>http://factormystic.net/blog/project-euler-in-fsharp-problem-2</link>
		<comments>http://factormystic.net/blog/project-euler-in-fsharp-problem-2#comments</comments>
		<pubDate>Mon, 05 Jul 2010 18:27:00 +0000</pubDate>
		<dc:creator>Factor Mystic</dc:creator>
				<category><![CDATA[f-sharp]]></category>
		<category><![CDATA[project-euler]]></category>

		<guid isPermaLink="false">http://factormystic.net/blog/?p=261</guid>
		<description><![CDATA[Problem 2 Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... Find the sum of all the even-valued terms in the sequence which do not exceed [...]]]></description>
			<content:encoded><![CDATA[<h2>Problem 2</h2>
<blockquote><p>Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:<br />
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...<br />
Find the sum of all the even-valued terms in the sequence which do not exceed four million.</p></blockquote>
<h2>The Thinking</h2>
<p>The problem is similar to <a href="http://factormystic.net/blog/project-euler-in-fsharp-problem-1">Problem 1</a>, but this time instead of a natural number sequence, we're to use a fibbonacci sequence, evens only, less than 4 million. Then, we'll need to sum them up; that we did in Problem 1 with Seq.sum. How can we generate the sequence? I'll be taking a simple two-step approach. First, figure out a function to generate a fibbonacci sequence (up through 4,000,000), then take all the evens. We can Seq.sum that resulting sequence to find our answer.</p>
<h2>Generating a Fibonacci Sequence</h2>
<p>Generating a fibbonacci sequence in F# is a textboook case, and so much so that it's actually an example snippet for the built-in F# function we're going to use to generate it: Seq.unfold. Seq.unfold is a  function that returns a sequence, based on a function we provide. It takes two parameters: a sequence element generator function, and the inital value to start with.</p>
<pre class="brush: php">Seq.unfold generator state</pre>
<p>The generator function must be defined with a single input parameter (the "state value"), and returning an "option tuple of the next element in the sequence and the next state value" (<a href="http://msdn.microsoft.com/en-us/library/ee340363.aspx">from documentation</a>).</p>
<p>A fibbonacci algorithm requires two inputs (the previous two digits), but we can only pass one parameter. Luckily in F# we have <a href="http://msdn.microsoft.com/en-us/library/dd233200.aspx">Tuples</a>. A tuple lets us package up several values into a single group, and is written with as a comma separated list inside parenthesis:</p>
<pre class="brush: php">let sometuple = (&quot;this&quot;, &quot;is&quot;, &quot;a&quot;, &quot;single&quot;, &quot;tuple&quot;)</pre>
<p>The return value is also something new, using the built-in <a href="http://msdn.microsoft.com/en-us/library/dd233245.aspx">Option module</a>. We'll be returning an Option, either Some or None. None is a signal to unfold that this is the end of sequence, and for all the rest of the return results, we need to return Some-thing (the next element of the sequence as well as the next state value in tuple form) as we learned above, from the documentation for unfold.</p>
<p>This might seem like a lot to process all at once, but it ends up looking pretty simple when it's all put together. The generator function for fibbonacci numbers less than 4m looks like this:</p>
<pre class="brush: php">let fibgen (x,y) = //define a function &#039;fibgen&#039; and pass in a single parameter, a tuple that represents the most recent two digits of the fibbonacci sequence so far
if(x &lt; 4000000) then // define a cut-off threshold to keep the sequence from going on forever
Some(x+y, (y, x+y)) // return an Option tuple; the next elemnet of the sequence: x+y (the two most recent elements added together), and the next state value- a single tuple that will be used next time the funciton is run
else None // we&#039;re up to 4m, so tell unfold we&#039;re done with the sequence
</pre>
<p>And now, we can plug that into Seq.unfold:</p>
<pre class="brush: php">let fibseq = Seq.unfold fibgen (1,1) // (1,1) is a single tuple parameter with the initial values for the fibgen function</pre>
<p>If we run this in the Interactive F# window in Visual Studio, we can confirm this produces the full fibbonacci sequence:</p>
<pre class="brush: php">val it : seq = seq [2; 3; 5; 8; ...]</pre>
<h2>Getting Just The Evens</h2>
<p>If you recall our solution to <a href="http://factormystic.net/blog/project-euler-in-fsharp-problem-1">Problem 1</a>, it should be easy to figure out how to make a new sequence with only the even values by using seq, modulo, and yield that we've already learned.</p>
<pre class="brush: php">let fibevens = seq{for i in fibseq do if i % 2 = 0 then yield i}</pre>
<h2>My Solution</h2>
<p>Putting it all together, with Seq.sum to add up the sequence:</p>
<pre class="brush: php">let fibgen (x,y) = if(x &lt; 4000000) then Some(x+y, (y, x+y)) else None
let fibseq = Seq.unfold fibgen (1,1)
let fibevens = seq{for i in fibseq do if i % 2 = 0 then yield i}
let result = Seq.sum fibevens
printfn &quot;%A&quot; result
</pre>
<p>Project Euler Problem 2: <strong><a href="http://projecteuler.net/index.php?section=profile&#038;profile=factormystic">Answered</a></strong></p>
<h2>Further Reading</h2>
<ul>
<li><a href="http://www.ctocorner.com/fsharp/book/ch8.aspx">Chapter 8- Functions &amp; Functional Concepts</a>, The F# Survival Guide</li>
<li><a href="http://geekswithblogs.net/MarkPearl/archive/2010/06/23/f-seq.unfold.aspx">Mark Pearl's post on Seq.Unfold</a>, using tuple parameters and pipelines</li>
<li><a href="http://msdn.microsoft.com/en-us/library/ee340363.aspx">Seq.unfold</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/dd233245.aspx">Options module</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/dd233200.aspx">Tuples</a></li>
</ul>
<h2>A Post Script</h2>
<p>Each part of the above solution is named for clarity. We could easily compose these functions for a more compact solution:</p>
<pre class="brush: php">printfn &quot;%A&quot; (Seq.sum(seq{for i in ((1,1) |&gt; Seq.unfold(fun (x,y) -&gt; if(x &lt; 4000000) then Some(x+y, (y, x+y)) else None)) do if i % 2 = 0 then yield i}))</pre>
<p>The only thing that gets weird in this compact version is the anonymous replacement for fibgen, which uses lambda syntax fun &amp; -&gt;, and the pipeline operator, |&gt; to pass in the intial state. There are some goofy rules for when you can and cannot use piplineing; check out the <a href="http://www.ctocorner.com/fsharp/book/ch8.aspx">Pipeline section</a> of Chapter 8 of The F# Survival Guide for a good primer.</p>
]]></content:encoded>
			<wfw:commentRss>http://factormystic.net/blog/project-euler-in-fsharp-problem-2/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Call for ideas for DPE 2.7</title>
		<link>http://factormystic.net/blog/call-for-ideas-for-dpe-2-7</link>
		<comments>http://factormystic.net/blog/call-for-ideas-for-dpe-2-7#comments</comments>
		<pubDate>Sat, 03 Jul 2010 16:05:14 +0000</pubDate>
		<dc:creator>Factor Mystic</dc:creator>
				<category><![CDATA[default-programs-editor]]></category>
		<category><![CDATA[dpe-cross-site]]></category>

		<guid isPermaLink="false">http://factormystic.net/blog/?p=255</guid>
		<description><![CDATA[After taking a bit of a break from the project, I'm reopening development of Default Programs Editor, with a couple of great ideas in mind. The feedback since I launched 2.0 almost a year ago has been outstanding, and has guided six minor releases in the mean time. For version 2.7 development I'm openly soliciting [...]]]></description>
			<content:encoded><![CDATA[<p>After taking a bit of a break from the project, I'm reopening development of Default Programs Editor, with a couple of great ideas in mind. The feedback since I launched 2.0 almost a year ago has been outstanding, and has guided six minor releases in the mean time. For version 2.7 development I'm openly soliciting ideas to make the next version even better.</p>
<h3>How you can help</h3>
<p>Download Default Programs Editor, and poke around. Mess with stuff. Make little tweaks to your system, then reverse them. What feels right? What gets annoying? What could be better? Let me know!</p>
<ul>
<li>Add a comment to this post</li>
<li>Vote on open ideas at <span style="color: #888888;"><a href="https://defaultprogramseditor.uservoice.com">Default Programs Editor's official UserVoice Feedback forum</a></span></li>
<li>Send me an <a href="mailto:factormystic@gmail.com">email</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://factormystic.net/blog/call-for-ideas-for-dpe-2-7/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SndVolPlus 1.1 Released</title>
		<link>http://factormystic.net/blog/sndvolplus-1-1-released</link>
		<comments>http://factormystic.net/blog/sndvolplus-1-1-released#comments</comments>
		<pubDate>Sun, 27 Jun 2010 21:02:36 +0000</pubDate>
		<dc:creator>Factor Mystic</dc:creator>
				<category><![CDATA[news]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[sndvolplus]]></category>

		<guid isPermaLink="false">http://factormystic.net/blog/?p=243</guid>
		<description><![CDATA[SndVolPlus SndVolPlus is a replacement sound volume control. Looks and acts like the default volume control, plus a few extra features. Changes Position Mixer and Volume Control windows next to the taskbar tray area, fixing issue #4 Get it Info/Download Changeset]]></description>
			<content:encoded><![CDATA[<h3>SndVolPlus</h3>
<p>SndVolPlus is a replacement sound volume control. Looks and acts like the default volume control, plus a few extra features.</p>
<h3>Changes</h3>
<ul>
<li>Position Mixer and Volume Control windows next to the taskbar tray area, fixing issue <a href="http://bitbucket.org/factormystic/sndvolplus/issue/4/open-volume-and-mixer-windows-close-to-the">#4</a></li>
</ul>
<h3>Get it</h3>
<p><a title="Download" href="http://factormystic.net/projects/apps/sndvolplus">Info/Download</a><br />
<a title="Changeset" href="http://bitbucket.org/factormystic/sndvolplus/changeset/ca37e67f252c">Changeset</a></p>
]]></content:encoded>
			<wfw:commentRss>http://factormystic.net/blog/sndvolplus-1-1-released/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Project Euler in F#: Problem 1</title>
		<link>http://factormystic.net/blog/project-euler-in-fsharp-problem-1</link>
		<comments>http://factormystic.net/blog/project-euler-in-fsharp-problem-1#comments</comments>
		<pubDate>Sun, 20 Jun 2010 00:36:59 +0000</pubDate>
		<dc:creator>Factor Mystic</dc:creator>
				<category><![CDATA[f-sharp]]></category>
		<category><![CDATA[project-euler]]></category>

		<guid isPermaLink="false">http://factormystic.net/blog/?p=214</guid>
		<description><![CDATA[About Project Euler I've wanted to take a crack at Project Euler for some time now. If you're not familiar, it's basically a list of mathematical problems. From the site: Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive [...]]]></description>
			<content:encoded><![CDATA[<h2>About Project Euler</h2>
<p>I've wanted to take a crack at Project Euler for some time now. If you're not familiar, it's basically a list of mathematical problems. From the site:</p>
<blockquote><p>Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems.</p>
<p>The motivation for starting Project Euler, and its continuation, is to provide a platform for the inquiring mind to delve into unfamiliar areas and learn new concepts in a fun and recreational context.</p></blockquote>
<p>And they <a href="http://projecteuler.net/index.php?section=scores">keep score</a>! In addition, I've also been looking for an excuse to learn F#. In truth, I've wanted to get down and dirty with some functional language, to learn the principles and hopefully become a better programmer. I chose F# because it's part of Visual Studio (starting with 2010), and I'm already handy with .NET, so in theory that will lower the barrier to entry just a little bit. At the very least, it allows me to dodge the hassle of installing another interpreter or environment on my system.</p>
<h2>Blogging It</h2>
<p>As I continue though Project Euler, I'll be posting my solutions here on my site under <a href="http://factormystic.net/projects/code">http://factormystic.net/projects/code</a>, and you can also check my progress by looking at my <a href="http://projecteuler.net/index.php?section=profile&amp;profile=factormystic">Project Euler profile</a> and I look forward to your mocking laughter gentle guidance as I fumble around in F#.</p>
<h2>On to Problem 1</h2>
<blockquote><p>If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.<br />
Find the sum of all the multiples of 3 or 5 below 1000.</p></blockquote>
<p>Straightforward enough, and easy to form a mental model around the problem. But how to implement this in F#? For a quick language primer, I skimmed <a href="http://msdn.microsoft.com/en-us/magazine/ee336127.aspx">An Introduction to Functional Programming for .NET Developers</a> and noticed a few things I might need:</p>
<ul>
<li>An add function<br />
<span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">let add x y = x + y<br />
</span></li>
<li>Sequence syntax and list comprehension<br />
<span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">let numbers = {0..10}<br />
</span></li>
<li>Modulo and ternary operators<br />
<span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">string result = x % 2 == 0 ? "yes" : "no";</span></li>
</ul>
<h2>The Thinking</h2>
<p>The thinking is this: sequences could be used to build a list of integers 1 to 1000; I could use modulo to get multiples of 3 and 5 (<a href="http://imranontech.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/">think </a><a href="http://dotnetpad.net/FizzBuzz/">FizzBuzz</a>), and somehow use that add function to get the sum. Reading the documentation for <a href="http://msdn.microsoft.com/en-us/library/dd233209.aspx">sequence expressions</a> turned out to be quite rewarding (!), as you can embed a filter on a sequence when you declare it:</p>
<pre class="brush: php">let multiples = seq { for i in 1 .. 1000 do if i % 3 = 0 || i % 5 = 0 then yield i }</pre>
<p>Yield is already a familiar concept from C#, from using Enumerables. In fact, from the documentation:</p>
<blockquote><p>Sequences are represented by the seq&lt;'T&gt; type, which is an alias for IEnumerable&lt;T&gt;. Therefore, any .NET Framework type that implements System.IEnumerable can be used as a sequence. The Seq module provides support for manipulations involving sequences.</p></blockquote>
<p>Thus our F# is roughly analogous to something like</p>
<pre class="brush: php">public static IEnumerable GiveMults()
{
foreach (int i in Enumerable.Range(1, 1000))
if (i % 3 == 0 || i % 5 == 0)
yield return i;
}</pre>
<p>Now that we have our sequence of natural numbers, let's figure out how to sum them up. I have the add function I grabbed from the article, and while poking around with the Seq module, I noticed a reduce function, which can apply an accumulator. That would give us</p>
<pre class="brush: php">
let multiples = seq { for i in 1 .. 1000 do if i % 3 = 0 || i % 5 = 0 then yield i }
let add x y = x + y
let result= Seq.reduce add multiples
printfn &quot;%A&quot; result
</pre>
<p>(Side note: <a href="http://msdn.microsoft.com/en-us/library/ee370560.aspx">printfn</a> is how we can write to stdout, much like Console.Writeline. The "%A" stuff works like string.Format parameters- %A indicates "Formats any value, printed with the default layout settings." In the case of a sequence, that means printing the first few values)</p>
<p>...and that code does indeed sum the multiples, as you would expect. But there is a better way. After all, we should expect something as simple as adding up a list to be built in already, and we do have our Seq module functions available.</p>
<p>Indeed, there is a Seq.sum function that does exactly what we're seeking to do, sum a sequence. Rewritten, we have:</p>
<pre class="brush: php">
let result = seq { for i in 1 .. 1000 do if i % 3 = 0 || i % 5 = 0 then yield i }
let total = Seq.sum result
printfn &quot;%A&quot; total
</pre>
<p>And this prints an answer, but that answer is WRONG. See the bug? The original problem stated that we're to "sum of all the multiples of 3 or 5 <strong>below</strong> 1000", but the list comprehension syntax (1..1000) is <strong>inclusive</strong>. Thus, our answer includes 1000, which is evenly divisible by 5, and is summed into the final total. The fix is simple, just write 1..999:</p>
<h2>My Solution</h2>
<pre class="brush: php">
let multiples = seq { for i in 1 .. 999 do if i % 3 = 0 || i % 5 = 0 then yield i }
let result = Seq.sum multiples
printfn &quot;%A&quot; result
</pre>
<p>Bingo.<br />
Project Euler Problem 1: <strong>Answered</strong></p>
<h2>Further Reading</h2>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/magazine/ee336127.aspx">An Introduction to Functional Programming for .NET Developers</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/dd233209.aspx">Sequences</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/ee370560.aspx">Core.Printf Module</a></li>
</ul>
<h2>A Post Script</h2>
<p>For the code golf crew:</p>
<pre class="brush: php">printfn &quot;%A&quot; (Seq.sum (seq { for i in 1 .. 999 do if i % 3 = 0 || i % 5 = 0 then yield i }))</pre>
]]></content:encoded>
			<wfw:commentRss>http://factormystic.net/blog/project-euler-in-fsharp-problem-1/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SndVolPlus 1.0 released</title>
		<link>http://factormystic.net/blog/sndvolplus-released</link>
		<comments>http://factormystic.net/blog/sndvolplus-released#comments</comments>
		<pubDate>Sun, 06 Jun 2010 22:51:49 +0000</pubDate>
		<dc:creator>Factor Mystic</dc:creator>
				<category><![CDATA[news]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[sndvolplus]]></category>
		<category><![CDATA[windows tweaks]]></category>

		<guid isPermaLink="false">http://factormystic.net/blog/?p=208</guid>
		<description><![CDATA[SndVolPlus is a tiny standalone app, that's a replacement for the standard Windows volume control icon. It functions exactly the same as the original "SndVol.exe", with two huge extras: Middle clicking the volume icon toggles mute Double clicking it opens the Volume Mixer directly I wrote it out of frustration when I couldn't easily mute [...]]]></description>
			<content:encoded><![CDATA[<p><strong>SndVolPlus </strong>is a tiny standalone app, that's a replacement for the standard Windows volume control icon.</p>
<div class="wp-caption aligncenter" style="width: 180px"><img title="SndVolPlus Volume Control" src="http://factormystic.net/utils/sndvolplus/sndvol-in-the-taskbar.png" alt="SndVolPlus Volume Control" width="170" height="100" /><p class="wp-caption-text">SndVolPlus Volume Control</p></div>
<p>It functions exactly the same as the original "SndVol.exe", with two huge extras:</p>
<ul>
<li>Middle clicking the volume icon toggles mute</li>
<li>Double clicking it opens the Volume Mixer directly</li>
</ul>
<div class="wp-caption aligncenter" style="width: 531px"><img title="Windows 7 Volume Mixer" src="http://i.imgur.com/Q9emX.png" alt="Windows 7 Volume Mixer" width="521" height="382" /><p class="wp-caption-text">Windows 7 Volume Mixer</p></div>
<p>I wrote it out of frustration when I couldn't easily mute Windows Media Center when watching live television. Now that I can, I've put it up so you can to! This, like most of my recent projects, is BSD licensed open source, with it's own repository on BitBucket (<a href="http://bitbucket.org/factormystic/sndvolplus">link</a>).</p>
<p><a href="http://factormystic.net/projects/apps/sndvolplus">Info Page + Download</a></p>
]]></content:encoded>
			<wfw:commentRss>http://factormystic.net/blog/sndvolplus-released/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Default Programs Editor 2.6 Update</title>
		<link>http://factormystic.net/blog/default-programs-editor-2-6-update</link>
		<comments>http://factormystic.net/blog/default-programs-editor-2-6-update#comments</comments>
		<pubDate>Sun, 14 Feb 2010 20:14:42 +0000</pubDate>
		<dc:creator>Factor Mystic</dc:creator>
				<category><![CDATA[default-programs-editor]]></category>
		<category><![CDATA[dpe-cross-site]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[windows stuff]]></category>

		<guid isPermaLink="false">http://factormystic.net/blog/?p=203</guid>
		<description><![CDATA[I discovered a couple stupid bugs right after I posted 2.5, so here's a quick 2.6 update to resolve them. Version 2.6.1837.1459 (February 14, 2010) Bugs Fixed: - Fixed a discrepancy between value data types when saving to a .reg file vs saving to the registry when changing a context menu item name. - DDE [...]]]></description>
			<content:encoded><![CDATA[<p>I discovered a couple stupid bugs right after I posted 2.5, so here's a quick 2.6 update to resolve them.</p>
<blockquote>
<div id="_mcePaste">Version 2.6.1837.1459 (February 14, 2010)</div>
<div id="_mcePaste"><strong>Bugs Fixed:</strong></div>
<div id="_mcePaste">- Fixed a discrepancy between value data types when saving to a .reg file vs saving to the registry when changing a context menu item name.</div>
<div id="_mcePaste">- DDE Message was not deleted if the program was running with elevated privileges.</div>
<div id="_mcePaste">- File type icon would sometimes not be detected correctly when the icon source was the default program.</div>
<div id="_mcePaste"><strong>Crashes Fixed:</strong></div>
<div id="_mcePaste">- Deleting a context menu item would sometimes result in a crash.</div>
<div id="_mcePaste">- Inputting invalid character for context menu item name sometimes caused a crash.</div>
<div id="_mcePaste">- In some cases, opening the autoplay handlers page for some media types caused a crash.</div>
<div id="_mcePaste">- Saving context menu changes after editing a command label (including implicit edits) caused a crash.</div>
</blockquote>
<p><a href="http://defaultprogramseditor.com">Download now</a></p>
]]></content:encoded>
			<wfw:commentRss>http://factormystic.net/blog/default-programs-editor-2-6-update/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Default Programs Editor 2.5 Update</title>
		<link>http://factormystic.net/blog/default-programs-editor-2-5-update</link>
		<comments>http://factormystic.net/blog/default-programs-editor-2-5-update#comments</comments>
		<pubDate>Sat, 13 Feb 2010 03:38:42 +0000</pubDate>
		<dc:creator>Factor Mystic</dc:creator>
				<category><![CDATA[default-programs-editor]]></category>
		<category><![CDATA[dpe-cross-site]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[windows stuff]]></category>

		<guid isPermaLink="false">http://factormystic.net/blog/?p=198</guid>
		<description><![CDATA[Default Programs Editor 2.5 was posted this week. The changelog is monstrous; this version has the most bug and crash fixes to date. If you've got an idea or gripe, head over to DPE's UserVoice forum and talk about it! Version 2.5.1823.2023 (February 9, 2010) New Features: + Added support for DropTarget objects as context menu [...]]]></description>
			<content:encoded><![CDATA[<p>Default Programs Editor 2.5 was posted this week. The changelog is monstrous; this version has the most bug and crash fixes to date. If you've got an idea or gripe, head over to <a href="http://defaultprogramseditor.uservoice.com">DPE's UserVoice forum</a> and talk about it!</p>
<blockquote><p>Version 2.5.1823.2023 (February 9, 2010)</p>
<div id="_mcePaste"><strong>New Features:</strong></div>
<div id="_mcePaste">+ Added support for DropTarget objects as context menu commands.</div>
<div id="_mcePaste">+ Added support for DelegateExecute objects as context menu commands.</div>
<div id="_mcePaste">+ Added support for Dynamic Data Exchange messages invoked with context menu commands.</div>
<div id="_mcePaste">+ On the Icon page, the raw resource path is now viewable and can be manually changed. It is also now possible to specify a file's own image in one click.</div>
<div id="_mcePaste">+ When changing an extension's file type, a revamped file type selection process shows all file types, even unused ones.</div>
<div id="_mcePaste">+ Added a checkbox to select/deselect all extensions on the extension selection page for Default Programs associations.</div>
<div id="_mcePaste">+ Added file path display to the final success page when changes are saved to file.</div>
<div><strong>Bugs Fixed:</strong></div>
<div id="_mcePaste">- Fixed a bug where the exported command path wouldn't be a normal string like it should have been.</div>
<div id="_mcePaste">- Fixed a bug where the wrong context menu item would be detected as the default.</div>
<div id="_mcePaste">- Fixed blank autoplay handler showing on the media options list after cancelling the creation of a new handler.</div>
<div id="_mcePaste">- Fixed incorrect default context menu item detection in some cases.</div>
<div id="_mcePaste">- Fixed a bug where an exported context menu .reg file could have a malformed key path.</div>
<div id="_mcePaste">- Saving edited file type Descriptions and Icons to file now correctly saves only those changed properties.</div>
<div id="_mcePaste">- The .reg file comment for Description and Icon changes will now also correctly describe which property is edited.</div>
<div id="_mcePaste">- The main instruction text on the Delete Extension page now reads appropriately.</div>
<div id="_mcePaste">- The link button to set a context menu item as default now enables or disables uniformly with the other controls.</div>
<div id="_mcePaste">- Some resource strings were not resolved properly (such as certain file type descriptions).</div>
<div id="_mcePaste">- Missing publisher information added to Control Panel uninstall data.</div>
<div id="_mcePaste">- Burnable Blu-ray discs now show correctly in the Autoplay media list.</div>
<div id="_mcePaste">- Fixed wrong capitalization for Blu-ray disc entry in the Autoplay media list.</div>
<div id="_mcePaste">- The behavior of the Done button on the Success page was not uniform for all page paths when launched from the Control Panel.</div>
<div id="_mcePaste">- The page history is cleared on the Success page to prevent old pages appearing as current.</div>
<div id="_mcePaste">- Fixed some extensions not being correctly detected as being registered for a Default Program.</div>
<div id="_mcePaste">- Fixed some extensions with blank descriptions on the Default Programs registration page.</div>
<div id="_mcePaste">- Additional small internal improvements, optimizations, and interface adjustments.</div>
<div><strong>Crashes Fixed:</strong></div>
<div id="_mcePaste">- Fixed a crash when saving a new file type without an icon set.</div>
<div id="_mcePaste">- Saving Autoplay settings after cancelling the creation of a new handler would cause a crash.</div>
<div id="_mcePaste">- Clicking the Help button would sometimes result in a crash on some systems.</div>
<div id="_mcePaste">- Attempting to install while another instance of the program was running caused a crash.</div>
<div id="_mcePaste">- Selecting a new default verb sometimes caused a crash when saving changes to file.</div>
<div id="_mcePaste">- Viewing certain file type descriptions sometimes caused a crash on the Extension Selection page.</div>
<div id="_mcePaste">- In certain cases, the program crashed when attempting to add or edit a context menu item where the destination registry key didn't yet exist.</div>
<div id="_mcePaste">- Adding a new file type but not entering optional details caused a crash when saving changes to file.</div>
<div id="_mcePaste">- Fixed a crash after clicking the Next button on the Default Programs selection page.</div>
</blockquote>
<p>Holy cow! With the addition of DelegateExecute, DropTarget, and DDE support, Default Programs Editor is now the most powerful and easy to use file association utility on the planet.</p>
<p><strong>Download</strong> now at <a href="http://defaultprogramseditor.com">http://defaultprogramseditor.com</a><br />
<a href="http://defaultprogramseditor.com"></a><strong>Have an idea or feature request?</strong> Put it on the feedback forum: <a href="http://defaultprogramseditor.uservoice.com">http://defaultprogramseditor.uservoice.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://factormystic.net/blog/default-programs-editor-2-5-update/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Aero.Wizard and Aero.Controls code pack released</title>
		<link>http://factormystic.net/blog/aero-wizard-and-aero-controls-code-pack-released</link>
		<comments>http://factormystic.net/blog/aero-wizard-and-aero-controls-code-pack-released#comments</comments>
		<pubDate>Fri, 20 Nov 2009 19:52:05 +0000</pubDate>
		<dc:creator>Factor Mystic</dc:creator>
				<category><![CDATA[aero.controls]]></category>
		<category><![CDATA[aero.wizard]]></category>
		<category><![CDATA[default-programs-editor]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[dpe-cross-site]]></category>
		<category><![CDATA[mercurial]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://factormystic.net/blog/?p=185</guid>
		<description><![CDATA[I'm pleased to announce the first stage of my roadmap to fully open Default Programs Editor with the release of Aero.Wizard and Aero.Controls. What are Aero.Wizard and Aero.Controls? Aero.Wizard is an WinForms implementation of an Aero Wizard Dialog. Aero.Controls is a package of a half dozen WinForms controls, intended for use with an Aero Wizard [...]]]></description>
			<content:encoded><![CDATA[<p>I'm pleased to announce the first stage of my roadmap to fully open <a href="http://defaultprogramseditor.com">Default Programs Editor</a> with the release of Aero.Wizard and Aero.Controls.</p>
<h3>What are Aero.Wizard and Aero.Controls?</h3>
<p>Aero.Wizard is an WinForms implementation of an Aero Wizard Dialog. Aero.Controls is a package of a half dozen WinForms controls, intended for use with an Aero Wizard Dialog. These are some of the components I wrote for the creation of Default Programs Editor 2.0 with the revised user interface, and I'm now freely releasing them to the public.</p>
<h3>Aero.Wizard:</h3>
<div class="wp-caption alignnone" style="width: 810px"><img title="Aero Wizard Info Screenshot" src="http://factormystic.net/utils/aero.wizard/wizard.png" alt="Aero Wizard Info Screenshot" width="800" height="530" /><p class="wp-caption-text">Aero.Wizard Info Screenshot</p></div>
<p>Aero.Wizard Features:</p>
<ul>
<li>History/Navigation handled automatically</li>
<li>Page contents are children of separate container controls, which can be created in design time like a regular Windows form</li>
<li>Glass title area degrades gracefully when running a theme without glass, or on XP</li>
<li>Blank Wizard Page template included</li>
<li>Use with Aero.Controls pack to make Windows UX Guidelines compatible user interfaces</li>
</ul>
<h3>Aero.Controls:</h3>
<div class="wp-caption alignnone" style="width: 271px"><img title="Aero.Controls Info Screenshot" src="http://factormystic.net/utils/aero.controls/example.png" alt="Aero.Controls Info Screenshot" width="261" height="301" /><p class="wp-caption-text">Aero.Controls Info Screenshot</p></div>
<p>Aero.Controls Includes:</p>
<ul>
<li><a title="Main Instructions Label on MSDN" href="http://msdn.microsoft.com/en-us/library/aa974176.aspx#mainInstructions">Main Instructions Label</a></li>
<li><a title="Command Link Button on MSDN" href=" http://msdn.microsoft.com/en-us/library/aa511455.aspx">Command Link button</a></li>
<li><a title="Instant Search Box on MSDN" href="http://msdn.microsoft.com/en-us/library/aa511489.aspx">Instant Search Box</a></li>
<li><a title="UAC Shield Button on MSDN" href="http://msdn.microsoft.com/en-us/library/aa511445.aspx">UAC Shield Button</a></li>
<li>Split Button</li>
<li>Listview with Mixed State checkbox</li>
<li><a title="Aero Link Label on MSDN" href="http://msdn.microsoft.com/en-us/library/aa511483.aspx">Aero Link Label</a></li>
</ul>
<p><span style="font-weight: normal;">Both of these projects strive to adhere to the <a href="http://msdn.microsoft.com/en-us/library/aa511258.aspx">Windows User Experience Guidelines</a>, freely available documentation from Microsoft which provided the basis for the DPE 2.0 restructuring. </span></p>
<h3>Licensing</h3>
<p>I debated for some time on this issue, trying to figure out a permissive license where I could retain some amount of ownership without being overbearing. I settled on BSD, which in my opinion is very permissive and seems to be low-friction for other developers to use this code in their projects.</p>
<h3>Downloading</h3>
<p>Both projects are hosted on Bitbucket (Mercurial) and you can either clone the repositories, or download the latest revision as a zip file. I encourage anyone to contribute bug fixes or report issues on each project's public issue ticketing system.</p>
<p><a title="Aero.Wizard download on bitbucket" href="http://bitbucket.org/factormystic/aero.wizard/wiki/Home">Aero.Wizard on Bitbucket</a></p>
<p><a title="Aero.Controls download on Bitbucket" href="http://bitbucket.org/factormystic/aero.controls/wiki/Home">Aero.Controls on Bitbucket</a></p>
<h3>What's next?</h3>
<p>With the release of this code pack, my plan for fully releasing <a href="http://defaultprogramseditor.com">Default Programs Editor</a> is underway. It is now possible to fully replicate the UI with this release. The next step is for me to continue refining and documenting the base file association library the project is built on, then release that as well as the UI logic for the program itself. Be looking for that in the next few months.</p>
]]></content:encoded>
			<wfw:commentRss>http://factormystic.net/blog/aero-wizard-and-aero-controls-code-pack-released/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)
Database Caching 36/39 queries in 0.012 seconds using disk: basic

Served from: factormystic.net @ 2012-05-17 20:27:44 -->
