<?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>Thing Every Once in a While</title>
	<atom:link href="http://joshodom.net/blag/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://joshodom.net/blag</link>
	<description>All in all you're just another blag in the wall</description>
	<pubDate>Sun, 24 May 2009 05:24:59 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.5</generator>
	<language>en</language>
			<item>
		<title>Chess, Work, and Spam</title>
		<link>http://joshodom.net/blag/?p=45</link>
		<comments>http://joshodom.net/blag/?p=45#comments</comments>
		<pubDate>Sun, 24 May 2009 05:24:59 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
		
		<category><![CDATA[Excuses]]></category>

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

		<guid isPermaLink="false">http://joshodom.net/blag/?p=45</guid>
		<description><![CDATA[So it turns out that wordpress has no sort of a &#8220;smart spam filter&#8221;.  Between April 4th and now, I got over 1,400 comments to this blag.  Now, that&#8217;s not all that bad, because I have to manually approve the comments.  However, it is eating up bandwidth on my home internet connection, and if a [...]]]></description>
			<content:encoded><![CDATA[<p>So it turns out that wordpress has no sort of a &#8220;smart spam filter&#8221;.  Between April 4th and now, I got over 1,400 comments to this blag.  Now, that&#8217;s not all that bad, because I have to manually approve the comments.  However, it is eating up bandwidth on my home internet connection, and if a real person posts a comment, there&#8217;s no way I will be able to find it to approve it.</p>
<p>For all you faithful readers, I have to apologize.  If I didn&#8217;t have work, I&#8217;d post here more often, but lately, work has been draining my motivation to work on personal projects.  Poor excuse, I know, but I needed a reason to categorize this post under &#8220;excuses&#8221;.</p>
<p>As most of you know, I created a weak chess engine as an independent study, for my last semester of school.  After I completed it, wrote a paper about it, and gave a presentation, I didn&#8217;t look back.  It&#8217;s not that I didn&#8217;t enjoy it as a project, it&#8217;s just that I stressed myself a lot over the project, and it was nice to be away from it for a long while.</p>
<p>Well, now I am revisiting the project, trying to correct a lot of the mistakes I made for my &#8220;release&#8221; version of my independent study.  Here are some of the mistakes I made, and how I plan to resolve them with my new chess engine:</p>
<ul>
<li>Objective-C.  Now, Objective-C isn&#8217;t a bad language, especially for GUIs and event-driven applications, but for something logical, rigid, and procedural (like a chess engine), the object-orientedness and message handling just turns into overhead and causes overly-complex code.  My resolution for this: implement everything in  pure c.</li>
<li>Profiling.  I inlined a bunch of macros and preprocessor definitions which I could turn off and on at compile time, which would keep track of how many times each function was called, and how many times an operation was performed in each function.  This is fine, until you realize how ugly and unreadable it made the code.  My resolution: to use GDB or some other product designed to analyze running code.</li>
<li>Premature optimization.  This was a twofold problem.  First, it caused me to write functions and procedures in an unreadable, inflexible way.  Second, it took up a <em>lot</em> of time that needed to be spent elsewhere.  An example of this would be where I created a heap object for the sole purpose of pushing moves into it, and pulling them out in a sorted, best-first order.  Note that the average number of moves from a specific position is somewhere around 30.  I could have gotten away with a fixed array which I sorted with insertion sort.  This would have caused no noticeable slowdown in the program, and would have saved me a good week of work.  The solution to premature optimization is this: don&#8217;t ever do it.</li>
<li>Interface.  When I was finished with the project, I created my own Java-based GUI, which allowed straightforward input of moves.  However, that meant I couldn&#8217;t play it against other chess engines.  This wasn&#8217;t a mistake, so much as a choice when I was running out of time to give it a usable interface.  This time I think it&#8217;s necessary to do it right.  I want to create a library which can talk with both the Xboard Chess Engine Communication Protocol and with the Universal Chess Interface.  That way, it will be easy to casually play against my engine, and it should be straightforward for my engine to talk to other engines.  Also, my library could reasonably be a springboard for chess projects anyone else might work on.</li>
</ul>
<p>There are also a few things I didn&#8217;t implement which would substantially increase the strength/speed of my program.</p>
<ul>
<li>Iterative deepening</li>
<li>Quiescence search</li>
<li>Positional-based/strategy-based static evaluation function (as opposed to pure material)</li>
</ul>
<p>Iterative deepening is just an algorithm and would be straightforward to implement, but those last two are crucial to making a chess engine strong.  However, I am too much a novice at chess to know what I should tell the engine.  &#8221;This is a volatile board position&#8221; and &#8220;White has the positional advantage&#8221; both seem like very subjective statements to me, and I can&#8217;t think of a practical way to make those objective.  My long-term plan is to get good at chess.  Maybe practical experience will help me to understand what it means to have &#8220;positional advantage&#8221;, in a way that a computer will understand.  I am probably joining a chess club&#8230;</p>
<p>My current focus is the interface.  I think that it&#8217;s one of the most useful parts of this project, in that other projects should be able to use it.  Also, it will be crucial for troubleshooting and testing my engine, once I have the engine working.  Let&#8217;s hope I make good progress on the interface.  I&#8217;ll keep you posted.</p>
<p> </p>
<p>Josh</p>
]]></content:encoded>
			<wfw:commentRss>http://joshodom.net/blag/?feed=rss2&amp;p=45</wfw:commentRss>
		</item>
		<item>
		<title>The Art of Escape</title>
		<link>http://joshodom.net/blag/?p=37</link>
		<comments>http://joshodom.net/blag/?p=37#comments</comments>
		<pubDate>Mon, 09 Mar 2009 18:30:20 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
		
		<category><![CDATA[Thoughts]]></category>

		<guid isPermaLink="false">http://joshodom.net/blag/?p=37</guid>
		<description><![CDATA[Being the purist that I am, I&#8217;ve often worried that there is no good way to escape text.  All of the paradigms I have seen do work, but whenever they recursively escape their self, they tend to grow exponentially (and often become extremely convoluted).  Also, there can usually be a contrived case in which the [...]]]></description>
			<content:encoded><![CDATA[<p>Being the purist that I am, I&#8217;ve often worried that there is no good way to escape text.  All of the paradigms I have seen do work, but whenever they recursively escape their self, they tend to grow exponentially (and often become extremely convoluted).  Also, there can usually be a contrived case in which the escaped text is virtually unreadable (as in, it&#8217;s not apparent what the text unescapes to).</p>
<p>I feel like I will insult everyone&#8217;s intelligence, but I feel the need to formally define the process of escaping:</p>
<ol>
<li><span style="text-decoration: line-through;">There needs to exist an &#8220;escape&#8221; function which will output arbitrary data which contains no &#8220;control characters&#8221; (where control characters are defined elsewhere).</span><br style="text-decoration: line-through;" />There needs to exist an &#8220;escape&#8221; function which will output arbitrary data, which either contains no &#8220;control characters&#8221;, or at least where every inline control character is unambiguously distinguishable from a control character itself.<span style="text-decoration: line-through;"></span></li>
<li>There needs to exist an &#8220;unescape function&#8221; which will unambiguously transform any escaped data into its original form.</li>
</ol>
<div>In the example of C-style escaping, we have the two following rules for escaping and unescaping (technically we have more, but we are only using these in the examples).  We are only considering the quote as a control character:</div>
<p><code> ESCAPE:<br />
" -&gt; \"<br />
\ -&gt; \\<br />
UNESCAPE:<br />
\\ -&gt; \<br />
\" -&gt; "<br />
</code></p>
<p>A good example of self-escaping: let&#8217;s say we need to write a line of code which will print out a line of code which will print out a line of code which will print out &#8220;hello, world&#8221;.  Give that we do this in C, with C-style escaping:</p>
<p><code>print "hello, world";<br />
print "print \"hello, world\";";<br />
print "print \"print \\\"hello, world\\\";\";";<br />
</code></p>
<p>An even more contrived example would be escaping the quoted string &#8220;hello world&#8221; 5 times in succession:</p>
<p><code>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"hello world\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"</code></p>
<p>I&#8217;ve only shown the example of quoting double-quotes, but the same applies to quoting backslashes, newlines, etcetera.  Note that this exponential functionality also applies to things like escaped HTML, which has rules like this (we are only considering the less-than as a control character):</p>
<p><code>ESCAPE:<br />
&lt; -&gt; &amp;lt;<br />
&amp; -&gt; &amp;amp;<br />
UNESCAPE:<br />
&amp;lt; -&gt; &lt;<br />
&amp;amp; -&gt; &amp;</code></p>
<p>I&#8217;ve come up with at least one clean/elegant solution to the problem of exponential size-increase.  This method of escaping only grows logarithmically, I have been unable to come up with convoluted escaping examples for it.  The rules are as follows (considering only the quote as an escape character):</p>
<p><code>ESCAPE:<br />
" -&gt; ["|1]<br />
["|<em>n</em>] <em>(where n is greater than 0)</em> -&gt; ["|<em>n+1</em>]<br />
UNESCAPE:<br />
["|1] -&gt; &#8221;<br />
["|<em>n</em>] <em>(where n is greater than 1)</em> -&gt; ["|<em>n-1</em>]</code></p>
<p>Note that because of the pairing of [, |, ], none of these have to be escaped in order for this to work.  Also note that for this to work, the way the numbers are represented must be precisely defined, so that only elements which have been escaped will be unescaped.  For example, if we escaped <em>a</em> to produce <em>b</em>, <em>b</em> would be unescaped to <em>c</em>, which would violate one of the properties of escaping.  So instead, when we escape <em>a</em> it should produce <em>d</em>, which would unescape back to <em>a</em>:</p>
<p><code>a: hello ["|1,138]<br />
b: hello ["|1139]<br />
c: hello ["|1138]<br />
d: hello [["|1]|1,138]</code></p>
<p>Now, here are my two previous examples, quoted in this fashion:</p>
<p><code>print "print ["|1] print ["|2]hello, world["|2];["|1];&#8221;;<br />
["|5]hello world["|5]<br />
</code></p>
<p>I doubt a method like this will be adopted by any language or standard, but it seems to me like it has many advantages and few disadvantages.  Assuming this post generates any interest, I am going to write up a follow-up post which analyzes the advantages and disadvantages of these rules of escaping, compared to more traditional escaping rules.</p>
]]></content:encoded>
			<wfw:commentRss>http://joshodom.net/blag/?feed=rss2&amp;p=37</wfw:commentRss>
		</item>
		<item>
		<title>File Query Tool</title>
		<link>http://joshodom.net/blag/?p=33</link>
		<comments>http://joshodom.net/blag/?p=33#comments</comments>
		<pubDate>Fri, 06 Feb 2009 18:49:13 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
		
		<category><![CDATA[Code Submission]]></category>

		<guid isPermaLink="false">http://joshodom.net/blag/?p=33</guid>
		<description><![CDATA[After months of delay, I&#8217;ve finally produced something useful.  I&#8217;ve written the tool I mentioned in my previous post, and I implemented the usage in the same way I described (with a few modifications).
This is the usage instructions I provided with the application.  Note that &#8220;and&#8221; always has higher precedence than &#8220;or&#8221;, and there&#8217;s no [...]]]></description>
			<content:encoded><![CDATA[<p>After months of delay, I&#8217;ve finally produced something useful.  I&#8217;ve written the tool I mentioned in my previous post, and I implemented the usage in the same way I described (with a few modifications).</p>
<p>This is the usage instructions I provided with the application.  Note that &#8220;and&#8221; always has higher precedence than &#8220;or&#8221;, and there&#8217;s no way to change that.</p>
<p><code>usage: filesql.pl -d{delim} select where {CONDITIONGROUP}<br />
usage: filesql.pl -d{delim} update set -f{number} = {TERMINAL} \<br />
       [-f{number} = {TERMINAL} ...] [where {CONDITIONGROUP}]<br />
usage: filesql.pl -d{delim} delete where {CONDITIONGROUP}</code></p>
<p><code> </code></p>
<p><code>{CONDITIONGROUP} := {ANDGROUP} [or {ANDGROUP} ...]<br />
{ANDGROUP}       := {CONDITION} [and {CONDITION} ...]<br />
{CONDITION}      := {TERMINAL} {OPERATOR} {TERMINAL}<br />
{TERMINAL}       := -f{number} | {constant}<br />
{OPERATOR}       := -eq | -ne | -gt | -lt | -ge | -le</code></p>
<p><a href="http://joshodom.net/weekly/filesql.pl">filesql.pl</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joshodom.net/blag/?feed=rss2&amp;p=33</wfw:commentRss>
		</item>
		<item>
		<title>Restructuring and Next Project</title>
		<link>http://joshodom.net/blag/?p=31</link>
		<comments>http://joshodom.net/blag/?p=31#comments</comments>
		<pubDate>Tue, 03 Feb 2009 18:47:47 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
		
		<category><![CDATA[Excuses]]></category>

		<guid isPermaLink="false">http://joshodom.net/blag/?p=31</guid>
		<description><![CDATA[So since I am lazy and obviously not going to do a new post a week, I am changing the tone of this blag to &#8220;Thing Every Once in a While&#8221;.  That way I am not creating false expectations for myself/my faithful viewers.
My next project I&#8217;ve been wanting to work on is as follows: a [...]]]></description>
			<content:encoded><![CDATA[<p>So since I am lazy and obviously not going to do a new post a week, I am changing the tone of this blag to &#8220;Thing Every Once in a While&#8221;.  That way I am not creating false expectations for myself/my faithful viewers.</p>
<p>My next project I&#8217;ve been wanting to work on is as follows: a unix tool which allows one to query a file as if it were a database.  It would only implement simple operations, but that&#8217;s all I ever find myself needing to do on a file anyhow.  Instead of actually updating the file, it would just output the updated information which could be used to replace the file (as most unix tools work anyhow).</p>
<p>One of the issues I&#8217;ve been trying to figure out is usage/invocation.  I&#8217;ve talked myself into putting all the &#8220;select&#8221; criteria onto the command line as arguments, but I can&#8217;t think of a clean way of pulling it off.  An example of what I have in mind:</p>
<p><code>filesql -d',' update set -f3 = "new value" where -f1 -eq "asdf" and -f2 -ne -f4 &lt;input.csv &gt;output.csv</code></p>
<p>If anyone else has a better idea for a &#8220;usage&#8221; paradigm, please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://joshodom.net/blag/?feed=rss2&amp;p=31</wfw:commentRss>
		</item>
		<item>
		<title>Weeks 3 and 4</title>
		<link>http://joshodom.net/blag/?p=29</link>
		<comments>http://joshodom.net/blag/?p=29#comments</comments>
		<pubDate>Sun, 11 Jan 2009 08:24:10 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
		
		<category><![CDATA[Excuses]]></category>

		<guid isPermaLink="false">http://joshodom.net/blag/?p=29</guid>
		<description><![CDATA[Okay, so I didn&#8217;t do anything the past two weeks, but did anyone really expect me to complete anything over the holidays?  Anyhow, I have a very exciting project for this week, and hopefully I will have it completed over the weekend.  Keep tuned!
]]></description>
			<content:encoded><![CDATA[<p>Okay, so I didn&#8217;t do anything the past two weeks, but did anyone really expect me to complete anything over the holidays?  Anyhow, I have a very exciting project for this week, and hopefully I will have it completed over the weekend.  Keep tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://joshodom.net/blag/?feed=rss2&amp;p=29</wfw:commentRss>
		</item>
		<item>
		<title>Week 2</title>
		<link>http://joshodom.net/blag/?p=21</link>
		<comments>http://joshodom.net/blag/?p=21#comments</comments>
		<pubDate>Sun, 21 Dec 2008 22:12:02 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
		
		<category><![CDATA[Code Submission]]></category>

		<guid isPermaLink="false">http://joshodom.net/blag/?p=21</guid>
		<description><![CDATA[Faithful followers of the Thing a Week project, rejoice!  Unexpectedly, I have a submission for week 2 (two days late, but who is paying attention anyhow?).
I&#8217;ve decided that DEFLATE (the algorithm used by &#8220;zip&#8221;, &#8220;gzip&#8221;, and a few other compression programs) would be a fun algorithm to implement.  At this point, I am [...]]]></description>
			<content:encoded><![CDATA[<p>Faithful followers of the Thing a Week project, rejoice!  Unexpectedly, I have a submission for week 2 (two days late, but who is paying attention anyhow?).</p>
<p>I&#8217;ve decided that DEFLATE (the algorithm used by &#8220;zip&#8221;, &#8220;gzip&#8221;, and a few other compression programs) would be a fun algorithm to implement.  At this point, I am basically recreating the wheel, because the &#8220;zlib&#8221; library already does what I am planning on doing and more, but my ultimate goal is to analyze different compression techniques in use, so the logical place to start is by implementing them.</p>
<p>DEFLATE works by first taking the raw data and performing a lempel-zip encoding on the data (scanning through data for duplicates, and replacing duplicate data with a reference to where the data is duplicated).  Then, this lempel-ziv encoded data is huffman-coded (codes of varying lengths are created for each symbol/character based on frequency of use).  The huffman tree and the huffman-coded data are then written to the file.</p>
<p>This week, I have only implemented huffman-encoding.  The huffman trees do not currently adhere to all the properties needed by DEFLATE, but the basic functionality of encoding symbols into a huffman tree seems to be working.</p>
<p><a title="http://joshodom.net/weekly/week2.tar.gz" href="http://joshodom.net/weekly/week2.tar.gz">http://joshodom.net/weekly/week2.tar.gz</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joshodom.net/blag/?feed=rss2&amp;p=21</wfw:commentRss>
		</item>
		<item>
		<title>Week 1</title>
		<link>http://joshodom.net/blag/?p=10</link>
		<comments>http://joshodom.net/blag/?p=10#comments</comments>
		<pubDate>Fri, 12 Dec 2008 03:30:02 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
		
		<category><![CDATA[Code Submission]]></category>

		<guid isPermaLink="false">http://joshodom.net/blag/?p=10</guid>
		<description><![CDATA[Off and on, I&#8217;ve always been pretty upset that when processing data in UNIX, you generally have to write out to another file than you read in from.  Of course, if you use a vi script or perl, you can have the file be edited in place, but if you want to use the normal [...]]]></description>
			<content:encoded><![CDATA[<p>Off and on, I&#8217;ve always been pretty upset that when processing data in UNIX, you generally have to write out to another file than you read in from.  Of course, if you use a vi script or perl, you can have the file be edited in place, but if you want to use the normal UNIX utilities, you have to do something like this:</p>
<p>cat file.dat | sort | cut -d, -f4 &gt; file.dat.tmp; mv file.dat.tmp file.dat</p>
<p>The issue being: if you try writing directly out to the input file (in this case, <em>file.dat</em>), it overwrites the file with a 0-byte file before the reading happens.  I&#8217;ve always wondered why someone can&#8217;t just make a program that will slurp in the whole intermediate file before even opening the file for writing, and then writing the whole file at once.</p>
<p>Well, after a few years of wondering, I&#8217;ve finally written it.  It should compile on any standard UNIX/Linux/BSD system.  Here&#8217;s the above command, using my utility:</p>
<p>cat file.dat | sort | cut -d, -f4 | dw file.dat</p>
<p>It&#8217;s very simplistic, and would need to be expanded upon to be used in live production environments, but it should be fine for simple scripts.  Enjoy!</p>
<p><a title="http://joshodom.net/weekly/week1.tar.gz" href="http://joshodom.net/weekly/week1.tar.gz">http://joshodom.net/weekly/week1.tar.gz</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joshodom.net/blag/?feed=rss2&amp;p=10</wfw:commentRss>
		</item>
		<item>
		<title>What&#8217;s all this then?</title>
		<link>http://joshodom.net/blag/?p=6</link>
		<comments>http://joshodom.net/blag/?p=6#comments</comments>
		<pubDate>Thu, 11 Dec 2008 01:29:50 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://joshodom.net/blag/?p=6</guid>
		<description><![CDATA[In the spirit of Jonathan Coulton, I am dedicating myself to completing a new coding project each week, and publishing it on the internet (i.e. here).  I will try to post my projects by midnight, Friday.
]]></description>
			<content:encoded><![CDATA[<p>In the spirit of Jonathan Coulton, I am dedicating myself to completing a new coding project each week, and publishing it on the internet (i.e. here).  I will try to post my projects by midnight, Friday.</p>
]]></content:encoded>
			<wfw:commentRss>http://joshodom.net/blag/?feed=rss2&amp;p=6</wfw:commentRss>
		</item>
	</channel>
</rss>
