<?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>matthewwhitworth.com &#187; Programming</title>
	<atom:link href="http://matthewwhitworth.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://matthewwhitworth.com</link>
	<description>The Personal Homepage of Matthew Whitworth (duh!)</description>
	<lastBuildDate>Wed, 18 Jun 2008 13:41:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The Great Photo Salvage</title>
		<link>http://matthewwhitworth.com/2008/01/26/the-great-photo-salvage/</link>
		<comments>http://matthewwhitworth.com/2008/01/26/the-great-photo-salvage/#comments</comments>
		<pubDate>Sat, 26 Jan 2008 19:30:47 +0000</pubDate>
		<dc:creator>matthew</dc:creator>
				<category><![CDATA[Diary]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://matthewwhitworth.com/2008/01/26/the-great-photo-salvage/</guid>
		<description><![CDATA[After the filesystem crash back in October I had 11 gigabytes worth of files without meaningful names just sitting in a lost+found directory.  I was forced to come up with some creative ways to salvage data.
$ find lost+found/ -type f &#124; wc -l
79370
$ du -sh lost+found/
11G&#160;&#160;&#160;&#160; lost+found/
One of the first things I thought people [...]]]></description>
			<content:encoded><![CDATA[<p>After the filesystem crash back in October I had 11 gigabytes worth of files without meaningful names just sitting in a lost+found directory.  I was forced to come up with some creative ways to salvage data.</p>
<p><code>$ find lost+found/ -type f | wc -l<br />
79370<br />
$ du -sh lost+found/<br />
11G&nbsp;&nbsp;&nbsp;&nbsp; lost+found/</code></p>
<p>One of the first things I thought people might want access to would be their digital photographs, so I decided to cook up a little program to sort through the entire lost+found directory, find JPEG&#8217;s with a &#8220;Camera Model&#8221; EXIF tag and then copy them into an appropriate directory based on the value of that tag.</p>
<p>My first attempt used the shell, but that proved unacceptably slow so I fell back to my good friend Python.  I installed the Python Image Library (python-imaging in Ubuntu), which I used to identify the JPEG&#8217;s (very fast, by the way), and which also has (kludgy, experimental) support for reading EXIF tags.</p>
<p>Here&#8217;s the code:</p>
<p><code>#! /usr/bin/python<br />
&nbsp;<br />
import sys<br />
import os<br />
import Image<br />
from ExifTags import TAGS<br />
from shutil import copyfile<br />
&nbsp;<br />
INDIR = &#039;lost+found&#039;<br />
OUTDIR = &#039;recovered-photos&#039;<br />
&nbsp;<br />
def recover_photo(infile, outdir):<br />
&nbsp;&nbsp;&nbsp;&nbsp;try:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;im = Image.open(infile)<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if im.format == &#039;JPEG&#039;:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tags = {}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exif = im._getexif()<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for tag, val in exif.items():<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lookup = TAGS.get(tag, tag)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tags[lookup] = val<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dirname = tags[&#039;Model&#039;].strip()<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dirname = dirname.replace(&#039; &#039;, &#039;_&#039;)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;outdirname = os.path.join(outdir, dirname)<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if not os.path.isdir(outdirname):<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;os.makedirs(outdirname)<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;outfile = os.path.basename(infile)<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if not outfile.endswith((&#039;.jpg&#039;, &#039;.JPG&#039;)):<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;outfile = outfile + &#039;.jpg&#039;<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;outfile = os.path.join(outdirname, outfile)<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;copyfile(infile, outfile)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print infile, &#039;-&gt;&#039;, outfile<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;except IOError, v:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(errno, errmsg) = v<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;except:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;errmsg = v<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print infile, errmsg<br />
&nbsp;&nbsp;&nbsp;&nbsp;except:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print infile, &#039;unknown error&#039;<br />
&nbsp;<br />
for root, dirs, files in os.walk(INDIR):<br />
&nbsp;&nbsp;&nbsp;&nbsp;for name in files:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;infile = os.path.join(root, name)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;recover_photo(infile, OUTDIR)</code></p>
<p>After running for 28m18s:</p>
<p><code>$ ls -l recovered-photos/<br />
total 492<br />
drwxr-xr-x 2 matthew matthew&nbsp;&nbsp;4096 2008-01-26 13:58 C2100UZ<br />
drwxr-xr-x 2 matthew matthew&nbsp;&nbsp;4096 2008-01-26 14:18 C3100Z,C3020Z<br />
drwxr-xr-x 2 matthew matthew 12288 2008-01-26 14:18 C860L,D360L<br />
drwxr-xr-x 2 matthew matthew 36864 2008-01-26 14:17 C960Z,D460Z<br />
&#46;..<br />
$ find recovered-photos/ -type f | wc -l<br />
9293<br />
$ du -sh recovered-photos/<br />
7.3G&nbsp;&nbsp;&nbsp;&nbsp;recovered-photos/</code></p>
<p>9293 digital photographs all nicely sorted.</p>
<p>I&#8217;ll clean the code up, flesh it out with some handy command-line args and post a link to the updated version here as soon as I have a few spare cycles.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewwhitworth.com/2008/01/26/the-great-photo-salvage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shakedown Cruise</title>
		<link>http://matthewwhitworth.com/2008/01/14/shakedown-cruise/</link>
		<comments>http://matthewwhitworth.com/2008/01/14/shakedown-cruise/#comments</comments>
		<pubDate>Tue, 15 Jan 2008 01:22:28 +0000</pubDate>
		<dc:creator>matthew</dc:creator>
				<category><![CDATA[Diary]]></category>
		<category><![CDATA[Meta]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://matthewwhitworth.com/2008/01/14/shakedown-cruise/</guid>
		<description><![CDATA[I got bold and decided to push matthewwhitworth.com into production today, and the bugs are already starting to shake out.  The big problems seem to be in the theme I chose to use, miniBits.  I liked it because of its clean layout and minimal graphics, but its small size also gave me the [...]]]></description>
			<content:encoded><![CDATA[<p>I got bold and decided to push matthewwhitworth.com into production today, and the bugs are already starting to shake out.  The big problems seem to be in the theme I chose to use, miniBits.  I liked it because of its clean layout and minimal graphics, but its small size also gave me the suspicion that some edge cases might not handle so well.</p>
<p>It turns out it&#8217;s more than the edge cases.  About 15 minutes after pushing the site into DNS I noticed that the simple &#8220;view post&#8221; action produces invalid xhtml and displays the sidebar all wonky down at the bottom of the page.</p>
<p>So why didn&#8217;t I (or maybe the author) notice this earlier?  Well, it&#8217;s only broken when you&#8217;re not logged in! I&#8217;ve been doing most of my development so far while logged in, either as myself or as admin, so the bug just wasn&#8217;t occurring.  It&#8217;s also possible that he sidebar was off the bottom of my browser window and consequently I wasn&#8217;t seeing how broken it was when I was viewing the first couple of posts.  Who knows?  But now it&#8217;s gonna be out in the open for a while until I can fix it.</p>
<p>(Interestingly, the bug also doesn&#8217;t manifest itself at the <a href="http://www.creativebits.it/demo/?theme=miniBits">demo site</a>.  The author freely admits that the theme has only been tested with WordPress 2.1 and hasn&#8217;t been maintained for a while.  Could version compatability be the culprit?)</p>
<p>I also need to do a bit of Internationalization and Localization.  The original author appears to be Italian, and the strings in the program are a mixture of Italian and English. That will actually give me a good &#8220;learn how to do something&#8221; project (as opposed to the more annoying &#8220;bug fix&#8221; project) .</p>
<p>So I&#8217;m pulling the theme code into bzr right now and getting ready to tweak.  Hopefully, I&#8217;ll knock out the sidebar display bug tonight and get the site linked over to okcomputer.org so it can <em>really</em> go live.</p>
<p><strong>UPDATE:</strong>  I found and fixed the bug, and it&#8217;s a PHP classic: mixing your layout code inside conditionals. Down in the comments.php file I found two &lt;/div&gt; tags were inside an if clause when they shouldn&#8217;t have been.  A quick cut &amp; paste moved them below the endif, and things are suddenly looking much better.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewwhitworth.com/2008/01/14/shakedown-cruise/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
