<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Procbits &#187; C#</title>
	<atom:link href="http://procbits.com/category/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://procbits.com</link>
	<description>source code snippets and other random musings about software</description>
	<lastBuildDate>Wed, 01 Feb 2012 19:41:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='procbits.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Procbits &#187; C#</title>
		<link>http://procbits.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://procbits.com/osd.xml" title="Procbits" />
	<atom:link rel='hub' href='http://procbits.com/?pushpress=hub'/>
		<item>
		<title>FridayThe13th the Best JSON Parser for Silverlight and C#/.NET</title>
		<link>http://procbits.com/2011/08/11/fridaythe13th-the-best-json-parser-for-silverlight-and-net/</link>
		<comments>http://procbits.com/2011/08/11/fridaythe13th-the-best-json-parser-for-silverlight-and-net/#comments</comments>
		<pubDate>Thu, 11 Aug 2011 19:01:33 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://procbits.com/?p=231</guid>
		<description><![CDATA[Up until a couple of months ago I was writing most of my code using WPF. Recently, a project came up where Silverlight made more sense to use. I&#8217;d thought that wouldn&#8217;t be a problem since I&#8217;d just use JavaScriptSerializer [wrote about it here] like I did for my WPF project. Uh oh. It turns [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&amp;blog=6893023&amp;post=231&amp;subd=procbits&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Up until a couple of months ago I was writing most of my code using WPF. Recently, a project came up where Silverlight made more sense to use. I&#8217;d thought that wouldn&#8217;t be a problem since I&#8217;d just use <a href="http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx">JavaScriptSerializer</a> [wrote about it <a href="http://procbits.com/2011/04/21/quick-json-serializationdeserialization-in-c/" title="here">here</a>] like I did for my WPF project.</p>
<p>Uh oh. It turns out that Silverlight doesn&#8217;t have JavaScriptSerializer. Never fear! <a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer(v=VS.95).aspx">DataContractJsonSerializer</a> is here! Or so I thought. </p>
<p>It turns out that if you want to use DataContractJsonSerializer you must actually create POCOs to backup this &#8220;data contract.&#8221; I didn&#8217;t want to do that.</p>
<p>I wanted to turn this&#8230;<br />
<pre class="brush: jscript;">
{
	&quot;some_number&quot;: 108.541,
	&quot;date_time&quot;: &quot;2011-04-13T15:34:09Z&quot;,
	&quot;serial_number&quot;: &quot;SN1234&quot;
	&quot;more_data&quot;: {
		&quot;field1&quot;: 1.0
		&quot;field2&quot;: &quot;hello&quot;
	}
}
</pre></p>
<p>into..</p>
<p><pre class="brush: csharp;">
using System.Web.Script.Serialization;

var jss = new JavaScriptSerializer();
var dict = jss.Deserialize&lt;dynamic&gt;(jsonText);

Console.WriteLine(dict[&quot;some_number&quot;]); //outputs 108.541
Console.WriteLine(dict[&quot;more_data&quot;][&quot;field2&quot;]); //outputs hello
</pre></p>
<p>So I set out to write my own JSON parser. I call it FridayThe13th&#8230; how fitting huh? Now, using either Silverlight or .NET 4.0, you can parse the previous JSON into the following:</p>
<p><pre class="brush: csharp;">
using FridayThe13th;

var jsonText = File.ReadAllText(&quot;mydata.json&quot;);

var jsp = new JsonParser(){CamelizeProperties = true};
dynamic json = jsp.Parse(jsonText);

Console.WriteLine(json.SomeNumber); //outputs 108.541
Console.WriteLine(json.MoreData.Field2); //outputs hello
</pre></p>
<p>Since I work with a lot of Ruby on Rails backends, I want to add a property &#8220;CamelizeProperties&#8221; to turn &#8220;some_number&#8221; into &#8220;SomeNumber&#8221;&#8230; it&#8217;s more .NET like.</p>
<p>Try it! You can find it on <a href="https://github.com/jprichardson/FridayThe13th">Github</a>. Oh yeah&#8230; it&#8217;s also faster than that <a href="http://json.codeplex.com/">other .NET JSON library</a> that everyone uses.</p>
<p>Are you a <a href="http://gitpilot.com" target="_blank">Git</a> user? Let me help you make project management with Git simple. Checkout <a href="http://gitpilot.com" target="_blank">Gitpilot</a>.</p>
<p>If you made it this far, read my blog on <a href="http://techneur.com">software entrepreneurship</a> and follow me on Twitter: <a href="http://twitter.com/jprichardson">@jprichardson</a>.</p>
<p>-JP</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/procbits.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/procbits.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/procbits.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/procbits.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/procbits.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/procbits.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/procbits.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/procbits.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/procbits.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/procbits.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/procbits.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/procbits.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/procbits.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/procbits.wordpress.com/231/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&amp;blog=6893023&amp;post=231&amp;subd=procbits&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://procbits.com/2011/08/11/fridaythe13th-the-best-json-parser-for-silverlight-and-net/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0f56a5e429de009a27b0ae8f796ef2df?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">JP</media:title>
		</media:content>
	</item>
		<item>
		<title>Missing DockPanel? Add DockPanel for Silverlight 4 or Silverlight 5</title>
		<link>http://procbits.com/2011/07/19/missing-dockpanel-add-dockpanel-for-silverlight-4-or-silverlight-5/</link>
		<comments>http://procbits.com/2011/07/19/missing-dockpanel-add-dockpanel-for-silverlight-4-or-silverlight-5/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 19:05:21 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://procbits.com/?p=180</guid>
		<description><![CDATA[When I first created a demo project for Silverlight 5, I opened the XAML code to start editing. I started typing &#8220;DockPanel&#8221; but then I noticed that intellisense didn&#8217;t show anything. It turns out that DockPanel and some other controls aren&#8217;t included in the default installation of Silverlight 4 or Silverlight 5 beta. Here&#8217;s what [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&amp;blog=6893023&amp;post=180&amp;subd=procbits&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When I first created a demo project for Silverlight 5, I opened the XAML code to start editing. I started typing &#8220;DockPanel&#8221; but then I noticed that intellisense didn&#8217;t show anything. It turns out that DockPanel and some other controls aren&#8217;t included in the default installation of Silverlight 4 or Silverlight 5 beta.</p>
<p>Here&#8217;s what you need to do:</p>
<ol>
<li>Download the <a href="http://silverlight.codeplex.com/releases/view/43528" target="_blank">Silverlight 4 Toolkit</a>. Install it. (Yes, this will work with Silverlight 5 beta)</li>
<li>Add a reference to &#8220;System.Windows.Controls.Toolkit&#8221;. In Silverlight 5, you will need to navigate to the file:<br />
%ProgramFiles%\Microsoft SDKs\Silverlight\v4.0\Toolkit\Apr10\Bin\System.Windows.Controls.Toolkit.dll
</li>
<li>Add the following attribute to your UserControl: xmlns:tk=&#8221;clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit&#8221;</li>
<p>So your code might look like:<br />
<pre class="brush: xml;">
&lt;UserControl x:Class=&quot;Project1.MainPage&quot;
    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
    xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
	xmlns:tk=&quot;clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit&quot;
    mc:Ignorable=&quot;d&quot;
    d:DesignHeight=&quot;300&quot; d:DesignWidth=&quot;400&quot;&gt;

    &lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;White&quot;&gt;
		&lt;tk:DockPanel&gt;
			
		&lt;/tk:DockPanel&gt;
    &lt;/Grid&gt;
	
&lt;/UserControl&gt;
</pre></p>
<p>Enjoy.</p>
<div style="background-color:#CCC;margin:10px;padding:5px;">
<span style="color:red;">Advertisement:</span><br />
Make Git simple. Let <a href="http://gitpilot.com" target="_blank">Gitpilot</a> show you the right way to Git things done. <a href="http://gitpilot.com" target="_blank">Gitpilot</a> will help you write software faster.
</div>
<p>Follow me on Twitter: <a href="http://twitter.com/jprichardson">@jprichardson</a> and read my blog on software entrepreneurship: <a href="http://techneur.com">Techneur</a></p>
<p>-JP</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/procbits.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/procbits.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/procbits.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/procbits.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/procbits.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/procbits.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/procbits.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/procbits.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/procbits.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/procbits.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/procbits.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/procbits.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/procbits.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/procbits.wordpress.com/180/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&amp;blog=6893023&amp;post=180&amp;subd=procbits&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://procbits.com/2011/07/19/missing-dockpanel-add-dockpanel-for-silverlight-4-or-silverlight-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0f56a5e429de009a27b0ae8f796ef2df?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">JP</media:title>
		</media:content>
	</item>
		<item>
		<title>Linear Regression in C#/.NET Using Least Squares</title>
		<link>http://procbits.com/2011/05/02/linear-regression-in-c-sharp-least-squares/</link>
		<comments>http://procbits.com/2011/05/02/linear-regression-in-c-sharp-least-squares/#comments</comments>
		<pubDate>Mon, 02 May 2011 18:21:35 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://procbits.com/?p=163</guid>
		<description><![CDATA[I had a class that handled the regression of my data sets, but it had too many business rules. It was necessary for me to refactor the code. Here&#8217;s how you can use it: The source is in my .NET CommonLib library. XYDataSet.cs: https://github.com/jprichardson/CommonLib/blob/master/CommonLib/Numerical/XYDataSet.cs XYDataSetTest.cs: https://github.com/jprichardson/CommonLib/blob/master/TestCommonLib/Numerical/XYDataSetTest.cs Here is the source for XYDataSet.cs: Are you a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&amp;blog=6893023&amp;post=163&amp;subd=procbits&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I had a class that handled the regression of my data sets, but it had too many business rules. It was necessary for me to refactor the code.</p>
<p>Here&#8217;s how you can use it:<br />
<pre class="brush: csharp;">
double[] X = { 75.0, 83, 85, 85, 92, 97, 99 };
double[] Y = { 16.0, 20, 25, 27, 32, 48, 48 };
var ds = new XYDataSet(X, Y);

Console.WriteLine(Math.Round(ds.Slope,2)); //1.45
Console.WriteLine(Math.Round(ds.YIntercept,2)); //-96.85
ConsoleWriteLine(Math.Round(ds.ComputeRSquared(), 3)); //0.927
</pre></p>
<p>The source is in my .NET CommonLib library.<br />
XYDataSet.cs: <a href="https://github.com/jprichardson/CommonLib/blob/master/CommonLib/Numerical/XYDataSet.cs">https://github.com/jprichardson/CommonLib/blob/master/CommonLib/Numerical/XYDataSet.cs</a><br />
XYDataSetTest.cs: <a href="https://github.com/jprichardson/CommonLib/blob/master/TestCommonLib/Numerical/XYDataSetTest.cs">https://github.com/jprichardson/CommonLib/blob/master/TestCommonLib/Numerical/XYDataSetTest.cs</a></p>
<p>Here is the source for XYDataSet.cs:<br />
<pre class="brush: csharp;">
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using CommonLib.Geometry;

namespace CommonLib.Numerical
{
	public class XYDataSet : IList&lt;PointD&gt;
	{
		
		private List&lt;PointD&gt; _internalList = new List&lt;PointD&gt;();

		public XYDataSet() : this(null, null) { }

		public XYDataSet(IEnumerable&lt;PointD&gt; points) {
			ResetValues();

			foreach (var point in points)
				Add(point);
		}

		public XYDataSet(IEnumerable&lt;double&gt; Xs, IEnumerable&lt;double&gt; Ys) {
			ResetValues();
			
			if (Xs != null || Ys != null) {
				if (Xs.Count() != Ys.Count())
					throw new Exception(&quot;X count must be the same as the Y count.&quot;);

				for (int i = 0; i &lt; Xs.Count(); ++i)
					Add(Xs.ElementAt(i), Ys.ElementAt(i));
			}
		}

		public int Count { get { return _internalList.Count; } }

		public bool IsReadOnly { get { return false; } }

		private double _maxX = Double.NegativeInfinity;
		public double XMax { get { return _internalList[XMaxIndex].X; } }
		private double _minX = Double.PositiveInfinity;
		public double XMin { get { return _internalList[XMinIndex].X; } }
		public int XMaxIndex { get; protected set; }
		public int XMinIndex { get; protected set; }

		private double _maxY = Double.NegativeInfinity;
		public double YMax { get { return _internalList[YMaxIndex].Y; } }
		private double _minY = Double.PositiveInfinity;
		public double YMin { get { return _internalList[YMinIndex].Y; } }
		public int YMaxIndex { get; protected set; }
		public int YMinIndex { get; protected set; }

		public double XMean { get { return XSum / Count; } }
		public double YMean { get { return YSum / Count; } }

		public double RSquare { get; protected set; }

		public PointD RegressionPoint0 { get; protected set; }
		public PointD RegressionPointN { get; protected set; }

		public double Slope { get; protected set; }

		public double XSum { get; set; }
		public double YSum { get; set; }
		public double XSquaredSum { get; set; }
		public double XYProductSum { get; set; }

		public double XIntercept { get { return -YIntercept / Slope; } }
		public double YIntercept { get; protected set; }


		public PointD this[int index] {
			get { return _internalList[index]; }
			set {
				var p = value;
				var old = _internalList[index];
				_internalList[index] = p;

				ComputeSums(old, SumMode.Subtract);
				ComputeSums(p, SumMode.Add);
				ComputeMinAndMax();
				ComputeSlopeAndYIntercept();
			}
		}

		public void Add(double x, double y) {
			Add(new PointD(x, y));
		}

		public void Add(PointD p) {
			_internalList.Add(p);
			RSquare = double.NaN;

			ComputeSums(p, SumMode.Add);
			ComputeMinAndMax(Count - 1, p);
			ComputeSlopeAndYIntercept();
		}

		public void Clear() {
			_internalList.Clear();
			ResetValues();
		}

		public void ComputeSlopeAndYIntercept() {
			double delta = Count * XSquaredSum - Math.Pow(XSum, 2.0);
			YIntercept = (1.0 / delta) * (XSquaredSum * YSum - XSum * XYProductSum);
			Slope = (1.0 / delta) * (Count * XYProductSum - XSum * YSum);

			RegressionPoint0.X = XMin;
			RegressionPoint0.Y = Slope * XMin + YIntercept;
			RegressionPointN.X = XMax;
			RegressionPointN.Y = Slope * XMax + YIntercept;
		}

		public double ComputeRSquared() {
			var SStot = _internalList.Sum(p =&gt; Math.Pow(p.Y - YMean, 2.0));
			var SSerr = _internalList.Sum(p =&gt; Math.Pow(p.Y - (Slope * p.X + YIntercept), 2.0));
			RSquare = 1.0 - SSerr / SStot;
			return RSquare;
		}

		public bool Contains(PointD p) {
			return _internalList.Contains(p);
		}

		public void CopyTo(PointD[] points, int index) {
			_internalList.CopyTo(points, index);
		}

		public IEnumerator&lt;PointD&gt; GetEnumerator() {
			return _internalList.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator() {
			return _internalList.GetEnumerator();
		}

		public int IndexOf(PointD p) {
			return _internalList.IndexOf(p);
		}

		public void Insert(int index, PointD p) {
			_internalList.Insert(index, p);
			RSquare = double.NaN;

			ComputeSums(p, SumMode.Add);
			ComputeMinAndMax();
			ComputeSlopeAndYIntercept();
		}

		public bool Remove(PointD p) {
			var success = _internalList.Remove(p);
			if (success) {
				RSquare = double.NaN;
				ComputeSums(p, SumMode.Subtract);
				ComputeMinAndMax();
				ComputeSlopeAndYIntercept();
			}
			return success;
		}

		public void RemoveAt(int index) {
			var old = _internalList[index];
			_internalList.RemoveAt(index);
			RSquare = double.NaN;

			ComputeSums(old, SumMode.Subtract);
			ComputeMinAndMax();
			ComputeSlopeAndYIntercept();
		}

		protected void ComputeMinAndMax() { //methods that call this, Insert, 
			ResetMinAndMax();

			for (int i = 0; i &lt; _internalList.Count; ++i)
				ComputeMinAndMax(i, _internalList[i]);
		}

		protected void ComputeMinAndMax(int index, PointD newPoint) {
			if (newPoint.X &lt;= _minX) {
				_minX = newPoint.X;
				XMinIndex = index;
			}

			if (newPoint.X &gt;= _maxX) {
				_maxX = newPoint.X;
				XMaxIndex = index;
			}

			if (newPoint.Y &lt;= _minY) {
				_minY = newPoint.Y;
				YMinIndex = index;
			}

			if (newPoint.Y &gt;= _maxY) {
				_maxY = newPoint.Y;
				YMaxIndex = index;
			}
		}

		protected enum SumMode { Add, Subtract };
		protected void ComputeSums(PointD p, SumMode mode) {
			if (mode == SumMode.Add) {
				XSum += p.X;
				YSum += p.Y;
				XSquaredSum += Math.Pow(p.X, 2.0);
				XYProductSum += (p.X * p.Y);
			}
			else if (mode == SumMode.Subtract) {
				XSum -= p.X;
				YSum -= p.Y;
				XSquaredSum -= Math.Pow(p.X, 2.0);
				XYProductSum -= (p.X * p.Y);
			}
		}

		protected void ResetMinAndMax() {
			_maxX = double.NegativeInfinity;
			_maxY = double.NegativeInfinity;
			_minX = double.PositiveInfinity;
			_minY = double.PositiveInfinity;
		}

		protected void ResetValues() {
			ResetMinAndMax();

			RegressionPoint0 = new PointD();
			RegressionPointN = new PointD();

			RSquare = double.NaN;

			Slope = double.NaN;
			YIntercept = double.NaN;

			XSum = 0.0;
			YSum = 0.0;
			XSquaredSum = 0.0;
			XYProductSum = 0.0;

			XMaxIndex = -1;
			YMaxIndex = -1;
			XMinIndex = -1;
			YMinIndex = -1;
		}
		
	}
}

</pre></p>
<p>Are you a <a href="http://gitpilot.com" target="_blank">Git</a> user? Let me help you make project management with Git simple. Checkout <a href="http://gitpilot.com" target="_blank">Gitpilot</a>.</p>
<p>Follow me on Twitter: <a href="http://twitter.com/jprichardson">@jprichardson</a> and read my blog on software entrepreneurship: <a href="http://techneur.com">Techneur</a></p>
<p>-JP</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/procbits.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/procbits.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/procbits.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/procbits.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/procbits.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/procbits.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/procbits.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/procbits.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/procbits.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/procbits.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/procbits.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/procbits.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/procbits.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/procbits.wordpress.com/163/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&amp;blog=6893023&amp;post=163&amp;subd=procbits&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://procbits.com/2011/05/02/linear-regression-in-c-sharp-least-squares/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0f56a5e429de009a27b0ae8f796ef2df?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">JP</media:title>
		</media:content>
	</item>
		<item>
		<title>Quick JSON Serialization/Deserialization in C#</title>
		<link>http://procbits.com/2011/04/21/quick-json-serializationdeserialization-in-c/</link>
		<comments>http://procbits.com/2011/04/21/quick-json-serializationdeserialization-in-c/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 18:38:48 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://procbits.com/?p=156</guid>
		<description><![CDATA[*This outdated*. You should use FridayThe13th the best JSON parser for Silverlight and .NET 4.0. You don&#8217;t need to download an additional libraryto serialize/deserialize your objects to/from JSON. Since .NET 3.5, .NET can do it natively. Add a reference to your project to &#8220;System.Web.Extensions.dll&#8221; Let&#8217;s look at this example JSON string: You can deserialize the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&amp;blog=6893023&amp;post=156&amp;subd=procbits&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>*This outdated*.</strong> You should use <a href="http://procbits.com/2011/08/11/fridaythe13th-the-best-json-parser-for-silverlight-and-net/">FridayThe13th the best JSON parser for Silverlight and .NET 4.0</a>.</p>
<p>You don&#8217;t need to download an <a href="http://json.codeplex.com/">additional library</a>to serialize/deserialize your objects to/from JSON. Since .NET 3.5, .NET can do it natively.</p>
<p>Add a reference to your project to &#8220;System.Web.Extensions.dll&#8221;</p>
<p>Let&#8217;s look at this example JSON string:<br />
<pre class="brush: jscript;">
{
	&quot;some_number&quot;: 108.541, 
	&quot;date_time&quot;: &quot;2011-04-13T15:34:09Z&quot;, 
	&quot;serial_number&quot;: &quot;SN1234&quot;
}
</pre></p>
<p>You can deserialize the previous JSON into a dictionary like so:<br />
<pre class="brush: csharp;">
using System.Web.Script.Serialization;

var jss = new JavaScriptSerializer();
var dict = jss.Deserialize&lt;Dictionary&lt;string,string&gt;&gt;(jsonText);

Console.WriteLine(dict[&quot;some_number&quot;]); //outputs 108.541
</pre></p>
<p>So what if your JSON is a bit more complex?<br />
<pre class="brush: jscript;">
{
	&quot;some_number&quot;: 108.541, 
	&quot;date_time&quot;: &quot;2011-04-13T15:34:09Z&quot;, 
	&quot;serial_number&quot;: &quot;SN1234&quot;
	&quot;more_data&quot;: {
		&quot;field1&quot;: 1.0
		&quot;field2&quot;: &quot;hello&quot;	
	}
}
</pre></p>
<p>Deserialize like so&#8230;<br />
<pre class="brush: csharp;">
using System.Web.Script.Serialization;

var jss = new JavaScriptSerializer();
var dict = jss.Deserialize&lt;Dictionary&lt;string,dynamic&gt;&gt;(jsonText);

Console.WriteLine(dict[&quot;some_number&quot;]); //outputs 108.541
Console.WriteLine(dict[&quot;more_data&quot;][&quot;field2&quot;]); //outputs hello
</pre></p>
<p>The field &#8220;more_data&#8221; gets deserialized into a Dictionary&lt;string, object&gt;.</p>
<p>You can actually just just deserialize like so:<br />
<pre class="brush: csharp;">
using System.Web.Script.Serialization;

var jss = new JavaScriptSerializer();
var dict = jss.Deserialize&lt;dynamic&gt;(jsonText);

Console.WriteLine(dict[&quot;some_number&quot;]); //outputs 108.541
Console.WriteLine(dict[&quot;more_data&quot;][&quot;field2&quot;]); //outputs hello
</pre></p>
<p>And everything still works the same. The only caveat is that you lose intellisense by using the &#8220;dynamic&#8221; data type. </p>
<p>Serialization is just as easy:<br />
<pre class="brush: csharp;">
using System.Web.Script.Serialization;

var jss = new JavaScriptSerializer();
var dict = jss.Deserialize&lt;dynamic&gt;(jsonText);

var json = jss.Serialize(dict);
Console.WriteLine(json);
</pre></p>
<p>Outputs&#8230;<br />
<pre class="brush: jscript;">
{
	&quot;some_number&quot;: 108.541, 
	&quot;date_time&quot;: &quot;2011-04-13T15:34:09Z&quot;, 
	&quot;serial_number&quot;: &quot;SN1234&quot;
	&quot;more_data&quot;: {
		&quot;field1&quot;: 1.0
		&quot;field2&quot;: &quot;hello&quot;	
	}
}
</pre></p>
<p>Do you use Git? If so, checkout <a href="http://gitpilot.com">Gitpilot</a> to make project management and collaborating on projects seamless.</p>
<p>If you made it this far, read my blog on <a href="http://techneur.com">software entrepreneurship</a> and follow me on Twitter: <a href="http://twitter.com/jprichardson">@jprichardson</a>.</p>
<p>-JP</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/procbits.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/procbits.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/procbits.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/procbits.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/procbits.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/procbits.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/procbits.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/procbits.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/procbits.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/procbits.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/procbits.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/procbits.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/procbits.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/procbits.wordpress.com/156/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&amp;blog=6893023&amp;post=156&amp;subd=procbits&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://procbits.com/2011/04/21/quick-json-serializationdeserialization-in-c/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0f56a5e429de009a27b0ae8f796ef2df?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">JP</media:title>
		</media:content>
	</item>
		<item>
		<title>StreamWriter Share Read Access in Another Process</title>
		<link>http://procbits.com/2011/02/18/streamwriter-share-read-access-in-another-process/</link>
		<comments>http://procbits.com/2011/02/18/streamwriter-share-read-access-in-another-process/#comments</comments>
		<pubDate>Fri, 18 Feb 2011 15:57:37 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://procbits.com/?p=141</guid>
		<description><![CDATA[I have two applications, one is the main application that generates a log file, the other is an application that reads the log file to compute statistics. I want my app that reads the log file to be able to read the file while the other app is running and generating the log file. If [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&amp;blog=6893023&amp;post=141&amp;subd=procbits&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have two applications, one is the main application that generates a log file, the other is an application that reads the log file to compute statistics.</p>
<p>I want my app that reads the log file to be able to read the file while the other app is running and generating the log file. If you just use the default StreamWriter and StreamReader constructors you will get a file access in error in one of the processes.</p>
<p>Log file generator: (1st process)<br />
<pre class="brush: csharp;">
static void Main(string[] args) {
	var file = @&quot;C:\logfile.txt&quot;;
	var sw = new StreamWriter(file);
	sw.AutoFlush = true;
	sw.WriteLine(&quot;some data&quot;);
	sw.WriteLine(&quot;some data2&quot;); //set breakpoint here
	
	sw.Close();
}
</pre></p>
<p>Log file reader: (2nd process)<br />
<pre class="brush: csharp;">
static void Main(string[] args) {
	var file = @&quot;C:\logfile.txt&quot;;
	var sr = new StreamReader(file);

	var l1 = sr.ReadLine();
	var l2 = sr.ReadLine(); //set breakpoint here

	sr.Close();
}
</pre></p>
<p>Startup the &#8220;log file generator&#8221; app and then startup the &#8220;log file reader&#8221; app, you&#8217;ll get an IOException.<br />
Here&#8217;s how you can fix this:</p>
<p>Log file generator: (1st process)<br />
<pre class="brush: csharp;">
static void Main(string[] args) {
	var file = @&quot;C:\logfile.txt&quot;;
	var fs = File.Open(file, FileMode.Append, FileAccess.Write, FileShare.Read);
	var sw = new StreamWriter(fs);
	sw.AutoFlush = true;
	sw.WriteLine(&quot;some data&quot;);
	sw.WriteLine(&quot;some data2&quot;); //set breakpoint here
	
	sw.Close();
}
</pre></p>
<p>Log file reader: (2nd process)<br />
<pre class="brush: csharp;">
static void Main(string[] args) {
	var file = @&quot;C:\logfile.txt&quot;;
	var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
	var sr = new StreamReader(fs);

	var l1 = sr.ReadLine();
	var l2 = sr.ReadLine(); //set breakpoint here

	sr.Close();
}
</pre></p>
<p>You&#8217;ll notice that the breakpoint on the 2nd process will now work without getting an IOException. In short this works because the <a href="http://msdn.microsoft.com/en-us/library/system.io.fileshare.aspx">FileShare</a> permissions are set properly. You can also read more about the <a href="http://msdn.microsoft.com/en-us/library/system.io.filemode.aspx">enum FileMode</a>.</p>
<p>Are you a <a href="http://gitpilot.com" target="_blank">Git</a> user? Let me help you make project management with Git simple. Checkout <a href="http://gitpilot.com" target="_blank">Gitpilot</a>.</p>
<p>Follow me on Twitter: <a href="http://twitter.com/jprichardson">@jprichardson</a> and read my <a href="http://techneur.com">blog on entrepreneurship</a>.</p>
<p>-JP</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/procbits.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/procbits.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/procbits.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/procbits.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/procbits.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/procbits.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/procbits.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/procbits.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/procbits.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/procbits.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/procbits.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/procbits.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/procbits.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/procbits.wordpress.com/141/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&amp;blog=6893023&amp;post=141&amp;subd=procbits&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://procbits.com/2011/02/18/streamwriter-share-read-access-in-another-process/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0f56a5e429de009a27b0ae8f796ef2df?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">JP</media:title>
		</media:content>
	</item>
		<item>
		<title>WPF Application Wide Exception Handling</title>
		<link>http://procbits.com/2011/02/07/wpf-application-exception-handling/</link>
		<comments>http://procbits.com/2011/02/07/wpf-application-exception-handling/#comments</comments>
		<pubDate>Mon, 07 Feb 2011 19:32:49 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://procbits.com/?p=117</guid>
		<description><![CDATA[What do you do if you want to catch all unhandled exceptions in an application? In App.xaml: Add &#8220;DispatcherUnhandledException&#8221; to App.xaml. Then in your App.xaml.cs file: That&#8217;s it. So now if the app crashes on your users, you don&#8217;t have to ask your users what steps they did to cause the crash. You can just [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&amp;blog=6893023&amp;post=117&amp;subd=procbits&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>What do you do if you want to catch all unhandled exceptions in an application?</p>
<p>In App.xaml:<br />
<pre class="brush: xml;">
&lt;Application x:Class=&quot;MyApp.App&quot;
    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    DispatcherUnhandledException=&quot;UnhandledException&quot;
&gt;
</pre></p>
<p>Add &#8220;DispatcherUnhandledException&#8221; to App.xaml. Then in your App.xaml.cs file:<br />
<pre class="brush: csharp;">
private void UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) {
	var time = DateTime.Now;
	File.AppendAllText(@&quot;C:\exps.csv&quot;, string.Format(&quot;{0},{1}&quot;, time, e.Exception.Message));
	File.AppendAllText(@&quot;C:\sts.txt&quot;, time + &quot;:\n&quot; + e.Exception.StackTrace + &quot;\n&quot;);
	e.Handled = false; //we want the user to experience the crash
}
</pre></p>
<p>That&#8217;s it. So now if the app crashes on your users, you don&#8217;t have to ask your users what steps they did to cause the crash. You can just look at the logs!</p>
<p>Are you a <a href="http://gitpilot.com" target="_blank">Git</a> user? Let me help you make project management with Git simple. Checkout <a href="http://gitpilot.com" target="_blank">Gitpilot</a>.</p>
<p>Follow me on Twitter <a href="http://twitter.com/jprichardson">@jprichardson</a> or read my <a href="http://techneur.com">blog on software entrepreneurship</a>.</p>
<p>-JP</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/procbits.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/procbits.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/procbits.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/procbits.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/procbits.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/procbits.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/procbits.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/procbits.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/procbits.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/procbits.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/procbits.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/procbits.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/procbits.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/procbits.wordpress.com/117/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&amp;blog=6893023&amp;post=117&amp;subd=procbits&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://procbits.com/2011/02/07/wpf-application-exception-handling/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0f56a5e429de009a27b0ae8f796ef2df?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">JP</media:title>
		</media:content>
	</item>
		<item>
		<title>Memcached Alternative for C#/.NET</title>
		<link>http://procbits.com/2011/01/21/memcached-alternative-for-c-net/</link>
		<comments>http://procbits.com/2011/01/21/memcached-alternative-for-c-net/#comments</comments>
		<pubDate>Fri, 21 Jan 2011 19:25:07 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://procbits.com/?p=110</guid>
		<description><![CDATA[I&#8217;m currently developing a software package that has to retrieve large amounts of data from a server. This data is needed frequently throughout the application and doesn&#8217;t change much in a given day. This sounds like a perfect use case for Memcached, or so I thought. After I installed the .NET Memcached adapters, I was [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&amp;blog=6893023&amp;post=110&amp;subd=procbits&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently developing a software package that has to retrieve large amounts of data from a server. This data is needed frequently throughout the application and doesn&#8217;t change much in a given day. This sounds like a perfect use case for <a href="http://en.wikipedia.org/wiki/Memcached">Memcached</a>, or so I thought. After I installed the .NET Memcached adapters, I was in for a big surprise. Memcached has a 1 MB value limit!</p>
<p>So, like any good developer I wrote my own tool. First, two caveats, as I don&#8217;t want to waste your time.<br />
1) I wouldn&#8217;t use this in a production environment. It just hasn&#8217;t had enough rigorous testing. YMMV.<br />
2) It only works on the same machine that the app resides on. Yes, I realize that this is a huge caveat.</p>
<h3>Why?</h3>
<p>So, what was my use case? I follow a loose Agile process of delivering every week. Well, as the production went on, more data would accumulate on the server. I needed a quick way to cache this data locally without rewriting my algorithms in the short term. Thus, <a href="https://github.com/jprichardson/MemMapCache">MemMapCache</a> was born.</p>
<h3>How Does It Work?</h3>
<p>It uses memory mapped files that are new in .NET 4.0 (they just wrap the Win32 API). The client creates a key and persists the object value to a memory mapped file using the said key. It then passes the key onto the server so that the server can keep the reference. This prevents the .NET garbage collector from cleaning up the memory mapped file so that upon a new instance of the client, it can still retrieve the data.</p>
<h3>How do you use it?</h3>
<p>Go clone this project: <a href="https://github.com/jprichardson/MemMapCache">https://github.com/jprichardson/MemMapCache</a> and then add MemMapCacheLib to your project. You&#8217;ll need to make sure that MemMapCache.exe is running on your system.</p>
<p><pre class="brush: csharp;">
var cache = new MemMapCache();
cache.Connect();

var col = new Dictionary&lt;string, int&gt;();
col.Add(&quot;hello&quot;, 5);
col.Add(&quot;hi&quot;, 2);

cache.Set(&quot;myKey&quot;, col);

var newCol = cache.Get&lt;Dictionary&lt;string,int&gt;&gt;(&quot;myKey&quot;);

//you can pass in an expiration time as DateTime or TimeSpan
cache.Set(&quot;newKey&quot;, &quot;some data&quot;, DateTime.Now.AddMinutes(4)); 

//hypothetical large data repository that returns IEnumerable&lt;double&gt;
var dataRepo = new DataRepository(); 

//you can even call one function to retrieve the last value for a key, if it doesn't exist set a new value
IEnumerable&lt;double&gt; largeDataSet = cache.TryGetThenSet(&quot;dataSetKey&quot;, () =&gt; dataRepo.LoadLargeDataSet());

//you can also specify for the cache to always miss, in case you have it deeply embedded in your code and you want to run unit tests that aren't cache dependent
cache.CacheHitAlwaysMiss = true
</pre></p>
<p>That&#8217;s it. It&#8217;s come in handy for me during development. If you find this useful please leave a comment. </p>
<p>Are you a <a href="http://gitpilot.com" target="_blank">Git</a> user? Let me help you make project management with Git simple. Checkout <a href="http://gitpilot.com" target="_blank">Gitpilot</a>.</p>
<p>Follow me on Twitter <a href="http://twitter.com/jprichardson">@jprichardson</a> or read my blog on entrepreneurship: <a href="http://techneur.com">Techneur</a></p>
<p>-JP</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/procbits.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/procbits.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/procbits.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/procbits.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/procbits.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/procbits.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/procbits.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/procbits.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/procbits.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/procbits.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/procbits.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/procbits.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/procbits.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/procbits.wordpress.com/110/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&amp;blog=6893023&amp;post=110&amp;subd=procbits&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://procbits.com/2011/01/21/memcached-alternative-for-c-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0f56a5e429de009a27b0ae8f796ef2df?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">JP</media:title>
		</media:content>
	</item>
		<item>
		<title>Forcing Single Instance for WPF Apps</title>
		<link>http://procbits.com/2010/12/29/forcing-single-instance-for-wpf/</link>
		<comments>http://procbits.com/2010/12/29/forcing-single-instance-for-wpf/#comments</comments>
		<pubDate>Wed, 29 Dec 2010 17:43:49 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://procbits.com/?p=107</guid>
		<description><![CDATA[Sometimes you may not want to allow multiple instances for your WPF apps. You can use a Mutex to accomplish this. Credit goes to this StackOverflow question: &#8220;What is the correct way to create a single instance application?&#8221; for mashing these ideas together. The basic idea is that the startup code checks the mutex and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&amp;blog=6893023&amp;post=107&amp;subd=procbits&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Sometimes you may not want to allow multiple instances for your WPF apps. You can use a Mutex to accomplish this. Credit goes to this <a href="http://stackoverflow.com/questions/19147/what-is-the-correct-way-to-create-a-single-instance-application">StackOverflow question: &#8220;What is the correct way to create a single instance application?&#8221;</a> for mashing these ideas together.</p>
<p><pre class="brush: csharp;">
public partial class App : Application
{
	[DllImport(&quot;user32.dll&quot;)]
	private static extern bool ShowWindow(IntPtr hWnd, int cmdShow);
	private const int SW_MAXIMIZE = 3;
	private const int SW_SHOWNORMAL = 1;

	private static Mutex singleInstanceMutex = new Mutex(true, &quot;AnyUniqueStringToYourApp&quot;);

	protected override void OnStartup(StartupEventArgs e) {
		base.OnStartup(e);
		if (singleInstanceMutex.WaitOne(TimeSpan.Zero, true))
			Program.OnStartup();
		else {
			var procs = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
			foreach (var p in procs.Where(p =&gt; p.MainWindowHandle != IntPtr.Zero)) {
				ShowWindow(p.MainWindowHandle, SW_MAXIMIZE);
					Application.Current.Shutdown();
					return;
				}
			}	
		}
	}
}
</pre></p>
<p>The basic idea is that the startup code checks the mutex and maximizes the application if the app isn&#8217;t already open. You can view the <a href="http://msdn.microsoft.com/en-us/library/ms633548(VS.85).aspx">MSDN docs for ShowWindow</a> and pass any of the associated constants to alter the behavior of the window if it is already running.</p>
<p>Are you a <a href="http://gitpilot.com" target="_blank">Git</a> user? Let me help you make project management with Git simple. Checkout <a href="http://gitpilot.com" target="_blank">Gitpilot</a>.</p>
<p>Read my <a href="http://techneur.com">blog on entrepreneurship</a> and follow me on <a href="http://twitter.com/jprichardson">Twitter</a>.</p>
<p>-JP</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/procbits.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/procbits.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/procbits.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/procbits.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/procbits.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/procbits.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/procbits.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/procbits.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/procbits.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/procbits.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/procbits.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/procbits.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/procbits.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/procbits.wordpress.com/107/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&amp;blog=6893023&amp;post=107&amp;subd=procbits&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://procbits.com/2010/12/29/forcing-single-instance-for-wpf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0f56a5e429de009a27b0ae8f796ef2df?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">JP</media:title>
		</media:content>
	</item>
		<item>
		<title>Including More than One ResourceDictionary in Your Xaml</title>
		<link>http://procbits.com/2010/12/08/including-more-than-one-resourcedictionary-in-your-xaml/</link>
		<comments>http://procbits.com/2010/12/08/including-more-than-one-resourcedictionary-in-your-xaml/#comments</comments>
		<pubDate>Wed, 08 Dec 2010 20:29:05 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[wpf]]></category>
		<category><![CDATA[xaml]]></category>

		<guid isPermaLink="false">http://procbits.com/?p=105</guid>
		<description><![CDATA[I have one giant Xaml ResourceDictionary that&#8217;s becoming unwieldy to manage. The solution is simple. Use MergedDictionaries. Snippet: Are you a Git user? Let me help you make project management with Git simple. Checkout Gitpilot. Follow me on Twitter @jprichardson and read my blog on entrepreneurship. -JP<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&amp;blog=6893023&amp;post=105&amp;subd=procbits&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have one giant Xaml ResourceDictionary that&#8217;s becoming unwieldy to manage. The solution is simple. Use <a href="http://msdn.microsoft.com/en-us/library/aa350178.aspx">MergedDictionaries</a>. </p>
<p>Snippet:<br />
<pre class="brush: xml;">
&lt;Window.Resources&gt;
	&lt;ResourceDictionary&gt;
		&lt;ResourceDictionary.MergedDictionaries&gt;
			&lt;ResourceDictionary Source=&quot;FileResources1.xaml&quot; /&gt;
			&lt;ResourceDictionary Source=&quot;FileResources2.xaml&quot; /&gt;
		&lt;/ResourceDictionary.MergedDictionaries&gt;
	&lt;/ResourceDictionary&gt;
&lt;/Window.Resources&gt;
</pre></p>
<p>Are you a <a href="http://gitpilot.com" target="_blank">Git</a> user? Let me help you make project management with Git simple. Checkout <a href="http://gitpilot.com" target="_blank">Gitpilot</a>.</p>
<p>Follow me on Twitter <a href="http://twitter.com/jprichardson">@jprichardson</a> and read my <a href="http://techneur.com">blog on entrepreneurship</a>.</p>
<p>-JP</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/procbits.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/procbits.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/procbits.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/procbits.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/procbits.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/procbits.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/procbits.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/procbits.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/procbits.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/procbits.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/procbits.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/procbits.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/procbits.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/procbits.wordpress.com/105/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&amp;blog=6893023&amp;post=105&amp;subd=procbits&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://procbits.com/2010/12/08/including-more-than-one-resourcedictionary-in-your-xaml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0f56a5e429de009a27b0ae8f796ef2df?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">JP</media:title>
		</media:content>
	</item>
		<item>
		<title>Get All ProgID on System for COM Automation</title>
		<link>http://procbits.com/2010/11/08/get-all-progid-on-system-for-com-automation/</link>
		<comments>http://procbits.com/2010/11/08/get-all-progid-on-system-for-com-automation/#comments</comments>
		<pubDate>Mon, 08 Nov 2010 16:48:07 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[com]]></category>

		<guid isPermaLink="false">http://procbits.com/?p=93</guid>
		<description><![CDATA[If you want to use Silverlight COM Automation, you need to know the ProgID of your COM component. These are buried in the registry. Here is a snippet that I found (don&#8217;t remember where) and modified a bit to do this: Are you a Git user? Let me help you make project management with Git [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&amp;blog=6893023&amp;post=93&amp;subd=procbits&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you want to use <a href="http://procbits.com/2010/10/28/silverlight-4-and-comactivex-integration/">Silverlight COM Automation</a>, you need to know the ProgID of your COM component. These are buried in the registry. Here is a snippet that I found (don&#8217;t remember where) and modified a bit to do this:</p>
<p><pre class="brush: csharp;">
var regClis = Registry.ClassesRoot.OpenSubKey(&quot;CLSID&quot;);
var progs = new List&lt;string&gt;();

foreach (var clsid in regClis.GetSubKeyNames()) {
	var regClsidKey = regClis.OpenSubKey(clsid);
	var ProgID = regClsidKey.OpenSubKey(&quot;ProgID&quot;);
	var regPath = regClsidKey.OpenSubKey(&quot;InprocServer32&quot;);

	if (regPath == null)
		regPath = regClsidKey.OpenSubKey(&quot;LocalServer32&quot;);

	if (regPath != null &amp;&amp; ProgID != null) {
		var pid = ProgID.GetValue(&quot;&quot;);
		var filePath = regPath.GetValue(&quot;&quot;);
		progs.Add(pid + &quot; -&gt; &quot; + filePath);
		regPath.Close();
	}

	regClsidKey.Close();
}

regClis.Close();

progs.Sort();

var sw = new StreamWriter(@&quot;c:\ProgIDs.txt&quot;);
foreach (var line in progs)
	sw.WriteLine(line);

sw.Close();
</pre></p>
<p>Are you a <a href="http://gitpilot.com" target="_blank">Git</a> user? Let me help you make project management with Git simple. Checkout <a href="http://gitpilot.com" target="_blank">Gitpilot</a>.</p>
<p>Follow me on Twitter: <a href="http://twitter.com/jprichardson">@jprichardson</a> and read my blog on entrepreneurship: <a href="http://techneur.com">Techneur</a></p>
<p>-JP</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/procbits.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/procbits.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/procbits.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/procbits.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/procbits.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/procbits.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/procbits.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/procbits.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/procbits.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/procbits.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/procbits.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/procbits.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/procbits.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/procbits.wordpress.com/93/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&amp;blog=6893023&amp;post=93&amp;subd=procbits&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://procbits.com/2010/11/08/get-all-progid-on-system-for-com-automation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0f56a5e429de009a27b0ae8f796ef2df?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">JP</media:title>
		</media:content>
	</item>
	</channel>
</rss>
