<?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>g:h</title>
	<atom:link href="http://hreidarsson.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://hreidarsson.com</link>
	<description></description>
	<lastBuildDate>Mon, 09 Aug 2010 07:47:49 +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>Titanium: Table view rows of the same class must be alike</title>
		<link>http://hreidarsson.com/2010/08/titanium-table-view-rows-of-the-same-class-must-be-alike/</link>
		<comments>http://hreidarsson.com/2010/08/titanium-table-view-rows-of-the-same-class-must-be-alike/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 07:47:49 +0000</pubDate>
		<dc:creator>gummi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[titanium iphone tableview]]></category>

		<guid isPermaLink="false">http://hreidarsson.com/?p=49</guid>
		<description><![CDATA[When I first started playing with Titanium, I found the &#8220;className&#8221; property of table view rows strange. The documentation describes it as
the class name of the table. each table view cell must have a unique class name if the cell layout is different. however, use the same name for rows that have the same structural [...]]]></description>
			<content:encoded><![CDATA[<p>When I first started playing with Titanium, I found the &#8220;className&#8221; property of table view rows strange. The documentation describes it as</p>
<blockquote><p>the class name of the table. each table view cell must have a unique class name if the cell layout is different. however, use the same name for rows that have the same structural layout (even if the content is different) to provide maximum rendering performance.</p></blockquote>
<p>Fair enough. But after playing with &#8220;real&#8221; iPhone developement for a couple of days, it makes more sense. The className is the row&#8217;s &#8220;reusableIdentifier&#8221; in Cocoa&#8217;s terms. It is used for enabling reuse of row objects, so that when rows move off the screen their instances can be reused.</p>
<p>Thus it makes sense, that as rows are reused, we must make sure that all rows with the same class name have the same structure. I didn&#8217;t realize that earlier, so I had written code like this:</p>
<pre><code>function mapListingToTableViewRow(listing) {
    var row = Ti.UI.createTableViewRow({ height: 53, className: "listing", hasChild: true });

    if (listing.pictures.length > 0) {
        var pic = listing.pictures[0];
        var imageView = Ti.UI.createImageView({ image: pic.url, width: pic.width, height: pic.height, left: 0 });
        row.add(imageView);
    }
    var label = Ti.UI.createLabel({ text: listing.title, left: 80 });
    row.add(label);

    return row;
}
</code></pre>
<p>This function builds up a row with the className &#8220;listing&#8221;, always adding a label, but only adding an imageView if there is an image on the listing. Sounds ok, right? What if Cocoa tries to reuse a row that only has a label, for a row that needs both image and a label? The app breaks down. It turned out that the error was in the method updateChildren in the Objective-C class TiUITableViewRowProxy. In particular, it was the  first line in this for-loop that failed:</p>
<pre><code>for (size_t x=0;x<[subviews count];x++)
{
    TiViewProxy *proxy = [self.children objectAtIndex:x];
    TiUIView *uiview = [subviews objectAtIndex:x];
    [self reproxyChildren:proxy view:uiview parent:self touchDelegate:contentView];
}
</code></pre>
<p>The cause was simple: the subviews were two, but the proxy array only contained one object. </p>
<p>Going back to the JavaScript code, this was easy to fix – adding an empty image view did the trick:</p>
<pre><code>
function mapListingToTableViewRow(listing) {
    var row = Ti.UI.createTableViewRow({ height: 53, className: "listing", hasChild: true });

    if (listing.pictures.length > 0) {
        var pic = listing.pictures[0];
        var imageView = Ti.UI.createImageView({ image: pic.url, width: pic.width, height: pic.height, left: 0 });
        row.add(imageView);
    } else {
        row.add(Ti.UI.createImageView({});
    }
    var label = Ti.UI.createLabel({ text: listing.title, left: 80 });
    row.add(label);

    return row;
}
</code></pre>
<p>This problem was driving me crazy a couple of days ago – I almost dropped using Titanium because of that. But after getting an insight into how things work underneath, and by running the Titanium app in debug mode through Xcode, I quickly was able to track down the error. So if you're running into strange breakdowns - fire up Xcode, set it to stop on Objective-C exceptions, and step through the breaking code. Hope you'll have the same luck as I did!</p>
]]></content:encoded>
			<wfw:commentRss>http://hreidarsson.com/2010/08/titanium-table-view-rows-of-the-same-class-must-be-alike/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Controlling the page count in LaTeX</title>
		<link>http://hreidarsson.com/2009/10/controlling-the-page-count-in-latex/</link>
		<comments>http://hreidarsson.com/2009/10/controlling-the-page-count-in-latex/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 23:26:29 +0000</pubDate>
		<dc:creator>gummi</dc:creator>
				<category><![CDATA[typesetting]]></category>
		<category><![CDATA[latex]]></category>

		<guid isPermaLink="false">http://hreidarsson.com/?p=24</guid>
		<description><![CDATA[I&#8217;ve been working on a project which involves generation of simple books for print in LaTeX. The print shop set the requirement that the page count of the PDFs we give them always are multiple of four.
As this is something LaTeX doesn&#8217;t provide out of the box, my first idea was to do some post [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a project which involves generation of simple books for print in LaTeX. The print shop set the requirement that the page count of the PDFs we give them always are multiple of four.</p>
<p>As this is something LaTeX doesn&#8217;t provide out of the box, my first idea was to do some post processing with the PostScript tools that you have on a Unix system. But introducing an extra tool wasn&#8217;t feasible at all: Running LaTeX from a webapp is fragile enough. Fortunately, LaTeX is just a module for TeX, and TeX is nothing but a programming language. So there most definitely is a way for doing this in plain TeX. Unfortunately, programming in TeX is everything but straight forward. Luckily I can&#8217;t resist language challenges&#8230;</p>
<p>And I did it! Here is my LaTeX macro that makes the number of pages in the document a multiple of some number:</p>
<p><script src="http://gist.github.com/205342.js"></script></p>
<p>The loop construct is the tricky part. It&#8217;s of the form</p>
<pre>
\loop
  ...
  \ifsomething...
  ...
\repeat
</pre>
<p>The if-statement in the middle controls whether we continue the loop or break out. Today, most people are probably more used to seeing the above logic written like this:</p>
<pre>
while (something) { .... }
</pre>
<p>A thing to note is that TeX-loops allow for statements to be run both before and after the if-statement is evaluated. Code before the statement is run in each iteration, similar to traditional <code>do {} while (...)</code> loops, but the code after is only run if the if-statement returns true:</p>
<pre>
\loop
  % Code to run in each iteration (do-while style)
  \ifsomething   %
  % Code to run if the if-statement above returned true (while-style)
\repeat
</pre>
<p>Finally, note that the if-statement must not have a closing <code>\fi</code>, as most if-statements in TeX have.</p>
<p>Tip: Finding material on programming in TeX is hard, but the <a href="http://www.amazon.com/TeXbook-Donald-E-Knuth/dp/0201134489">TeXbook</a> provides some help. Deep down in chapter 20 there are some examples of looping and conditionals, which proved to be enough for me.</p>
<p><strong>Update:</strong> kongo09 came up with a more robust solution to this, which also works when resetting the page counter. <a href="#comment-106">See below</a>. Thanks kongo09!</p>
]]></content:encoded>
			<wfw:commentRss>http://hreidarsson.com/2009/10/controlling-the-page-count-in-latex/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Chord progressions – now for the Ukulele</title>
		<link>http://hreidarsson.com/2009/09/chord-progressions-%e2%80%93%c2%a0now-for-the-ukulele/</link>
		<comments>http://hreidarsson.com/2009/09/chord-progressions-%e2%80%93%c2%a0now-for-the-ukulele/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 15:29:41 +0000</pubDate>
		<dc:creator>gummi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://hreidarsson.com/?p=22</guid>
		<description><![CDATA[I&#8217;ve updated my chord progressions page and added Ukulele chords:
Ukulele chord progressions
The progressions currently lack some basic variations, most notably some seventh chords. So that&#8217;s up next!
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve updated my chord progressions page and added Ukulele chords:</p>
<p><a href="http://hreidarsson.com/chords/ukulele.html">Ukulele chord progressions</a></p>
<p>The progressions currently lack some basic variations, most notably some seventh chords. So that&#8217;s up next!</p>
]]></content:encoded>
			<wfw:commentRss>http://hreidarsson.com/2009/09/chord-progressions-%e2%80%93%c2%a0now-for-the-ukulele/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mandolin Chord Progressions</title>
		<link>http://hreidarsson.com/2009/09/mandolin-chord-progressions/</link>
		<comments>http://hreidarsson.com/2009/09/mandolin-chord-progressions/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 13:46:15 +0000</pubDate>
		<dc:creator>gummi</dc:creator>
				<category><![CDATA[music]]></category>
		<category><![CDATA[chords]]></category>
		<category><![CDATA[mandolin]]></category>

		<guid isPermaLink="false">http://hreidarsson.com/?p=16</guid>
		<description><![CDATA[I&#8217;ve just uploaded a hobby project of mine – mandolin chord database. It currently displays standard chord progressions needed to play most songs, e.g. the major chords C-F-G and the accompanying minors Am-Dm-E.
Ukulele and guitar versions coming!
Here it is: Mandolin chord database.
The implementation is pure JavaScript, using the canvas element for displaying the chords.
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just uploaded a hobby project of mine – mandolin chord database. It currently displays standard chord progressions needed to play most songs, e.g. the major chords C-F-G and the accompanying minors Am-Dm-E.</p>
<p>Ukulele and guitar versions coming!</p>
<p>Here it is: <a href="http://hreidarsson.com/chords">Mandolin chord database</a>.</p>
<p>The implementation is pure JavaScript, using the canvas element for displaying the chords.</p>
]]></content:encoded>
			<wfw:commentRss>http://hreidarsson.com/2009/09/mandolin-chord-progressions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Making jQuery code readable</title>
		<link>http://hreidarsson.com/2009/06/making-jquery-code-readable/</link>
		<comments>http://hreidarsson.com/2009/06/making-jquery-code-readable/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 18:26:28 +0000</pubDate>
		<dc:creator>gummi</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[bestpractices]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://hreidarsson.com/?p=4</guid>
		<description><![CDATA[As a long time jQuery user I use many of it&#8217;s features, and much more than just the most basic ones. I love it, especially when I find new tricks to simplify or shorten my code. But my code is most often only read by me.
Recently I&#8217;ve been working with developers new to jQuery, and [...]]]></description>
			<content:encoded><![CDATA[<p>As a long time jQuery user I use many of it&#8217;s features, and much more than just the most basic ones. I love it, especially when I find new tricks to simplify or shorten my code. But my code is most often only read by me.</p>
<p>Recently I&#8217;ve been working with developers new to jQuery, and it has come clear to me that my code – as simple and smooth I find it – is often hard to understand. I&#8217;ve gotten the same looks I would get presenting a Perl-golf program. Ah well, maybe not quite. But you get my point.</p>
<p>I have set to make my code more readable, without making it ugly. Below are a few best-practices I&#8217;ve made for myself.</p>
<h3>Break down long chains</h3>
<p>Here is a typical bit of code I might write:</p>
<pre>$('table')
    .find('.activate').click(function () { activate(this.id) }).end()
    .find('.deactivate').click(function () { deactivate(this.id) }).end()
    .find('a').show();</pre>
<p>Long chains of code tend to use jQuery commands like <code>end</code> and <code>andSelf</code> to modify the wrapped set. Those methods are good to have when you know them, but their semantics can&#8217;t be easily deducted from their names. A long chain performing many tasks can also be harder to walk through than smaller independent bits. So it is wise to break chains down:</p>
<pre>var table = $('table');
$(table).find('.activate').click(function () { activate(this.id) });
$(table).find('.deactivate').click(function () { deactivate(this.id) });
$(table).find('a').show();</pre>
<p>This version – without doubt – lacks the beauty of the chain above, but is more readable, especially to someone unfamiliar.</p>
<h3>Bind events using explicitly using <code>bind</code></h3>
<p>Having the same method to bind and fire an event is bound to confuse – hell, I get confused again and again:</p>
<pre>$('select')
    .change(function () { ... })
    .change();</pre>
<p>Explicitly calling the <code>bind</code> command to bind to the change event is much easier to grasp:</p>
<pre>$('select')
    .bind('change', function () { ... })
    .change();</pre>
<p>This holds for all events who have shortcuts for binding, e.g <code>blur</code>, <code>click</code> and <code>mousedown</code>.</p>
<h3>Clarify what <code>this</code> means</h3>
<p>The <code>this</code> keyword is probably one of the most infamous elements in the JavaScript language. And even when you&#8217;ve gotten fluent in using it, you never can be quite sure it&#8217;s used the same way in the same contexts.</p>
<p>This is a typical code snippet:</p>
<pre>$('a')
    .addClass('logged')
    .bind('click', function() {
        logUrl(this.href);
    });</pre>
<p>What does <code>this</code> point to? This example is that simple, and the <code>href</code> attribute that specific, that it&#8217;s maybe not hard to guess. But in more complex situations it&#8217;s hard to find out.</p>
<p>Copying <code>this</code> to a clearly named variable does a great deal in clarifying what&#8217;s going on:</p>
<pre>$('a')
    .addClass('logged')
    .bind('click', function() {
        var clickedLink = this;
        logUrl(clickedLink.href);
    });</pre>
]]></content:encoded>
			<wfw:commentRss>http://hreidarsson.com/2009/06/making-jquery-code-readable/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
