<?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>Borgar.net &#187; programming</title>
	<atom:link href="http://borgar.net/tagged/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://borgar.net</link>
	<description>All the wisdom of the rainbow.</description>
	<lastBuildDate>Tue, 23 Mar 2010 23:12:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0-RC1-15022</generator>
		<item>
		<title>CSS :target</title>
		<link>http://borgar.net/s/2009/08/css-target/</link>
		<comments>http://borgar.net/s/2009/08/css-target/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 23:24:23 +0000</pubDate>
		<dc:creator>Borgar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://borgar.net/?p=1455</guid>
		<description><![CDATA[jQuery (or Sizzle) supports :target in browsers where it runs querySelectorAll to handle the work. In older browsers, it doesn&#8217;t offer fallback support. I guess that this is simply because :target is such an uncommon selector? I have no idea why you would want to use it, but because I have this selector extension and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://docs.jquery.com/Selectors">jQuery</a> (or <a href="http://sizzlejs.com/">Sizzle</a>) supports <code>:target</code> in browsers where it runs <a href="http://www.w3.org/TR/selectors-api/">querySelectorAll</a> to handle the work. In older browsers, it doesn&#8217;t offer fallback support. I guess that this is simply because <code>:target</code> is such an uncommon selector?</p>
<p>I have no idea why you would want to use it, but because I have this selector extension and nowhere to put it, here it is:</p>
<pre><code>jQuery.expr[':'].target = function ( a, h ) {
  return (a.id &#038;&#038; (h = document.location.hash) &#038;&#038; h === '#' + a.id)
};</pre>
<p></code></p>
<p>Updated 6. aug. 2009: <a href="http://twitter.com/maranomynet/status/3156396467">Optimized by @maranomynet</a></p>]]></content:encoded>
			<wfw:commentRss>http://borgar.net/s/2009/08/css-target/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sōkoban</title>
		<link>http://borgar.net/s/2009/07/sokoban/</link>
		<comments>http://borgar.net/s/2009/07/sokoban/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 22:57:14 +0000</pubDate>
		<dc:creator>Borgar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://borgar.net/?p=1427</guid>
		<description><![CDATA[A few days without internet do strange things to a computer addict. In my case I start to rummage frenetically though old projects to see if there is anything I can finish, polish, or do something with that doesn&#8217;t require internet access. So I found my old Sokoban game. Originally a Windows application, I though [...]]]></description>
			<content:encoded><![CDATA[<p>A few days without internet do strange things to a computer addict. In my case I start to rummage frenetically though old projects to see if there is anything I can finish, polish, or do something with that doesn&#8217;t require internet access.</p>
<p><img title="Sokoban for windows" src="http://borgar.net/wp-content/uploads/sokoban.png" alt="sokoban" align="right" width="210" height="178" /></p>
<p>So I found my old Sokoban game. Originally a Windows application, I though it could be fun to try to remake it in JavaScript. <a title="Sokoban in jQuery" href="http://borgar.net/programs/sokoban/">So that&#8217;s what I did.</a></p>
<p>I wrote the bulk of it in about an evening, and spent a few more evenings applying spit and polish until I was satisfied that it worked the way I wanted. The <a href="http://borgar.net/programs/sokoban/js/sokoban.js">whole thing</a> is about  300 lines of mostly uncommented code running on top of jQuery &mdash; well, actually as a jQuery plugin.</p>
<h3>The interresting bits</h3>
<p>There are a few characteristics that make this implementation interesting. The first is that the game uses progressive enhancement methodology. The script runs through marked items on the webpage and makes valid Sokoban levels playable. If you don&#8217;t have JavaScript you can still read the level codes, which are normally written in a standard like this:</p>
<pre>####
# .#
#  ###
#*@  #
#  $ #
#  ###
####</pre>
<p>The <code>@</code> is the worker, <code>#</code> are walls, <code>.</code> are docks, <code>$</code> are boxes, and so on&#8230; </p>
<p>The symbols are image-replaced with <acronym title="Cascading Style Sheets">CSS</acronym> when the level is live, but the whole thing works without <acronym title="Cascading Style Sheets">CSS</acronym>. You can disable the styles if you desire to play the levels in pure ASCII.</p>
<p>This also means that the game is printable. At any moment in gameplay you can grab a hardcopy of your status and frame it. I am hard pressed to think of other printable games. Copying the level onto the clipboard also works just as it would any other text. Not really useful features for a game, but interesting side-effects nonetheless.</p>
<p>Because parsing all the levels immediately as the game loads up &mdash; especially on level collections that have very many levels &mdash; is quite labour intensive, I am applying a recent jQuery plugin of mine, <a href="http://borgar.net/svn/public/trunk/javascript/jquery.processEach/jquery.processEach.js">.processEach()</a>, to prevent the browser from locking up. In short, it works like <em>.each()</em> but yields the process every iteration to allow the browser some time to do other things. It&#8217;s perhaps a subject of another entry.</p>
<h3>Have fun</h3>
<p>Have fun with <a href="http://borgar.net/programs/sokoban/">the game</a> and the source (which are released under the <acronym title="GNU General Public License">GPL</acronym> v3). I suspect that it might one day be exactly what a Sokoban level blog is looking for, but for now it mostly remains a curiosity rather than a spectacular reproduction of the game, </p>]]></content:encoded>
			<wfw:commentRss>http://borgar.net/s/2009/07/sokoban/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSON for old PHP installations</title>
		<link>http://borgar.net/s/2008/06/simplejson/</link>
		<comments>http://borgar.net/s/2008/06/simplejson/#comments</comments>
		<pubDate>Sun, 15 Jun 2008 14:30:07 +0000</pubDate>
		<dc:creator>Borgar</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://borgar.undraland.com/?p=1014</guid>
		<description><![CDATA[I use PHP a lot. Mostly to work with existing products, or to create mockups of things that will get replaced with something else later. The great thing about PHP is that it is present in some form on nearly all servers. If you&#8217;re careful to avoid version 5 features then you can pretty much [...]]]></description>
			<content:encoded><![CDATA[<p>I use <acronym title="Hypertext PreProcessing">PHP</acronym> a lot. Mostly to work with <a href="http://wordpress.org/" title="WordPress">existing products</a>, or to create mockups of things that will get replaced with something else later.</p>
<p>The great thing about <acronym title="Hypertext PreProcessing">PHP</acronym> is that it is present in some form on nearly all servers. If you&#8217;re careful to avoid version 5 features then you can pretty much expect your code to run wherever.</p>
<p>For a recent prototype I needed <a href="http://www.json.org/">JSON</a> (which wasn&#8217;t introduced to <acronym title="Hypertext PreProcessing">PHP</acronym> until version 5) on a 4.3 system. Being a relentless do-it-yourself&#8217;er I have written a tiny JSON functionality &#8220;library&#8221; for older versions of <acronym title="Hypertext PreProcessing">PHP</acronym>.</p>
<p>It&#8217;s about 5k of mostly comments. Available under MIT licence from <a href="http://code.google.com/p/simplejson-php/" title="Simple JSON for PHP">Google code</a>. Have fun.</p>]]></content:encoded>
			<wfw:commentRss>http://borgar.net/s/2008/06/simplejson/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>What is the column index of a table cell</title>
		<link>http://borgar.net/s/2008/02/table-cell-column-index/</link>
		<comments>http://borgar.net/s/2008/02/table-cell-column-index/#comments</comments>
		<pubDate>Wed, 27 Feb 2008 00:36:25 +0000</pubDate>
		<dc:creator>Borgar</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://borgar.undraland.com/s/2008/02/what-is-the-column-index-of-a-table-cell/</guid>
		<description><![CDATA[A peculiar but fascinating problem presented itself to me today. It was one of those; &#8220;oh yeah, I&#8217;d better look at that&#8221; kind of problems that you think you&#8217;ll solve in a few minutes but eventually grow to take hours. Given a cell in a HTML table, what is it&#8217;s column index? This seems like [...]]]></description>
			<content:encoded><![CDATA[<p>A peculiar but fascinating problem presented itself to me today. It was one of those; &#8220;oh yeah, I&#8217;d better look at that&#8221; kind of problems that you think you&#8217;ll solve in a few minutes but eventually grow to take hours.</p>
<p><strong>Given a cell in a <acronym title="HyperText Markup Language">HTML</acronym> table, what is it&#8217;s column index?</strong></p>
<p>This seems like it&#8217;s simple. You just count the cells preceding it. Fine. Works for 99% of cases. But what if the table looks like this?:</p>
<table cellspacing="4" cellpadding="8" border="1" width="100%">
<tbody>
<tr>
<td rowspan="4">cell 1</td>
<td>cell 2</td>
<td colspan="2">cell 3</td>
<td rowspan="4">cell 4</td>
<td rowspan="2">cell 5</td>
<td id="last">cell 6</td>
</tr>
<tr>
<td>cell 7</td>
<td rowspan="3">cell 8</td>
<td rowspan="2" id="">cell 9</td>
<td>cell 10</td>
</tr>
<tr>
<td rowspan="2">cell 11</td>
<td>cell 12</td>
<td rowspan="2">cell 13</td>
</tr>
<tr>
<td><b title="What is cell 14's index">My index?</b></td>
<td>cell 15</td>
</tr>
</tbody>
</table>
<p>Suddenly things are very complicated again. The last row really only contains two cells and the browser reports cell indexes 0 and 1 on those, respectively. Not the 3 and 4 I was hoping for.</p>
<p>My first thought was simply adding up the number of cells preceding this one which had a greater <em>row index</em> + <em>row span</em> than the <em>row index</em> of my subject cell. This doesn&#8217;t work because of cells like #4 &#038; #13.</p>
<p>Eventually I simply ended up with a brute force method that does the job. But is unfortunately neither fast nor elegant. But then, what code of mine is?</p>
<p>It&#8217;s presented here in case anyone else needs to solve the same annoying problem. Or if anyone can suggest a nicer (or preferably a faster) method of doing this.</p>
<p><a href="/programs/cell-offset/">View demo and code</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://borgar.net/s/2008/02/table-cell-column-index/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Safe fun with Object.prototype.</title>
		<link>http://borgar.net/s/2007/11/object-prototype-trick/</link>
		<comments>http://borgar.net/s/2007/11/object-prototype-trick/#comments</comments>
		<pubDate>Sun, 11 Nov 2007 14:07:19 +0000</pubDate>
		<dc:creator>Borgar</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://borgar.undraland.com/s/2007/11/11/14.07.19/</guid>
		<description><![CDATA[Lets look at two &#8220;shortcommings&#8221; of Javascript in todays browsers. The first is that you should stay away from Object.prototype (so as not to break other peoples programs). The second is that Javascript only has a single thread. We can fix the first using the advantage of the second. My idea is that if we [...]]]></description>
			<content:encoded><![CDATA[<p>Lets look at two <q>&#8220;shortcommings&#8221;</q> of Javascript in todays browsers. The first is that you should stay away from <code>Object.prototype</code></a> (so as not to <a href="http://erik.eae.net/archives/2005/06/06/22.13.54/">break other peoples programs</a>). The second is that Javascript only has a single thread. We can fix the first using the advantage of the second.</p>
<p>My idea is that if we have a process that would benefit from extending <code>Object.prototype</code>, then we can do this during the time we are processing. Afterwards we simply remove the extensions and everything is back to normal.</p>
<pre><code>Object.prototype.toHTML = htmlGenerationFunction;
myObject.toHTML();
delete Object.prototype.toHTML;
</code></pre>
<p>This trick won&#8217;t work on browsers that don&#8217;t implement the <code>delete</code> operator (IE3), and it&#8217;s going to be a pain if <code>hasOwnProperty</code> isn&#8217;t supported either (Safari 1 and <acronym title="Microsoft Internet Explorer 5">IE5</acronym>.0). But if you&#8217;re not supporting those browsers then you can consider this trick (<a href="http://borgar.undraland.com/programs/json/">test yours here</a>).</p>
<p>I&#8217;ve thrown together a <a href="http://borgar.undraland.com/programs/json/json.js"><code>toJSON</code> converter using this method</a>. Admittedly, the code is no cleaner than the <a href="http://www.json.org/json2.js">original example</a>, but it works, will use native methods where available, and proves the concept.</p>]]></content:encoded>
			<wfw:commentRss>http://borgar.net/s/2007/11/object-prototype-trick/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
