<?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>Defective Semantics &#187; Problems</title>
	<atom:link href="http://scarff.id.au/blog/category/the-struggle/feed/" rel="self" type="application/rss+xml" />
	<link>http://scarff.id.au</link>
	<description>Dean Scarff's perpetual struggle with technology, and other anecdotes</description>
	<lastBuildDate>Sat, 31 Jul 2010 02:44:44 +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>XHTML fixes for the WordPress reCAPTCHA plugin</title>
		<link>http://scarff.id.au/blog/2010/xhtml-fixes-for-the-wordpress-recaptcha-plugin/</link>
		<comments>http://scarff.id.au/blog/2010/xhtml-fixes-for-the-wordpress-recaptcha-plugin/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 16:01:39 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Problems]]></category>
		<category><![CDATA[wordpress xhtml]]></category>

		<guid isPermaLink="false">http://scarff.id.au/?p=456</guid>
		<description><![CDATA[<p>The wp-recaptcha plugin for WordPress breaks when you&#8217;re serving pages as application/xhtml+xml.  I inadvertently broke comments when I installed it (silly me for not testing!).  I&#8217;ve written a patch that fixes it.</p>
<p><span id="more-456"></span></p>
<p>Under firefox, you get an error like:</p>
<pre>
Error: uncaught exception:
[Exception... "Operation is not supported"  code: "9"
 nsresult: "0x80530009 (NS_ERROR_DOM_NOT_SUPPORTED_ERR)"
 location: "http://www.google.com/recaptcha/api/challenge?k=xxx Line: 12"]
</pre>
<p>While under Chrome it&#8217;s</p>
<pre>
Uncaught TypeError: Object #&#60;a Document&#62; has no method 'write'
api.recaptcha.net/challengek=xxx
</pre>
<p>The default javascript API uses <code>document.write</code>, which isn&#8217;t a DOM method and hence is not a method of true XML documents.  It&#8217;s not a new issue either, wp-recaptcha has had a history of breaking XHTML.  The thing is, the WordPress plugin (which uses the PHP library by the recaptcha people) has an option to &#8220;Be XHTML 1.0 Strict compliant&#8221;; but this only fixes the use of iframes!</p>
<p>The real solution is to use the reCAPTCHA&#8230; <a href="http://scarff.id.au/blog/2010/xhtml-fixes-for-the-wordpress-recaptcha-plugin/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>The wp-recaptcha plugin for WordPress breaks when you&#8217;re serving pages as application/xhtml+xml.  I inadvertently broke comments when I installed it (silly me for not testing!).  I&#8217;ve written a patch that fixes it.</p>
<p><span id="more-456"></span></p>
<p>Under firefox, you get an error like:</p>
<pre>
Error: uncaught exception:
[Exception... "Operation is not supported"  code: "9"
 nsresult: "0x80530009 (NS_ERROR_DOM_NOT_SUPPORTED_ERR)"
 location: "http://www.google.com/recaptcha/api/challenge?k=xxx Line: 12"]
</pre>
<p>While under Chrome it&#8217;s</p>
<pre>
Uncaught TypeError: Object #&lt;a Document&gt; has no method 'write'
api.recaptcha.net/challengek=xxx
</pre>
<p>The default javascript API uses <code>document.write</code>, which isn&#8217;t a DOM method and hence is not a method of true XML documents.  It&#8217;s not a new issue either, wp-recaptcha has had a history of <a href="http://rickardandersson.com/recaptcha-and-xhtml">breaking XHTML</a>.  The thing is, the WordPress plugin (which uses the PHP library by the recaptcha people) has an option to &#8220;Be XHTML 1.0 Strict compliant&#8221;; but this only fixes the use of iframes!</p>
<p>The real solution is to use the <a href="http://code.google.com/apis/recaptcha/docs/display.html#AJAX">reCAPTCHA AJAX API</a>, which for whatever reason isn&#8217;t exposed in the PHP library.  You can grab my <a href="http://github.com/p00ya/wp-recaptcha">xml fix for wp-recaptcha</a> from github.</p>
<p><small class="postscript">Updated: pushed fork to github</small></p>
]]></content:encoded>
			<wfw:commentRss>http://scarff.id.au/blog/2010/xhtml-fixes-for-the-wordpress-recaptcha-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Duplicating ggplot axis labels</title>
		<link>http://scarff.id.au/blog/2010/duplicating-ggplot-axis-labels/</link>
		<comments>http://scarff.id.au/blog/2010/duplicating-ggplot-axis-labels/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 14:39:36 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Problems]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[ggplot]]></category>
		<category><![CDATA[R]]></category>

		<guid isPermaLink="false">http://scarff.id.au/?p=392</guid>
		<description><![CDATA[<p>I&#8217;ve been trying for a while to find an elegant solution for duplicating axis ticks and labels in a ggplot chart.  Hadley replied on the ggplot2 mailing list, but a working solution within ggplot2 seems a way off.</p>
<p>The situation is this: imagine you have a faceted plot that is tall enough that the x-axis ticks and labels become obscured (e.g. when using a clipped viewport such as a browser window).  This is particularly destructive when you&#8217;re using an x-scale with manual breaks or a transformation.</p>
<pre class="codeblock R">
library(ggplot2)
g &#60;- ggplot(diamonds, aes(carat, ..density..)) +
   geom_histogram(aes(fill = clarity), binwidth = 0.2) +
   facet_grid(cut ~ .)
print(g)
</pre>
<p>There simply isn&#8217;t a way to repeat the x-axis labels in ggplot2 at the moment without discarding faceting and rendering each facet as a separate ggplot call.  I&#8217;ve seen some examples of selective plotting used to good effect in combining multiple plots&#8230; <a href="http://scarff.id.au/blog/2010/duplicating-ggplot-axis-labels/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been trying for a while to find an elegant solution for duplicating axis ticks and labels in a ggplot chart.  Hadley <a href="http://groups.google.com/group/ggplot2/browse_thread/thread/499e438a7c79994f">replied on the ggplot2 mailing list</a>, but a working solution within ggplot2 seems a way off.</p>
<p>The situation is this: imagine you have a faceted plot that is tall enough that the x-axis ticks and labels become obscured (e.g. when using a clipped viewport such as a browser window).  This is particularly destructive when you&#8217;re using an x-scale with manual breaks or a transformation.</p>
<pre class="codeblock R">
library(ggplot2)
g &lt;- ggplot(diamonds, aes(carat, ..density..)) +
   geom_histogram(aes(fill = clarity), binwidth = 0.2) +
   facet_grid(cut ~ .)
print(g)
</pre>
<p>There simply isn&#8217;t a way to repeat the x-axis labels in ggplot2 at the moment without discarding faceting and rendering each facet as a separate ggplot call.  I&#8217;ve seen some <a href="http://learnr.wordpress.com/2009/05/26/ggplot2-two-or-more-plots-sharing-the-same-legend/">examples of selective plotting</a> used to good effect in combining multiple plots with common elements, but I can&#8217;t find anything applicable to keep consistent scales and binning without duplicating a lot of the (internal) facet and bin logic.</p>
<p><span id="more-392"></span></p>
<p>Instead my best shot was to clone some of the grob elements and redraw them at different locations:</p>
<pre class="codeblock R">
grob &lt;- ggplotGrob(g)
xtext &lt;- getGrob(grob, "layout::axis_h::axis.text", grep = TRUE)
xtext &lt;- editGrob(xtext, gp = gpar(fontsize = 8))
downViewport("background::panels::layout::axis_h-13-3") # ids from grid.ls()
pushViewport(viewport(y = unit(34, "npc"), name = "axis_h_rep-1"))
 grid.draw(xtext)
popViewport()
</pre>
<p>Unfortunately I couldn&#8217;t find a consistent way of querying the grid graphics internals for the measurements necessary to move the &#8220;mirrored&#8221; axis labels to the right place.  The 34 there is a magic number I found with <code>grid.locator()</code> and trial-and-error; it changes depending on the graphics device.  At one point I hoped I could clone the entire <code>axis_h</code> viewport, pry some vertical space from in between the facet panels, and paste the clones in between.  Unfortunately grid layouts don&#8217;t seem to be very mutable once they&#8217;ve been created, and redrawing the text grob seemed like the best I could do to reuse the output.</p>
<p>While looking at the <a href="http://stackoverflow.com/questions/1532535/showing-multiple-axis-labels-using-ggplot2-with-facet-wrap-in-r">stackoverflow answer for the same problem</a>, I came across Harlan&#8217;s assessment:</p>
<blockquote><p>
GGplot&#8217;s philosophy is about doing the right thing with a minimum of customization, which means, naturally, that you can&#8217;t customize things as much as other packages.
</p></blockquote>
<p>This is more significant when contrasted with the context of R itself; in R, <a href="http://www.r-project.org/about.html">the user retains full control</a>.  Coming up against ggplot&#8217;s choice of only exposing high-level primitives often leaves the user with the choice of:</p>
<ul>
<li>accepting The Way ggplot Does Things and not getting what they want</li>
<li>waiting for Hadley to write a patch (next summer, if you&#8217;re lucky?)</li>
<li>wading through ggplot internals so you can duplicate its functionality with <code>plyr</code> and <code>grid</code> calls</li>
<li>abandoning ggplot completely</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://scarff.id.au/blog/2010/duplicating-ggplot-axis-labels/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Debian almquist shell on Mac OS X</title>
		<link>http://scarff.id.au/blog/2010/debian-almquist-shell-on-mac-os-x/</link>
		<comments>http://scarff.id.au/blog/2010/debian-almquist-shell-on-mac-os-x/#comments</comments>
		<pubDate>Tue, 04 May 2010 13:15:35 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Problems]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[dash]]></category>
		<category><![CDATA[mac os x]]></category>

		<guid isPermaLink="false">http://scarff.id.au/?p=342</guid>
		<description><![CDATA[<p>I&#8217;ve recently changed the default shell <code>/bin/sh</code> on my Leopard install to dash from bash.  Why would I do this?  Well, by bash&#8217;s own admission (see BUGS in its manpage), bash is &#8220;too big and too slow&#8221;.  dash is used for /bin/sh by default on Ubuntu nowadays, and it&#8217;s a goal for Debian (supposedly for Lenny, but I can&#8217;t see it noted in the release notes and it&#8217;s only &#8220;confirmed&#8221; in the Lenny goals).  dash is significantly smaller and faster.</p>
<p>Ubuntu and Debian ran into plenty of bashisms when they tried to change, how about Mac OS X?  So far I&#8217;ve found problems with <code>/usr/libexec/path_helper</code> (I just changed the shebang line to <code>#!/bin/bash</code>).  There was also a problem with X11&#8242;s startx, and my patch was quickly committed.</p>
<p>Interestingly enough, when I went to move the sh binary, there are actually two versions of bash in /bin.  Both report</p>
<blockquote><p>GNU bash,</p></blockquote><p>&#8230; <a href="http://scarff.id.au/blog/2010/debian-almquist-shell-on-mac-os-x/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently changed the default shell <code>/bin/sh</code> on my Leopard install to <a href="http://gondor.apana.org.au/~herbert/dash/">dash</a> from bash.  Why would I do this?  Well, by bash&#8217;s own admission (see BUGS in its manpage), bash is &#8220;too big and too slow&#8221;.  dash is used for /bin/sh by default on Ubuntu nowadays, and it&#8217;s a goal for Debian (supposedly for Lenny, but I can&#8217;t see it noted in the release notes and it&#8217;s only &#8220;confirmed&#8221; in the <a href="http://release.debian.org/lenny/goals.txt">Lenny goals</a>).  dash is significantly smaller and faster.</p>
<p>Ubuntu and Debian ran into plenty of bashisms when they tried to change, how about Mac OS X?  So far I&#8217;ve found problems with <code>/usr/libexec/path_helper</code> (I just changed the shebang line to <code>#!/bin/bash</code>).  There was also a problem with X11&#8242;s startx, and my patch was quickly <a href="http://cgit.freedesktop.org/xorg/app/xinit/commit/?id=8464a8ab360b72f6817b19ce99b12f0793fbee74">committed</a>.</p>
<p>Interestingly enough, when I went to move the sh binary, there are actually two versions of bash in /bin.  Both report</p>
<blockquote><p>GNU bash, version 3.2.17(1)-release (i386-apple-darwin9.0)</p></blockquote>
<p>but differ at the binary level (they aren&#8217;t even the same size).  I wonder if Apple tried to optimize their /bin/sh given that it gets more usage.</p>
<p>I built dash-0.5.5.1 from the tarball without a problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://scarff.id.au/blog/2010/debian-almquist-shell-on-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Firefox NS_ERROR_INVALID_POINTER with innerHTML</title>
		<link>http://scarff.id.au/blog/2010/firefox-ns_error_invalid_pointer-with-innerhtml/</link>
		<comments>http://scarff.id.au/blog/2010/firefox-ns_error_invalid_pointer-with-innerhtml/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 04:33:46 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Problems]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[prettify]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://scarff.id.au/?p=329</guid>
		<description><![CDATA[<p>When trying to use prettify here on Defective Semantics I ran into problems with firefox.  Here are the errors from the error console:</p>
<pre class="error">
Error: undefined entity
Error: uncaught exception: [Exception...
 "Component returned failure code: 0x80004003
 (NS_ERROR_INVALID_POINTER) [nsIDOMNSHTMLElement.innerHTML]"
  nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)"
  location: "JS frame :: hxxp://example.net/prettify.js ::
             replaceWithPrettyPrintedHtml :: line 1414"
  data: no]
</pre>
<p>My insistence on trying to use XHTML on the blog is partly to blame.  Prettify tries to add &#8220;&#38;nbsp;&#8221; entities to the source (even if it&#8217;s a pre element) to appease Internet Explorer.  This entity only semi-works in XHTML: I&#8217;ve run into similar problems with some HTML entities not being loaded, because some browsers don&#8217;t load the DTD (which in turn loads the entity sets).  It also appears that while Firefox claims to support HTML latin 1 entities in a document with a PUBLIC XHTML identifier, it doesn&#8217;t actually reparse innerHTML assignments according to those&#8230; <a href="http://scarff.id.au/blog/2010/firefox-ns_error_invalid_pointer-with-innerhtml/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>When trying to use <a href="http://code.google.com/p/google-code-prettify/">prettify</a> here on Defective Semantics I ran into problems with firefox.  Here are the errors from the error console:</p>
<pre class="error">
Error: undefined entity
Error: uncaught exception: [Exception...
 "Component returned failure code: 0x80004003
 (NS_ERROR_INVALID_POINTER) [nsIDOMNSHTMLElement.innerHTML]"
  nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)"
  location: "JS frame :: hxxp://example.net/prettify.js ::
             replaceWithPrettyPrintedHtml :: line 1414"
  data: no]
</pre>
<p>My insistence on trying to use XHTML on the blog is partly to blame.  Prettify tries to add &#8220;&amp;nbsp;&#8221; entities to the source (even if it&#8217;s a pre element) to appease Internet Explorer.  This entity only semi-works in XHTML: I&#8217;ve run into similar problems with some HTML entities not being loaded, because some browsers don&#8217;t load the DTD (which in turn loads the entity sets).  It also appears that while Firefox <a href="https://developer.mozilla.org/en/XML_in_Mozilla#XHTML">claims to support HTML latin 1 entities</a> in a document with a PUBLIC XHTML identifier, it doesn&#8217;t actually reparse innerHTML assignments according to those rules.</p>
<p>My solution is to add a conditional test for XML.  Having a look at the <a href="https://developer.mozilla.org/en/DOM/document">Javascript document object</a> there doesn&#8217;t seem to be a <em>reliable</em> way to detect whether the browser is treating the document as XML from javascript.  My best attempt was:</p>
<pre class="codeblock javascript">
document.xmlVersion &#038;&#038; (document.compatMode=='CSS1Compat');
</pre>
<p>which works for Firefox and Opera.</p>
<p>As a separate issue, Chrome and Safari (and presumably anything WebKit based) don&#8217;t allow assignment of innerHTML for XML documents, giving <code class="error">NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7</code>.<br />
Fixing prettify to use only DOM methods instead of building up a string and assigning it to innerHTML could be a lot of work.  At least this exception, unlike the Firefox error, doesn&#8217;t leave the pretty-printed block in an inconsistent state.</p>
<p>I submitted a patch to the <a href="http://code.google.com/p/google-code-prettify/issues/detail?id=108">prettify issue tracker</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://scarff.id.au/blog/2010/firefox-ns_error_invalid_pointer-with-innerhtml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
