<?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>Geeks By Nature</title>
	<atom:link href="http://geeksbynature.dk/feed/" rel="self" type="application/rss+xml" />
	<link>http://geeksbynature.dk</link>
	<description>because we just can't help it...</description>
	<lastBuildDate>Wed, 20 Oct 2010 15:29:32 +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>Mormon bubbling made easy &#8211; or why I ported an EEDT from C to Javascript</title>
		<link>http://geeksbynature.dk/2010/10/20/mormon-bubbling-made-easy-or-why-i-ported-an-eedt-from-c-to-javascript/</link>
		<comments>http://geeksbynature.dk/2010/10/20/mormon-bubbling-made-easy-or-why-i-ported-an-eedt-from-c-to-javascript/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 02:04:46 +0000</pubDate>
		<dc:creator>Christian Sonne</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://geeksbynature.dk/?p=92</guid>
		<description><![CDATA[First let us get the terminology straightened out:

Mormon bubbling
The idea came from here (semi-nsfw), and basically entails covering parts of an image to force the viewers brain to fill in the blanks
EEDT
Exact Euclidean Distance Transform

As an avid GIMP&#8217;er (that&#8217;s open source for Photoshop, for those who are wondering) and redditor, I inevitably ended up trying [...]]]></description>
			<content:encoded><![CDATA[<p>First let us get the terminology straightened out:</p>
<dl>
<dt>Mormon bubbling</dt>
<dd>The idea came from <a href="http://forum.bodybuilding.com/showthread.php?t=127185813">here</a> (semi-nsfw), and basically entails covering parts of an image to force the viewers brain to fill in the blanks</dd>
<dt>EEDT</dt>
<dd>Exact Euclidean Distance Transform</dd>
</dl>
<p>As an avid GIMP&#8217;er (that&#8217;s open source for Photoshop, for those who are wondering) and redditor, I inevitably ended up trying my hands at Mormon bubbling. While it wasn&#8217;t difficult as such, it sure was laborious. It got me thinking &#8211; would it be possible to do this algorithmically? The answer it turns out, is yes and no.</p>
<p>My early sketch of how it could be done included calculating a distance map from the parts of the image you didn&#8217;t want shown. I knew this task to be non-trivial, but I also knew that other people had done it before me &#8211; though as I was to find out, not in Javascript.</p>
<p>I settled on an implementation from <a href="http://distance.sourceforge.net/">Animal</a>, more specifically the algorithm called meijster2000. Before I started porting this to Javascript, I noted all the problems I thought I would encounter, such that I would hopefully have an easier time spotting them:</p>
<ul>
<li>Array indexes</li>
<li>Pointers</li>
<li>unsigned variables</li>
</ul>
<p>but as I started the port, it became clear that there was another problem: passing around huge amounts of data. In C that&#8217;s just a pointer, but in Javascript that would quickly end up hurting the performance. Instead, I opted to deviate slightly from the C version, and make it Object Oriented, which would let me attach the relevant functions to the image object, and keep the data in one place. After some hours work, I had an algorithm that ran in as far as it didn&#8217;t have any syntactical or runtime errors. It just didn&#8217;t exactly do what it should either. On the way to figure out why, I ran into amongst other things a <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=604905">Firefox bug</a> that reduced my performance by about 1000%, and not reading the <a href="https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/doc/spec/TypedArray-spec.html">specs</a> carefully enough on typed arrays also lead me to one of the most elusive bugs I&#8217;ve had to deal with in Javascript.</p>
<h2>Working with typed arrays</h2>
<p>For those of you who do not know how Array.slice() works, here is an excerpt from <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/slice">MDC</a>:</p>
<blockquote><p>Returns a one-level deep copy of a portion of an array.</p></blockquote>
<p>Not having carefully read the rest of the document (for neither Array or typed arrays) this is all I knew &#8211; that and experience from using it over the years. This oversight led me to believe that both of these examples would return true:</p>
<pre>var foo = Array(0,1,2,3,4); var bar = foo.slice(0,5); foo[0]=42; bar[0]==0
var foo = Float64Array(0,1,2,3,4); var bar = foo.slice(0,5); foo[0]=42; bar[0]==0</pre>
<p>However as it turns out, in the latter example bar[0]==42, and that took me hours to spot.</p>
<p>I will note that typed arrays do make a significant difference in speed, so as long as you know what you are doing, use them whenever you can!</p>
<h2>A missing difference</h2>
<p>It also turned out that I had completely missed one important difference between <tt>unsigned u</tt> and <tt>var u</tt> namely that the Javascript variable is not constrained to being an integer (remember I already took care of the unsignedness because I had that on my list) &#8211; luckily I didn&#8217;t have any other plans for he weekend, which left me plenty of time to debug.</p>
<h2>Other biproducts</h2>
<p>To create the UI needed for the project, I also created a drop in canvas editor with unlimited undo, and a small lib to make receiving files via drag and drop easier. Both of these could use more features, and I plan on working more on them and describing them in separate posts at a later time. For now, along with my image library, they can be scrounged from the <a href="http://bitbucket.org/cers/bublthis">source code</a> of my bubbler.</p>
<p>In addition to my own creations, I also included the work of several others, including <a href="http://acko.net/dev/farbtastic">Farbtastic</a> (a color picker by Steven Wittens) and <a href="http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html">StackBlur</a> (a blur algorithm for canvas by Mario Klingemann, slightly modified for my needs).</p>
<h2>The bubbling algorithm</h2>
<p>The idea is fairly simple. Ask the user to mark out which parts of the image he doesn&#8217;t want shown, place a bubble as far away as possible from all markings, include the bubble as a marking, repeat. I&#8217;ve set a limit of 30 bubbles, and it stops placing bubbles if the radius of the biggest possible bubble is less than 2.</p>
<p>This is a very naive algorithm, that doesn&#8217;t take into account that there might be places you really want shown and others you don&#8217;t really care about. The biggest possible bubble wins. I might extend the algorithm to let users place a few bubbles themselves before filling in the rest, or possibly even letting the user place all the bubbles by hand, restricted in size by the distance map.</p>
<h2>Demo</h2>
<p>Here is a <a href="http://geeksbynature.dk/BublThis/">live demo</a> of the project, instructions can be found in the bottom left corner. While it should work in most recent browsers, the best experience can be found in Firefox 4b6, as later nightlies suffer from aforementioned bug making them fairly slow, and chrome is quite a bit slower when it comes to canvas manipulations and slightly slower calculating the distance maps. It does not appear to work in Safari, but I am not sure why.</p>
]]></content:encoded>
			<wfw:commentRss>http://geeksbynature.dk/2010/10/20/mormon-bubbling-made-easy-or-why-i-ported-an-eedt-from-c-to-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Common pitfalls of jetpack.tabs events</title>
		<link>http://geeksbynature.dk/2010/03/13/common-pitfalls-of-jetpack-tabs-events/</link>
		<comments>http://geeksbynature.dk/2010/03/13/common-pitfalls-of-jetpack-tabs-events/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 16:45:54 +0000</pubDate>
		<dc:creator>Christian Sonne</dc:creator>
				<category><![CDATA[Jetpack]]></category>

		<guid isPermaLink="false">http://geeksbynature.dk/?p=82</guid>
		<description><![CDATA[These are a few mistakes I&#8217;ve caught myself and others making over and over, often causing very weird behaviour that may cause you to question jetpack&#8217;s sanity &#8211; or even your own.
Where am I?
A common mistake I&#8217;ve seen repeated several times (and caught myself making a few times too) goes something like this:
// Displays the [...]]]></description>
			<content:encoded><![CDATA[<p>These are a few mistakes I&#8217;ve caught myself and others making over and over, often causing very weird behaviour that may cause you to question jetpack&#8217;s sanity &#8211; or even your own.</p>
<h2>Where am I?</h2>
<p>A common mistake I&#8217;ve seen repeated several times (and caught myself making a few times too) goes something like this:</p>
<pre>// Displays the page url when it loads
jetpack.tabs.onReady(function(){
  jetpack.notifications.show(jetpack.tabs.focused.url);
});
</pre>
<p>Did you spot the mistake? This is a very concise example, so even if you did, you might not have in a larger more complicated script. The problem is of course, that the currently focused tab, might not have anything to do with the tab that fired the <em>onReady</em> event (the same goes for <em>onFocus</em> of course, though in the latter case, you can argue with slightly higher confidence that the event is probably fired by the currently focused tab.)</p>
<p>So how do you know where you are? the callback function is passed a single variable, but that is a reference to the document, and thus not of much use in this matter. Instead, you should use <em>this.url</em>, so the correct version becomes:</p>
<pre>// Displays the page url when it loads
jetpack.tabs.onReady(function(){
  jetpack.notifications.show(this.url);
});
</pre>
<h2>Where&#8217;s the content?</h2>
<p>This question usually stems from one of two issues. If you&#8217;re trying to access javascript objects in the document, you need to use the JSObject wrapper like so:</p>
<pre>jetpack.tabs.onReady(function(doc){doc.JSObject.myVar});
</pre>
<p>But this might fail too, if the object isn&#8217;t defined in the main document, but is loaded via a script tag or similar. <em>onReady </em>is triggered before external scripts (and frames, images, etc) are loaded, which means that a lot of content might not yet be available at run time. The remedy, according to the tutorial,  is to use onLoad instead, transforming the example thus</p>
<pre>jetpack.tabs.onLoad(function(doc){doc.JSObject.myVar});
</pre>
<p>however, there is no such thing as <em>jetpack.tabs.onLoad</em>. Why it is in the tutorial, no-one seems to know.</p>
<p>So how do you do it? My best attempt is this:</p>
<pre>function doStuff(doc) {
  var window = this;
  window.alert("test");
  $(doc).find("body").css("background","red");
};
jetpack.tabs.onReady(function(doc){
  $(this.contentWindow).load(function(){doStuff(doc);});
  if (doc.readyState == "complete") {
    doStuff(doc);
  }
});
</pre>
<p>But that doesn&#8217;t work either, and I&#8217;m not sure why. If anyone has a way that actually works, I&#8217;d appreciate a comment.</p>
<h2>API inconsistencies</h2>
<p>Unlike <em>onReady,</em> <em>onFocus</em> does not pass a reference to the document to the callback function. This &#8220;feature&#8221; usually shows itself when you attempt something like this:</p>
<pre>function showTitle(doc) {
  jetpack.notifications.show(doc.title);
}
jetpack.tabs.onFocus(showTitle);
jetpack.tabs.onReady(ShowTitle);
</pre>
<p>Unfortunately, it is way too easy to forget to treat these events differently, and not always obvious what mistake you&#8217;ve made afterwards. The solution is to either change <em>showTitle</em> to this:</p>
<pre>function showTitle() {
  jetpack.notifications.show(this.contentDocument.title);
}
</pre>
<p>or the call to <em>onFocus</em> to this:</p>
<pre>jetpack.tabs.onFocus(function() showTitle(this.contentDocument));
</pre>
]]></content:encoded>
			<wfw:commentRss>http://geeksbynature.dk/2010/03/13/common-pitfalls-of-jetpack-tabs-events/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>QR Code Generator in Firefox</title>
		<link>http://geeksbynature.dk/2009/11/11/qr-code-generator-in-firefox/</link>
		<comments>http://geeksbynature.dk/2009/11/11/qr-code-generator-in-firefox/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 03:15:04 +0000</pubDate>
		<dc:creator>Christian Sonne</dc:creator>
				<category><![CDATA[Ubiquity]]></category>

		<guid isPermaLink="false">http://geeksbynature.dk/?p=67</guid>
		<description><![CDATA[Some hours ago, a reddit user suggested an extension for Firefox that I thought would be a good example of why Jetpack is going to change the way users think about modifying their browser experience.
It took me literally minutes to complete this extension, and all in 7 lines of code. I can&#8217;t seem to make [...]]]></description>
			<content:encoded><![CDATA[<p>Some hours ago, a reddit user <a href="http://www.reddit.com/r/firefox/comments/a2wqk/hey_firefox_subreddit_i_have_an_idea_for_a/">suggested an extension</a> for Firefox that I thought would be a good example of why <a href="https://jetpack.mozillalabs.com/">Jetpack</a> is going to change the way users think about modifying their browser experience.</p>
<p>It took me literally minutes to complete this extension, and all in <a href="http://geeksbynature.dk/uploads/qrcode/qrcode.js">7 lines of code</a>. I can&#8217;t seem to make wordpress play along, so go to <a href="http://geeksbynature.dk/uploads/qrcode/">this page</a> and click &#8220;install&#8221; to try it out.</p>
<p>This is how easy modifying your browser should be. This is how easy it is going to be for everyone in the not too distant future. Jetpack is here to stay!</p>
<p>Note: other people have written similar extensions the old fashioned way (<a href="https://addons.mozilla.org/en-US/firefox/addon/2780">Mobile Barcoder</a>, and probably other), however this is an illustration on how easy it can be to do it yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://geeksbynature.dk/2009/11/11/qr-code-generator-in-firefox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello World! (polyglot edition)</title>
		<link>http://geeksbynature.dk/2009/10/23/hello-world-polyglot-edition/</link>
		<comments>http://geeksbynature.dk/2009/10/23/hello-world-polyglot-edition/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 05:32:54 +0000</pubDate>
		<dc:creator>Christian Sonne</dc:creator>
				<category><![CDATA[Ubiquity]]></category>

		<guid isPermaLink="false">http://geeksbynature.dk/?p=61</guid>
		<description><![CDATA[Sparked from a conversation I had with a friend and fellow programmer some odd hours ago, I decided it would be fun to try to make a program that would run in more than one language. Initially, I thought of Brainf*ck and C(++), but my friend suggested I add Whitespace to the mix too. As [...]]]></description>
			<content:encoded><![CDATA[<p>Sparked from a conversation I had with a friend and fellow programmer some odd hours ago, I decided it would be fun to try to make a program that would run in more than one language. Initially, I thought of <a href="http://en.wikipedia.org/wiki/Brainfuck">Brainf*ck</a> and C(++), but my friend suggested I add <a href="http://en.wikipedia.org/wiki/Whitespace_(programming_language)">Whitespace</a> to the mix too. As it turned out, I managed to throw in Python as well.</p>
<p>After some kind people in #esoteric@irc.freenode.net (I joined originally because it was my first foray into the madness that  is Whitespace) told me that this is what is called a <a href="http://en.wikipedia.org/wiki/Polyglot_(computing)">polyglot</a>, they helped me shave the last fat off and <a href="http://geeksbynature.dk/uploads/helloworld.ws.bf.py.cpp">this is the result</a>. A 384 byte &#8220;Hello World!\n&#8221; that works in Brainf*ck, Whitespace, Python and C++. Not the worst thing I&#8217;ve spent a sleepless night on.</p>
<p>As for acknowledgements, I admit that the bf version was one I had lying around, and I don&#8217;t know if it was my own or someone else&#8217;s. I did the ws version myself because I couldn&#8217;t find a working version anywhere. I do owe thanks to coppro and immibis from #esoteric, they were most helpful in the final stages of the process.</p>
<p>UPDATE: reddit users <a href="http://www.reddit.com/r/programming/comments/9xpa7/hello_world_polyglot_in_python_c_whitespace_and/c0ey05e">mallardtheduck</a>, <a href="http://www.reddit.com/r/programming/comments/9xpa7/hello_world_polyglot_in_python_c_whitespace_and/c0expy5">isionous and youreameme</a> have suggested further enhancements, which have resulted in shaving off a further 28  bytes, so here is an <a href="http://geeksbynature.dk/uploads/helloworld_reddit.ws.bf.py.cpp">updated version</a> weighing in at 356 bytes. Many thanks, reddit!</p>
]]></content:encoded>
			<wfw:commentRss>http://geeksbynature.dk/2009/10/23/hello-world-polyglot-edition/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Breaking &#8220;The Next Big Thing in CAPTCHAs&#8221;</title>
		<link>http://geeksbynature.dk/2009/10/16/breaking-the-next-big-thing-in-captchas/</link>
		<comments>http://geeksbynature.dk/2009/10/16/breaking-the-next-big-thing-in-captchas/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 23:45:53 +0000</pubDate>
		<dc:creator>Christian Sonne</dc:creator>
				<category><![CDATA[Ubiquity]]></category>

		<guid isPermaLink="false">http://geeksbynature.dk/?p=49</guid>
		<description><![CDATA[I just stumbled upon this article (since taken down, see google  cache) by Catch My Fame, and figured I would take him up on the challenge to break it. It was a good opportunity to play around with canvas and bookmarklets, neither of which I had tried before.
I won&#8217;t bore you with too many [...]]]></description>
			<content:encoded><![CDATA[<p>I just stumbled upon this <a title="The Next Big Thing in CAPTCHAs" href="http://www.catchmyfame.com/2009/10/14/the-next-big-thing-in-captchas/">article</a> (since taken down, see <a href="http://74.125.155.132/search?q=cache:nq1_85EP12sJ:www.catchmyfame.com/2009/10/14/the-next-big-thing-in-captchas/">google  cache</a>) by Catch My Fame, and figured I would take him up on the challenge to break it. It was a good opportunity to play around with canvas and bookmarklets, neither of which I had tried before.</p>
<p>I won&#8217;t bore you with too many details, but the gist of it all is to transfer the image into canvas, then do some edge matching and figure out the best solution.</p>
<p>Without further ado, here are the solutions as a <a href="http://geeksbynature.dk/uploads/breakSlide.html">bookmarklet</a> (follow the link to see it, WordPress wouldn&#8217;t let me link directly) and as a <a title="breakSlide" href="http://gist.github.com/211389">Ubiquity command</a></p>
<p>It does have it&#8217;s limits, but I&#8217;ve only seen it fail once, so it has a success rate of about 98% (which is better than my success rate when using Facebook&#8217;s CAPTCHA.) Also, I have only tested in Firefox, so no promises if you&#8217;re using something else.</p>
<p>If you want to understand what&#8217;s going on, I&#8217;d advise you to look at the Ubiquity command first; very little is related to Ubiquity.</p>
<p>Does this mean I caught his fame? <img src='http://geeksbynature.dk/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>UPDATE: It appears Mr. Catch My Fame didn&#8217;t want to display his post touting a broken CAPTCHA system, so he took the post down &#8211; the demo is still up, so if you hurry you can still see it in action: <a href="http://www.catchmyfame.com/jquery/slider_captcha/">http://www.catchmyfame.com/jquery/slider_captcha/</a></p>
<p>UPDATE 2: I have made a small change in the fitness function, making it much more reliable &#8212; you can track changes by looking at the Ubiquity command at github</p>
<p>UPDATE 3: The demo has since also been taken down, but as they say, once burned twice shy, and I made a copy well in advance: <a href="http://geeksbynature.dk/uploads/sliderCAPTCHA/">sliderCAPTCHA</a>. Also, the original blog post appears in <a href="http://74.125.155.132/search?q=cache:nq1_85EP12sJ:www.catchmyfame.com/2009/10/14/the-next-big-thing-in-captchas/">google cache</a> (thanks <a href="http://www.reddit.com/r/programming/comments/9uiy3/breaking_a_really_slick_new_idea_in_captchas/c0eih5o">semanticist</a>/Reddit)</p>
]]></content:encoded>
			<wfw:commentRss>http://geeksbynature.dk/2009/10/16/breaking-the-next-big-thing-in-captchas/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Bespin in Ubiquity and Jetpack</title>
		<link>http://geeksbynature.dk/2009/09/21/bespin-in-ubiquity-and-jetpack/</link>
		<comments>http://geeksbynature.dk/2009/09/21/bespin-in-ubiquity-and-jetpack/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 14:44:26 +0000</pubDate>
		<dc:creator>Christian Sonne</dc:creator>
				<category><![CDATA[Ubiquity]]></category>

		<guid isPermaLink="false">http://geeksbynature.dk/?p=40</guid>
		<description><![CDATA[Lately I&#8217;ve been spending some time working on Bespin integration in Jetpack and Ubiquity. &#8220;But Jetpack already had Bespin support!&#8221; some of you might think, an yes it did &#8211; but only for people running OSX. The rest of us was stuck with a textarea, styled to look slightly like Bespin (and indeed, most people [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I&#8217;ve been spending some time working on Bespin integration in Jetpack and Ubiquity. <em>&#8220;But Jetpack already had Bespin support!&#8221;</em> some of you might think, an yes it did &#8211; but only for people running OSX. The rest of us was stuck with a textarea, styled to look slightly like Bespin (and indeed, most people didn&#8217;t even notice it wasn&#8217;t the real one). Ubiquity had CodeMirror for certain version of Firefox, but for most users it would be disabled due to an incompatibility between later versions of Firefox (3.1b1+ I think) and the CodeMirror project.</p>
<p>The problem &#8212; and the reason Ubiquity didn&#8217;t change over sooner &#8212; was that the official version of Bespin embedded was running a quite old Bespin (0.2.2), while the current version is 0.4.3, and the former didn&#8217;t support clipboard copy/paste in anything but OSX.</p>
<p>Long story short: a few bugs later and a lot of help from some very friendly Bespin devels (thanks Alex and Kevin!), inquisitive readers can now try out Bespin 0.4.3 in <a title="Bespin in Jetpack" href="https://bugzilla.mozilla.org/show_bug.cgi?id=517441">Jetpack</a> and <a title="Bespin in Ubiquity" href="http://users.skumleren.net/cers/ubiquity-bespin.diff">Ubiquity</a>. It will require you to apply patches by hand against the latest development versions of the relevant project, or wait until the changes land.</p>
<p>EDIT: <a title="Bespin in Ubiquity with useful settings" href="http://users.skumleren.net/cers/ubiquity-bespin-closepairs.diff">here</a> is an updated version of the Ubiquity Bespin patch, that includes autoindent, closepairs, and other useful settings.</p>
<p>Feedback (and bug reports) would be greatly appreciated.</p>
]]></content:encoded>
			<wfw:commentRss>http://geeksbynature.dk/2009/09/21/bespin-in-ubiquity-and-jetpack/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to track changes in the localization process</title>
		<link>http://geeksbynature.dk/2009/06/30/how-to-track-changes-in-the-localization-process/</link>
		<comments>http://geeksbynature.dk/2009/06/30/how-to-track-changes-in-the-localization-process/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 00:42:19 +0000</pubDate>
		<dc:creator>Christian Sonne</dc:creator>
				<category><![CDATA[Ubiquity]]></category>

		<guid isPermaLink="false">http://geeksbynature.dk/?p=35</guid>
		<description><![CDATA[Now that Ubiquity 0.5 is on the verge of release, we have scrambled to demonstrate the localization-possibilities by including a couple of alternative languages for the standard feeds (and for the new parser.)
By the looks of it, the languages Catalan, Danish and Japanese are going to make it in, but we hope more will join [...]]]></description>
			<content:encoded><![CDATA[<p>Now that Ubiquity 0.5 is on the verge of release, we have scrambled to demonstrate the localization-possibilities by including a couple of alternative languages for the standard feeds (and for the new parser.)</p>
<p>By the looks of it, the languages Catalan, Danish and Japanese are going to make it in, but we hope more will join them before the 0.6 release.</p>
<p>Being a localizer myself (I did the Danish translation) I know the pain of keeping up with ever-changing-, new- and deleted keys. Mostly for my own benefit, I have put together a script that helps you track changes  between the templates and the translations. If you place <a href="http://geeksbynature.dk/ubiquity/localization.py">this script</a> in your ubiquity/localization/ folder and run it, it should list relevant information for each language.</p>
<h3>Examples:</h3>
<p>If you want all the information, simply run the script:</p>
<pre>python localization.py</pre>
<p>In the current development version, this produces quite a lot of output, so I&#8217;ll paste a representative section only:</p>
<pre>$ python localization.py
! Missing translation: da/developer.po
! 2 keys are missing in pageedit(da):
----------------------------------------------------
["If you used the 'edit page' command to put the page into editable mode, use this command to end that mode and go back to normal page viewing. If you want the changes to persist on page reload, issue the 'save' command first."]
----------------------------------------------------
["Saves edits you've made to this page in an annotation. They will persist on page reload. You can remove them with the 'undo page edits' command."]
----------------------------------------------------
! 2 keys are superfluous in pageedit(da):
----------------------------------------------------
["If you used the 'edit page' command to put the page into editable mode, use this command to end that mode and go back to normal page viewing."]
----------------------------------------------------
["Saves edits you've made to this page in an annotation. Undo with the 'undo page edits' command."]
----------------------------------------------------</pre>
<p>If you just want an overview and not all the details (I imagine this will be useful for project leaders) you can run the command:</p>
<pre>python localization.py | grep -E ^\!</pre>
<p>which again produces a lot of information but looks something like:</p>
<pre>$ python localization.py | grep -E ^\!
! Missing translation: da/developer.po
! 2 keys are missing in pageedit(da):
! 2 keys are superfluous in pageedit(da):
! 1 keys are missing in email(da):
! 1 keys are superfluous in email(da):</pre>
<h3>The future</h3>
<p>The script is not yet added to the ubiquity source distribution, as there are still a lot of changes that I feel need to go in before it is production-ready. I plan to integrate more options into the script, making it easier to get the overview, getting info about only one language, or about only one template. It will also become smarter, and realize when a key has changed, and what it has changed to. Currently as the above example show, it lists each as a missing and superfluous key. As the deadline for 0.5 is looming, I don&#8217;t expect it to be ready by then.</p>
<p>For the adventurous localizer, I do think it will already in its present state be a big help, so feel free to try it out and report back with any suggestions, improvements or bugs you may encounter.</p>
<p>Happy hacking and translating,</p>
<p>&#8211; cers / Christian Sonne</p>
]]></content:encoded>
			<wfw:commentRss>http://geeksbynature.dk/2009/06/30/how-to-track-changes-in-the-localization-process/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Making a search command &#8211; part 3</title>
		<link>http://geeksbynature.dk/2009/02/26/making-a-search-command-part-3/</link>
		<comments>http://geeksbynature.dk/2009/02/26/making-a-search-command-part-3/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 15:27:14 +0000</pubDate>
		<dc:creator>Christian Sonne</dc:creator>
				<category><![CDATA[Ubiquity]]></category>

		<guid isPermaLink="false">http://geeksbynature.dk/?p=30</guid>
		<description><![CDATA[Another couple of days have passed, so another round of updates is in order. Some of the changes I&#8217;ll mention here affect the previous articles: Making a search command &#8211; the easy way! and Making a search command &#8211; part 2, so if you&#8217;ve read them: read this one too!
This is the part that broke [...]]]></description>
			<content:encoded><![CDATA[<p>Another couple of days have passed, so another round of updates is in order. Some of the changes I&#8217;ll mention here affect the previous articles: <a href="http://geeksbynature.dk/?p=4">Making a search command &#8211; the easy way!</a> and <a href="http://geeksbynature.dk/?p=24">Making a search command &#8211; part 2</a>, so if you&#8217;ve read them: read this one too!</p>
<h3>This is the part that broke your commands</h3>
<p>And in more than one way. If you&#8217;ve tried some of the commands before the recent updates, you might have noticed that for some reason, certain queries wouldn&#8217;t return any previews, while other would work just fine. This is because some search engines return &#8220;strange&#8221; results in the middle of the normal results &#8211; and only do it sometimes &#8211; but the only way the parser knew which titles, previews and thumbnails fit together, was by their index in each of their own lists. This was a very fragile system, and while it it still available as fallback, using it isn&#8217;t recommended.</p>
<p>The main difference is that the parameter <code>options.parser.container</code> should no longer select the element that contains <em>all</em> the results, but rather it should select a list containing <em>each</em> result. Each results title, preview and thumbnail will then be found (if available) inside the result, and grouping is no longer dependant on indexes. This means that any given result can have a missing preview or thumbnail, and it won&#8217;t affect any of the others.</p>
<p>Obviously, changing the meaning of the parameter means you will have to rewrite any search command you have that uses it. I hope the benefit of stability will outweigh this initial annoyance.</p>
<h3>JSON as promised</h3>
<p>In my last post, I said I was going to be working on JSON support, and as of about 4 hours ago, initial support has landed in hg. I have successfully rewritten our default google and yahoo commands to use this new system, and still use the JSON API provided by the services, but as I don&#8217;t have much experience with this sort of interface, it is entirely possible that I have in some way limited the functionality and thus the compatibility with some services. If this is the case, the JSON support will of course be expanded.</p>
<p>A slight note on the usage is perhaps needed here. Let us take google as an example:</p>
<pre><code>CmdUtils.makeSearchCommand({
  name: "Google",
  url: "http://www.google.com/search?q={QUERY}",
  parser: {type: "JSON",
           url: "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&amp;q={QUERY}",
           container: "responseData.results",
           title: "titleNoFormatting",
           preview: "content",
           href: "url"}
});
</code></pre>
<p>First you might notice that there are two fields called <code>url</code>, one outside the parser and one inside. In that order, the first one does exactly what it usually did, except it&#8217;s only used if the user presses return to go directly to the search page. The second is the one used for the actual searching if you pass <code>type: "JSON"</code> to the parser. If the API requires you to use POST, this works the same way as you&#8217;re used to.</p>
<p>Secondly, if you happen to be uncannily familiar with the structure of the JSON google returns, you might notice that the container parameter I talked about earlier in this very post doesn&#8217;t seem to be pointing to each result. Instead, it&#8217;s pointing to the container of all the results. If you think about it however, in the HTML-case, jQuery makes sure we are returned a list of results, but in JSON, the parent element holding the results is already a list of results &#8211; so it sort of makes sense.</p>
<p>The only other new thing is the addition of the <code>options.parser.href</code> parameter, which was automatically calculated in the HTML version. In JSON, the url is usually held in a separate field, so this is needed to make sure we actually link to the results.</p>
<h3>What you can do to speed things up</h3>
<p>These changes that break backward compatibility will happen less often &#8211; or hopefully not at all &#8211; if I get fast feedback and suggestions. The more you complain, the more likely I am to do something about it fast <img src='http://geeksbynature.dk/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> </p>
<p>To try these changes out, run Ubiquity from source, or wait for 0.1.7 or 0.2pre15 where they will most likely be included.</p>
]]></content:encoded>
			<wfw:commentRss>http://geeksbynature.dk/2009/02/26/making-a-search-command-part-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Making a search command &#8211; part 2</title>
		<link>http://geeksbynature.dk/2009/02/23/making-a-search-command-part-2/</link>
		<comments>http://geeksbynature.dk/2009/02/23/making-a-search-command-part-2/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 14:09:32 +0000</pubDate>
		<dc:creator>Christian Sonne</dc:creator>
				<category><![CDATA[Ubiquity]]></category>

		<guid isPermaLink="false">http://geeksbynature.dk/?p=24</guid>
		<description><![CDATA[A few days have passed since my first post Making a search command &#8211; the easy way!, and a few new features have been implemented, most of which were suggested by readers &#8211; so keep up filling the suggestion box!
Picture this
Most notably, it is now possible to include a thumbnail in the preview, which will [...]]]></description>
			<content:encoded><![CDATA[<p>A few days have passed since my first post <a href="http://geeksbynature.dk/?p=4">Making a search command &#8211; the easy way!</a>, and a few new features have been implemented, most of which were suggested by readers &#8211; so keep up filling the suggestion box!</p>
<h3>Picture this</h3>
<p>Most notably, it is now possible to include a thumbnail in the preview, which will be automatically formatted and inserted to the left of the preview text. This is especially useful for search-sites which display images to help identify the result &#8211; such as books, cd, movies, etc&#8230;</p>
<p>As an example, here is the Wikipedia command redone with this enhancement:</p>
<pre><code>CmdUtils.makeSearchCommand({
  name: "Amazon",
  url: "http://www.amazon.com/s/ref=nb_ss_gw?url=search-alias%3Dstripbooks&amp;field-keywords={QUERY}",
  parser: {container: "div.listView",
           title: "div.productTitle a",
           preview: "div.productTitle span.ptBrand",
           thumbnail: "div.productImage"}
});</code></pre>
<p>You will also note the lack of an icon and description, but if you try it out (in latest source) you&#8217;ll see that it makes no difference. If left out, they are automatically generated from url and name respectively.</p>
<div id="attachment_25" class="wp-caption aligncenter" style="width: 310px"><a href="http://geeksbynature.dk/wp-content/uploads/2009/02/search_with_thumbnail.png"><img class="size-medium wp-image-25" src="http://geeksbynature.dk/wp-content/uploads/2009/02/search_with_thumbnail-300x208.png" alt="Search preview with thumbnails" width="300" height="208" /></a><p class="wp-caption-text">Search preview with thumbnails</p></div>
<h3>Correcting errors</h3>
<p>Some sites (like Amazon) have a tendency to return weird results in the middle of the set, without any real indication that it isn&#8217;t an actual result, and this can cause the parser to become confused (say, if the number of titles and the number of preview do not match up, which belongs to which?), and before, it would give you a warning in console and then most likely die before returning any output to the user. Now, it will fall back to just supplying a list of titles, and explain to the user why the previews are missing.</p>
<div id="attachment_26" class="wp-caption aligncenter" style="width: 310px"><a href="http://geeksbynature.dk/wp-content/uploads/2009/02/search_thumbnail_error.png"><img class="size-medium wp-image-26" src="http://geeksbynature.dk/wp-content/uploads/2009/02/search_thumbnail_error-300x208.png" alt="Search with broken preview" width="300" height="208" /></a><p class="wp-caption-text">Search with broken preview</p></div>
<h3>What&#8217;s next?</h3>
<p>The next thing I&#8217;ll be looking into, is allowing makeSearchCommand to use services that return JSON encoded data. This will enable us to use APIs made public by many search engines instead of scraping the HTML, and is a feature that has not only been requested by early adopters, but will also make it possible (and/or easier) to switch over to this new parser system for all of our default search commands.</p>
<p>As usual, I encourage you all to try out the new features, and see if anything breaks or behaves unexpectedly. And of course, if they do: let me know! <img src='http://geeksbynature.dk/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://geeksbynature.dk/2009/02/23/making-a-search-command-part-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Making a search command &#8211; the easy way!</title>
		<link>http://geeksbynature.dk/2009/02/20/making-a-search-command-the-easy-way/</link>
		<comments>http://geeksbynature.dk/2009/02/20/making-a-search-command-the-easy-way/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 01:40:24 +0000</pubDate>
		<dc:creator>Christian Sonne</dc:creator>
				<category><![CDATA[Ubiquity]]></category>

		<guid isPermaLink="false">http://geeksbynature.dk/?p=4</guid>
		<description><![CDATA[Ubiquity prides itself on not only making it easy for the average user to understand how ubiquity works, but also for making it easy for command authors to enhance it &#8211; and for good reason. Anyone should be able to write a simple command, to make their day just a little less tedious, just a [...]]]></description>
			<content:encoded><![CDATA[<p>Ubiquity prides itself on not only making it easy for the average user to understand how ubiquity works, but also for making it easy for command authors to enhance it &#8211; and for good reason. Anyone should be able to write a simple command, to make their day just a little less tedious, just a little more efficient.</p>
<h3>How it used to be</h3>
<p>Now, making a search command has been very easy for a while, thanks to the excellent work of a handful of the core devels. To show how simple it has been, I&#8217;ll develop a command to search our own trac, and use this process to illustrate the recently added features.</p>
<p>First thing we do, is head over to <a title="Trac" href="https://ubiquity.mozilla.com/trac/">Trac</a> and do a <a title="example search" href="https://ubiquity.mozilla.com/trac/search?q=example">search</a> to see where it takes us. This url is quite human readable:<br />
<code>https://ubiquity.mozilla.com/trac/search?q=example</code><br />
We can then create the search command with this simple code:</p>
<pre><code>CmdUtils.makeSearchCommand({
  name: "Trac",
  url: "https://ubiquity.mozilla.com/trac/search?q={QUERY}",
  icon: "https://ubiquity.mozilla.com/trac/chrome/common/trac.ico",
  description: "Searches Trac for your words."
});</code></pre>
<p>and that would work just fine. Go ahead, try it &#8211; just paste it into your command editor (note: wordpress is refusing to let me link this, so here you go instead: chrome://ubiquity/content/editor.html .) Now just bring up ubiquity and type &#8220;Trac example&#8221; and hit enter &#8211; you should end up at the same place as the link above.</p>
<p>Here is a screenshot of how it looks:</p>
<div id="attachment_6" class="wp-caption alignnone" style="width: 160px"><a href="http://geeksbynature.dk/wp-content/uploads/2009/02/trac.png"><img class="size-thumbnail wp-image-6" src="http://geeksbynature.dk/wp-content/uploads/2009/02/trac-150x150.png" alt="Screenshot of simple Trac search" width="150" height="150" /></a><p class="wp-caption-text">Screenshot of simple Trac search</p></div>
<p>&#8220;But what about a decent preview of the results?&#8221;, I hear you cry, &#8220;like the one the google search has, or wikipedia &#8211; you can even navigate it by using your keyboard!&#8221;. Well here&#8217;s the thing &#8211; those aren&#8217;t that simple to do. The more technically inclined can take a look at how it&#8217;s done <a title="The search standard feed" href="https://ubiquity.mozilla.com/xpi/0.1.6/standard-feeds/search.xhtml">here</a> (note: you have to view source.)</p>
<p>As if this hurdle wasn&#8217;t enough &#8211; we should also be thinking about standardizing the way search commands look and feel. This is key in user experience: <em>consistency</em>.</p>
<h3>Easy does it</h3>
<p>Instead of having the user write a lot of semi-redundant javascript each time he or she wants to make a search command, or indeed at all, it is now possible to pass a simple parser argument to makeSearchCommand which makes Ubiquity do all the hard work for you &#8211; now doesn&#8217;t that sound nice?</p>
<p>The argument is called <em>parser</em>, and is an array of options: (note: this feature has only recently landed in hg, so you&#8217;ll have to run either ubiquity from source, or wait till version 0.1.7 or 0.2pre14, which will almost certainly include this feature)</p>
<dl>
<dt>container</dt>
<dd>a jQuery selector that can help you narrowing in your search for the actual results on the page</dd>
<dt>title</dt>
<dd>a jQuery selector that will match each of the titles in the results</dd>
<dt>preview</dt>
<dd>same as above, except it will match the preview data returned by the search engine (if left out, only titles will be previewed)</dd>
<dt>baseurl</dt>
<dd>a string prepended to the link in the title (should only be passed if the search engine returns relative paths)</dd>
</dl>
<p>Finding the right jQuery selectors to pass is still a bit more technical than what might be expected of the average user, and we hope to alleviate that problem sometime in the future, perhaps with a neat UI that helps you pick out the titles and previews with a simple mouseclick. For now though, let&#8217;s settle for this and move on with the demonstration.</p>
<p>For Trac, where the HTML is fairly clean, finding the right values was a breeze, and for the avid reader wanting to try this out for themselves, I recommend using <a title="Official Firebug website" href="http://http://getfirebug.com/">Firebug</a> along with its &#8220;inspect&#8221; feature.</p>
<p>As soon as we pass the parser option to makeSearchCommand like so:</p>
<pre><code>CmdUtils.makeSearchCommand({
  name: "Trac",
  url: "https://ubiquity.mozilla.com/trac/search?q={QUERY}",
  icon: "https://ubiquity.mozilla.com/trac/chrome/common/trac.ico",
  parser: {container: "dl#results",
           title: "dt",
           preview: "dd.searchable",
           baseurl: "https://ubiquity.mozilla.com"},
  description: "Searches Trac for your words."
});</code></pre>
<p>Will do a pretty good job of emulating all that hard work that would otherwise have gone into creating the preview. Again just paste the above into your command editor, or simply insert the parser argument by hand.<br />
This is a screenshot of the new behaviour:</p>
<div id="attachment_7" class="wp-caption alignnone" style="width: 160px"><a href="http://geeksbynature.dk/wp-content/uploads/2009/02/trac_parser.png"><img class="size-thumbnail wp-image-7" src="http://geeksbynature.dk/wp-content/uploads/2009/02/trac_parser-150x150.png" alt="Trac search with preview" width="150" height="150" /></a><p class="wp-caption-text">Trac search with preview</p></div>
<p>Of course in the future, this might very well be improved upon, better looking template, better error-handling, there are lots of potential improvements out there. And that is where I leave you &#8211; with the freedom to play around with this cool new feature, and the opportunity to help evolve this beyond its current state, and hopefully towards something better for everyone. The easiest way to do this is to try it out on your favourite sites, and report back here any bugs or shortcomings you may find.</p>
]]></content:encoded>
			<wfw:commentRss>http://geeksbynature.dk/2009/02/20/making-a-search-command-the-easy-way/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

