<?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>Code Zen</title>
	<atom:link href="http://code-zen.info/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://code-zen.info</link>
	<description>If there is a bug that no one finds, does it exist?</description>
	<lastBuildDate>Wed, 16 Dec 2009 16:48:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Twitter Image</title>
		<link>http://code-zen.info/?p=15</link>
		<comments>http://code-zen.info/?p=15#comments</comments>
		<pubDate>Thu, 18 Jun 2009 17:28:43 +0000</pubDate>
		<dc:creator>rjzii</dc:creator>
				<category><![CDATA[Experiments]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[stackoverflow]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://code-zen.info/?p=15</guid>
		<description><![CDATA[Background This project arose out of a contest that was held on StackOverflow that grew out someone else&#8217;s project involving image compression. The overall objective of the project is to be able to encode an image in such a way that you can send it via a 140 character tweet on Twitter. Algorithm The basic [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Background</strong></p>
<p>This project arose out of a <a href="http://stackoverflow.com/questions/891643/twitter-image-encoding-challenge" title="Twitter Image Encoding Challenge">contest</a> that was held on <a href="http://stackoverflow.com" title="StackOverflow">StackOverflow</a> that grew out someone else&#8217;s project involving <a href="http://www.flickr.com/photos/quasimondo/3518306770/" title="MonaTweeta II">image compression</a>. The overall objective of the project is to be able to encode an image in such a way that you can send it via a 140 character tweet on <a href="http://twitter.com/" title="Twitter">Twitter</a>.</p>
<p>		<strong>Algorithm</strong></p>
<p>		The basic idea behind the algorithm is as follows:</p>
<ol>
<li>Down sample the image to gray-scale such that there are about 16 shades of gray.</li>
<li>Set a sampling block size for the image.</li>
<li>Encode the image using <a href="http://en.wikipedia.org/wiki/Run-length_encoding" title="Run-lenth Encoding">RLE</a>.</li>
<li>Pack the results into the UTF-16 characters such that there are two run lengths to a character and four color shades to a character.</li>
<li>Preform additional RLE on the packed data such that duplicated run-leghts are replaced by a number followed by a value.</li>
<li>Check to see if the resulting string is less than or equal to 140 characters, if so return it, otherwise, return to step two.</li>
</ol>
<p>		<strong>Results</strong></p>
<table border="1" style="margin-left: auto;margin-right: auto;width: 50%">
<tr>
<th>Reference Image</th>
<th>Tweet Output</th>
<th>Image Output</th>
<th>Run Time</th>
<th>Tweet Size</th>
</tr>
<tr>
<td><a href="twitterimage/images/cornell-box.png">cornell-box.png</a></td>
<td><a href="twitterimage/images/cornell-box.txt">cornell-box.txt</a></td>
<td><a href="twitterimage/images/cornell-box.bmp">cornell-box.bmp</a></td>
<td>61ms</td>
<td>135 characters</td>
</tr>
<tr>
<td><a href="twitterimage/images/cornell-box-large.png">cornell-box-large.png</a></td>
<td><a href="twitterimage/images/cornell-box-large.txt">cornell-box-large.txt</a></td>
<td><a href="twitterimage/images/cornell-box-large.bmp">cornell-box-large.bmp</a></td>
<td>365ms</td>
<td>124 characters</td>
</tr>
<tr>
<td><a href="twitterimage/images/lena.png">lena.png</a></td>
<td><a href="twitterimage/images/lena.txt">lena.txt</a></td>
<td><a href="twitterimage/images/lena.bmp">lena.bmp</a></td>
<td>39ms</td>
<td>103 characters</td>
</tr>
<tr>
<td><a href="twitterimage/images/lena-large.png">lena-large.png</a></td>
<td><a href="twitterimage/images/lena-large.txt">lena-large.txt</a></td>
<td><a href="twitterimage/images/lena-large.bmp">lena-large.bmp</a></td>
<td>1159ms</td>
<td>137 characters</td>
</tr>
<tr>
<td><a href="twitterimage/images/mona-lisa.png">mona-lisa.png</a></td>
<td><a href="twitterimage/images/mona-lisa.txt">mona-lisa.txt</a></td>
<td><a href="twitterimage/images/mona-lisa.bmp">mona-lisa.bmp</a></td>
<td>26ms</td>
<td>97 characters</td>
</tr>
<tr>
<td><a href="twitterimage/images/mona-lisa-large.png">mona-lisa-large.png</a></td>
<td><a href="twitterimage/images/mona-lisa-large.txt">mona-lisa-large.txt</a></td>
<td><a href="twitterimage/images/mona-lisa-large.bmp">mona-lisa-large.bmp</a></td>
<td>2187ms</td>
<td>131 characters</td>
</tr>
<tr>
<td><a href="twitterimage/images/stackoverflow-logo.png">stackoverflow-logo.png</a></td>
<td><a href="twitterimage/images/stackoverflow-logo.txt">stackoverflow-logo.txt</a></td>
<td><a href="twitterimage/images/stackoverflow-logo.bmp">stackoverflow-logo.bmp</a></td>
<td>37ms</td>
<td>111 characters</td>
</tr>
</table>
<p>
		<strong>Discussion</strong></p>
<p>Twitter makes use of Unicode characters; however, based upon discussion on the contest page it seems that web submission only recognizes UTF-16 where as the API can use the full UTF-32 space. For the purposes of this implementation the code is limited to making use of the UTF-16 space which is also conveniently the char data type in C#.</p>
<p>Give the simple nature of the algorithm it is unlikely that this project broke any new ground; however, it did server as an excellent exercise for my own skills in that it exposed me to image manipulation which is not something I do in the course of my job and likewise, it had been a long time since I had to do any bitwise manipulations to data.</p>
<p>		<strong>Source Code</strong></p>
<p>There are two main files for this project: <a href="twitterimage/source/Program.cs">program.cs</a> and <a href="twitterimage/source/TwitterImage.cs">twitterimage.cs</a>. The following is the cloc output for the files:</p>
<pre>
http://cloc.sourceforge.net v 1.07  T=0.5 s (4.0 files/s, 832.0 lines/s)
-------------------------------------------------------------------------------
Language          files     blank   comment      code    scale   3rd gen. equiv
-------------------------------------------------------------------------------
C#                    2        23       106       303 x   1.36 =         412.08
-------------------------------------------------------------------------------
	</pre>
]]></content:encoded>
			<wfw:commentRss>http://code-zen.info/?feed=rss2&amp;p=15</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kiva World</title>
		<link>http://code-zen.info/?p=11</link>
		<comments>http://code-zen.info/?p=11#comments</comments>
		<pubDate>Fri, 05 Jun 2009 01:53:42 +0000</pubDate>
		<dc:creator>rjzii</dc:creator>
				<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[kiva]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://code-zen.info/?p=11</guid>
		<description><![CDATA[Kiva World is a project that arose out of a recent graduate course I took in dynamic web development and while it is it is not the first one of its type it is the version that I wrote and as such I do have a bit of an attachment to it. This particular application [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Code Zen: Kiva World" href="http://kivaworld.code-zen.info/" target="_blank">Kiva World</a> is a project that arose out of a recent graduate course I took in dynamic web development and while it is <a title="Kiva World" href="http://kivaworld.com/">it is not the first one of its type</a> it is the version that I wrote and as such I do have a bit of an attachment to it. This particular application was written using a combination of PHP and JavaScript to provide the dynamic interaction in the user&#8217;s browser and leans heavily upon the <a title="Google Maps API" href="http://code.google.com/apis/maps/">Google Maps API</a> along with <a title="build.kiva.org" href="http://build.kiva.org/">the API exposed by Kiva</a>.</p>
<p>One of the interesting things about the version that I wrote, that does not appear to have been implemented by the other version as of the time of this writing, is the ability to see lender data as well as lendee data. This actually presented an interesting challenge due to the fact that Kiva exposes their data with extremly accurate geocoding for the lendees, but lenders are able to free text their location. As such aggreigating the lenders is exteremly hard and coupled with anonomyous lenders, I actually filter out a lot of them from the displayed results.</p>
<p>For those of you that are not familar with <a title="Kiva" href="http://www.kiva.org/" target="_blank">Kiva</a> they are a charitable service that provides <a title="Wikipedia: Microcredit" href="http://en.wikipedia.org/wiki/Microcredit" target="_blank">microloans</a> to those living in poverty with the purpose of helping them develop their own business.  Since it is a charitable service, lenders do not get any interest, but if the loan is successfully repaid, they can get their money back.</p>
]]></content:encoded>
			<wfw:commentRss>http://code-zen.info/?feed=rss2&amp;p=11</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Greetings</title>
		<link>http://code-zen.info/?p=8</link>
		<comments>http://code-zen.info/?p=8#comments</comments>
		<pubDate>Fri, 05 Jun 2009 01:38:26 +0000</pubDate>
		<dc:creator>rjzii</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://code-zen.info/?p=8</guid>
		<description><![CDATA[Greetings! Welcome to my small, little coner of the internet. The purpose of this &#8220;blog&#8221; is provide a small area where I can discuss various technological issues that I have encountered and hopefully help others to avoid some of the many pitfalls that are part of Information Technology and software development.]]></description>
			<content:encoded><![CDATA[<p>Greetings! Welcome to my small, little coner of the internet. The purpose of this &#8220;blog&#8221; is provide a small area where I can discuss various technological issues that I have encountered and hopefully help others to avoid some of the many pitfalls that are part of Information Technology and software development.</p>
]]></content:encoded>
			<wfw:commentRss>http://code-zen.info/?feed=rss2&amp;p=8</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
