<?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>Nayruden&#039;s /dev/random</title>
	<atom:link href="http://nayruden.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://nayruden.com</link>
	<description>Ramblings of an insane programmer</description>
	<lastBuildDate>Wed, 07 Jul 2010 02:46:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>A simple SQL/Flatfile abstraction in Lua</title>
		<link>http://nayruden.com/?p=117</link>
		<comments>http://nayruden.com/?p=117#comments</comments>
		<pubDate>Wed, 07 Jul 2010 02:41:07 +0000</pubDate>
		<dc:creator>Nayruden</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Lua]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[SQLite]]></category>

		<guid isPermaLink="false">http://nayruden.com/?p=117</guid>
		<description><![CDATA[I&#8217;ve been wondering if it was possible to make a MySQL/SQLite/Flatfile abstracted interface for Lua for some time now. At first I thought I&#8217;d try something like LINQ, but realized that there was really no reasonable way to do that in Lua since we don&#8217;t have the power of expression trees. I then considered writing [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been wondering if it was possible to make a MySQL/SQLite/Flatfile abstracted interface for Lua for some time now. At first I thought I&#8217;d try something like <a href="http://en.wikipedia.org/wiki/Language_Integrated_Query">LINQ</a>, but realized that there was really no reasonable way to do that in Lua since we don&#8217;t have the power of expression trees. I then considered writing the queries in a simplified pseudo-Lua language, but that would take too much time to parse and no one really wants to learn another language anyways.</p>
<p>What I settled on instead was a very simplified abstraction of the data access. It can&#8217;t do everything you can do yourself from SQL or raw file I/O, but I found that it serves up exactly the kind of interface I&#8217;d need for all my past projects in Lua that use some form of I/O.</p>
<p>Here&#8217;s an example of declaring a table of data:</p>
<div class="codecolorer-container lua default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="lua codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">users <span style="color: #66cc66;">=</span> CreateDataTable<span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;users&quot;</span>, <span style="color: #ff0000;">&quot;steamid&quot;</span>, <span style="color: #ff0000;">&quot;string(32)&quot;</span>, <span style="color: #ff0000;">&quot;The steamid of the user&quot;</span> <span style="color: #66cc66;">&#41;</span><br />
users:AddKey<span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;group&quot;</span>, <span style="color: #ff0000;">&quot;string(16)&quot;</span>, <span style="color: #ff0000;">&quot;The group the user belongs to&quot;</span> <span style="color: #66cc66;">&#41;</span><br />
users:AddKey<span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;name&quot;</span>, <span style="color: #ff0000;">&quot;string(32)&quot;</span>, <span style="color: #ff0000;">&quot;The name the player was last seen with&quot;</span> <span style="color: #66cc66;">&#41;</span><br />
users:AddListOfKeyValues<span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;allow&quot;</span>, <span style="color: #ff0000;">&quot;string(16)&quot;</span>, <span style="color: #ff0000;">&quot;string(128)&quot;</span>, <span style="color: #ff0000;">&quot;The allows for the user&quot;</span> <span style="color: #66cc66;">&#41;</span></div></div>
<p>We&#8217;re defining a primary key &#8216;steamid&#8217; for each of the rows in the table &#8216;users&#8217;. We&#8217;re saying that steamid is going to be a string of max length 32 characters, and we define a comment that&#8217;s used in MySQL and Flatfiles. We then go on to add regular keys &#8216;group&#8217; and &#8216;name&#8217; to the table in a similar fashion, and you should note that regular keys are optional in the table. Finally, we&#8217;re making an additional key-value table named &#8216;allow&#8217; (A key-value table basically means a regular, unrestricted Lua table). So, to make sure you&#8217;ve got the idea, the Lua table structure of would look like this:</p>
<div class="codecolorer-container lua default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="lua codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">users <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; my_steamid1 <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; group <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;admin&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; allow <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; slap <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;*&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; kick <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;*&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>,<br />
&nbsp; &nbsp; my_steamid2 <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; name <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;Bob&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; allow <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>The API around such a clean representation of data couldn&#8217;t be much simpler. You have four operations: insert a new row by primary key, fetch an existing row by primary key, delete a row by primary key, and get the entire table. When inserting a row you can optionally pass in the data for the row. With both the insert and fetch functions you get back a table for the row that&#8217;s being &#8220;tracked&#8221;. When you change any of the contents, the change is immediately reflected into the DB or file.</p>
<p>There&#8217;s a caching system built around the system so if you fetch the same row multiple times, it won&#8217;t be going out to the DB or reading the file each time. You can request the cache be flushed or disabled altogether if you need to. Unlike file I/O I&#8217;ve done in the past, this system doesn&#8217;t need to parse the whole file to get a single row, which means it should probably work okay using flatfiles on very large files.</p>
<p>Though I haven&#8217;t coded this portion yet, I&#8217;m also planning on adding the ability to convert between MySQL/SQLite/flatfiles on the fly. This may be problematic for very large databases, so I&#8217;ve also taken care to make sure that this system can be run as a standalone script apart from any specific application.</p>
<p>So&#8230; if you&#8217;ve read this far, your next question is probably, &#8220;Why bother with such a system? Why not just stick with a single format?&#8221;. A single format (usually flatfiles) is great for about 95% of my users. The other 5%, however, are the power users who want to do crazy things like hook up a PHP billboard with blinking lights showing how many times a second someone says the word &#8216;the&#8217;. It&#8217;s the power users I prefer to cater to, so I&#8217;ve always felt guilty in the past that this was one area I couldn&#8217;t do much for them in. But now I can!</p>
]]></content:encoded>
			<wfw:commentRss>http://nayruden.com/?feed=rss2&amp;p=117</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Damerau–Levenshtein Distance, Lua Implementation</title>
		<link>http://nayruden.com/?p=115</link>
		<comments>http://nayruden.com/?p=115#comments</comments>
		<pubDate>Sun, 06 Jun 2010 07:08:28 +0000</pubDate>
		<dc:creator>Nayruden</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Lua]]></category>

		<guid isPermaLink="false">http://nayruden.com/?p=115</guid>
		<description><![CDATA[I stumbled across Levenshtein distance today and had to try my hand at writing an implementation in Lua. I choose the slightly more complex Damerau–Levenshtein distance, and I think it turned out pretty well. Some notes of interest: Complexity is O( (#t+1) * (#s+1) ) when lim isn&#8217;t specified. This function can be used to [...]]]></description>
			<content:encoded><![CDATA[<p>I stumbled across <a href="http://en.wikipedia.org/wiki/Levenshtein_distance">Levenshtein distance</a> today and had to try my hand at writing an implementation in Lua. I choose the slightly more complex <a href="http://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance">Damerau–Levenshtein distance</a>, and I think it turned out pretty well.</p>
<p>Some notes of interest:</p>
<ul>
<li>Complexity is O( (#t+1) * (#s+1) ) when lim isn&#8217;t specified.</li>
<li>This function can be used to compare array-like tables as easily as strings.</li>
<li>This function is case sensitive when comparing strings.</li>
<li>Using this function to compare against a dictionary of 250,000 words took about 0.6 seconds on my machine for the word &#8220;Teusday&#8221;, around 10 seconds for very poorly spelled words. Both tests used lim.</li>
</ul>
<p>
<p />
<div class="codecolorer-container lua default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br /></div></td><td><div class="lua codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">--[[<br />
&nbsp; &nbsp; Function: EditDistance<br />
<br />
&nbsp; &nbsp; Finds the edit distance between two strings or tables. Edit distance is the minimum number of<br />
&nbsp; &nbsp; edits needed to transform one string or table into the other.<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; Parameters:<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; s - A *string* or *table*.<br />
&nbsp; &nbsp; &nbsp; &nbsp; t - Another *string* or *table* to compare against s.<br />
&nbsp; &nbsp; &nbsp; &nbsp; lim - An *optional number* to limit the function to a maximum edit distance. If specified<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and the function detects that the edit distance is going to be larger than limit, limit<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; is returned immediately.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; Returns:<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; A *number* specifying the minimum edits it takes to transform s into t or vice versa. Will<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; not return a higher number than lim, if specified.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; Example:<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; :EditDistance( &quot;Tuesday&quot;, &quot;Teusday&quot; ) -- One transposition.<br />
&nbsp; &nbsp; &nbsp; &nbsp; :EditDistance( &quot;kitten&quot;, &quot;sitting&quot; ) -- Two substitutions and a deletion.<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; returns...<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; :1<br />
&nbsp; &nbsp; &nbsp; &nbsp; :3<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; Notes:<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; * Complexity is O( (#t+1) * (#s+1) ) when lim isn't specified.<br />
&nbsp; &nbsp; &nbsp; &nbsp; * This function can be used to compare array-like tables as easily as strings.<br />
&nbsp; &nbsp; &nbsp; &nbsp; * The algorithm used is Damerau–Levenshtein distance, which calculates edit distance based<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; off number of subsitutions, additions, deletions, and transpositions.<br />
&nbsp; &nbsp; &nbsp; &nbsp; * Source code for this function is based off the Wikipedia article for the algorithm<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;http://en.wikipedia.org/w/index.php?title=Damerau%E2%80%93Levenshtein_distance&amp;oldid=351641537&gt;.<br />
&nbsp; &nbsp; &nbsp; &nbsp; * This function is case sensitive when comparing strings.<br />
&nbsp; &nbsp; &nbsp; &nbsp; * If this function is being used several times a second, you should be taking advantage of<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; the lim parameter.<br />
&nbsp; &nbsp; &nbsp; &nbsp; * Using this function to compare against a dictionary of 250,000 words took about 0.6<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; seconds on my machine for the word &quot;Teusday&quot;, around 10 seconds for very poorly <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spelled words. Both tests used lim.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; Revisions:<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; v1.00 - Initial.<br />
]]</span><br />
<span style="color: #b1b100;">function</span> EditDistance<span style="color: #66cc66;">&#40;</span> s, t, lim <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">local</span> s_len, t_len <span style="color: #66cc66;">=</span> #s, #t <span style="color: #808080; font-style: italic;">-- Calculate the sizes of the strings or arrays</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> lim <span style="color: #b1b100;">and</span> <span style="color: #b1b100;">math.abs</span><span style="color: #66cc66;">&#40;</span> s_len - t_len <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;=</span> lim <span style="color: #b1b100;">then</span> <span style="color: #808080; font-style: italic;">-- If sizes differ by lim, we can stop here</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> lim<br />
&nbsp; &nbsp; <span style="color: #b1b100;">end</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">-- Convert string arguments to arrays of ints (ASCII values)</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #b1b100;">type</span><span style="color: #66cc66;">&#40;</span> s <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">==</span> <span style="color: #ff0000;">&quot;string&quot;</span> <span style="color: #b1b100;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; s <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #b1b100;">string.byte</span><span style="color: #66cc66;">&#40;</span> s, <span style="color: #cc66cc;">1</span>, s_len <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">end</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #b1b100;">type</span><span style="color: #66cc66;">&#40;</span> t <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">==</span> <span style="color: #ff0000;">&quot;string&quot;</span> <span style="color: #b1b100;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; t <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #b1b100;">string.byte</span><span style="color: #66cc66;">&#40;</span> t, <span style="color: #cc66cc;">1</span>, t_len <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">end</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">local</span> <span style="color: #b1b100;">min</span> <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">math.min</span> <span style="color: #808080; font-style: italic;">-- Localize for performance</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">local</span> num_columns <span style="color: #66cc66;">=</span> t_len + <span style="color: #cc66cc;">1</span> <span style="color: #808080; font-style: italic;">-- We use this a lot</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">local</span> d <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span> <span style="color: #808080; font-style: italic;">-- (s_len+1) * (t_len+1) is going to be the size of this array</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">-- This is technically a 2D array, but we're treating it as 1D. Remember that 2D access in the</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">-- form my_2d_array[ i, j ] can be converted to my_1d_array[ i * num_columns + j ], where</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">-- num_columns is the number of columns you had in the 2D array assuming row-major order and</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">-- that row and column indices start at 0 (we're starting at 0).</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">for</span> i<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">0</span>, s_len <span style="color: #b1b100;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; d<span style="color: #66cc66;">&#91;</span> i <span style="color: #66cc66;">*</span> num_columns <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> i <span style="color: #808080; font-style: italic;">-- Initialize cost of deletion</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">end</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">for</span> j<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">0</span>, t_len <span style="color: #b1b100;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; d<span style="color: #66cc66;">&#91;</span> j <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> j <span style="color: #808080; font-style: italic;">-- Initialize cost of insertion</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">end</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">for</span> i<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span>, s_len <span style="color: #b1b100;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">local</span> i_pos <span style="color: #66cc66;">=</span> i <span style="color: #66cc66;">*</span> num_columns<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">local</span> best <span style="color: #66cc66;">=</span> lim <span style="color: #808080; font-style: italic;">-- Check to make sure something in this row will be below the limit</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> j<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span>, t_len <span style="color: #b1b100;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">local</span> add_cost <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#40;</span>s<span style="color: #66cc66;">&#91;</span> i <span style="color: #66cc66;">&#93;</span> ~<span style="color: #66cc66;">=</span> t<span style="color: #66cc66;">&#91;</span> j <span style="color: #66cc66;">&#93;</span> <span style="color: #b1b100;">and</span> <span style="color: #cc66cc;">1</span> <span style="color: #b1b100;">or</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">local</span> val <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">min</span><span style="color: #66cc66;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; d<span style="color: #66cc66;">&#91;</span> i_pos - num_columns + j <span style="color: #66cc66;">&#93;</span> + <span style="color: #cc66cc;">1</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">-- Cost of deletion</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; d<span style="color: #66cc66;">&#91;</span> i_pos + j - <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#93;</span> + <span style="color: #cc66cc;">1</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">-- Cost of insertion</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; d<span style="color: #66cc66;">&#91;</span> i_pos - num_columns + j - <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#93;</span> + add_cost &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">-- Cost of substitution, it might not cost anything if it's the same</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; d<span style="color: #66cc66;">&#91;</span> i_pos + j <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> val<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">-- Is this eligible for tranposition?</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> i <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #b1b100;">and</span> j <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #b1b100;">and</span> s<span style="color: #66cc66;">&#91;</span> i <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">==</span> t<span style="color: #66cc66;">&#91;</span> j - <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#93;</span> <span style="color: #b1b100;">and</span> s<span style="color: #66cc66;">&#91;</span> i - <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">==</span> t<span style="color: #66cc66;">&#91;</span> j <span style="color: #66cc66;">&#93;</span> <span style="color: #b1b100;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; d<span style="color: #66cc66;">&#91;</span> i_pos + j <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">min</span><span style="color: #66cc66;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; val, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">-- Current cost</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; d<span style="color: #66cc66;">&#91;</span> i_pos - num_columns - num_columns + j - <span style="color: #cc66cc;">2</span> <span style="color: #66cc66;">&#93;</span> + add_cost &nbsp; <span style="color: #808080; font-style: italic;">-- Cost of transposition</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> lim <span style="color: #b1b100;">and</span> val <span style="color: #66cc66;">&lt;</span> best <span style="color: #b1b100;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; best <span style="color: #66cc66;">=</span> val<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> lim <span style="color: #b1b100;">and</span> best <span style="color: #66cc66;">&gt;=</span> lim <span style="color: #b1b100;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> lim<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">end</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">end</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> d<span style="color: #66cc66;">&#91;</span> #d <span style="color: #66cc66;">&#93;</span><br />
<span style="color: #b1b100;">end</span></div></td></tr></tbody></table></div>
<p><a href="http://gist.github.com/427389">Gist of the same source code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nayruden.com/?feed=rss2&amp;p=115</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Philosophy of higher education</title>
		<link>http://nayruden.com/?p=112</link>
		<comments>http://nayruden.com/?p=112#comments</comments>
		<pubDate>Thu, 04 Feb 2010 16:39:39 +0000</pubDate>
		<dc:creator>Nayruden</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[School]]></category>

		<guid isPermaLink="false">http://nayruden.com/?p=112</guid>
		<description><![CDATA[For one of my classes today we came up with our &#8220;purpose statement&#8221; for our being at college. It&#8217;s quite enlightening to sit down and actually think about the reasons why you&#8217;re actually spending all this time and money when the only direct, physical result is a piece of paper. Here&#8217;s my philosophy: Higher education [...]]]></description>
			<content:encoded><![CDATA[<p>For one of my classes today we came up with our &#8220;purpose statement&#8221; for our being at college. It&#8217;s quite enlightening to sit down and actually think about the reasons <em>why</em> you&#8217;re actually spending all this time and money when the only direct, physical result is a piece of paper. Here&#8217;s my philosophy:</p>
<p>Higher education primarily ensures that graduates have the tools and knowledge they need for the career field they want to go into. The time spent learning while earning the degree is invested into research in the field and honing professional and interpersonal skills. Studying at an academic institution is often necessary to make certain that topics are fully understood, that any questions are answers, and that the new knowledge can be easily referenced if needed in the future.</p>
<p>Attending a higher learning facility and living in school&#8217;s dormitory has extra added benefits. Living with other people that you don&#8217;t initially know helps immensely in helping students learn to empathize with those around them as well as help the students realize what kind of person they are versus what kind of person they&#8217;d like to be. This social experience is every bit just as important as the traditional academic learning that the school provides and needs to be treated as such when students are considering college options.</p>
]]></content:encoded>
			<wfw:commentRss>http://nayruden.com/?feed=rss2&amp;p=112</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>GUI for NetTunnel</title>
		<link>http://nayruden.com/?p=104</link>
		<comments>http://nayruden.com/?p=104#comments</comments>
		<pubDate>Tue, 02 Feb 2010 07:18:19 +0000</pubDate>
		<dc:creator>Nayruden</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[NetTunnel]]></category>
		<category><![CDATA[WinForms]]></category>

		<guid isPermaLink="false">http://nayruden.com/?p=104</guid>
		<description><![CDATA[Designing the GUI for NetTunnel put my creativity to the test. I&#8217;ve never actually designed a GUI before, but I&#8217;ve seen and read a lot about GUI design theory, but theory seems to be fairly pointless for this design process. It was interesting for me to try to translate the idea in my head to [...]]]></description>
			<content:encoded><![CDATA[<p>Designing the GUI for NetTunnel put my creativity to the test. I&#8217;ve never actually designed a GUI before, but I&#8217;ve seen and read a lot about GUI design theory, but theory seems to be fairly pointless for this design process. It was interesting for me to try to translate the idea in my head to the controls given in Visual Studios.</p>
<p>My first attempt ended up like this:</p>
<div id="attachment_105" class="wp-caption alignnone" style="width: 310px"><a href="http://nayruden.com/wp-content/uploads/2010/02/GUIv1-main.png"><img class="size-medium wp-image-105" title="GUIv1-main" src="http://nayruden.com/wp-content/uploads/2010/02/GUIv1-main-300x224.png" alt="Main Window" width="300" height="224" /></a><p class="wp-caption-text">Main Window</p></div>
<div id="attachment_106" class="wp-caption alignnone" style="width: 255px"><a href="http://nayruden.com/wp-content/uploads/2010/02/GUIv1-services.png"><img class="size-medium wp-image-106" title="GUIv1-services" src="http://nayruden.com/wp-content/uploads/2010/02/GUIv1-services-245x300.png" alt="Services Window" width="245" height="300" /></a><p class="wp-caption-text">Services Window</p></div>
<p>This is okay, but not great. Most of those elements are static elements that don&#8217;t move even if you resize it. It&#8217;s certainly not something I&#8217;d feel comfortable working with every day. After getting lots and lots of advice from friends, my second and final GUI design ended up like so:</p>
<div id="attachment_107" class="wp-caption alignnone" style="width: 310px"><a href="http://nayruden.com/wp-content/uploads/2010/02/GUIv2-main.png"><img class="size-medium wp-image-107" title="GUIv2-main" src="http://nayruden.com/wp-content/uploads/2010/02/GUIv2-main-300x300.png" alt="Main Window" width="300" height="300" /></a><p class="wp-caption-text">Main Window</p></div>
<div id="attachment_108" class="wp-caption alignnone" style="width: 310px"><a href="http://nayruden.com/wp-content/uploads/2010/02/GUIv2-services.png"><img class="size-medium wp-image-108" title="GUIv2-services" src="http://nayruden.com/wp-content/uploads/2010/02/GUIv2-services-300x285.png" alt="Services Window" width="300" height="285" /></a><p class="wp-caption-text">Services Window</p></div>
<p>A much cleaner and easier to understand layout. Services can be toggled just by clicking on the &#8216;service&#8217; menu and then clicking on the appropriate service from the drop-down, or they can be toggled within the service window proper. All the most commonly used items in the gui are put in obvious places, while making sure that everything&#8217;s just a few clicks away. Everything resizes and can have the size proportions for it changed.</p>
<p>Now that I know how easy it is to create GUIs, I think I might start using them in future projects while retaining a command line version for power users.</p>
]]></content:encoded>
			<wfw:commentRss>http://nayruden.com/?feed=rss2&amp;p=104</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Introducing NetTunnel</title>
		<link>http://nayruden.com/?p=103</link>
		<comments>http://nayruden.com/?p=103#comments</comments>
		<pubDate>Sat, 30 Jan 2010 20:22:14 +0000</pubDate>
		<dc:creator>Nayruden</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[NetTunnel]]></category>

		<guid isPermaLink="false">http://nayruden.com/?p=103</guid>
		<description><![CDATA[As part of my requirements for obtaining my degree, I&#8217;m doing a network capstone project this semester.  I&#8217;ve always been somewhat fascinated with NATs and specifically, how to break them, so I decided to work on a NAT traversal application. Enter NetTunnel: The purpose of NetTunnel is to provide a means for users with a [...]]]></description>
			<content:encoded><![CDATA[<p>As part of my requirements for obtaining my degree, I&#8217;m doing a network capstone project this semester.  I&#8217;ve always been somewhat fascinated with <a href="http://en.wikipedia.org/wiki/Network_address_translation">NATs</a> and specifically, how to break them, so I decided to work on a NAT traversal application. Enter NetTunnel: The purpose of NetTunnel is to provide a means for users with a lack of knowledge of networking or on a restrictive network an easy and simple means to share network services with other users.</p>
<p>Basically, say I&#8217;m on a restrictive network (like the dorm network) that does not allow me to host servers with the world due to NAT restrictions. I want to run ventrilo on my machine and have my friends join so I can chat with them. Unaided, this would be impossible, but if my friends and I are running NetTunnel a &#8220;hole&#8221; will be opened up in the network so they can connect.</p>
<p>It&#8217;s a pretty simple concept that&#8217;s already done in most modern desktop applications like Skype and peer to peer games. As far as I could tell this idea&#8217;s never been extended to a general level like NetTunnel, so there is a definite need for it. The closest application to it I could find is <a href="http://www.gameranger.com/">GameRanger</a>, though GameRanger is aimed specifically at games.</p>
<p>I&#8217;ve set up a quick static page for NetTunnel at <a href="http://nettunnel.nayruden.com">nettunnel.nayruden.com</a>. Keep an eye out for further development, and I&#8217;d love to hear feedback about it!</p>
]]></content:encoded>
			<wfw:commentRss>http://nayruden.com/?feed=rss2&amp;p=103</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CODN</title>
		<link>http://nayruden.com/?p=102</link>
		<comments>http://nayruden.com/?p=102#comments</comments>
		<pubDate>Fri, 29 Jan 2010 06:48:20 +0000</pubDate>
		<dc:creator>Nayruden</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[CODN]]></category>

		<guid isPermaLink="false">http://nayruden.com/?p=102</guid>
		<description><![CDATA[While talking to LightSys, an organization that offers free IT services to mission organizations, I was told about the Christian Open Development Network or CODN (pronounced codin&#8217;). The site is in dire need of a refresh and a core community (last update is 2005?!). I felt like God was nudging me while they described what [...]]]></description>
			<content:encoded><![CDATA[<p>While talking to <a href="http://www.lightsys.org/">LightSys</a>, an organization that offers free IT services to mission organizations, I was told about the <a href="http://codn.net">Christian Open Development Network</a> or CODN (pronounced codin&#8217;). The site is in dire need of a refresh and a core community (last update is 2005?!). I felt like God was nudging me while they described what they wanted CODN to be, especially since what they need is exactly what I have experience with from managing the Ulysses community.</p>
<p>So, if you or any friends are interested in Christian open source development, be sure to watch the site over the following months as we work on it. If you&#8217;ve got any ideas on what you&#8217;d like to see there, be sure to drop a note in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://nayruden.com/?feed=rss2&amp;p=102</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Callback system in D</title>
		<link>http://nayruden.com/?p=97</link>
		<comments>http://nayruden.com/?p=97#comments</comments>
		<pubDate>Mon, 24 Nov 2008 14:50:41 +0000</pubDate>
		<dc:creator>Nayruden</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[d]]></category>
		<category><![CDATA[Daydream]]></category>

		<guid isPermaLink="false">http://meg-tech.com/blog/?p=97</guid>
		<description><![CDATA[We&#8217;ve been evaluating D for use in Daydream, and I decided to see how easy it would be to create a callback system in the D  language (aka events or signals). This is a daunting task in C++ because C++ templates can only accept a static number of arguments&#8230; very bad when you have a [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve been evaluating D for use in Daydream, and I decided to see how easy it would be to create a callback system in the D  language (aka events or signals). This is a daunting task in C++ because C++ templates can only accept a static number of arguments&#8230; very bad when you have a function that can accept any number of arguments. To solve this problem in C++ you need to create a separate template for each number of possible arguments.</p>
<p>In D you can create templates that accept any number of arguments! You can treat these as a tuple, an array, or use them with <a href="http://en.wikipedia.org/wiki/Tail_recursion">tail recursion</a> (à la PROLOG).</p>
<p>Combine this with the natural awesomeness of D and you&#8217;re setup for a power punch. Following this text is a very simple callback system in D.<br />
A short but sweet 50 lines of code; it stores both functions and delegates and gives you a good launching point to create a more complicated call back system.</p>
<div class="codecolorer-container d default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br /></div></td><td><div class="d codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">import</span> tango.<span style="color: #006600;">io</span>.<span style="color: #006600;">Stdout</span><span style="color: #66cc66;">;</span><br />
<br />
<span style="color: #808080; font-style: italic;">// Converts a function to a delegate. Stolen from http://dsource.org/projects/tango/ticket/1174</span><br />
<span style="color: #808080; font-style: italic;">// Note that it doesn't handle ref or out though</span><br />
R <span style="color: #000000; font-weight: bold;">delegate</span><span style="color: #66cc66;">&#40;</span>T<span style="color: #66cc66;">&#41;</span> toDg<span style="color: #66cc66;">&#40;</span>R<span style="color: #66cc66;">,</span> T<span style="color: #66cc66;">...</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>R <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>T<span style="color: #66cc66;">&#41;</span> fp<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">struct</span> dg <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; R opCall<span style="color: #66cc66;">&#40;</span>T t<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">cast</span><span style="color: #66cc66;">&#40;</span>R <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; R <span style="color: #000000; font-weight: bold;">delegate</span><span style="color: #66cc66;">&#40;</span>T<span style="color: #66cc66;">&#41;</span> t<span style="color: #66cc66;">;</span><br />
&nbsp; &nbsp; t.<span style="color: #006600;">ptr</span> <span style="color: #66cc66;">=</span> fp<span style="color: #66cc66;">;</span><br />
&nbsp; &nbsp; t.<span style="color: #006600;">funcptr</span> <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&amp;</span>amp<span style="color: #66cc66;">;</span>dg.<span style="color: #006600;">opCall</span><span style="color: #66cc66;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> t<span style="color: #66cc66;">;</span><br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #993333;">class</span> SimpleCallback<span style="color: #66cc66;">&#40;</span>R<span style="color: #66cc66;">,</span> P<span style="color: #66cc66;">...</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">alias</span> R <span style="color: #000000; font-weight: bold;">delegate</span><span style="color: #66cc66;">&#40;</span>P<span style="color: #66cc66;">&#41;</span> callbacktype<span style="color: #66cc66;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">alias</span> R <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>P<span style="color: #66cc66;">&#41;</span> function_callbacktype<span style="color: #66cc66;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #993333;">private</span> callbacktype<span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> callback_list<span style="color: #66cc66;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">typeof</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">this</span> <span style="color: #66cc66;">&#41;</span> opCatAssign<span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">in</span> callbacktype callback <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; callback_list <span style="color: #66cc66;">~=</span> callback<span style="color: #66cc66;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">this</span><span style="color: #66cc66;">;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">typeof</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">this</span> <span style="color: #66cc66;">&#41;</span> opCatAssign<span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">in</span> function_callbacktype callback <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">auto</span> dg <span style="color: #66cc66;">=</span> toDg<span style="color: #66cc66;">!</span><span style="color: #66cc66;">&#40;</span>R<span style="color: #66cc66;">,</span> P<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span> callback <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">this</span> <span style="color: #66cc66;">~=</span> dg<span style="color: #66cc66;">;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; R emit<span style="color: #66cc66;">&#40;</span> P p <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">static</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">!</span><span style="color: #000000; font-weight: bold;">is</span><span style="color: #66cc66;">&#40;</span> R <span style="color: #66cc66;">==</span> <span style="color: #993333;">void</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; R last<span style="color: #66cc66;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span> callback<span style="color: #66cc66;">;</span> callback_list <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">static</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">!</span><span style="color: #000000; font-weight: bold;">is</span><span style="color: #66cc66;">&#40;</span> R <span style="color: #66cc66;">==</span> <span style="color: #993333;">void</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; last <span style="color: #66cc66;">=</span> callback<span style="color: #66cc66;">&#40;</span> p <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; callback<span style="color: #66cc66;">&#40;</span> p <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">static</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">!</span><span style="color: #000000; font-weight: bold;">is</span><span style="color: #66cc66;">&#40;</span> R <span style="color: #66cc66;">==</span> <span style="color: #993333;">void</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> last<span style="color: #66cc66;">;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">alias</span> emit opCall<span style="color: #66cc66;">;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>Here&#8217;s some example code:</p>
<div class="codecolorer-container d default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="d codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SimpleCallback<span style="color: #66cc66;">!</span><span style="color: #66cc66;">&#40;</span> <span style="color: #993333;">void</span> <span style="color: #66cc66;">&#41;</span> sc <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimpleCallback<span style="color: #66cc66;">!</span><span style="color: #66cc66;">&#40;</span> <span style="color: #993333;">void</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span><br />
SimpleCallback<span style="color: #66cc66;">!</span><span style="color: #66cc66;">&#40;</span> <span style="color: #993333;">bool</span><span style="color: #66cc66;">,</span> <span style="color: #993333;">char</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#41;</span> sc2 <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimpleCallback<span style="color: #66cc66;">!</span><span style="color: #66cc66;">&#40;</span> <span style="color: #993333;">bool</span><span style="color: #66cc66;">,</span> <span style="color: #993333;">char</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span><br />
sc <span style="color: #66cc66;">~=</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #993333;">void</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> Stdout.<span style="color: #006600;">formatln</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;#1&quot;</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">;</span><br />
sc <span style="color: #66cc66;">~=</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #993333;">void</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> Stdout.<span style="color: #006600;">formatln</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;#2&quot;</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">;</span><br />
sc2 <span style="color: #66cc66;">~=</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #993333;">bool</span><span style="color: #66cc66;">&#40;</span> <span style="color: #993333;">char</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> str <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> Stdout.<span style="color: #006600;">formatln</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;#1 called with {}, returning false&quot;</span><span style="color: #66cc66;">,</span> str <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">;</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">;</span><br />
sc2 <span style="color: #66cc66;">~=</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #993333;">bool</span><span style="color: #66cc66;">&#40;</span> <span style="color: #993333;">char</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> str <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> Stdout.<span style="color: #006600;">formatln</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;#2 called with {}, returning true&quot;</span><span style="color: #66cc66;">,</span> str <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">;</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">;</span><br />
sc<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span><br />
Stdout.<span style="color: #006600;">formatln</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;Last sc2 callback returned {}&quot;</span><span style="color: #66cc66;">,</span> sc2<span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;coffee&quot;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span></div></div>
<p>And here&#8217;s the output:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#1<br />
#2<br />
#1 called with coffee, returning false<br />
#2 called with coffee, returning true<br />
Last sc2 callback returned true</div></div>
]]></content:encoded>
			<wfw:commentRss>http://nayruden.com/?feed=rss2&amp;p=97</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Pleased with Daydream</title>
		<link>http://nayruden.com/?p=95</link>
		<comments>http://nayruden.com/?p=95#comments</comments>
		<pubDate>Sun, 26 Oct 2008 09:38:03 +0000</pubDate>
		<dc:creator>Nayruden</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Daydream]]></category>

		<guid isPermaLink="false">http://meg-tech.com/blog/?p=95</guid>
		<description><![CDATA[The response I got with Daydream far exceeded my expectations! We now have four excellent developers onboard, myself included. We&#8217;ve been putting the rubber to the road and have been coming up with basic design documents for Daydream. This is tedious work for now, but well worth the time it will save us in the [...]]]></description>
			<content:encoded><![CDATA[<p>The response I got with Daydream far exceeded my expectations! We now have four excellent developers onboard, myself included. We&#8217;ve been putting the rubber to the road and have been coming up with basic design documents for Daydream. This is tedious work for now, but well worth the time it will save us in the coming months.</p>
<p>Are you a modeler or texture artist looking to bolster your profile? Join Daydream and help us and your resume. We&#8217;re looking for all skill levels at this point.</p>
<p>Thank you all for your support, and watch this blog for various news about Daydream in the future. <img src='http://nayruden.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Here&#8217;s some links for Daydream:</p>
<p><strong>Website: </strong><a href="http://daydreamonline.net">http://daydreamonline.net</a> (just redirects to forums right now)<a href="http://daydreamonline.net"><br />
</a></p>
<p><strong>Twitter updates: </strong><a href="https://twitter.com/ProjectDaydream">https://twitter.com/ProjectDaydream</a></p>
<p><strong>Wiki: </strong><a href="http://wiki.daydreamonline.net" target="_blank">http://wiki.daydreamonline.net</a></p>
<p><strong>Git repo: </strong><a href="http://github.com/Nayruden/daydream" target="_blank">http://github.com/Nayruden/daydream</a></p>
<p>For those who may be interested, we&#8217;ve decided to use the LGPL license.</p>
]]></content:encoded>
			<wfw:commentRss>http://nayruden.com/?feed=rss2&amp;p=95</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Project Daydream</title>
		<link>http://nayruden.com/?p=88</link>
		<comments>http://nayruden.com/?p=88#comments</comments>
		<pubDate>Tue, 14 Oct 2008 05:39:38 +0000</pubDate>
		<dc:creator>Nayruden</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Daydream]]></category>

		<guid isPermaLink="false">http://meg-tech.com/blog/?p=88</guid>
		<description><![CDATA[Daydream has been a dream of mine (haha, get it?) for quite some time. It&#8217;s something that I believe is needed, but when I start looking at the time/effort needed to work on it, I usually run for the hills. I&#8217;ve compromised with myself in this regard, I do not expect to complete it. No [...]]]></description>
			<content:encoded><![CDATA[<p>Daydream has been a dream of mine (haha, get it?) for quite some time. It&#8217;s something that I believe is needed, but when I start looking at the time/effort needed to work on it, I usually run for the hills. I&#8217;ve compromised with myself in this regard, I do not expect to complete it. No matter how much I work on it or not, it will be worth the experience. I&#8217;ll take it nice and slow, baby steps the whole way. This is part of the reason I named it &#8216;Daydream&#8217;. If Garry Newman, whose <a href="http://www.garry.tv/?p=594">math</a> (see quaternion section) and <a href="http://www.garry.tv/?p=521">programming</a> <a href="http://www.garry.tv/?p=346">skills</a> never cease to amuse, can code something similar, I certainly can too.</p>
<p><strong>So, what is it?</strong></p>
<p>Daydream takes a page from <a href="http://en.wikipedia.org/wiki/Garry%27s_Mod">Garry&#8217;s Mod</a>&#8216;s book, an open sandbox. It makes a good starting point for our explanation and most of the readers have experience in GMod, so we&#8217;ll list some of the major points of difference between Daydream and GMod below instead of starting from scratch.</p>
<ul>
<li><strong>Stability</strong>. This is the crux of what&#8217;s holding GMod back from wide public acceptence. Server owners simply have to expect a popular to crash roughly once an hour. If you don&#8217;t believe me, I&#8217;d happily get you in touch with some other server owners. GMod is built off HL2, which was simply not built to do what GMod is doing. It&#8217;s true that VALVe has put a lot of effort into supporting this, but it&#8217;s simply not enough. Daydream will have a high emphasis on making it as stable as humanly possible.</li>
<li><strong>Cross-platform</strong>. Steam, which powers HL2 clients, does not support anything except windows. This does not hold true for servers, but Garry has <a href="http://steamcommunity.com/groups/LinBins4gmod">repeatedly refused to support Linux</a>. Our goal for Daydream is to have it run on Mac, Linux, and Windows. I have lots of experience programming on all the platforms except Mac, but now that I own a Mac, supporting it shouldn&#8217;t be a problem. <img src='http://nayruden.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </li>
<li><strong>FOSS (Free and Open Source Software)</strong>. The community has been vital to GMod&#8217;s success, and the same would certainly be true of Daydream. What better way to do this than to have true community collaboration? I personally believe that the community is what would make or break Daydream. Making this open source also brings in the traditional benefits&#8230; more help with coding, greater bug visibility, easier to make modifications, etc.</li>
<li><strong>Support for more players</strong>. Garry built GMod with exclusively single player in mind, telling people asking for multiplayer that they were essentially crazy. I have no idea if Garry still sticks by this design decision, but the impacts can be clearly seen. Garry is also relegated to the fact that Source cannot support more than 32/64 players on a server. One of Daydream&#8217;s long-term goals is to be essentially an MMO (similar to Second Life). This isn&#8217;t a feature that can happen overnight, and considerations for hardware must be made. Phsyics sandboxes are very intensive in memory and CPU.</li>
<li><strong>More focus on learning</strong>. An online MMO physics sandbox is a great place to learn about the real world! What happens when a soccer ball is hit with a tornado? What&#8217;s the best way to light a wooden house on fire? Users should feel like they have nearly limitless possiblities while using Daydream.</li>
<li><strong>Persistance</strong>. Disconnecting from a server shouldn&#8217;t be a death sentence. You should be able to bring your creations with you wherever you go, share them with others as you like (maybe even sell!). If someone&#8217;s created an awesome model (the building blocks of a sandbox game), they should be able to show the model to other people without intervention of the server owners (with reservations). Ideally (until Daydream is a true MMO), there would be some sort of cooperation between server hosts in order to store information about players.</li>
</ul>
<p><strong>Other features we want to implement:</strong></p>
<ul>
<li>In place script editor. You should be able to look at the scripts powering, for example, an ATV and change the behavior of the object on the fly. I want to be able to create a sphere, bring up the editor and see all relevant functions either stubbed out for me or easily dropped in the script, and make the sphere act like the the <a href="http://en.wikipedia.org/wiki/The_Golden_Snitch#The_Golden_Snitch">golden snitch</a> from Harry Potter within a period of five minutes.</li>
<li>Clearly defined and standardized object I/O. If an object can move, other objects should be able to control this outside the script editor. IE, I should be able to create a button, give it a value of 0 when off and 255 when on, and hook it up to say, a cube, specifying acceleration along the z-axis or such. Then, when I press the button, the cube will shoot straight up into the air accelerating at 255 units/sec. This clean I/O interface allows even non-programmers to take full advantage of their surroundings in new and innovative ways.</li>
<li>Everything must be standardized, modular, and extensible. We realize that we&#8217;re a small team and relatively inexperienced. To counter this, everything should be as modular and extensible as possible so we can come along later and easily improve previous work. This also goes toward our MMO goal. We should litterally be able to replace the server software completely with as few changes to the clients as possible. Even if clients written in completely different languages were to join the server, this shouldn&#8217;t be a problem. I know this goal sounds lofty, but it <em>is </em>attainable.</li>
</ul>
<p><strong>An invitation for other developers:</strong></p>
<p>If you are experienced in C++ or Lua, we&#8217;d like to have your help! Our development approach is very casual. So far the development team is made up of college students who are in this mostly to learn. We&#8217;re in no rush, we want to go slowly and make sure we get this right.</p>
<p>If this sounds like your type of project, please get in touch with me! Either leave a comment here, or email me, using megiddo AT (the address of this domain).</p>
<p>Technologies you should be willing to learn and become familiar with as a developer:</p>
<ul>
<li><a href="http://ogre3d.org/">Ogre3d</a> &#8211; This is our graphics engine</li>
<li><a href="http://en.wikipedia.org/wiki/Git_(software)">Git</a> &#8211; Our source control (via github)</li>
<li><a href="http://lua.org/">Lua</a> &#8211; Our scripting language</li>
<li><a href="http://swig.org">SWIG</a> &#8211; Our interface to Lua</li>
<li><a href="http://www.newtondynamics.com/">Newton</a> &#8211; Probably? We&#8217;re still toying around, PhysX seems to limited</li>
</ul>
<p><strong>An invitation for ideas:</strong></p>
<p>Have an idea for this project? Leave it in the comments! We appreciate any feedback we can get at all.</p>
<p><strong>Website for daydream:</strong></p>
<p>Not much to look at yet, but it&#8217;s <a href="http://daydreamonline.net">http://daydreamonlinet.net</a></p>
]]></content:encoded>
			<wfw:commentRss>http://nayruden.com/?feed=rss2&amp;p=88</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Howto: Install Boot Camp 2.1 drivers on a new MacBook Pro using a Leopard install DVD</title>
		<link>http://nayruden.com/?p=86</link>
		<comments>http://nayruden.com/?p=86#comments</comments>
		<pubDate>Sun, 07 Sep 2008 07:40:07 +0000</pubDate>
		<dc:creator>Nayruden</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Handong]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://meg-tech.com/blog/?p=86</guid>
		<description><![CDATA[So you&#8217;re in Korea and you stupidly forgot your MacBook Pro install DVD that you need in order to install Boot Camp drivers, huh? Have no fear, as long as you can borrow a Leopard install DVD off someone, it&#8217;s possible to get everything working. The problem here is that even with the Leopard install [...]]]></description>
			<content:encoded><![CDATA[<p>So you&#8217;re in Korea and you stupidly forgot your MacBook Pro install DVD that you need in order to install Boot Camp drivers, huh? Have no fear, as long as you can borrow a Leopard install DVD off someone, it&#8217;s possible to get everything working. The problem here is that even with the Leopard install DVD (at least in my case), the DVD has the Boot Camp 2.0 drivers which will give you a blue screen of death if you try to install it on the latest MacBook Pro revision.</p>
<p>Step 1: Copy the Boot Camp driver install files from the Leopard CD to your Boot Camp desktop.</p>
<p>Step 2: Find the Broadcom/wireless driver installer and delete it.</p>
<p>Step 3: Install the 2.0 firmware through Drivers\Apple\BootCamp.msi. It will automagically pass through the wireless driver installation with no BSoD. You&#8217;ll need to reboot after this install</p>
<p>Step 4: Now run the 2.1 update, found here: <a href="http://www.apple.com/support/downloads/bootcampupdate21forwindowsxp.html">http://www.apple.com/support/downloads/bootcampupdate21forwindowsxp.html</a>. Reboot.<a href="http://www.apple.com/support/downloads/bootcampupdate21forwindowsxp.html"><br />
</a></p>
<p>Step 5: Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://nayruden.com/?feed=rss2&amp;p=86</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 1.441 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-09-07 20:26:44 -->
