<?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"
	>

<channel>
	<title>spladug.net</title>
	<atom:link href="http://www.spladug.net/feed/" rel="self" type="application/rss+xml" >
	<link>http://www.spladug.net</link>
	<description></description>
	<pubDate>Mon, 05 Jan 2009 20:05:26 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<item>
		<title>NUnit and XNA on Windows x64</title>
		<link>http://www.spladug.net/2008/11/nunit-and-xna-on-windows-x64/</link>
		<comments>http://www.spladug.net/2008/11/nunit-and-xna-on-windows-x64/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 03:32:00 +0000</pubDate>
		<dc:creator>Neil Williams</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.spladug.net/2008/11/nunit-and-xna-on-windows-x64/</guid>
		<description><![CDATA[I&#8217;ve been working on a project using XNA recently, and since I&#8217;ve been learning TDD and unit testing I wanted to use NUnit. However, whenever I tried to load the test assembly in the test runner, I&#8217;d get the following (rather unhelpful) error:
Could not load file or assembly 'Spladug.Project.Tests' or one of 
its dependencies. The [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a project using XNA recently, and since I&#8217;ve been learning TDD and unit testing I wanted to use NUnit. However, whenever I tried to load the test assembly in the test runner, I&#8217;d get the following (rather unhelpful) error:</p>
<pre class="powershell code">Could not load file or assembly <span class="st0">'Spladug.Project.Tests'</span> or one of 
its dependencies. The system cannot find the file specified.</pre>
<p>After poking around for a while, I discovered that my problem stemmed from being on Windows x64. XNA&#8217;s libraries are 32-bit only, which means that despite being .NET, applications (and class libraries) built on XNA are always 32-bit.  As described in <a href="http://geekswithblogs.net/lance/archive/2006/12/28/102191.aspx">a post about testing 32-bit applications on Windows x64</a>, you have to configure NUnit to run in 32-bit mode as well to be able to load the test assembly.</p>
<p>To do this, simply run the following command in a console with sufficient permissions and with filenames tweaked as necessary:</p>
<pre class="powershell code">C:\<span class="sy0">&gt;</span>corflags <span class="st0">&quot;C:\Program Files (x86)\NUnit 2.5\net-2.0\nunit.exe&quot;</span> <span class="sy0">/</span>32BIT<span class="sy0">+</span></pre>
<p><code>corflags</code> is a utility that comes with the .NET Framework SDK.  See <a href="http://msdn.microsoft.com/en-us/library/d9kh6s92(VS.80).aspx">the documentation for .NET Framework Tools</a> for more details.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.spladug.net/2008/11/nunit-and-xna-on-windows-x64/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Temporary Files in Unix</title>
		<link>http://www.spladug.net/2008/10/temporary-files-in-unix/</link>
		<comments>http://www.spladug.net/2008/10/temporary-files-in-unix/#comments</comments>
		<pubDate>Sat, 18 Oct 2008 22:47:49 +0000</pubDate>
		<dc:creator>Neil Williams</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.spladug.net/?p=61</guid>
		<description><![CDATA[
EDIT: It is recommended to use mkstemp instead of tmpfile for security reasons. mkstemp does not work the same way as tmpfile, and so a manual call to unlink would be required to get the automatic delete behavior.

A recent question on Stack Overflow asked why locked files can be deleted in Linux, but not Windows. [...]]]></description>
			<content:encoded><![CDATA[<p class="update">
EDIT: It is recommended to use <a href="http://en.wikipedia.org/wiki/Mkstemp">mkstemp</a> instead of tmpfile for security reasons. mkstemp does not work the same way as tmpfile, and so a manual call to <a href="http://en.wikipedia.org/wiki/Unlink_(Unix)">unlink</a> would be required to get the automatic delete behavior.
</p>
<p>A recent question on <a href="http://www.stackoverflow.com/">Stack Overflow</a> asked why locked files can be deleted in Linux, but not Windows. As the answer states, it&#8217;s because of the underlying nature of <a href="http://en.wikipedia.org/wiki/Inode">inodes</a> in the Unix filesystem architecture.</p>
<h3>Background</h3>
<p>Files in Unix are stored in an inode, which contains all the metadata for the file.  Paths on the filesystem then link to the inode that contains the actual file data.  As a result, &#8220;deleting&#8221; a file from the filesystem is really just removing a link to and decrementing a reference count for an inode.  An inode that is still opened by a running process, but unlinked from everywhere on the filesystem, will continue to exist until the process closes and the reference count drops to zero.</p>
<h3>Temporary Files</h3>
<p>In <a href="http://stackoverflow.com/questions/196897/locking-executing-files-windows-does-linux-doesnt-why#196910">my answer to the question</a>, I mentioned that Unix programs use this behavior explicitly to make temporary files that a) don&#8217;t clutter up the file system, and b) are more secure. In the comments for the question, I was asked for examples of this usage. I had learned this tidbit of trivia during an operating systems class in college, and had forgotten the specifics, so I decided to look it up.</p>
<h3>glibc</h3>
<p>I started poking around looking for an explicit example of this usage, and found out that the behavior is built directly into the glibc.  Specifically, the <a href="http://www.opengroup.org/onlinepubs/009695399/functions/tmpfile.html">tmpfile</a> function, which <q>creates a temporary file and opens a corresponding stream</q> automatically unlinks the file internally! Here is the psuedocode for the tmpfile function in glibc 2.7, with setup and error-checking snipped for clarity:</p>
<pre class="c code">FILE <span class="sy0">*</span>tmpfile <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
  <span class="kw4">char</span> buf<span class="br0">&#91;</span>FILENAME_MAX<span class="br0">&#93;</span>;
  <span class="kw4">int</span> fd;
  FILE <span class="sy0">*</span>f;
&nbsp;
  <span class="coMULTI">/* get a new filename and open it  */</span>
  fd <span class="sy0">=</span> __gen_tempname<span class="br0">&#40;</span>buf<span class="br0">&#41;</span>;
&nbsp;
  <span class="coMULTI">/* Note that this relies on the Unix semantics that
     a file is not really removed until it is closed.  */</span>
  <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span> __unlink <span class="br0">&#40;</span>buf<span class="br0">&#41;</span>;
&nbsp;
  <span class="coMULTI">/* make a FILE* for the file */</span>
  f <span class="sy0">=</span> __fdopen<span class="br0">&#40;</span>fd<span class="sy0">,</span> <span class="st0">&quot;w+b&quot;</span><span class="br0">&#41;</span>;
&nbsp;
  <span class="kw1">return</span> f;
<span class="br0">&#125;</span></pre>
<p>So the tmpfile function automatically takes advantage of this behavior and unlinks the inode after opening it.</p>
<h3>Test Program</h3>
<p>To see this in action, I wrote a small test program in C:</p>
<pre class="c code"><span class="co2">#include &lt;stdio.h&gt;</span>
<span class="co2">#include &lt;unistd.h&gt;</span>
<span class="co2">#include &lt;sys/stat.h&gt;</span>
&nbsp;
<span class="kw4">int</span> main<span class="br0">&#40;</span><span class="kw4">int</span> argc<span class="sy0">,</span> <span class="kw4">char</span><span class="sy0">**</span> argv<span class="br0">&#41;</span>
<span class="br0">&#123;</span>
    FILE <span class="sy0">*</span>temp;
    <span class="kw4">struct</span> stat buffer;
    <span class="kw4">char</span> line<span class="br0">&#91;</span><span class="nu0">100</span><span class="br0">&#93;</span>;
    <span class="kw4">int</span> fd;
&nbsp;
    <span class="coMULTI">/* open a temporary file and  figure out its inode */</span>
    temp <span class="sy0">=</span> tmpfile<span class="br0">&#40;</span><span class="br0">&#41;</span>;
    fd <span class="sy0">=</span> fileno<span class="br0">&#40;</span>temp<span class="br0">&#41;</span>;
    fstat<span class="br0">&#40;</span>fd<span class="sy0">,</span> <span class="sy0">&amp;</span><span class="co2">#038;buffer);</span>
    <span class="kw3">printf</span><span class="br0">&#40;</span><span class="st0">&quot;inode: %d<span class="es0">\n</span>&quot;</span><span class="sy0">,</span> buffer.<span class="me1">st_ino</span><span class="br0">&#41;</span>;
&nbsp;
    <span class="coMULTI">/* wait */</span>
    fgets<span class="br0">&#40;</span>line<span class="sy0">,</span> <span class="nu0">100</span><span class="sy0">,</span> stdin<span class="br0">&#41;</span>;
&nbsp;
    <span class="kw1">return</span> <span class="nu19">0</span>;
<span class="br0">&#125;</span></pre>
<p>Running the program spits out an inode number then waits around with the file held open.  Searching for filenames pointing to that inode returns nothing:</p>
<pre class="bash code"><span class="br0">&#91;</span>neil <span class="sy0">/</span><span class="br0">&#93;</span>$ <span class="kw2">find</span> <span class="re5">-inum</span> <span class="nu0">1221</span> <span class="nu0">2</span><span class="sy0">&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null
<span class="br0">&#91;</span>neil <span class="sy0">/</span><span class="br0">&#93;</span>$</pre>
<p>So it would seem that my vague memory from operating systems class was correct; temporary files can be created, opened, and unlinked and the facilities to do this are built in to the system libraries themselves.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.spladug.net/2008/10/temporary-files-in-unix/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Initial experiences with WordPress</title>
		<link>http://www.spladug.net/2008/10/initial-experiences-with-wordpress/</link>
		<comments>http://www.spladug.net/2008/10/initial-experiences-with-wordpress/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 19:09:03 +0000</pubDate>
		<dc:creator>Neil Williams</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.spladug.net/2008/10/initial-experiences-with-wordpress/</guid>
		<description><![CDATA[I&#8217;m happily running this site on WordPress now. I&#8217;ve even moved my design over to being a WordPress template. After a few days of tweaking things, I think it&#8217;s time to actually get blogging! As a starting point I&#8217;m going to write about my initial experiences with WordPress and its setup.
The dreaded XHTML
For a while, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m happily running this site on <a href="http://www.wordpress.com/">WordPress</a> now. I&#8217;ve even moved my design over to being a WordPress template. After a few days of tweaking things, I think it&#8217;s time to actually get blogging! As a starting point I&#8217;m going to write about my initial experiences with WordPress and its setup.</p>
<h3>The dreaded XHTML</h3>
<p>For a while, it seemed that XHTML was going to be the future of the web, and so everyone pushed towards it. Unfortunately, XHTML 2.0 has been a long time coming and the end is not in sight. With the recent progress on <a href="http://www.w3.org/html/wg/html5/">HTML 5</a> and the <a href="http://hixie.ch/advocacy/xhtml">backlash against serving XHTML as text/html</a> things seem to be swinging back in favor of HTML.</p>
<p>I wanted to make my site output valid, semantic, HTML 4.01 Strict. This seems like a reasonable goal to me. However, WordPress isn&#8217;t exactly too happy about that. As part of the push towards XHTML, WordPress, like many other <abbr title="Content Management System">CMS</abbr>s converted to XHTML 1.0 at the exclusion of HTML. Generally, all this means is that those silly &quot;one-off&quot; tags like <code>&lt;br&gt;</code> and <code>&lt;link&gt;</code> get a self-closing / inserted in to them: <code>&lt;br /&gt;</code>. Of course, this is invalid HTML 4.</p>
<p>Poking around in the WordPress source to see if it would be an easy change I realised that the developers had directly echo&#8217;d out the various snippets of (X)HTML whenever they needed it. Despite their highly flexible plugin API, only one of the four invalid tags that were affecting every page of my site was designed to be flexible in the output it generated.</p>
<p>According to <a href="http://codex.wordpress.org/HTML_to_XHTML#Problems_with_XHTML">the official WordPress documentation</a> the only way to switch WordPress from XHTML to HTML is a plugin that filters all of the software&#8217;s output through a regular expression. What a hack! Oh well, that&#8217;s what I&#8217;ve ended up using.</p>
<p>Not wanting to complain about problems without offering a solution, I&#8217;ll put this forward: run all markup output through a single class that does it in one place. This not only affords an easy way to switch between HTML and XHTML modes (not to mention whatever may exist in the future!), but helps maintain the <a href="http://en.wikipedia.org/wiki/DRY_code">DRY principle</a>. A simple class not unlike ASP.NET&#8217;s <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.htmltextwriter.aspx">HtmlTextWriter</a> would do the trick admirably.</p>
<h3>I love it!</h3>
<p>I don&#8217;t mean to sound jaded after all of this; I love WordPress! I really do. After maintaining my site without a CMS for years and then trying to get <a href="http://www.drupal.com/">Drupal</a> set up as a blog (nothing wrong with Drupal, it just felt <em>too</em> general for blogging), WordPress has been a breeze. The install was painless, the documentation excellent, and the interface slick. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.spladug.net/2008/10/initial-experiences-with-wordpress/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Building Regular Polygons</title>
		<link>http://www.spladug.net/2008/10/creating-polygons-in-python/</link>
		<comments>http://www.spladug.net/2008/10/creating-polygons-in-python/#comments</comments>
		<pubDate>Sat, 11 Oct 2008 06:56:55 +0000</pubDate>
		<dc:creator>Neil Williams</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.spladug.net/?p=4</guid>
		<description><![CDATA[A few months ago, I worked on a distributed multi-player Pong in python as part of a class project. I found that there wasn&#8217;t a whole lot of info on calculating the points that make up a regular polygon. So, using the indispensable Wolfram MathWorld reference, I wrote some code.
The purpose of this code is [...]]]></description>
			<content:encoded><![CDATA[<p>A few months ago, I worked on a distributed multi-player <a href="http://en.wikipedia.org/wiki/Pong">Pong</a> in python as part of a class project. I found that there wasn&#8217;t a whole lot of info on calculating the points that make up a regular polygon. So, using the <a href="http://mathworld.wolfram.com/RegularPolygon.html">indispensable Wolfram MathWorld reference</a>, I wrote some code.</p>
<p>The purpose of this code is to construct a regular polygon with <code>n</code> sides (though it doesn&#8217;t really make sense with <code>n < 3</code> sides). When given the number of sides and the length (in “units” of each side), the code will generate a sequence of points starting at the origin, and proceeding counter-clockwise around the polygon.</p>
<p>One of the most helpful quantities when constructing a regular polygon is the <a href="http://mathworld.wolfram.com/ExteriorAngle.html">exterior angle</a>.</p>
<pre class="python code"><span class="kw1">import</span> <span class="kw3">math</span>
&nbsp;
<span class="kw1">def</span> polygon<span class="br0">&#40;</span>number_of_sides, side_length = <span class="nu0">10</span><span class="br0">&#41;</span>:
    <span class="co1"># the exterior angle is the difference in angle</span>
    <span class="co1"># between sides of the polygon and is the same</span>
    <span class="co1"># for every side of a simple polygon</span>
    exterior_angle = 2. <span class="sy0">*</span> <span class="kw3">math</span>.<span class="me1">pi</span> / number_of_sides
&nbsp;
    point = <span class="br0">&#40;</span>0, 0<span class="br0">&#41;</span>
    angle = 0.
&nbsp;
    <span class="kw1">yield</span> point
&nbsp;
    <span class="kw1">for</span> i <span class="kw1">in</span> <span class="kw2">xrange</span><span class="br0">&#40;</span>number_of_sides - <span class="nu0">1</span><span class="br0">&#41;</span>:
        point = <span class="br0">&#40;</span>point<span class="br0">&#91;</span>0<span class="br0">&#93;</span> + side_length <span class="sy0">*</span> <span class="kw3">math</span>.<span class="me1">cos</span><span class="br0">&#40;</span>angle<span class="br0">&#41;</span>,
                 point<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span> + side_length <span class="sy0">*</span> <span class="kw3">math</span>.<span class="me1">sin</span><span class="br0">&#40;</span>angle<span class="br0">&#41;</span><span class="br0">&#41;</span>
&nbsp;
        angle += exterior_angle
&nbsp;
        <span class="kw1">yield</span> point</pre>
<p>To use this, just iterate over the result of the function:</p>
<pre class="python code"><span class="kw1">for</span> point <span class="kw1">in</span> polygon<span class="br0">&#40;</span><span class="nu0">5</span><span class="br0">&#41;</span>:
    do_something<span class="br0">&#40;</span>point<span class="br0">&#41;</span></pre>
<p>or if you just want a list of points:</p>
<pre class="python code"><span class="co1"># use a list comprehension</span>
<span class="br0">&#91;</span>pt <span class="kw1">for</span> pt <span class="kw1">in</span> polygon<span class="br0">&#40;</span><span class="nu0">4</span><span class="br0">&#41;</span><span class="br0">&#93;</span>
&nbsp;
<span class="co1"># which results in:</span>
<span class="br0">&#91;</span><span class="br0">&#40;</span>0, 0<span class="br0">&#41;</span>, <span class="br0">&#40;</span><span class="nu0">10.0</span>, <span class="nu0">0.0</span><span class="br0">&#41;</span>, <span class="br0">&#40;</span><span class="nu0">10.0</span>, <span class="nu0">10.0</span><span class="br0">&#41;</span>, <span class="br0">&#40;</span><span class="nu0">0.0</span>, <span class="nu0">10.000000000000002</span><span class="br0">&#41;</span><span class="br0">&#93;</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.spladug.net/2008/10/creating-polygons-in-python/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
