<?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>Dawn of Dankind</title>
	<atom:link href="http://www.dawnofdankind.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dawnofdankind.com</link>
	<description>The work of Daniel Harvey</description>
	<lastBuildDate>Thu, 07 Jul 2011 06:25:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Getting Aptana working under Ubuntu 11.04</title>
		<link>http://www.dawnofdankind.com/2011/programming/getting-aptana-working-under-ubuntu-11-04/</link>
		<comments>http://www.dawnofdankind.com/2011/programming/getting-aptana-working-under-ubuntu-11-04/#comments</comments>
		<pubDate>Thu, 07 Jul 2011 06:21:27 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[aptana]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[ubuntu 11.04]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.dawnofdankind.com/?p=272</guid>
		<description><![CDATA[Apparently, Unity breaks Aptana&#8217;s file menu. Here&#8217;s how to get it working Make sure you have sun java installed (not open). Extract the zip into /usr/lib/ Then, a work around is necessary in order to get the menu working right &#8230; <a href="http://www.dawnofdankind.com/2011/programming/getting-aptana-working-under-ubuntu-11-04/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Apparently, Unity breaks Aptana&#8217;s file menu. Here&#8217;s how to get it working</p>
<ol>
<li>Make sure you have <a href="http://www.multimediaboom.com/how-to-install-java-in-ubuntu-11-04-natty-narwhal-ppa/">sun java installed</a> (not open).</li>
<li>Extract the zip into /usr/lib/</li>
<li>Then, a work around is necessary in order to get the menu working right under Unity. Create a script with <a href="http://wiki.appcelerator.org/display/tis/Installing+Studio+on+Linux#InstallingStudioonLinux-Ubuntu11.04%2FNattyNarwhalMenuIssues">this</a> in it:
<div title="Hint: double-click to select code"></div>
<pre Lang="bash">#!/bin/bash
export UBUNTU_MENUPROXY=0
./AptanaStudio3</pre>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.dawnofdankind.com/2011/programming/getting-aptana-working-under-ubuntu-11-04/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Customized search bar in drupal, jQuery vs Preprocess</title>
		<link>http://www.dawnofdankind.com/2011/programming/customized-jquery-search-bar-in-drupal/</link>
		<comments>http://www.dawnofdankind.com/2011/programming/customized-jquery-search-bar-in-drupal/#comments</comments>
		<pubDate>Wed, 29 Jun 2011 19:06:07 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[jquery C# search drupal css]]></category>
		<category><![CDATA[preprocess template]]></category>

		<guid isPermaLink="false">http://www.dawnofdankind.com/?p=254</guid>
		<description><![CDATA[I wanted a search to bar display &#8216;Search..&#8217; until clicked in a Drupal site I&#8217;m building. jQuery immediately came to mind. As it turns out, jQuery is actually the wrong way to do this under Drupal, but when I first &#8230; <a href="http://www.dawnofdankind.com/2011/programming/customized-jquery-search-bar-in-drupal/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I wanted a search to bar display &#8216;Search..&#8217; until clicked in a Drupal site I&#8217;m building. jQuery immediately came to mind. As it turns out, jQuery is actually the wrong way to do this under Drupal, but when I first went looking for an answer to this problem I didn&#8217;t know that, so I&#8217;m going to provide both solutions.<br />
<span id="more-254"></span></p>
<p>The jQuery solution looks like this entails using the very messy looking jQuery() instead of $() because of drupal:</p>
<pre class="brush:js:collapse">
// check that the document is loaded before initiating changes
jQuery(document).ready(function()
{
  // select the element you want to change,
  // in this case our input with id #edit-search-block-form--2
  jQuery("#edit-search-block-form--2")
    .val("Search...")                                             // change the value to Search...
    .css("color", "#b1b1b1")                                 // and the color of the text to whitish according to the needs of my theme
    .focus(function(){                                          // if in focus, we want to change some properties
        jQuery(this).css("color", "black");               // black so the user doesn't have to squint at the text they're entering
        if (jQuery(this).val() == "Search...") {        // if it's still Search, delete that punk
            jQuery(this).val("");
        }
    })
    .blur(function(){                                            // once back from the anarchy of being in focus
        jQuery(this).css("color", "#b1b1b1");          // set the color back
        if (jQuery(this).val() == "") {                     // and replace our trusty Search...
            jQuery(this).val("Search...");
        }
    });
});
</pre>
<p>The reason this is wrong is because Drupal is already building this form from scratch with the <a href="http://drupal.org/node/1043838">form api</a>. jQuery is coming in after the fact and wasting our users precious processing power. The <a href="http://drupal.org/node/154137">correct way</a> to do it is to intercept the form during preprocess, and in my case in my template.php, and attach the javascript functions then. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.dawnofdankind.com/2011/programming/customized-jquery-search-bar-in-drupal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a script/gui relationship with antlr and C#</title>
		<link>http://www.dawnofdankind.com/2011/programming/creating-a-scriptgui-relationship-with-antlr-and-c/</link>
		<comments>http://www.dawnofdankind.com/2011/programming/creating-a-scriptgui-relationship-with-antlr-and-c/#comments</comments>
		<pubDate>Tue, 21 Jun 2011 05:14:23 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ANTLR]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[data driven design]]></category>
		<category><![CDATA[grammars]]></category>
		<category><![CDATA[user interfaces]]></category>

		<guid isPermaLink="false">http://www.dawnofdankind.com/?p=237</guid>
		<description><![CDATA[I&#8217;ll be editing and adding to this post heavily in the near future. I&#8217;m about to head to Austin for an interview and just wanted my latest up before taking off.  I also just just posted a new project over &#8230; <a href="http://www.dawnofdankind.com/2011/programming/creating-a-scriptgui-relationship-with-antlr-and-c/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll be editing and adding to this post heavily in the near future. I&#8217;m about to head to Austin for an interview and just wanted my latest up before taking off.  I also just just posted a new project over at <a href="https://github.com/keithharvey/Script-Parser">github.</a></p>
<p>Better tidbits: <a title="Evaluator" href="https://github.com/keithharvey/Script-Parser/blob/master/Installer/Model/DAL/SourceEval.g"></a></p>
<p><a href="https://github.com/keithharvey/Script-Parser/blob/master/Installer/Model/DAL/SourceExpr.g">AST Evaluation grammar<br />
Parser/Lexer grammar</a></p>
<p><a href="https://github.com/keithharvey/Script-Parser/tree/master/Installer/Model/BLL">Business Logic Layer</a> and the <a href="https://github.com/keithharvey/Script-Parser/blob/master/Installer/Model/BLL/SourceMetaToggle.cs">Toggle </a>interface control implementation of <a href="https://github.com/keithharvey/Script-Parser/blob/master/Installer/Model/IMeta.cs">IMeta</a></p>
<p><span id="more-237"></span>More explanation to come soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dawnofdankind.com/2011/programming/creating-a-scriptgui-relationship-with-antlr-and-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Beast lives!</title>
		<link>http://www.dawnofdankind.com/2011/programming/the-beast-lives/</link>
		<comments>http://www.dawnofdankind.com/2011/programming/the-beast-lives/#comments</comments>
		<pubDate>Sun, 12 Jun 2011 01:17:19 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[cell phone]]></category>
		<category><![CDATA[cell phone development]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.dawnofdankind.com/?p=156</guid>
		<description><![CDATA[The Beast, to those that know her, is a notorious, merciless home wrecker. In a fast paced game of cards, the odds drift elusively in your favor, and then, the beast takes off an arm. Taming her is a challenge &#8230; <a href="http://www.dawnofdankind.com/2011/programming/the-beast-lives/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="alignleft">
<div class="wp-caption alignleft" style="width: 204px"><a href="http://www.dawnofdankind.com/wp-content/uploads/2011/06/logo.jpg"><img class="size-full wp-image-185" title="THE BEAST" src="http://www.dawnofdankind.com/wp-content/uploads/2011/06/logo.jpg" alt="THE BEAST lives!" width="194" height="96" /></a><br />
<embed style="margin: auto;" width="194px" height="15px" src="http://www.dawnofdankind.com/wp-content/uploads/2011/06/nib_2.mid" autostart="false"></embed><br />
<p class="wp-caption-text">Play music to fully enter the lair.</p></div>
</div>
<p>The Beast, to those that know her, is a notorious, merciless home wrecker. In a fast paced game of cards, the odds drift elusively in your favor, and then, the beast takes off an arm. Taming her is a challenge worthy of today’s cell phone gamer.</p>
<p>That was the tag line for my newly-open-sourced cell phone game, The Beast! <span id="more-156"></span></p>
<ul> <a href="https://github.com/keithharvey/The-Beast">Source code at the github repository</a><br />
&nbsp; &nbsp; &nbsp; &nbsp;&raquo;&nbsp;<a href="https://github.com/keithharvey/The-Beast/blob/master/src/com/j2me/part3/MyGameCanvas.java"> the core engine loop</a><br />
<a href="http://www.dawnofdankind.com/wp-content/uploads/2011/06/The-Beast.zip">The latest build (zipped .jar)</a></ul>
<p>The project was done in Java and essentially just virtualized a game my friends and I used to play in college (think lots of raucous yelling about the Beast every time someone lost). Before I started I drew up a <a href="http://www.dawnofdankind.com/the-beast-design-document/">design document</a> and did all the regular rigamarole of game design. It is functionally complete, but a little rough around the edges. The first thing that you will notice is the cpu timing. My <a href="http://webstart.mpowerplayer.com/?origin=7db8a2dc">modern emulator</a> made input a little lurchy because the processor was doing too many ticks/ms. The good ol&#8217; days that weren&#8217;t so good.. This project was a great learning opportunity for both minimalist programming techniques and how to scale a program with limited resources. It also makes pretty nifty use of vector graphics. I&#8217;m glad it&#8217;s finally getting shared.</p>
<p>An Android refactor is coming, so stay tuned.<a href="http://www.dawnofdankind.com/wp-content/uploads/2011/06/logo.jpg"></a></p>
<div id="attachment_209" class="wp-caption alignleft" style="width: 247px"><a href="http://www.dawnofdankind.com/wp-content/uploads/2011/06/intoScreen.jpg"><img class="size-full wp-image-209" title="intoScreen" src="http://www.dawnofdankind.com/wp-content/uploads/2011/06/intoScreen.jpg" alt="intro screen" width="237" height="317" /></a><p class="wp-caption-text">Main menu</p></div>
<div id="attachment_204" class="wp-caption alignleft" style="width: 245px"><a href="http://www.dawnofdankind.com/wp-content/uploads/2011/06/aiSelection.jpg"><img class="size-full wp-image-204" title="number of players" src="http://www.dawnofdankind.com/wp-content/uploads/2011/06/aiSelection.jpg" alt="number of players" width="235" height="317" /></a><p class="wp-caption-text">player selection screen</p></div>
<div id="attachment_212" class="wp-caption alignleft" style="width: 251px"><a href="http://www.dawnofdankind.com/wp-content/uploads/2011/06/yourBetScreen.jpg"><img class="size-full wp-image-212" title="your bet" src="http://www.dawnofdankind.com/wp-content/uploads/2011/06/yourBetScreen.jpg" alt="make a bet" width="241" height="314" /></a><p class="wp-caption-text">Prompt for player to make a bet</p></div>
<div id="attachment_213" class="wp-caption alignleft" style="width: 247px"><a href="http://www.dawnofdankind.com/wp-content/uploads/2011/06/yourTurn2.jpg"><img class="size-full wp-image-213" title="yourTurn2" src="http://www.dawnofdankind.com/wp-content/uploads/2011/06/yourTurn2.jpg" alt="Player raising his bet" width="237" height="314" /></a><p class="wp-caption-text">This player is betting! Pressing select here would bet 3. </p></div>
<div id="attachment_205" class="wp-caption alignleft" style="width: 251px"><a href="http://www.dawnofdankind.com/wp-content/uploads/2011/06/aisTurn.jpg"><img class="size-full wp-image-205" title="aisTurn" src="http://www.dawnofdankind.com/wp-content/uploads/2011/06/aisTurn.jpg" alt="the ai gets a chance to play" width="241" height="312" /></a><p class="wp-caption-text">the ai gets a chance to play</p></div>
<div id="attachment_208" class="wp-caption alignleft" style="width: 248px"><a href="http://www.dawnofdankind.com/wp-content/uploads/2011/06/cardSlide.jpg"><img class="size-full wp-image-208" title="cardSlide" src="http://www.dawnofdankind.com/wp-content/uploads/2011/06/cardSlide.jpg" alt="cards slide to that sade of the table" width="238" height="314" /></a><p class="wp-caption-text">Notice how the cards slide to their respective sides of the &quot;table&quot;.</p></div>
<div id="attachment_210" class="wp-caption alignleft" style="width: 248px"><a href="http://www.dawnofdankind.com/wp-content/uploads/2011/06/lowOrHighAce.jpg"><img class="size-full wp-image-210" title="lowOrHighAce" src="http://www.dawnofdankind.com/wp-content/uploads/2011/06/lowOrHighAce.jpg" alt="ace selection" width="238" height="321" /></a><p class="wp-caption-text">If a player gets an ace on their first card, they get to choose whether it&#39;s low or high, if it&#39;s the second card it&#39;s automatically high.</p></div>
<div id="attachment_207" class="wp-caption alignleft" style="width: 247px"><a href="http://www.dawnofdankind.com/wp-content/uploads/2011/06/BEASTPWNS.jpg"><img class="size-full wp-image-207" title="BEASTPWNS" src="http://www.dawnofdankind.com/wp-content/uploads/2011/06/BEASTPWNS.jpg" alt="the beast wins!" width="237" height="316" /></a><p class="wp-caption-text">The Beast wins! Little surprise there!</p></div>
<div id="attachment_214" class="wp-caption alignleft" style="width: 246px"><a href="http://www.dawnofdankind.com/wp-content/uploads/2011/06/youWin.jpg"><img class="size-full wp-image-214" title="you win" src="http://www.dawnofdankind.com/wp-content/uploads/2011/06/youWin.jpg" alt="You were one of the lucky few to slay the beast!" width="236" height="313" /></a><p class="wp-caption-text">You were one of the lucky few to slay the beast!</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.dawnofdankind.com/2011/programming/the-beast-lives/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://www.dawnofdankind.com/wp-content/uploads/2011/06/nib_2.mid" length="7791" type="audio/midi" />
		</item>
		<item>
		<title>Refactoring refrain</title>
		<link>http://www.dawnofdankind.com/2011/programming/refactoring-refrain/</link>
		<comments>http://www.dawnofdankind.com/2011/programming/refactoring-refrain/#comments</comments>
		<pubDate>Sat, 11 Jun 2011 04:10:37 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[mvvm]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[refactor]]></category>
		<category><![CDATA[refactoring]]></category>

		<guid isPermaLink="false">http://www.dawnofdankind.com/?p=122</guid>
		<description><![CDATA[In an effort to become more prolific and less of a perfectionist, I&#8217;ve decided to post all my nerdy endeavors, including mistakes. The original program I&#8217;m discussing in this article can be found in source here or explained here. Today, &#8230; <a href="http://www.dawnofdankind.com/2011/programming/refactoring-refrain/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In an effort to become more prolific and less of a perfectionist, I&#8217;ve decided to post all my nerdy endeavors, including mistakes. The original program I&#8217;m discussing in this article can be found in source <a href="https://github.com/keithharvey/Line-of-Business-Financial-Data-Parser/">here </a>or explained <a href="http://www.dawnofdankind.com/?p=47">here.</a></p>
<p>Today, I loaded up my billing parser and saw this:<br />
<span id="more-122"></span></p>
<pre class="brush: csharp">void LoadSpreadsheet()
{

var connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;", _filename);

var adapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", connectionString);

var ds = new DataSet();

// grab our spreadsheet data from the adapter

adapter.Fill(ds, "Activity Number");

// now, make it enumerable

var data = ds.Tables["Activity Number"].AsEnumerable();

// grab our data fromt he spreadsheet data with a LINQ query

_query = data.Where(x =&gt; x.Field&lt;string&gt;("Activity Number") != string.Empty).Select(x =&gt;

new ActivityStruct

{

activityID = x.Field&lt;string&gt;("Activity Number"),

lineItem = x.Field&lt;string&gt;("Product Line"),

install = x.Field&lt;string&gt;("Order Sub Type") == "New Install"

});

List&lt;string&gt; uniqueActivities = new List&lt;string&gt;();

List&lt;string&gt; uniqueItems = new List&lt;string&gt;();

// populate a list of unique activities

// TODO: Figure out a way to do this and uniqueItems with one pass, // leaving it the way it is now because of time table

uniqueActivities = (from x in _query

where x.activityID != null

select x.activityID).Distinct().ToList();

uniqueItems = (from x in _query

where x.lineItem != null

select x.lineItem).Distinct().ToList();

// TODO: This status text system doesn't seem consistent with the MVVM pattern, look into it

OnPropertyChanged("StatusText");

_spvm.AddItems(uniqueItems);

_spvm.OkPressed += this.OnPricesFinalized;

}</pre>
<p>Seeing this made me do this:</p>
<div id="attachment_123" class="wp-caption alignnone" style="width: 650px"><a href="http://www.dawnofdankind.com/wp-content/uploads/2011/06/2011-06-10-18-28-03.409.jpg"><img class="size-full wp-image-123" title="bad code" src="http://www.dawnofdankind.com/wp-content/uploads/2011/06/2011-06-10-18-28-03.409.jpg" alt="eww bad code" width="640" height="360" /></a><p class="wp-caption-text">the bad code face</p></div>
<p>There&#8217;s multiple problems with this but let&#8217;s start with the most obvious:</p>
<ol>
<li>Lots of unnecessary looping.</li>
<li>Redundant data.</li>
</ol>
<p>Not to mention it&#8217;s ugly. I knew this when I wrote it (the TODOs made me laugh, may as well say DISCLAIMER) but was under time constraints so just wrote it like it was a python script and made sure it worked. But it&#8217;s not OOP at all and takes really bad advantage of referencing, and the rest of the program deserved better. The <a href="https://github.com/keithharvey/Line-of-Business-Financial-Data-Parser/blob/master/LineOfBusinessFinancialDataParser/ViewModel/MainWindowViewModel.cs">refactored </a>LoadSpreadsheet method builds the model tree structure in one pass.</p>
<pre class="brush: csharp">void LoadSpreadsheet()
{
var connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;", _filename);

var adapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", connectionString);
var ds = new DataSet();

// grab our spreadsheet data from the adapter
adapter.Fill(ds, "Activity Number");

// now, make it enumerable
var data = ds.Tables["Activity Number"].AsEnumerable();

Dictionary&lt;string, LineItem&gt; uniqueLineItems = new Dictionary&lt;string, LineItem&gt;();
// iterate through every line of the excel table
foreach (var x in data)
{
// get the raw strings from our data, used for dictionary keys and model unique IDs
string lineItemID = x.Field&lt;string&gt;("Product Line");
string activityID = x.Field&lt;string&gt;("Activity Number");

// make sure our line item and activity string aren't null
// if line item is null, we don't really care about the entry
if (activityID != null &amp;&amp; lineItemID != null)
{
bool isInstall = x.Field&lt;string&gt;("Order Sub Type") == "New Install";

// see if the new line item is already in our unique list
if(!uniqueLineItems.Keys.Contains(lineItemID))
{
//instantiate the new line data we're going to add to our tree structure
LineItem newLineItem = new LineItem(lineItemID, 0);
// add it, referencing newLineItem.Name saves redundant data
uniqueLineItems.Add(newLineItem.Name, newLineItem);
}

if (!_activities.Keys.Contains(activityID))
{
Activity newActivity = new Activity(activityID, isInstall, uniqueLineItems);
// we add the new activity to the list using the same method we used earlier with lineItem
_activities.Add(newActivity.ActivityNumber, newActivity);
// passes a reference to the uniqueLineItems instance of our object
// that way, when it updates from the VM data bind our models auto-update
_activities[activityID].AddLineItem(uniqueLineItems[lineItemID]);
}
else
{
_activities[activityID].AddLineItem(uniqueLineItems[lineItemID]);
}
}
}

_spvm.AddItems(uniqueLineItems);
_spvm.OkPressed += this.OnPricesFinalized;

// TODO: This status text system doesn't seem consistent with the MVVM pattern, look into it
OnPropertyChanged("StatusText");
}</pre>
<p>Now, one thing I still failed to do was to implement HashSet. HashSet, at first glance, looked perfect for my needs in this case. I needed a unique list and the models contained within the collection already had unique identifiers. Unfortunately HashSet in .net 3.5 is designed for immutable objects (based on its math counterpart no doubt) and the generic derivative of it I made ultimately wasn&#8217;t as clean as just using a dictionary because it would&#8217;ve meant I had to implement IEquatable on my model classes, which as a general rule I don&#8217;t do because they&#8217;re mutable and you don&#8217;t want the wrong class (or worse, programmer) to think an instance is equal when it&#8217;s not. I think I actually might of even gone down that path a bit when I first worked on the project but decided to forget it because I realized it was going to be a time sink. The solution turned out to be super simple! By using a Dictionary with the string linking to the model.uniqueID. This gave an easy lookup within the loop without any data structure and memory redundancy, which for whatever reason still bothers me despite having 16gb of ram. Cell phone development 4 life!</p>
<p>The other change you&#8217;ll notice was I passed a copy of UniqueLineItems to both the SPVM and our models, which acts as a master list of objects. In <a href="https://github.com/keithharvey/Line-of-Business-Financial-Data-Parser/blob/master/LineOfBusinessFinancialDataParser/Model/Activity.cs">activities</a>, in order to track the quantity of items each activity had, I implemented a Dictionary, with the LineItem being a reference to the instance within the UniqueLineItems collection and the int being the quantity of that item. This saves a lot of code.</p>
<pre class="brush: csharp">
// ..........
// client gets a free receiver install with the price of an install
bool installReceiverNotPaid = true;
//now we process the line items for value
foreach (var item in itemQuantities)
{
// if there is a quantity associated with the item (should never happen)
if (item.Key.Value != 0)
{
// now we iterate however many times the item appears in the activity
for (int individualItem = 0; individualItem &lt; item.Value; individualItem++)
{
// if activity is an install, item is a receiver, and we haven't already acknowledged the first receiver
if (_isInstall &amp;&amp; installReceiverNotPaid &amp;&amp; item.Key.IsReceiver)
{
Debug.WriteLine("First receiver accounted for.");
// value remains the same
installReceiverNotPaid = false;
}
// this catches everything else for both installs, upgrades, non-first receivers
else
{
Debug.WriteLine("Added " + item.Key.Name + ": " + item.Key.Value);
value += item.Key.Value;
}
}
}
</pre>
<p>Any feedback, as usual, is welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dawnofdankind.com/2011/programming/refactoring-refrain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Line of Business Financial Billing Parser</title>
		<link>http://www.dawnofdankind.com/2011/programming/line-of-business-financial-billing-parser/</link>
		<comments>http://www.dawnofdankind.com/2011/programming/line-of-business-financial-billing-parser/#comments</comments>
		<pubDate>Thu, 09 Jun 2011 03:32:19 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[data binding]]></category>
		<category><![CDATA[data driven design]]></category>
		<category><![CDATA[excel parsing]]></category>
		<category><![CDATA[mvvm]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[parser]]></category>

		<guid isPermaLink="false">http://www.dawnofdankind.com/?p=47</guid>
		<description><![CDATA[This article describes a program which parses an excel file for information and then, using data driven design, solicits user input for the final valuation of the data. Full source code available in an open source github repository. The problem: &#8230; <a href="http://www.dawnofdankind.com/2011/programming/line-of-business-financial-billing-parser/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This article describes a program which parses an excel file for information and then, using data driven design, solicits user input for the final valuation of the data.<br />
<a href="https://github.com/keithharvey/Line-of-Business-Financial-Data-Parser/">Full source code available in an open source github repository.</a></p>
<p>The problem:</p>
<p>A Directv installation company recently hired me because they had a problem: they get paid in bulk and really had no idea what they were getting paid for because their client was just handing them a check. The only thing they were given as an invoice was a normalized database dump. They had no idea what to do with this information so asked me to write something that would tell them exactly how much they were supposed to be paid. Stripped of any proprietary information, the database dump looks like this with approximately 2000 more entries:</p>
<table border="0" cellspacing="0" cellpadding="0" width="595">
<colgroup>
<col width="98"></col>
<col width="93"></col>
<col width="74"></col>
<col width="209"></col>
<col width="121"></col>
</colgroup>
<tbody>
<tr height="20">
<td width="98" height="20">Activity   Number</td>
<td width="93">Order Sub Type</td>
<td width="74">OLI Number</td>
<td width="209">Product Line</td>
<td width="121">Access Card   Number</td>
</tr>
<tr height="20">
<td width="98" height="20">1-VUE1JLK</td>
<td width="93">New   Install</td>
<td width="74">1</td>
<td width="209">IRD   &#8211; STANDARD</td>
<td width="121">002212408963</td>
</tr>
<tr height="20">
<td width="98" height="20">1-VUE1JLK</td>
<td width="93">New   Install</td>
<td width="74">3</td>
<td width="209">Multi-Switch</td>
<td width="121">002331691473</td>
</tr>
</tbody>
</table>
<p><span id="more-47"></span><br />
Notice the conspicuous lack of basic things like amount paid per line item. They knew how much they were supposed to get paid per job, but with just the individual line items in a big list it had to be extrapolated from the data given by the client. What further complicated matters was that the prices for a given line item isn&#8217;t entirely consistent, it would depend on the type of job done (upgrade or install) how much you got paid for a particular item. I also wanted to give them the ability to input that information since the prices they were paid could change in the future.</p>
<p>The Solution:</p>
<p>A WPF project based on the <a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx" target="_blank">MVVM</a> design pattern.  This afforded several advantages:</p>
<ul>
<li>tidy seperation of concerns and interface driven</li>
<li>easy to solicit user input at run-time due to good data binding support in WPF</li>
<li>xaml interface creation allowed me to make a fluid, robust interface in a short amount of time</li>
<li>Automatically generated documentation</li>
<li>.net gave me access to OLE-DB for easily parsing the excel files</li>
</ul>
<p>I started with normal MVVM stuff like rerouting the App code-behind to my primary ViewModel, named <a href="https://github.com/keithharvey/Line-of-Business-Financial-Data-Parser/blob/master/LineOfBusinessFinancialDataParser/ViewModel/MainWindowViewModel.cs">MainWindowViewModel</a>, which derives from <a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx#id0090051">ViewModelBase</a>, giving us access to INotifyPropertyChanged, and virtual string DisplayName.</p>
<pre class="brush: csharp">void AppStartup(object sender, StartupEventArgs args)
{
MainWindow window = new MainWindow();

// Create the ViewModel to which
// the main window binds.
var viewModel = new MainWindowViewModel();

// Allow all controls in the window to
// bind to the ViewModel by setting the
// DataContext, which propagates down
// the element tree.
window.DataContext = viewModel;

window.Show();
}</pre>
<p>The main window itself consists of 3 controls: an open spreadsheet button, a status text to give user feedback, and a third area for user input of prices. The open spreadsheet button opens a file dialogue and is data bound to class that implements ViewModelBase and contains an <a href="http://msdn.microsoft.com/en-us/library/system.windows.input.icommand.aspx">ICommand field</a>. This is essentially just a relay command that gets delegated to a private method within MainWindowViewModel and makes sure the interface stays abstracted from our implementation. The StatusText is just a string property that updates according to various state triggers. I&#8217;m sure there&#8217;s probably a better way to handle this in .net but haven&#8217;t had a chance to look into it, yet. The ContentControl is bound to a property called Spvm (<a href="https://github.com/keithharvey/Line-of-Business-Financial-Data-Parser/blob/master/LineOfBusinessFinancialDataParser/ViewModel/SelectPricesViewModel.cs">SelectPricesViewModel</a>), with its visibility tied to an &#8220;IsPopulated&#8221; boolean. This checks if the spreadsheet has been opened and passed a unique list of items. So, by default it is not visible (not collapsed, however the data isn&#8217;t there yet so it will expand once the data populates):</p>
<div id="attachment_54" class="wp-caption alignnone" style="width: 412px"><a href="http://www.dawnofdankind.com/wp-content/uploads/2011/06/DefaultState.jpg"><img class="size-full wp-image-54 " title="DefaultState" src="http://www.dawnofdankind.com/wp-content/uploads/2011/06/DefaultState.jpg" alt="Default Application State" width="402" height="203" /></a><p class="wp-caption-text">The default state of of the application before opening a spreadsheet.</p></div>
<p>&nbsp;</p>
<p>SelectPricesViewModel contains a list of unique line items, queried and passed from MainWindowViewModel:</p>
<pre class="brush: csharp"> uniqueItems = (from x in _query
                where x.lineItem != null
                select x.lineItem).Distinct().ToList();</pre>
<p>Subsequently, there is also a model <a href="https://github.com/keithharvey/Line-of-Business-Financial-Data-Parser/blob/master/LineOfBusinessFinancialDataParser/Model/LineItem.cs">LineItem </a>and <a href="https://github.com/keithharvey/Line-of-Business-Financial-Data-Parser/blob/master/LineOfBusinessFinancialDataParser/ViewModel/LineItemViewModel.cs">LineItemViewModel</a>. LineItem contains very little business logic, but does provide a value, name, and whether or not the line item is a receiver or a &#8220;OneOff&#8221;, or in other words counted only once per activity. LineItemViewModel just mirrors LineItem but calls NotifyPropertyChanged() where appropriate. SPVM uses an ObserveableCollection of LineItemViewModels to populate a data template contained within <a href="https://github.com/keithharvey/Line-of-Business-Financial-Data-Parser/blob/master/LineOfBusinessFinancialDataParser/MainWindowResources.xaml">MainWindowResources</a> and solicit input from the user. I did have a user specified IsReceiver boolean within the ViewModel (which I left notify capable) but have since edited that to be accomplished programmatically with a regular expression checking for the keyword &#8220;IRD&#8221; in the line item name. Here&#8217;s how it looks after the spreadsheet has been loaded and SPVM is populated and visible:</p>
<div id="attachment_93" class="wp-caption alignnone" style="width: 310px"><a href="http://www.dawnofdankind.com/wp-content/uploads/2011/06/AfterOpening.jpg"><img class="size-medium wp-image-93" title="AfterOpening" src="http://www.dawnofdankind.com/wp-content/uploads/2011/06/AfterOpening-300x160.jpg" alt="State of the program after the spreadsheet is selected." width="300" height="160" /></a><p class="wp-caption-text">State of the program after the spreadsheet is selected.</p></div>
<p>The user then uses our &#8220;compute&#8221; button (a <a href="https://github.com/keithharvey/Line-of-Business-Financial-Data-Parser/blob/master/LineOfBusinessFinancialDataParser/ViewModel/CommandViewModel.cs">CommandViewModel</a>) to trigger an event which is routed within MainWindowViewModel to our OnPricesFinalized private method. This basically just iterates through the <a href="https://github.com/keithharvey/Line-of-Business-Financial-Data-Parser/blob/master/LineOfBusinessFinancialDataParser/Model/Activity.cs">activities </a>from the database query, matches them with the prices from the SPVM, and has them calculate their own prices. The activity value algorithm looks like this:</p>
<pre class="brush: csharp">public double Value(double PriceOfInstall, double PriceOfUpgrade)
{
    double value = 0;
    Debug.WriteLine("Activity #" + ActivityNumber);

    if (_isInstall)
    {
        Debug.WriteLine("Install - Value: " + PriceOfInstall);
        value += PriceOfInstall;
    }
    else
    {
        Debug.WriteLine("Upgrade - Value: " + PriceOfUpgrade);
        value += PriceOfUpgrade;
    }

    bool skippedOne = false;
    // Populate a dictionary to track one-offs, bool is true if the line item
    // has already been counted
    Dictionary OneOffTracker = new Dictionary();
    foreach (LineItem li in OneOffLineItems)
    {
        OneOffTracker.Add(li, false);
    }
    //now we process the line items for value
    foreach (LineItem li in LineItems)
    {
        if (li.Value != 0)
        {
            if (li.IsReceiver == false
                &amp;&amp; li.SkipDuplicates == false)
            {
                value += li.Value;
                Debug.WriteLine(li.Name + " - Value: " + li.Value);
            }
            else if (li.SkipDuplicates == true &amp;&amp;
                !OneOffTracker[li])
            {
                OneOffTracker[li] = true;
                value += li.Value;
                Debug.WriteLine(li.Name + " - Value: " + li.Value);
            }
            // if it's a SkipOnInstall item, check to see if one has
            // already been skipped before adding the value
            else if (_isInstall &amp;&amp;
                !skippedOne)
            {
                skippedOne = true;
            }
            else
            {
                value += li.Value;
                Debug.WriteLine(li.Name + " - Value: " + li.Value);
            }
        }
    }
    Debug.WriteLine("TOTAL VALUE: $" + value);
    Debug.WriteLine("");

    return value;
}</pre>
<p>That&#8217;s the guts of it. Note that the first receiver in an install does not receive payment, it&#8217;s included in the cost of the install. After iterating through all the unique activities, the status text is updated with the cumulative value and subsequent spreadsheet reloads clear out the unique items from SPVM.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dawnofdankind.com/2011/programming/line-of-business-financial-billing-parser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating user interfaces dynamically</title>
		<link>http://www.dawnofdankind.com/2010/programming/creating-user-interfaces-dynamically/</link>
		<comments>http://www.dawnofdankind.com/2010/programming/creating-user-interfaces-dynamically/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 13:33:18 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ANTLR]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[data binding]]></category>
		<category><![CDATA[data driven design]]></category>
		<category><![CDATA[model-view-viewmodel]]></category>
		<category><![CDATA[object oriented programming]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://www.dawnofdankind.com/?p=31</guid>
		<description><![CDATA[This was my first foray into content driven design and was a lot of fun to develop in WPF.  The idea was to create a centralized cloud delivery method for third party scripts, HUDs, and modifications for a variety of &#8230; <a href="http://www.dawnofdankind.com/2010/programming/creating-user-interfaces-dynamically/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This was my first foray into content driven design and was a lot of fun to develop in WPF.  The idea was to create a centralized cloud delivery method for third party scripts, HUDs, and modifications for a variety of games on the PC platform. Using <a href="http://www.antlr.org/">ANTLR</a> to generate a parser, I made it understand Source engine&#8217;s scripting language as a starting poing and it generates user interfaces so that end users can easily modify important attributes of a script. This is generic, so it works over all TF2 and many CSS scripts and could easily be augmented to understand scripting languages in other games. It&#8217;s about 60-70% done. The parser and interface generation is complete, but I really need to finish the cloud features to publish it or it&#8217;s kind of pointless.</p>
<p><a href="http://www.dawnofdankind.com/wp-content/uploads/2010/07/CompConfigInstaller0.5.png"><img class="alignnone size-medium wp-image-33" title="CompConfigInstaller0.5" src="http://www.dawnofdankind.com/wp-content/uploads/2010/07/CompConfigInstaller0.5-184x300.png" alt="" width="184" height="300" /></a></p>
<p>On a side note, I don&#8217;t quite understand why Steam doesn&#8217;t do this already. Anything that brings third party developers closer to consumers is kind of Valve&#8217;s thing. I really need to touch this thing up and publish it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dawnofdankind.com/2010/programming/creating-user-interfaces-dynamically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ze Germans!</title>
		<link>http://www.dawnofdankind.com/2010/modeling/ze-germans/</link>
		<comments>http://www.dawnofdankind.com/2010/modeling/ze-germans/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 13:07:07 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Modeling]]></category>

		<guid isPermaLink="false">http://www.dawnofdankind.com/?p=28</guid>
		<description><![CDATA[One day, I will get around to rigging this thing.]]></description>
			<content:encoded><![CDATA[<p>One day, I will get around to rigging this thing.</p>
<p><a href="http://www.dawnofdankind.com/wp-content/uploads/2010/07/34.jpg"><img class="alignnone size-medium wp-image-16" title="34" src="http://www.dawnofdankind.com/wp-content/uploads/2010/07/34-300x128.jpg" alt="" width="300" height="128" /></a><a href="http://www.dawnofdankind.com/wp-content/uploads/2010/07/tigerSide.jpg"><img class="alignnone size-medium wp-image-17" title="tigerSide" src="http://www.dawnofdankind.com/wp-content/uploads/2010/07/tigerSide-300x168.jpg" alt="" width="300" height="168" /></a><a href="http://www.dawnofdankind.com/wp-content/uploads/2010/07/tigerBack.jpg"><img class="alignnone size-medium wp-image-29" title="tigerBack" src="http://www.dawnofdankind.com/wp-content/uploads/2010/07/tigerBack-300x168.jpg" alt="" width="300" height="168" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dawnofdankind.com/2010/modeling/ze-germans/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First post!</title>
		<link>http://www.dawnofdankind.com/2010/game-development/first-post/</link>
		<comments>http://www.dawnofdankind.com/2010/game-development/first-post/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 12:24:03 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Game Development]]></category>

		<guid isPermaLink="false">http://www.harveytrade.com/dawnofdankind/?p=6</guid>
		<description><![CDATA[Let&#8217;s start this thing off with some work I did with my roomates. This was done in UT2004 and I remember that waterfall looking like it had more hours of my life in it.]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s start this thing off with some work I did with my <a href="http://www.chrisemond3d.com" target="_blank">roomates</a>. This was done in UT2004 and I remember that waterfall looking like it had more hours of my life in it.</p>
<p><a href="http://www.harveytrade.com/dawnofdankind/wp-content/uploads/2010/07/front.jpg"><img class="alignnone size-medium wp-image-11" title="front" src="http://www.harveytrade.com/dawnofdankind/wp-content/uploads/2010/07/front-300x161.jpg" alt="" width="300" height="161" /></a><a href="http://www.harveytrade.com/dawnofdankind/wp-content/uploads/2010/07/reverse1.jpg"><img class="alignnone size-medium wp-image-12" title="reverse" src="http://www.harveytrade.com/dawnofdankind/wp-content/uploads/2010/07/reverse1-300x151.jpg" alt="" width="300" height="151" /></a><a href="http://www.harveytrade.com/dawnofdankind/wp-content/uploads/2010/07/waterfall1.jpg"><img class="alignnone size-medium wp-image-13" title="waterfall" src="http://www.harveytrade.com/dawnofdankind/wp-content/uploads/2010/07/waterfall1-300x148.jpg" alt="" width="300" height="148" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dawnofdankind.com/2010/game-development/first-post/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

