<?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>David McMurray Dot Net&#187; Programming</title>
	<atom:link href="http://www.davidmcmurray.net/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.davidmcmurray.net</link>
	<description>Live To Code, Code To Live</description>
	<lastBuildDate>Wed, 18 Aug 2010 19:24:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Fleshing out the beast</title>
		<link>http://www.davidmcmurray.net/2009/05/18/fleshing-out-the-beast/</link>
		<comments>http://www.davidmcmurray.net/2009/05/18/fleshing-out-the-beast/#comments</comments>
		<pubDate>Mon, 18 May 2009 21:54:29 +0000</pubDate>
		<dc:creator>David McMurray</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.davidmcmurray.net/?p=220</guid>
		<description><![CDATA[I&#8217;m starting to put the AJAX game framework to the test, and applying it to some game rules. Although currently I&#8217;m starting from a higher level not covered by the rules at the moment, which is where individual game instances are created. Whoever is running a particular game instance can set the parameters of the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m starting to put the AJAX game framework to the test, and applying it to some game rules. Although currently I&#8217;m starting from a higher level not covered by the rules at the moment, which is where individual game instances are created. Whoever is running a particular game instance can set the parameters of the game; starting conditions and victory conditions for instance. Then once the players have joined, the game can begin.</p>
<p>As this system is turn based I intend to allow a turn period to be set as part of the starting parameters. But also provide the option to have this as a maximum turn duration, and process turns as soon as all players have submitted their turn. Since turn processing will take a matter of seconds and the next turn will start once processing has completed, it would actually be possible for all players to be logged in at the same time and submit turn after turn.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmcmurray.net/2009/05/18/fleshing-out-the-beast/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Trigger Happy with MySQL</title>
		<link>http://www.davidmcmurray.net/2009/05/15/trigger-happy-with-mysql/</link>
		<comments>http://www.davidmcmurray.net/2009/05/15/trigger-happy-with-mysql/#comments</comments>
		<pubDate>Fri, 15 May 2009 01:16:21 +0000</pubDate>
		<dc:creator>David McMurray</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[triggers]]></category>

		<guid isPermaLink="false">http://www.davidmcmurray.net/?p=211</guid>
		<description><![CDATA[I have to say I am a rather big fan of db triggers, in an effort to bring some discipline to my databases. Since audit tables have become quite a habit of mine, this is probably my main use for triggers. Although MySQL has a little way to go yet before we have the kind [...]]]></description>
			<content:encoded><![CDATA[<p>I have to say I am a rather big fan of db triggers, in an effort to bring some discipline to my databases. Since audit tables have become quite a habit of mine, this is probably my main use for triggers. Although MySQL has a little way to go yet before we have the kind of experience that SQL Server has brought to us in the past, but it&#8217;s getting there.</p>
<p>I was surprised to see how little documentation there is on the &#8216;BEFORE&#8217; and &#8216;AFTER&#8217; keywords. I was looking for something that would explain to me when I should use each of these, and wherever I found *something* on it, it wasn&#8217;t enough.</p>
<p>Through a little bit of testing however, I have found that using &#8216;AFTER&#8217; delivers desirable results for Inserts, Updates and Deletes. Is it important? Well, considering that after performing the tasks of a &#8216;BEFORE&#8217; trigger the actual Insert, Update or Delete might fail, but this doesn&#8217;t undo the effects of the trigger. Using &#8216;AFTER&#8217; triggers ensures that the task has completed before we create the audit record.</p>
<p>An example of auditing triggers, for Insert, Update and Delete:</p>
<p>
<pre><code>
CREATE TRIGGER mytable_audit_trigger_insert
AFTER INSERT ON mytable
FOR EACH ROW BEGIN
    INSERT INTO mytable_audit (
        id, date, name
    )
    VALUES(
        NEW.id, NOW(), NEW.name
    );
END;
</code></pre>
</p>
<p>
<pre><code>
CREATE TRIGGER mytable_audit_trigger_update
AFTER UPDATE ON mytable
FOR EACH ROW BEGIN
    INSERT INTO mytable_audit (
        id, date, name
    )
    VALUES(
        NEW.id, NOW(), NEW.name
    );
END;
</code></pre>
</p>
<p>
<pre><code>
CREATE TRIGGER mytable_audit_trigger_delete
AFTER DELETE ON mytable
FOR EACH ROW BEGIN
    INSERT INTO mytable_audit (
        id, date, name
    )
    VALUES(
        OLD.id, NOW(), OLD.name
    );
END;
</code></pre>
</p>
<p>It would be nice to be able to query/edit triggers, but unfortunately you can only CREATE and DROP them, certainly within the MySQL Query Browser. I&#8217;ve not tried any 3rd party tools as I&#8217;m happy to keep .sql files, with the details of the CREATE TRIGGER statements so I know what&#8217;s in them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmcmurray.net/2009/05/15/trigger-happy-with-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SPI Ajax Application Development</title>
		<link>http://www.davidmcmurray.net/2009/05/10/spi-ajax-application-development/</link>
		<comments>http://www.davidmcmurray.net/2009/05/10/spi-ajax-application-development/#comments</comments>
		<pubDate>Sun, 10 May 2009 12:25:40 +0000</pubDate>
		<dc:creator>David McMurray</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[SPI]]></category>
		<category><![CDATA[web application]]></category>

		<guid isPermaLink="false">http://www.davidmcmurray.net/?p=194</guid>
		<description><![CDATA[<p>Writing an Ajax-based web application is far from new, and neither is the conundrum of choosing a single-page interface (SPI) or multi-page interface (MPI) and which patterns to implement. But these decisions are made much simpler if you're developing a web version of some traditional local application. For instance the issues of browsing history and bookmarking for which SPI applications would require additional code to implement are not needed. We don't expect this functionality from traditional local applications other than the menus and controls that would be implemented in an Ajax web-based version of the application.</p>

<p>This is why I chose to implement the SPI model for my browser-based application framework, primarily intended for strategy/RPG gaming. Since users will need to be authenticated by the application before they can use it, and once logged in they are presented with navigational controls via menus and other web controls, I see no real requirement for them to bookmark anything other than the main application page. Which they are free to do. Admittedly, particularly in the case of online gaming, there would generally be some content intended for non-members, introduction to the application and enticing screenshots etc, which they may feel the need to bookmark. But if a sufficiently intuitive public menu is on offer then bookmarking and browsing history is still not really necessary.</p>

<p>Anyway, enough of justifying my apparent laziness ;P Time for some code...</p>
]]></description>
			<content:encoded><![CDATA[<p>Writing an Ajax-based web application is far from new, and neither is the conundrum of choosing a single-page interface (SPI) or multi-page interface (MPI) and which patterns to implement. But these decisions are made much simpler if you&#8217;re developing a web version of some traditional local application. For instance the issues of browsing history and bookmarking for which SPI applications would require additional code to implement are not needed. We don&#8217;t expect this functionality from traditional local applications other than the menus and controls that would be implemented in an Ajax web-based version of the application.</p>
<p>This is why I chose to implement the SPI model for my browser-based application framework, primarily intended for strategy/RPG gaming. Since users will need to be authenticated by the application before they can use it, and once logged in they are presented with navigational controls via menus and other web controls, I see no real requirement for them to bookmark anything other than the main application page. Which they are free to do. Admittedly, particularly in the case of online gaming, there would generally be some content intended for non-members, introduction to the application and enticing screenshots etc, which they may feel the need to bookmark. But if a sufficiently intuitive public menu is on offer then bookmarking and browsing history is still not really necessary.</p>
<p>Anyway, enough of justifying my apparent laziness ;P Time for some code&#8230;</p>
<p>I devised an XMLHttpRequest model which uses a single Ajax callback function that receives XML containing individual page updates. For example I have started with a two part interface made up of a menu and main content area. When the user clicks on a menu option an XMLHttpRequest is sent to a specific server-side script for that menu option which will compile an XML update document and pass it back. This will then be picked up from my one, generic callback function. This will then extract each xml page update and perform each update on the page. These updates will specify an ID, which relates to an element on the page.</p>
<p>For example, consider a very simplified situation below, with 2 menu items for introduction and about us sections, a header section that just informs the user where they are in the application and a main content section initially displaying the introduction:</p>
<pre><code>
&lt;html&gt;
  &lt;body&gt;
    &lt;div id="header"&gt;Introduction&lt;/div&gt;
    &lt;div id="menu"&gt;
      &lt;div onclick="AjaxReq('intro');"&gt;Introduction&lt;/div&gt;
      &lt;div onclick="AjaxReq('about');"&gt;About Us&lt;/div.
    &lt;/div&gt;
    &lt;div id="main"&gt;
      This is the introduction page.
    &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;
</code></pre>
</p>
<p>The AjaxReq function will then look at it&#8217;s one parameter and call the appropriate server-side script, in this case maybe either intro{.php,.asp,.aspx,etc.} or aboutus for example. The aboutus script might then return the following XML:</p>
<pre><code>
&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;
&lt;updates&gt;
  &lt;update target="header"&gt;
    &lt;![CDATA[
      About Us
    ]]&gt;
  &lt;/update&gt;
  &lt;update target="main"&gt;
    &lt;![CDATA[
      This is the about us page.
    ]]&gt;
  &lt;/update&gt;
&lt;/updates&gt;
</code></pre>
</p>
<p>The generic callack function that receives this can then simply replace the contents of each of the html elements specified by the target attributes, with the contents of the CDATA sections. This will give a page that looks like:</p>
<pre><code>
&lt;html&gt;
  &lt;body&gt;
    &lt;div id="header"&gt;About Us&lt;/div&gt;
    &lt;div id="menu"&gt;
      &lt;div onclick="AjaxReq('intro');"&gt;Introduction&lt;/div&gt;
      &lt;div onclick="AjaxReq('about');"&gt;About Us&lt;/div.
    &lt;/div&gt;
    &lt;div id="main"&gt;
      This is the about us page.
    &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;
</code></pre>
</p>
<p>So a single Ajax request-response can make several updates to the page. So we could expand this to also update the menu if we wanted to include sub-menus.</p>
<p>Also, a single section might have a specific layout and controls within the &#8220;main&#8221; element, whose controls make Ajax requests that return updates for elements specific to that &#8220;main&#8221; section. This is made easier by the addition of passing parameters in the request. So not only can you start with a simple menu-content layout, but each of those sections could load sub-sections whose content can be updated directly.</p>
<p>Time for an example of the Javascript Ajax request and callback functions that could be used in an application implementing this method. These also rely on the use of the prototype library. Here&#8217;s the Ajax request function:</p>
<pre><code>
function AjaxRequest(url, params, callBack) {
    new Ajax.Request(url, {
        parameters: params,
        onSuccess: callBack,
        onFailure: AjaxRequestError
    });
}</code></pre>
</p>
<p>Here&#8217;s the generic callback function:</p>
<pre><code>function AjaxResponse(req) {
    var xmlDoc = req.responseXML;
    var xhtmlUpdate = xmlDoc.getElementsByTagName("xhtmlupdate");
    var i,target;
    for(i=0; i&lt;xhtmlUpdate.length; i++) {
        target = xhtmlUpdate[i].getAttribute("target");
        xhtml = GetNodeXML(xhtmlUpdate[i]);
        // Clear previous data.
        while($(target).hasChildNodes()) {
            $(target).removeChild($(target).lastChild);
        }
        // Add new data if there is any.
        if (xhtml != "") {
            var tmpDiv = document.createElement("div");
            tmpDiv.innerHTML = xhtml;
            $(target).appendChild(tmpDiv);
        }
    }
}</code></pre>
</p>
<p>I&#8217;ve included a login section in my application framework, with the ability for a user to register an account and retrieve forgotten login details. I have also provided a public and private application menu depending on whether the user is currently logged in or not. I&#8217;m hoping to apply it to some game rules soon for a small SPI Ajax space colonisation strategy game. But I&#8217;m also thinking of moving from Prototype to JQuery.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmcmurray.net/2009/05/10/spi-ajax-application-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Busy Bee</title>
		<link>http://www.davidmcmurray.net/2009/03/06/busy-bee/</link>
		<comments>http://www.davidmcmurray.net/2009/03/06/busy-bee/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 01:24:20 +0000</pubDate>
		<dc:creator>David McMurray</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.davidmcmurray.net/?p=180</guid>
		<description><![CDATA[January to March seems to be just the most manic time of the year for me, sooo busy at work and often having to work till the wee hours to get my main project updated for the college I work for, so that staff can plan their courses and budgets for the next academic year. [...]]]></description>
			<content:encoded><![CDATA[<p>January to March seems to be just the most manic time of the year for me, sooo busy at work and often having to work till the wee hours to get my main project updated for the college I work for, so that staff can plan their courses and budgets for the next academic year. The LSC decided to change the funding methodologies for 08/09, although we didn&#8217;t change things in the last planning period. But now we have the details we&#8217;ve implemented it in this years budget planning tool. Anyway enough of that, I am so booking some holiday when things have settled down a bit.</p>
<p>What else have I been doing? Mostly PHP, JavaScript (although it&#8217;s on my list to give JQuery a try after listening to the FLOSS Weekly podcast no. 55), cURL, libxml2, mySQL, Visual Studio C++ 2008 Express (for my sins ;). Oh and I&#8217;ve converted myself to Gnome, after a long and painful struggle with KDE, swapping kate for gedit and not looking back, much.</p>
<p>Oh and more dabbling with Drupal, wrote a newsfeed reader module for grabbing news items for a website.</p>
<p>Well, that&#8217;s it for now, back to the grind&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmcmurray.net/2009/03/06/busy-bee/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Grabbed By The Attributes</title>
		<link>http://www.davidmcmurray.net/2008/12/19/grabbed-by-the-attributes/</link>
		<comments>http://www.davidmcmurray.net/2008/12/19/grabbed-by-the-attributes/#comments</comments>
		<pubDate>Fri, 19 Dec 2008 01:21:39 +0000</pubDate>
		<dc:creator>David McMurray</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript attributes getElementById grid]]></category>

		<guid isPermaLink="false">http://www.davidmcmurray.net/?p=155</guid>
		<description><![CDATA[The Javascript function &#8216;document.getElementById(&#8220;&#60;ElementId&#62;&#8221;)&#8217; which returns a reference to the first object within a document with the specified id, is certainly in my experience a highly utilised method. But it&#8217;s a bit restricting, certainly in a lot of grid work I&#8217;ve done over the past few years. Why should we restrict the locating of specific [...]]]></description>
			<content:encoded><![CDATA[<p>The Javascript function &#8216;document.getElementById(&#8220;&lt;ElementId&gt;&#8221;)&#8217; which returns a reference to the first object within a document with the specified id, is certainly in my experience a highly utilised method. But it&#8217;s a bit restricting, certainly in a lot of grid work I&#8217;ve done over the past few years.</p>
<p>Why should we restrict the locating of specific elements to just the id attribute? Why not any other attribute? If I have a grid of elements, for example text inputs, I might want to organise them into rows and columns.</p>
<p>
<pre><code>
&lt;input type="text" id="cost" row="4" col="6"/&gt;
</code></pre>
</p>
<p>Now if I want to reference this control from the entire page of controls by it&#8217;s position without knowing it&#8217;s id is &#8216;cost&#8217;, there&#8217;s no straightforward way of doing so. It feels like this should already be available to us. For example, perhaps the control directly below this (on row 5 col 6) has focus and we wish to be able to press the up cursor key and have the focus change to this control on row 4 col 6. This would be much like using cursor keys to move around a spreadsheet. If we could search for the controls by some other attribute like row and col this would be easy. Don&#8217;t get me wrong, this is completely possible using getElementById, you could simply encode the row and column into the id attribute, as I have done many times before.</p>
<p>
<pre><code>
&lt;input type="text" id="r4c6"/&gt;...
&lt;input type="text" id="r5c6"/&gt;...  control with current focus
</code></pre>
</p>
<p><span id="more-155"></span></p>
<p>Then by parsing the id of the control which currently has focus into row and column variables (r5c6 becomes row=5 and col=6) we can simply subtract 1 from the row, re-encode the id (which would now be r4c6). But the problem is you might want the id to have more meaning than just the position of the control, perhaps calculations are done using several different controls on the page. If you then need to move a control to a different row and/or column you would then need to change all calculations to reference the new grid position. Surely it would be better to reference controls in calculations by a more meaningful id, like &#8216;travelCost&#8217;, &#8216;hourPerDay&#8217;, &#8216;distance&#8217;, etc.</p>
<p>&#8230;And this is the very problem that drove me to write the following function, giving the ability to gain a reference to an HTML element via any attribute it might have.</p>
<p>
<pre><code>
function getElementByAttr(attrName, attrValue)
{
    var tags = document.getElementsByTagName("*");
    var result = [];
    var elem, attr;
    var regex = RegExp("^"+attrValue+"$");
    var i = 0;

    while(elem = tags.item(i++))
    {
	attr = elem.getAttribute(attrName);
	if (attr != null)
	    if (regex.test(attr))
		result.push(elem);		
    }

    return result[0];
}
</code></pre>
</p>
<p>This is great for picking out elements by a single attribute, but in the case of the row and col scenario it really doesn&#8217;t help a lot. So I&#8217;m thinking a few more functions are needed for a complete coverage of functionality. What I could do with is a function that can return a subset of the elements, for example an entire row. So I need a getElementsByAttr(attrName, attrValue) (notice the plural Element*s*) function. This would then allow us to do the following which would return an array of references to all elements where the row number is 4 and store them in the variable &#8216;myRow&#8217;:
<p>
<pre><code>
var myRow = getElementsByAttr("row", "4");
</code></pre>
</p>
<p>. But we still need to root out the correct column from that row, so another function is needed, or rather an extension of the original as getElementByAttr(attrName, attrValue, arrayOfElements). Then this would allow us to restrict the search to only those elements currently in the arrayOfElements.</p>
<p>
<pre><code>
//Grab all the elements on row 4.
myRow = getElementsByAttr("row", "4");
//Grab the column 6 element from the array of row 4 elements.
myElement = getElementByAttr("col", "6", myRow);
</code></pre>
</p>
<p>Additionally the getElementsByAttr function would have it&#8217;s uses in instances where you might want to process an entire row or column. E.g. summing the values in a single column.</p>
<p>Assuming a grid with columns and rows numbered from 1 onwards.</p>
<pre><code>
total = 0;
myCol = getElementsByAttr("col","9");
for(i=1; i&lt;=myCol.length; i++)
{
    newVal = parseFloat(myCol[i].value);
    total += (isNaN(newVal))?0:newVal;
}
alert("Total for column 9 = "+total);
</code></pre>
</p>
<p>When I get chance I&#8217;ll post the getElementsByAttr and extended getElementByAttr, but for the last one I need to decide whether to split getElementByAttr(attrName, attrValue) and getElementByAttr(attrName, attrValue, arrayOfElements) into two differently named functions or combine them and allow &#8216;null&#8217; to be passed for the array when it&#8217;s not required.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmcmurray.net/2008/12/19/grabbed-by-the-attributes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Busy busy busy&#8230;</title>
		<link>http://www.davidmcmurray.net/2008/11/17/busy-busy-busy/</link>
		<comments>http://www.davidmcmurray.net/2008/11/17/busy-busy-busy/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 03:14:37 +0000</pubDate>
		<dc:creator>David McMurray</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.davidmcmurray.net/?p=144</guid>
		<description><![CDATA[I&#8217;m currently working on a couple of projects, as usual too many at once but one is coming along at a reasonable pace, so atleast that&#8217;s something. I hope to spend more time on the AJAX framework I&#8217;ve been developing, well it&#8217;s more of a framework + design pattern combined and focuses on web applications [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently working on a couple of projects, as usual too many at once but one is coming along at a reasonable pace, so atleast that&#8217;s something.</P></p>
<p>I hope to spend more time on the AJAX framework I&#8217;ve been developing, well it&#8217;s more of a framework + design pattern combined and focuses on web applications completely produced from a single page. Basically you navigate to the site and every navigation within that site from then on is handled using AJAX, there is no loading of a new page. Unless of course the user forces a page reload, in which case the session state defines what the user was seeing before and recreates the page as it was before. This also means that during the current session the user never loses their state. It&#8217;s based on PHP for the server side scripting and it&#8217;s something I started a couple of years ago and keep chipping away at it now and then.</p>
<p>So far I&#8217;ve got login functionality, allowing users to register an account, login/logout and viewing public/private &#8220;screens&#8221; depending on whether they are logged in or not.</p>
<p>I&#8217;ve not got anything online as yet, only running on my private RedHat 9 LAMP server.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmcmurray.net/2008/11/17/busy-busy-busy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Universe in code.</title>
		<link>http://www.davidmcmurray.net/2007/08/19/the-universe-in-code/</link>
		<comments>http://www.davidmcmurray.net/2007/08/19/the-universe-in-code/#comments</comments>
		<pubDate>Sun, 19 Aug 2007 23:59:16 +0000</pubDate>
		<dc:creator>David McMurray</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.davidmcmurray.net/2007/08/19/the-universe-in-code/</guid>
		<description><![CDATA[If you&#8217;re old, and lucky enough to have spent many an hour piloting your spacecraft from star system to star system, and spacestation to spacestation, buying and selling goods, taking on pirates and alien attacks in the game &#8216;Elite&#8217;, by David Braben and Ian Bell. Then you may well have been amazed by the sheer [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re old, and lucky enough to have spent many an hour piloting your spacecraft from star system to star system, and spacestation to spacestation, buying and selling goods, taking on pirates and alien attacks in the game &#8216;Elite&#8217;, by David Braben and Ian Bell. Then you may well have been amazed by the sheer size of the game, hosting thousands of stars, planets and moons, with coordinates, descriptions, stats and stock market prices all tightly packed into 48KB of memory (in the case of the spectrum I owned, that is). Now it&#8217;s no mystery how they managed to do this, generating all their data procedurally through a fixed algorithm, so I decided to set about creating my own Universe-generating algorithm for my own projects.</p>
<p>Initially I found an interesting <a href="http://www.jongware.com/galaxy1.html">page</a> which gives an example of creating star names from 32 &#8216;sounds&#8217;. So I started from this idea and expanded it to use a lot more &#8216;sounds&#8217; and a list of optional name endings, which are in the vein of star, planet and moon names found in science fact and fiction, like -rsae, -peia, -ing, -land, etc. It started off very simple and I&#8217;d take a look at the resulting names and wonder how I could improve on them, until I arrived at something fairly useable. I&#8217;ll probably expand on it a little more and tweak it here and there.</p>
<p>At the time of writing this there are 100 &#8216;sounds&#8217;, which are:</p>
<pre><code>const std::string nameParts[] = {
	"a"              , "e"              , "i"              , "o"              , "u"           ,
	"b[lr][eio]a"    , "b[lr][a]e"      , "b[lr][ae]i"     , "b[lr][aeio]o"   , "b[lr]u"      ,
	"z[eioy]a"       , "z[aeo]e"        , "z[ae]i"         , "z[aeo]o"        , "zu"          ,
	"c[hlr][eio]a"   , "c[hlr][aeo]e"   , "c[hlr][ae]i"    , "c[hlr][aeo]o"   , "c[hlr]u"     ,
	"y[e]a"          , "y[e]e"          , "y[eo]o"         , "d[eiory]a"      , "d[r]e"       ,
	"d[aer]i"        , "d[aeior]o"      , "d[r]u"          , "x[i]a"          , "xe"          ,
	"f[aeilor]a"     , "f[aelor]e"      , "f[aelr]i"       , "f[aeilor]o"     , "f[lr]u"      ,
	"w[aei]a"        , "w[aeo]e"        , "w[ae]i"         , "w[aeo]o"        , "wu"          ,
	"g[aeilory]a"    , "g[aelor]e"      , "g[aelr]i"       , "g[aeilor]o"     , "g[r]u"       ,
	"v[eio]a"        , "v[ael]e"        , "v[ae]i"         , "v[aeio]o"       , "vu"          ,
	"h[eioy]a"       , "h[ae]e"         , "h[ae]i"         , "h[aeo]o"        , "hu"          ,
	"t[h][r][aeio]a" , "t[h][r][ae]e"   , "t[h][r][ae]i"   , "t[h][r][aeo]o"  , "t[h][r]u"    ,
	"j[eio]a"        , "j[ae]e"         , "j[ae]i"         , "j[eo]o"         , "ju"          ,
	"s[hl][aeio]a"   , "s[hl][ae]e"     , "s[hl][ae]i"     , "s[hl][aeo]o"    , "s[hl]u"      ,
	"k[lr][aeio]a"   , "k[lr][ae]e"     , "k[lr][ae]i"     , "k[lr][aeo]o"    , "k[lr]u"      ,
	"r[aeioy]a"      , "r[ae]e"         , "r[ae]i"         , "r[aeoy]o"       , "r[y]u"       ,
	"l[l][eio]a"     , "l[l][ae]e"      , "l[ae]i"         , "l[aeio]o"       , "lu"          ,
	"p[hlr][ey]a"    , "p[hlr][e]e"     , "p[hlr]i"        , "p[hlr][aeo]o"   , "p[hlr]u"     ,
	"m[eioy]a"       , "m[ae]e"         , "m[ae]i"         , "m[aeo]o"        , "mu"          ,
	"n[aeio]a"       , "n[ae]e"         , "n[ae]i"         , "n[aeo]o"        , "nu"          };</code></pre>
</p>
<p>The letters within square braces &#8216;[]&#8216; are optional characters, where there is a chance that an optional letter may appear and each optional character has an equal chance of being the one that does appear. Some &#8216;sounds&#8217; have more than one optional character. For example &#8220;p[hlr][ey]a&#8221; may give &#8220;pa&#8221;, &#8220;pea&#8221;, &#8220;pya&#8221;, &#8220;pha&#8221;, &#8220;plya&#8221;, etc. Of course these &#8216;chances&#8217; are also determined in particular order so as to ensure the names are consistent each time you enter the same seed into the algorithm. You might notice that each &#8216;sound&#8217; ends with a vowel, this was just to ensure that it could create a good variety of words that (hopefully) weren&#8217;t too awkward to pronounce. I found it was quite easy to rectify many unwanted occurances of unpronounceable words by tweaking these strings.</p>
<p>The name-endings, of which there are currently 243, are:</p>
<pre><code>const std::string nameEndings[] = {
	"c"    , "d"    , "g"    , "k"    , "l"    , "m"    , "n"    , "p"    , "r"    , "s"    ,
	"t"    , "x"    , "z"    , "boo"  , "bok"  , "bock" , "beia" , "beus" , "bham" , "bu"   ,
	"bi"   , "bia"  , "bae"  , "buth" , "boz"  , "biz"  , "bic"  , "bol"  , "buk"  , "cham" ,
	"ci"   , "cia"  , "ce"   , "cuth" , "car"  , "col"  , "di"   , "dia"  , "de"   , "duth" ,
	"dar"  , "dol"  , "duk"  , "du"   , "doo"  , "din"  , "dok"  , "dock" , "ding" , "deia" ,
	"dium" , "deus" , "dham" , "fi"   , "fia"  , "fah"  , "fun"  , "foo"  , "ff"   , "foon" ,
	"fael" , "frey" , "fham" , "gi"   , "gia"  , "ge"   , "gah"  , "gun"  , "gol"  , "guth" ,
	"gee"  , "goo"  , "goz"  , "gol"  , "geus" , "gham" , "ho"   , "ham"  , "han"  , "jar"  ,
	"jam"  , "jo"   , "jok"  , "kul"  , "kor"  , "king" , "kar"  , "kol"  , "kik"  , "kia"  ,
	"kol"  , "kham" , "land" , "lam"  , "lor"  , "lar"  , "ler"  , "lad"  , "lik"  , "lia"  ,
	"lus"  , "lim"  , "lphi" , "leus" , "lham" , "mar"  , "mand" , "mir"  , "mor"  , "moor" ,
	"mock" , "mak"  , "mik"  , "mitz" , "ming" , "mad"  , "mia"  , "mae"  , "mus"  , "meus" ,
	"nar"  , "nd"   , "nir"  , "nor"  , "noor" , "nock" , "nak"  , "nik"  , "nitz" , "ning" ,
	"nad"  , "nia"  , "nol"  , "nae"  , "nus"  , "neus" , "nham" , "par"  , "pia"  , "pock" ,
	"pitz" , "por"  , "pak"  , "ping" , "pad"  , "polus", "peia" , "peus" , "pae"  , "poe"  ,
	"pod"  , "pol"  , "phor" , "phus" , "phon" , "phoon", "pha"  , "phir" , "phog" , "phong",
	"phi"  , "pham" , "que"  , "rah"  , "ring" , "rhea" , "rom"  , "rok"  , "rock" , "rus"  ,
	"rag"  , "rol"  , "reus" , "rham" , "seus" , "sol"  , "som"  , "son"  , "sing" , "sand" ,
	"sik"  , "sur"  , "sog"  , "sae"  , "saeus", "sia"  , "sham" , "ti"   , "tia"  , "tae"  ,
	"teus" , "tus"  , "tos"  , "tir"  , "ton"  , "ting" , "tong" , "tom"  , "th"   , "thum" ,
	"tham" , "theus", "thom" , "thium", "thon" , "than" , "wath" , "wart" , "warg" , "wurt" ,
	"witz" , "wham" , "via"  , "vog"  , "voz"  , "vol"  , "vig"  , "vitz" , "xy"   , "y"    ,
	"bay"  , "day"  , "fay"  , "gay"  , "hay"  , "kay"  , "lay"  , "ly"   , "ley"  , "my"   ,
	"ny"   , "py"   , "ry"   , "dry"  , "ndry" , "gry"  , "ngry" , "sy"   , "ty"   , "sty"  ,
	"set"  , "rsae" , "rseus"};</code></pre>
</p>
<p>In order to generate the names for a star map, I decided on using a coordinate system based on 3 sets of 3D Integer data (giving 9 digits in total) as the random seed. The first three digits are used as the X, Y and Z coordinates for what I call a &#8216;Quadrant&#8217;, giving a total of 1,000 quadrants in this Universe (Where X, Y and Z can each be 0 to 9), these being the largest unit of area in this particular system. Next is the &#8216;Sector&#8217;, again using 3 digits to represent the X, Y and Z coordinates within a quadrant. This gives 1,000 Sectors per quadrant. Finally, the last 3 digits represent a &#8216;SubSector&#8217; within the specified Sector. Therefore we can procedurally generate names for 1,000 quadrants containing 1,000,000 sectors hosting 1,000,000,000 subsectors, which is a fair amount I&#8217;m sure you&#8217;ll agree.</p>
<p>For example, 439,016,224 would be the random seed for quadrant(4,3,9), sector(0,1,6), subsector(2,2,4). Details of the quadrant, including the name, would be determined by it&#8217;s 3 digits (439), the sector details would be dependant on the quadrant and sector coordinates (439016). This would give different results for a sector with the same number but in a different quadrant. And finally the subsector details would come from the whole number (439016224). This is reasonable when using 32-bit unsigned integers which handle numbers up to 4,294,967,295 as a single integer can store the whole random seed. Initially I was working on just producing the quadrant, sector and subsector names, where the subsector would also be the name of a star system if one was found to exist there. But this can also be used to procedurally create descriptions, statistics and other data for each item.</p>
<p>For good measure I decided to throw in a little extra option for subsector/star systems, whereby they had a chance of being denoted by a code. For this I chose it to be 2 letters, followed by a number between 132 and 9999, a hyphen &#8216;-&#8217;, a 2 digit number and then a single character either &#8216;A&#8217;, &#8216;B&#8217;, &#8216;C&#8217; or &#8216;D&#8217;. This is just a preliminary code, until I have time to go into this further.</p>
<p>After this it struck me that although I was using the coordinates as the random seed within a C++ program, the same results would not necessarily appear in Java, Pascal, Php, etc. The only way to ensure that the coordinate numbers always gave the same results would be to write my own random number generator functions. This was in fact incredibly easier than I first thought, because Wikipedia actually had a set of pseudo code listed for the <a href="http://en.wikipedia.org/wiki/Mersenne_twister">Mersenne Twister random number generator algorithm</a>, and porting this to C++ was straightforward.</p>
<p>And this is currently as far as I have reached with this little sub-project. Although I intend to create a PHP version to place on a webpage whereby you can select a particular set of coordinates, that is a particular quadrant, sector and subsector/star system and receive names for them, or just click a button and receive a random, procedurally generated name.</p>
<p>Here&#8217;s a few examples of the output the current program gives for the first 16 quadrants, and the first sector and subsector/system name in each of those quadrants:</p>
<pre><code>[Q000]:zamee,       [S000]:hexebay,   [s000]:klikelu
[Q001]:dokol,       [S000]:moa'gonir, [s000]:vocosaa
[Q002]:taejoneus,   [S000]:wedabok,   [s000]:ER3317-89D
[Q003]:benus,       [S000]:bujihe,    [s000]:tijuthom
[Q004]:xiaha,       [S000]:loamy,     [s000]:traopoe
[Q005]:peseus,      [S000]:claivoory, [s000]:mebajei
[Q006]:jubu,        [S000]:ritralam,  [s000]:julopak
[Q007]:charom,      [S000]:gagham,    [s000]:mizibu
[Q008]:owaakik,     [S000]:vaklu,     [s000]:AM8968-34A
[Q009]:wileateus,   [S000]:wer,       [s000]:mosufham
[Q010]:hia,         [S000]:xalo,      [s000]:waita
[Q011]:zaxavi,      [S000]:hetrulo,   [s000]:gileus
[Q012]:idi,         [S000]:trumo,     [s000]:duci
[Q013]:duulay,      [S000]:kunep,     [s000]:sevo
[Q014]:kacucla,     [S000]:sholuwart, [s000]:hajuhi
[Q015]:chaewaecuth, [S000]:nobiz,     [s000]:zema</code></pre>
</p>
<p>I wonder how much alloys are going for in the Gileus system&#8230; You know the Gileus system, it&#8217;s in the Hetrulo sector on the edge of the Zaxavi quadrant&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmcmurray.net/2007/08/19/the-universe-in-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>StarCom: Progress</title>
		<link>http://www.davidmcmurray.net/2007/03/21/starcom-progress/</link>
		<comments>http://www.davidmcmurray.net/2007/03/21/starcom-progress/#comments</comments>
		<pubDate>Wed, 21 Mar 2007 02:24:51 +0000</pubDate>
		<dc:creator>David McMurray</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.davidmcmurray.net/?p=71</guid>
		<description><![CDATA[This is my first post about a project I&#8217;ve been working on for a good while now. Unfortunately I&#8217;ve never been sure what the project was destined to be. Initially it was a simple 3D star map for use in space based games on a campaign scale, to replace one I wrote a few years [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.davidmcmurray.net/wp-content/uploads/2007/03/starcom_125_pythons.jpg"><img src="http://www.davidmcmurray.net/wp-content/uploads/2007/03/starcom_125_pythons.jpg" alt="" title="StarCom: 125 Pythons" width="300" height="235" class="alignleft size-medium wp-image-70" /></a>This is my first post about a project I&#8217;ve been working on for a good while now. Unfortunately I&#8217;ve never been sure what the project was destined to be. Initially it was a simple 3D star map for use in space based games on a campaign scale, to replace one I wrote a few years ago which seemed fairly popular called 3D StarMap. But things have developed and I&#8217;m considering a full blown multiplayer online Elite clone. I might settle for something inbetween, but I&#8217;m not working to a deadline so I&#8217;ll see where it takes me. This screenshot was just to test frame rates with varying numbers of polygons, here showing a 5x5x5 cube of Python-style ships from the old Elite game. There are only about 1625 polygons for the ships, although the starfield background is mapped onto a large sphere, so that&#8217;s a few extra polys. I think I managed to get upto just over 145,000 polygons before the frame rate changed from 71 fps (frames per second) which isn&#8217;t bad.</p>
<p>So far I&#8217;ve been trudging through <a href="http://www.blender.org/">Blender</a> to create the models, primarily because I want to keep to free software in developing this project. I use <a href="http://www.bloodshed.net/devcpp.html">DevCpp</a> from Bloodshed Software for development, using C++ of course, Blender as I mentioned for the 3D modelling and soon I&#8217;ll switch to <a href="http://www.gimp.org/">GIMP</a> for the textures and other graphics. To begin with exporting raw ASCII models from Blender was sufficient, until I wanted to include the textures which aren&#8217;t supported in the raw format. So I switched to the <a href="http://www.inivis.com/ac3d/man/ac3dfileformat.html">AC3D ASCII format</a> which does provide support for textures and I&#8217;d much rather Blender calculated the texture coordinates that do it manually myself.</p>
<p>I need to find some better way of creating the background starfield, the image used is quite big as it is, but it still gets blown-up and causes the stars to look fuzzy and dull. I&#8217;m going to have to work on some functions to load .PNG format textures as the compression on these is pretty awesome, which is extremely useful as these textures could end up being rather large. I&#8217;ve had some problems with compiling a working .PNG library (libpng and glpng) for windows anyway, probably a cinch on Linux. I&#8217;ve managed to create the zlib but it seems to have problems after that which I won&#8217;t go into now.</p>
<p>Of course the whole thing is written using the OpenGL graphics library.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmcmurray.net/2007/03/21/starcom-progress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>It&#8217;s a Date!</title>
		<link>http://www.davidmcmurray.net/2006/07/30/its-a-date/</link>
		<comments>http://www.davidmcmurray.net/2006/07/30/its-a-date/#comments</comments>
		<pubDate>Sun, 30 Jul 2006 00:17:58 +0000</pubDate>
		<dc:creator>David McMurray</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.davidmcmurray.net/?p=66</guid>
		<description><![CDATA[There&#8217;s one aspect of programming that has always given me cause to spout prolific expletives and yet it&#8217;s something that is required in most applications. I am of course talking about Date handling. If I had my way then everyone would use a format which, like number systems, book contents pages and many other structures [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s one aspect of programming that has always given me cause to spout prolific expletives and yet it&#8217;s something that is required in most applications. I am of course talking about Date handling.</p>
<p>If I had my way then everyone would use a format which, like number systems, book contents pages and many other structures in everyday life, starts with the largest denomination or unit down to the smallest. I.e. Year Month Day Hour Minute Second, using whichever separator is preferred and unit format, e.g. &#8217;2006-JAN-21 12:15:34&#8242;, &#8217;06/01/21&#8242;, &#8217;2006, January 15th&#8217;, etc.</p>
<p>But that would be just too logical for everyone and many systems in many countries have already adopted their preferred format. For me in the UK we have the date in reverse, eg. 10-Jan-2006 (smallest unit -> largest), whereas Americans have an almost random order with Jan-10-2006 (middle unit -> smallest -> largest). I don&#8217;t know of any other system of measurement that is affected like this, we don&#8217;t have measurements like &#8217;4m 8mm 12cm&#8217; or &#8217;4lbs 8st&#8217;, so why measure time differently? So, many countries like the UK need to take extra care when dealing with dates, unlike the US which sets the standard in many languages/development tools like .NET. With the difference between the UK and US date formats it can be rather ambiguous when working with the first 12 days of any month. For example, 10/08/2006 in the UK would be regarded as the 10th of August, whereas in the US this would be the 8th of October.</p>
<p>Now, .NET does have it&#8217;s ways of handling these issues, but of course there&#8217;s always more than one way to skin a cat as they say.</p>
<p>When converting a DateTime value to say a string the conversion is relatively simple, there are mechanisms for producing the date in whatever format you choose. One way is to use the old VBScript Format function eg.</p>
<p>
<pre><code>Dim str As String = Format(Now, "dd-MM-yy")</code></pre>
</p>
<p>Which gives the current date in the Format defined by the string &#8220;dd-MM-yy&#8221; as a string. But in .NET we want to avoid using the old VBScript methods and instead use the .NET framework. For this .NET provides the ability to format various objects for conversion to strings in the very method that does the conversion, i.e. the &#8216;ToString&#8217; method:</p>
<p>
<pre><code>Dim str As String = Now.ToString("dd-MM-yy")</code></pre>
</p>
<p>Well that&#8217;s the easy side covered as a String object is both fairly simple in its definition and flexible in it&#8217;s data, the Date object on the other hand is a little more complex in structure and far more constrained in its data. The process of converting a date contained in a String object for transfer into a Date/DateTime object can be a little more challenging.</p>
<p>I&#8217;ve seen many people suggest using the following:</p>
<pre><code>Dim myDateTime As DateTime = Convert.ToDateTime("01/02/2006")</code></pre>
</p>
<p>Apparently, the interpretation of a date string, e.g. &#8217;01/02/2006&#8242;, is rather dependant on the locale settings of the machine on which it is running. But I haven&#8217;t been able to replicate this at all. Regardless of whether my regional setting is set to US or English and even though it states very clearly in the regional settings that the US format is &#8216;Month/Day/Year&#8217;, the string above is still interpreted as &#8216;Day/Month/Year&#8217;. So, it appears that I might as well use the Convert.ToDateTime method of reading date strings and stop worrying, but I won&#8217;t&#8230;.</p>
<p>For starters the Convert.ToDateTime method invokes the DateTime.Parse method according to MSDN, so the following seems more efficient:</p>
<pre><code>Dim myDateTime As DateTime = DateTime.Parse("01/02/2006")</code></pre>
</p>
<p>Which again gives me the same results regardless of regional setting. I&#8217;d rather not rely on this very loose method of string to date conversion, especially when I have no idea why the regional setting isn&#8217;t making a difference. The methods so far are very open and return a date of &#8217;01/02/2006&#8242; interpreted as the 1st of February, 2006 for all of these strings: &#8217;01/02/2006&#8242;, &#8217;01/02/06&#8242;, &#8217;01-02-2006&#8242;, &#8217;01-02-06&#8242;, &#8217;01.02.2006&#8242;, &#8217;01.02.06&#8242;, &#8216;feb 01 06&#8242;, 01 feb 06&#8242;, &#8217;2006 feb 01&#8242;, &#8216;february 1 2006&#8242;, &#8217;1.2.6&#8242;, etc, etc. I don&#8217;t know about you, but I&#8217;d say that was pretty loose.</p>
<p>There is a more strict alternative, which is the DateTime.ParseExact method and this will allow a particular expected date and time format to be specified. The ParseExact method I&#8217;ll be looking at takes 3 parameters, the date string to be converted, a format string and something called an IFormatProvider which contains information about a particular culture to be used. For the initial example I shall not provide any information about the culture and simply pass &#8216;Nothing&#8217; as the third parameter. So, if we store our date string to be converted in a string variable called &#8216;myString&#8217; for example:</p>
<pre><code>Dim myDateTime as DateTime = DateTime.ParseExact(myString, "dd/MM/yyyy", Nothing)</code></pre>
</p>
<p>This will throw a &#8216;FormatException&#8217; exception for any value in myString that does not exactly match the &#8216;dd/MM/yyyy&#8217; format string. So anything like &#8217;01-02-2006&#8242;, &#8217;01/02/06&#8242; or &#8217;1/2/2006&#8242; will all result in generating an exception. Although, for the last example it would be valid if you set the format string to &#8216;d/M/yyyy&#8217; since a single &#8216;d&#8217; or &#8216;M&#8217; allows 1 or 2 digit values, whereas &#8216;dd&#8217; and &#8216;MM&#8217; allows only 2 digits so you must prefix single digit values with zeros.</p>
<p>You can also use format characters to represent whole format strings, such as &#8216;d&#8217; which indicates a ShortDatePattern, &#8216;D&#8217; is for a LongDatePattern, &#8216;G&#8217; indicates a General format with a short date and a long time, etc. The whole list of these are available from <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationdatetimeformatinfoclasstopic.asp">MSDN</a> along with the format pattern information for creating your own format strings like the &#8216;dd/MM/yyyy&#8217; I used above.</p>
<p>This isn&#8217;t so bad if you are only ever going to receive the date string in one particular format, but you might want to allow some variations on the date format. We&#8217;re not trying to limit the format of the date strings we can successfully convert to DateTime objects, all we&#8217;re really after is being safe in the knowledge that we are interpreting the date strings correctly and consistently. Using the UK format I want to be sure that whenever the day and month values are represented in numerical format, that the first value is the day and the second is the month for example. So in order to specify several format strings you can pass a string array rather than just one string, again with our date string stored in myString:</p>
<pre><code>Dim myFormatStrings() as String = {"d", "D"}
Dim myDateTime as DateTime = DateTime.ParseExact(myString, myFormatStrings, Nothing)</code></pre>
</p>
<p>Which will convert date strings in the Short and Long formats. Also&#8230;</p>
<pre><code>Dim myFormatStrings() as String = {"d/M/yyyy", "d-M-yyyy"}
Dim myDateTime as DateTime = DateTime.ParseExact(myString, myFormatStrings, Nothing)</code></pre>
</p>
<p>Will allow dates with 1 or 2 day and month numbers and a 4 digit year, with either &#8216;/&#8217; or &#8216;-&#8217; date separators.</p>
<p>Finally, I should probably say a few words about the third parameter for ParseExact, IFormatProvider, since it&#8217;s not a good idea to pass Nothing as I have done so far. This parameter can be specified in a few ways but I&#8217;ll only show one here, there&#8217;s a fair few examples around the net on this if you need more info. It is possible to select the  format provider based on the current culture setting for the machine, but as I mentioned before, I&#8217;d rather be a little more specific about what I require. So this example will explicitly set the format provider to &#8220;en-GB&#8221;, known as English &#8211; Great Britain. In a nutshell I create an IFormatProvider object by supplying my specific culture to the CultureInfo method of System.Globalization. So using myString and myFormatString from examples above:</p>
<pre><code>Dim myFormatProvider as IFormatProvider = New System.Globalization.CultureInfo("en-GB")
Dim myDateTime As DateTime = DateTime.ParseExact(myString,myFormatString,myFormatProvider)</code></pre>
</p>
<p>And that&#8217;s that, besides since I got married a couple of months ago you would think I wouldn&#8217;t need to worry about dates anymore&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmcmurray.net/2006/07/30/its-a-date/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Back again</title>
		<link>http://www.davidmcmurray.net/2006/03/18/58/</link>
		<comments>http://www.davidmcmurray.net/2006/03/18/58/#comments</comments>
		<pubDate>Sat, 18 Mar 2006 01:57:23 +0000</pubDate>
		<dc:creator>David McMurray</dc:creator>
				<category><![CDATA[Bits N Bytes]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.davidmcmurray.net/?p=58</guid>
		<description><![CDATA[What was I saying about technology and spending more time playing about with setting it up and less time actually using it? Here I am having installed and moved all my previous posts to another piece of blogging software. Well it&#8217;s half the fun I suppose, the other half of the fun is inserting a [...]]]></description>
			<content:encoded><![CDATA[<p>What was I saying about technology and spending more time playing about with setting it up and less time actually using it? Here I am having installed and moved all my previous posts to another piece of blogging software. Well it&#8217;s half the fun I suppose, the other half of the fun is inserting a rusty knitting needle through your eye, or something like that.</p>
<p>So, I&#8217;m now trying out this WordPress blogging software and I&#8217;m pretty impressed, especially with the admin interface. Although the WYSIWYG post editor leaves a lot to be desired and enjoys infuriating me to within an inch of my life. I *need* to display code in my blog and for that I chose Priyadi Iman Nurcahyos &#8216;Code Auto Escape&#8217;, especially since many developers of WordPress code displaying facilities opted to dump their efforts and adopt Priyadi&#8217;s plugin instead. But the WYSIWYG editor continued to strip html tags from within the <code></code> tags of the plugin, so I&#8217;m having to use the old style post editor, although there&#8217;s nothing to complain about there to be honest.</p>
<p>Considering the popularity and notoriety of Six Apart&#8217;s &#8216;MovableType&#8217; blogging software I was surprised when I saw the features covered by WordPress that MovableType had missed. WordPress covers multiple level categories with a simpe interface, more control over perma links, ability to create static pages as well as posts, extremely simple plugin installation, etc. Well, I am pleased but I guess it is early days yet and if my posting frequency doesn&#8217;t pick up I may never realise it&#8217;s true power.</p>
<p>Anyway, I&#8217;ll finish off my first post on my new blog, with a little bit of code to sort life out&#8230;</p>
<pre><code>#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

void swap(char *a, char *b);

int main(int argc, char *argv[])
{
  char c[5];
  int i,j;
  
  sprintf(c, "LIFE");
  
  printf("Sorting '%s' to ",c);
  for (i=0;i&lt;strlen(c)-1;i++)
    for (j=strlen(c)-1;j&gt;i;j--)
      if (c[j-1] &gt; c[j])
        swap(&amp;c[j-1],&amp;c[j]);
  printf("'%s'\n", c);
}

void swap(char *a, char *b)
{
  char c;
  c = *a;
  *a = *b;
  *b = c;
}</code></pre>
<p>Which should give you: Sorting &#8216;LIFE&#8217; to &#8216;EFIL&#8217;</p>
<p>From this we can deduce that in order to sort out your life you must be backward.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmcmurray.net/2006/03/18/58/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

