<?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>Otaqui.Com &#187; webdev</title>
	<atom:link href="http://otaqui.com/blog/tag/webdev/feed/" rel="self" type="application/rss+xml" />
	<link>http://otaqui.com/blog</link>
	<description>Pete Otaqui's blog about web development and everything else</description>
	<lastBuildDate>Tue, 31 Jan 2012 23:23:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Simple Javascript Validator Library &#8211; Validator.js</title>
		<link>http://otaqui.com/blog/1076/simple-javascript-validator-library-validator-js/</link>
		<comments>http://otaqui.com/blog/1076/simple-javascript-validator-library-validator-js/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 05:58:36 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=1076</guid>
		<description><![CDATA[I had a need to do some data validation in javascript, and all the libraries I looked at seemed quite opinionated about *what* you were going to validate &#8211; i.e. form data &#8211; let alone the increase in server-side javascript in the last couple of years. My data wasn&#8217;t directly tied to a form, so [...]]]></description>
			<content:encoded><![CDATA[<p>I had a need to do some data validation in javascript, and all the libraries I looked at seemed quite opinionated about *what* you were going to validate &#8211; i.e. form data &#8211; let alone the increase in server-side javascript in the last couple of years. My data wasn&#8217;t directly tied to a form, so it didn&#8217;t quite seem worthwhile trying to shoe horn my needs into what the libraries expected, and I could also see a need for a validation library that could be adapted for Node.</p>
<p>Enter <a href="https://pete-otaqui.github.com/Validator.js">Validator.js</a>.</p>
<p>Validator&#8217;s only dependency is on <a href="http://documentcloud.github.com/underscore.js">underscore.js</a> from Document Cloud.</p>
<p>Validator has two usage forms: the first for very quick and simple one-off cases:</p>
<pre class="brush: javascript">
// Simple use:
var result
result = Validator.isEmail(&#039;not_an_email&#039;);
console.log(result); // false
result = Validator.isEmail(&#039;joe@example.com&#039;);
console.log(result); // true
</pre>
<p>I found this on its own quite a lot more flexible than most of the form-driven libraries out there.  However, I also wanted to be able to create more complex sets of validations to run on a piece of data.  For that case, you create an instance of Validator and use it&#8217;s add() method:</p>
<pre class="brush: javascript">
var result,
    myValidator

myValidator = new Validator();

myValidator.add(&#039;unique&#039;);
myValidator.add(&#039;minLength&#039;, 6);

result = myValidator.validate( [1, 2, 3, 4, 5, 6, 6] );
console.log(result); // false, the array is long enough but contains non-unique members
</pre>
<p>This got me a fair bit closer to what I wanted, but you don&#8217;t know which part failed, so it&#8217;s harder to give reasonable feedback. I added a set of error messages to validator instances which gets populated after a call to validate():</p>
<pre class="brush: javascript">
var result,
    myValidator

myValidator = new Validator();

myValidator.add(&#039;unique&#039;);
myValidator.add(&#039;minLength&#039;, 6);
myValidator.add(&#039;maxLength&#039;, 8);

result = myValidator.validate( [1, 2, 3, 4, 5, 6, 6, 8, 9, 10] );
console.log(result); // false, the array is long enough but contains non-unique members
console.log(myValidator.errors);
/*
myValidator.errors == [
    &#039;The list must be made up of unique items&#039;,
    &#039;The list is too long&#039;
]
*/
</pre>
<p>Again, this is pretty good but even though Validator supports adding messages in any language you want and falling back (by default) to English (see the source code), default error messages still aren&#8217;t always what you need.  I also added the ability to set a custom error message per &#8220;validation&#8221;.</p>
<pre class="brush: javascript">
var result,
    myValidator

myValidator = new Validator();

myValidator.add(&#039;unique&#039;).message(&#039;You are repeating yourself&#039;);
myValidator.add(&#039;minLength&#039;, 6).message(&#039;Too tiny!&#039;);
myValidator.add(&#039;maxLength&#039;, 8).message(&#039;Too bloated!&#039;);

result = myValidator.validate( [1, 2, 3, 4, 5, 6, 6, 8, 9, 10] );
console.log(result); // false, the array is long enough but contains non-unique members
console.log(myValidator.errors);
/*
myValidator.errors == [
    &#039;You are repeating yourself&#039;,
    &#039;Too bloated!&#039;
]
*/
</pre>
<p>You can also chain calls to add() and message():</p>
<pre class="brush: javascript">
var result,
    myValidator

myValidator = new Validator();

myValidator.add(&#039;unique&#039;).message(&#039;You are repeating yourself&#039;)
    .add(&#039;minLength&#039;, 6).message(&#039;Too tiny!&#039;)
    .add(&#039;maxLength&#039;, 8).message(&#039;Too bloated!&#039;);
</pre>
<p>I&#8217;ve added some code which should make it easy to use this as a CommonJS AMD javascript module.  In it&#8217;s default form you can just include it with a script tag.</p>
<p>If you&#8217;re interested in developing Validator itself, the project is tested with <a href="http://pivotal.github.com/jasmine/">Jasmine</a> and documented with <a href="http://code.google.com/p/jsdoc-toolkit/">JSDoc</a>.  Both of these can be run with Rake, and the easiest way to get setup is to use <a href="http://gembundler.com/">Bundler</a>.  Once you&#8217;ve got the dependencies you get three rake tasks:</p>
<pre class="brush: bash">
# Start the jasmine server, and open http://localhost:8888/ to run the test suite:
$ rake jasmine
# Start the jasmine server and also run a browser through the tests automatically:
$ rake jasmine:ci
# Generate the docs
$ rake jsdoc
</pre>
<p>If you fork the project and add any more validations, please also add tests and docs.</p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/1076/simple-javascript-validator-library-validator-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building Conway&#8217;s Game of Life in Javascript</title>
		<link>http://otaqui.com/blog/1020/building-conways-game-of-life-in-javascript/</link>
		<comments>http://otaqui.com/blog/1020/building-conways-game-of-life-in-javascript/#comments</comments>
		<pubDate>Tue, 02 Aug 2011 12:00:06 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=1020</guid>
		<description><![CDATA[As part of an interesting exercise at work, I built an implementation of Conway&#8217;s Game Of Life in Javascript. If you haven&#8217;t come across the Game Of Life, it&#8217;s really quite interesting and worth looking at. My colleagues also made variations, including canvas-based and Web GL 3 dimensional (there was even discussion about n-dimensional, with [...]]]></description>
			<content:encoded><![CDATA[<p>As part of an interesting exercise at work, I built an implementation of <a href="http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life">Conway&#8217;s Game Of Life</a> in Javascript.  If you haven&#8217;t come across the Game Of Life, it&#8217;s really quite interesting and worth looking at.  My colleagues also made variations, including canvas-based and Web GL 3 dimensional (there was even discussion about n-dimensional, with sliders to view the 4th, 5th and further dimensions).  My particular take was to make the game space &#8220;infinite&#8221; rather than a fixed grid.</p>
<p>It&#8217;s not really infinite of course, I haven&#8217;t made any attempt to have a position greater than Number.MAX_VALUE.  The real point is that it is possible to have a huge playing area, and only the living &#038; possibly-living-next-round cells are taken into account.</p>
<p>I avoided using any ready-made frameworks, in part so that it could be transported to the server-side on top of something like <a href="http://nodejs.org">NodeJS</a> &#8211; I was imagining a multi-player game where each user could &#8220;paint&#8221; cells onto the canvas, and maybe even that next-generation cells would take an identifier from their parents, letting people &#8220;fight&#8221;.  I haven&#8217;t really got the time for that at the moment, but it seemed a nice idea.</p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/1020/building-conways-game-of-life-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RTL Input text with large text-indent value &#8220;magically scrolls&#8221; in Opera</title>
		<link>http://otaqui.com/blog/1028/rtl-input-text-with-large-text-indent-value-magically-scrolls-in-opera/</link>
		<comments>http://otaqui.com/blog/1028/rtl-input-text-with-large-text-indent-value-magically-scrolls-in-opera/#comments</comments>
		<pubDate>Tue, 25 Jan 2011 16:32:31 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=1028</guid>
		<description><![CDATA[This is a pretty weird browser bug. Opera RTL Scrolly Text Indent Bug. If your content is RTL and you are using the large text-indent CSS property on an input tag (so that you can use a background image, while keeping the text invisible to most users but still available to screen readers) you get [...]]]></description>
			<content:encoded><![CDATA[<p>This is a pretty weird browser bug.</p>
<p><a href="http://otaqui.com/code/opera-rtl-scrolly-text-indent/">Opera RTL Scrolly Text Indent Bug</a>.</p>
<p>If your content is RTL and you are using the large text-indent CSS property on an input tag (so that you can use a background image, while keeping the text invisible to most users but still available to screen readers) you get a couple of odd behaviours in Opera:</p>
<ol>
<li>The text is not indented.  Well ok, that&#8217;s at least a &#8220;normal&#8221; kind of bug.</li>
<li>If you right-click on the button, and leave the menu open for a few seconds, the text <em><strong>magically starts scrolling out of the way</strong></em>.</li>
</ol>
<p>I&#8217;ve submitted a bug report to Opera.  I&#8217;d be interested if anyone else is seeing the same behaviour, or any related RTL weirdness.</p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/1028/rtl-input-text-with-large-text-indent-value-magically-scrolls-in-opera/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Started work on jQuery UI Modal widget</title>
		<link>http://otaqui.com/blog/919/started-work-on-jquery-ui-modal-widget/</link>
		<comments>http://otaqui.com/blog/919/started-work-on-jquery-ui-modal-widget/#comments</comments>
		<pubDate>Wed, 13 Oct 2010 14:26:49 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=919</guid>
		<description><![CDATA[I&#8217;ve started working a jQuery UI Modal widget, for use in a project built on top of the widget library. We have very high accessibility standards, and the current &#8220;{modal:true}&#8221; option for the dialog widget unfortunately wasn&#8217;t as good as we needed. Seeing that the team had identified the need for a standalone Modal widget, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve started working a jQuery UI Modal widget, for use in a project built on top of the widget library.</p>
<p>We have very high accessibility standards, and the current &#8220;{modal:true}&#8221; option for the dialog widget unfortunately wasn&#8217;t as good as we needed.  Seeing that the team had identified the need for <a href="http://wiki.jqueryui.com/Modal">a standalone Modal widget</a>, the team thought we could try and get the ball rolling.</p>
<p>You can see the work in progress here in <a href="http://github.com/pete-otaqui/jquery-ui/blob/master/ui/jquery.ui.modal.js">the modal widget in my fork of jquery ui</a>.</p>
<p>I&#8217;ve also been having <a href="http://forum.jquery.com/topic/refactoring-dialog-overlay-in-preparation-for-modal-better-keyboard-accessibility">a discssion about the modal widget</a> with Scott Gonzalez of the jQuery UI team.</p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/919/started-work-on-jquery-ui-modal-widget/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSSP: Loading CSS with Javascript &#8211; and getting an onload callback.</title>
		<link>http://otaqui.com/blog/890/cssp-loading-css-with-javascript-and-getting-an-onload-callback/</link>
		<comments>http://otaqui.com/blog/890/cssp-loading-css-with-javascript-and-getting-an-onload-callback/#comments</comments>
		<pubDate>Tue, 28 Sep 2010 14:16:18 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=890</guid>
		<description><![CDATA[It seems fairly straightforward to require CSS with Javascript. The most obvious method that I thought of was creating a &#60;link&#62; tag and appending it to the head of the document. An alternative would be to load the text of the css file with an ajax XHR call, and then inject that into a &#60;style&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>It seems fairly straightforward to require CSS with Javascript.  The most obvious method that I thought of was creating a &lt;link&gt; tag and appending it to the head of the document. An alternative would be to load the text of the css file with an ajax XHR call, and then inject that into a &lt;style&gt; tag.</p>
<p>These are both fine for most cases, but what about a situation where you have a hard dependency on the css for the javascript to work correctly?  You could take a best-guess at a wait time for the CSS to load, or even set the XHR to be synchronous &#8211; however both of these are very poor for both actual and perceived performance of your page (and the former may simply fail).</p>
<p>When might this be the case?  Let&#8217;s say you have some asynchronously loaded javascript that is intended to create a widget on the page, something like this (which assumes you are using jQuery as your dom library):</p>
<pre class="brush: javascript">

function moveLargePanels() {
    // make a panel container for large panels
    $(&#039;&lt;div id=&quot;largePanelContainer&quot;&gt;&lt;/div&gt;&#039;)
        .appendTo(&#039;body&#039;);
    $(&#039;.panel&#039;).each( function(i, panel) {
        if ( panel.outerWidth() &gt; 300 ) {
            panel.appendTo(&#039;#largePanelContainer&#039;);
        }
    }
}
</pre>
<p>And some corresponding CSS:</p>
<pre class="brush: css">
.panel {
    border:1px solid #000;
    padding: 20px;
}
</pre>
<p>The idea here is that, since there is some interaction between the logic in the javascript (a test for the &#8220;outerWidth&#8221;) and the styling in the CSS (setting the padding) that the javascript can only work correctly once the CSS has been loaded and applied.</p>
<p>This should be fine right?  Start the javascript and the css loading, and have events attached to the load of each letting you know when everything is ready and it&#8217;s safe to fire &#8220;moveLargePanels()&#8221;.  Wrong, or at least tricky, and essentially impossible if the CSS is loaded from a different domain to the hosting webpage.</p>
<p>You can get James Burke&#8217;s excellent description of this problem here:<br />
<a href="http://requirejs.org/docs/faq-advanced.html#css">http://requirejs.org/docs/faq-advanced.html#css</a><br />
And a first pass at solving this (in some browsers) here:<br />
<a href="http://bugs.dojotoolkit.org/ticket/5402">http://bugs.dojotoolkit.org/ticket/5402</a></p>
<p>Burke mentions a using a &#8220;well known&#8221; style rule to test whether the style is loaded.  I suggest a standard pattern for the rule, and also a mechanism for dynamically setting it.</p>
<h2>Enter CSSP</h2>
<p>You may have heard of <a href="http://remysharp.com/2007/10/08/what-is-jsonp/">JsonP</a> &#8211; a way of serving dynamically generated JSON which is padded with a method call (the method name is supplied in the query string of the URL), which allows for cross domain loading of javascript.  The idea behind CSSP is similar &#8211; it defines a pattern for loading css cross domain.  Instead of wrapping in a callback though, we can use the URL query string mechanism to supply the special &#8220;test rule&#8221; that we use.</p>
<h3>Dynamic Rule Pattern</h3>
<p>Given this url:</p>
<p>http://someserver.com/stylefile.css?cssp=123456</p>
<pre class="brush: php">
.panel { ... }
.largePanelsContainer { .. }

/* and the special rule: */
cssp { zIndex:123456; }
</pre>
<p>So, in whatever loader we want to build, we can add something like this (n.b. this isn&#8217;t tested code):</p>
<pre class="brush: javascript">
var cssp_counter = 0;
function loadCss(url, callback, className, zIndex) {
    // create a counter for special class names, so they are unique
    className = className || &#039;cssp&#039; + (cssp_counter++);
    zIndex = zIndex || 123456;
    url = url + &#039;?&#039; + className + &#039;=&#039; + zIndex;
    $(&#039;&lt;link&gt;&#039;)
        .attr({
            rel: &quot;stylesheet&quot;,
            type: &quot;text/css&quot;,
            href: url
        .appendTo(&#039;head&#039;);
    // append a dummy div to the body for the test
    var div = $(&#039;&lt;div&gt;&lt;/div&gt;&#039;)
        .addClass(className)
        .appendTo(&#039;body&#039;);
    // now poll for the z-index value:
    var cssp_interval = setInterval( function() {
        // if the zIndex is applied, we know the css has loaded
        if ( div.css(&#039;zIndex&#039;) == zIndex ) {
            div.remove();
            // callback:
            callback();
            clearInterval( cssp_interval );
        }
    }, 100);

}
</pre>
<p>The code above to do the loading and fire a callback is very naive.  It would be much better to have an event that can have listeners added, and to have some tests and some failure management like a maximum timeout.</p>
<h3>Default Rule Pattern</h3>
<p>This obviously presupposes that the CSS is dynamically generated to some degree, even just by adding the special rule to an otherwise static file.  I think that an alternative to the performance-conscious would be a &#8220;default&#8221; special rule, based on the css filename.  This needs some thought, and could well be tied to a build-step in your deployment process (you do have one, right?).  The pattern comes in two parts:</p>
<ul>
<li>There is a standard zIndex that is always used.</li>
<li>The filename includes the &#8220;special class name&#8221; that is used within.</li>
</ul>
<p>For example:</p>
<p>Given the file: <strong>styles.fhddgso9j.css</strong></p>
<pre class="brush: css">
.someclass { ... }
.otherclass { ... }

/* and the special rule */
.fhddgso9j { z-index: 123456; }
</pre>
<p>The javascript to go alone with this might look something like:</p>
<pre class="brush: javascript">
var cssp_counter = 0;
function loadCss(url, callback) {
    // create a counter for special class names, so they are unique
    className = getSpecialClassName(url);
    zIndex = 123456;
    $(&#039;&lt;link&gt;&#039;)
        .attr({
            rel: &quot;stylesheet&quot;,
            type: &quot;text/css&quot;,
            href: url
        .appendTo(&#039;head&#039;);
    // append a dummy div to the body for the test
    var div = $(&#039;&lt;div&gt;&lt;/div&gt;&#039;)
        .addClass(className)
        .appendTo(&#039;body&#039;);
    // now poll for the z-index value:
    var cssp_interval = setInterval( function() {
        // if the zIndex is applied, we know the css has loaded
        if ( div.css(&#039;zIndex&#039;) == zIndex ) {
            div.remove();
            // callback:
            callback();
            clearInterval( cssp_interval );
        }
    }, 100);
}
function getSpecialClassName(url) {
  // get just the filename, e.g. &quot;styles.9ufosdfij.css&quot;
  var filename = url.substring( url.lastIndexOf(&#039;/&#039;)+1, url.length);
  // split on the &quot;.&quot; marks
  var parts = filename.split(&#039;.&#039;);
  // assume it will be the second-to-last part (since the last should be &quot;css&quot;)
  var className = parts[ parts.length-2 ];
  return className;
}
</pre>
<p>As noted above, this naive, untested code.</p>
<h2>Wrapping Up</h2>
<p>Ideally I&#8217;d like any &#8220;css loader&#8221; to use actual browser events (or properties) where possible, and to fallback on this setup as a last resort.</p>
<p>If I get time I&#8217;ll implement this and put the code on github.  Please do get in touch if you&#8217;d like to pair on this!</p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/890/cssp-loading-css-with-javascript-and-getting-an-onload-callback/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Adobe CS3 &#8220;licensing for this product has stopped working&#8221; fix</title>
		<link>http://otaqui.com/blog/699/adobe-cs3-licensing-for-this-product-has-stopped-working-fix/</link>
		<comments>http://otaqui.com/blog/699/adobe-cs3-licensing-for-this-product-has-stopped-working-fix/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 09:55:00 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=699</guid>
		<description><![CDATA[After getting a new computer, and restoring my old system from a Time Machine backup, I found my Adobe Web Premium CS3 stopped working. Every application I started (Photoshop, Fireworks, Flash, etc) gave the error message: Licensing for this product has stopped working. After following every suggestion I could find in Adobe&#8217;s knowledge base and [...]]]></description>
			<content:encoded><![CDATA[<p>After getting a new computer, and restoring my old system from a Time Machine backup, I found my Adobe Web Premium CS3 stopped working.  Every application I started (Photoshop, Fireworks, Flash, etc) gave the error message:</p>
<blockquote><p>Licensing for this product has stopped working.</p></blockquote>
<p>After following every suggestion I could find in Adobe&#8217;s knowledge base and various online articles, I still couldn&#8217;t get any of the applications to start.</p>
<p>As a final act of complete desperation, after many rounds of removal-reboot-reinstall, I finally ran the installer and chose a product that I had not installed before (Contribute).  Once that was done I started up the new app, and it asked me for my license key &#8211; which I entered and the app started.  Then I tried Photoshop and it started up fine!</p>
<p>So &#8211; if you didn&#8217;t do a complete install int he first place, one of the easiest things could be to add a new app to your install, and get that to reset your licensing for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/699/adobe-cs3-licensing-for-this-product-has-stopped-working-fix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>If We Had A Web Of Data I Would Build &#8230;</title>
		<link>http://otaqui.com/blog/643/if-we-had-a-web-of-data-i-would-build/</link>
		<comments>http://otaqui.com/blog/643/if-we-had-a-web-of-data-i-would-build/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 14:24:45 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[linked-data]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=643</guid>
		<description><![CDATA[Georgi Kobilarov has a post up asking what would you build with a function web of data and I have a few ideas. These all need fleshing out (and probably spell-checking ;), but if I didn&#8217;t post them now I might never get round to it! Shopping I think there are a few ways you [...]]]></description>
			<content:encoded><![CDATA[<p>Georgi Kobilarov has a post up asking <a href="http://blog.georgikobilarov.com/2010/04/with-a-web-of-data-what-would-you-do/">what would you build with a function web of data</a> and I have a few ideas.  These all need fleshing out (and probably spell-checking ;), but if I didn&#8217;t post them now I might never get round to it!</p>
<p><strong>Shopping</strong></p>
<p>I think there are a few ways you could use a web of linked data to make online grocery shopping better &#8211; comparing prices across stores, create shopping lists from recipes, and get recipes from lists of goods.</p>
<p><strong>Recruitment</strong></p>
<p>With jobs and resumés available as linked data, recruitment could become much more machine-enabled, giving managers better abilities to find people themselves rather than relying on agents who don&#8217;t always understand their clients&#8217; business or industry.  It could also help people looking for work in a similar way.  Types of skill, training and qualification could also be linked in, as could &#8220;linkedin&#8221; style personal recommendations.</p>
<p><strong>E-Learning</strong></p>
<p>Serious attempts have been made at making learning materials shareable and reusable.  As part of the data web, finding and consuming these materials becomes easier but more than that we could build a development plan generator.  Competency can be aligned to skills or training received, something that could be useful to government departments, schools, universities and business.</p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/643/if-we-had-a-web-of-data-i-would-build/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BBC Fisheye Greasemonkey Script</title>
		<link>http://otaqui.com/blog/646/bbc-fisheye-greasemonkey-script/</link>
		<comments>http://otaqui.com/blog/646/bbc-fisheye-greasemonkey-script/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 09:15:08 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=646</guid>
		<description><![CDATA[Greasemonkey script to reformat &#8220;Author&#8221; select elements on the BBC&#8217;s Fisheye repository browser, which are ridiculously long (because they contain a considerable chunk of certificate data) which messes with the whole page layout. Shrinking the selects to a more reasonable width fixes this and makes the site more usable. http://otaqui.com/code/bbc-fisheye/bbc-fisheye.user.js // ==UserScript== // @name BBC [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.greasespot.net/">Greasemonkey</a> script to reformat &#8220;Author&#8221; select elements on the BBC&#8217;s Fisheye repository browser, which are ridiculously long (because they contain a considerable chunk of certificate data) which messes with the whole page layout.  Shrinking the selects to a more reasonable width fixes this and makes the site more usable.</p>
<p><a href="http://otaqui.com/code/bbc-fisheye/bbc-fisheye.user.js">http://otaqui.com/code/bbc-fisheye/bbc-fisheye.user.js</a></p>
<pre class="brush: javascript">
// ==UserScript==
// @name           BBC FishEye
// @namespace      http://otaqui.com/code/bbc-fisheye
// @description    Make BBC&#039;s Fisheye look more like it should
// @include        https://fisheye.dev.bbc.co.uk/*
// ==/UserScript==
var elems = document.evaluate(
    &#039;//select[@name=&quot;wbauthor&quot;]&#039;,
    document,
    null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    null
);
var i=0;
var sel;
while ( sel = elems.snapshotItem(i++) ) sel.style.width = &#039;200px&#039;;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/646/bbc-fisheye-greasemonkey-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bash Script for Serving Multiple Trac Projects and Sharing Authentication</title>
		<link>http://otaqui.com/blog/600/bash-script-for-serving-multiple-trac-projects-and-sharing-authentication/</link>
		<comments>http://otaqui.com/blog/600/bash-script-for-serving-multiple-trac-projects-and-sharing-authentication/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 08:55:25 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=600</guid>
		<description><![CDATA[I use Trac for personal projects, and I share some of these out with people as required. I use tracd (TracStandalone) for this, rather than a full-blown apache setup, since it serves my needs quite nicely and is a lot easier to turn on and off as required without tweaking apache config and rebooting the [...]]]></description>
			<content:encoded><![CDATA[<p>I use Trac for personal projects, and I share some of these out with people as required.  I use tracd (TracStandalone) for this, rather than a full-blown apache setup, since it serves my needs quite nicely and is a lot easier to turn on and off as required without tweaking apache config and rebooting the whole webserver.</p>
<p>All my projects live under a single parent directory, and I prefer to share a single users digest file between them all &#8211; so ideally I wanted to share a single tracd to run all my projects.  This is fairly straightforward on the command line:</p>
<pre class="brush: bash">
tracd --hostname=webhost.com -p 9876 \
--auth=&quot;*,/path/projects/people.htdigest,Realm&quot; \
/path/projects/p1 \
/path/projects/p2
</pre>
<p>That is &#8230;.<br />
Line 1 &#8211; start tracd for a given hostname and port,<br />
Line 2 &#8211; specify auth for all projects (*), the auth file and the &#8220;Realm&#8221; you specified when creating the file with apache&#8217;s htdigest command<br />
Lines 3+ &#8211; specify as many projects as you want to run</p>
<p>This is ok with a couple of projects, but gets unwieldy quite quickly.  What I needed was a little shell script to open up all projects under a given directory quickly.  Here&#8217;s what I came up with:</p>
<pre class="brush: bash">
#!/bin/bash

# make / truncate a temp file to store names:
temp=/tmp/tracdpaths
&gt; $temp

# specify base directory:
base=/path/projects/

# output all subdirectories to temp file:
find $base -maxdepth 1 -mindepth 1 -type d \
-exec echo -n &quot;{} &quot; &gt; $temp \;

# now start tracd
tracd --hostname=webhost.com -p 9876 \
--auth=&quot;*,/path/projects/people.htdigest,Realm&quot; \
`cat $temp`
</pre>
<p>Essentially this script uses &#8216;find&#8217; to get all of the directories exactly 1 level down from your projects directory, and will echo their paths to a temp file (suppressing the newlines).  It will then run run tracd, appending the contents of this file to the end of the call.</p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/600/bash-script-for-serving-multiple-trac-projects-and-sharing-authentication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom User Agent with Cucumber Tests and Webrat in Mechanize Mode</title>
		<link>http://otaqui.com/blog/541/custom-user-agent-with-cucumber-tests-and-webrat-in-mechanize-mode/</link>
		<comments>http://otaqui.com/blog/541/custom-user-agent-with-cucumber-tests-and-webrat-in-mechanize-mode/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 12:08:50 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=541</guid>
		<description><![CDATA[It&#8217;s pretty straightforward to set a custom user agent with mechanize if you&#8217;re using it directly, KickAssLabs has a good example. If you&#8217;re using Mechanize through Webrat though, things are a little different. The nice thing though, is that you can do this in a step definition &#8211; allowing features to be based on different [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s pretty straightforward to set a custom user agent with mechanize if you&#8217;re using it directly, <a href="http://www.kickasslabs.com/2009/03/31/quick-hits-setting-the-user-agent-header-in-webrat/">KickAssLabs has a good example</a>.</p>
<p>If you&#8217;re using Mechanize through Webrat though, things are a little different.  The nice thing though, is that you can do this in a step definition &#8211; allowing features to be based on different browser scenarios (this is great if you&#8217;re developing across devices).</p>
<p>First off there are two accessors of interest in mechanize, &#8220;user_agent&#8221; and &#8220;user_agent_alias&#8221;.  The former is fairly self evident and lets you define the user agent at will, the latter gives you shortcut access to a list of common user agents baked into mechanize.  You can see that list in <a href="http://github.com/tenderlove/mechanize/blob/master/lib/mechanize.rb#L48">the mechanize.rb source</a>.  It contains some desktop browsers, the iPhone and the default Mechanize UA strings.</p>
<p>If you&#8217;re happy with the default alias list, you can just write a step definition like this:</p>
<pre class="brush: ruby">
Given /^I am using the &quot;(.*)&quot; browser$/ do |browser|
  webrat.adapter.mechanize.user_agent_alias = browser
end
</pre>
<p>And then you can use this in your features:</p>
<pre class="brush: text">
Given I am using the &quot;iPhone&quot; browser
When I visit the home page
Then I should see &quot;You are using an iPhone!&quot;
</pre>
<p>If you want to be able to specify your own UA strings, and as I said this is especially likely if you are developing cross-device applications where capabilities are important, then you can just use your own hash instead, and set &#8220;user_agent&#8221; rather than &#8220;user_agent_alias&#8221;:</p>
<pre class="brush: ruby">
Given /^I am using the &quot;(.*)&quot; browser$/ do |browser|
  UA_ALIASES = {
    &quot;Nokia N95&quot; =&gt; &quot;Mozilla/5.0 (SymbianOS/9.2; .....&quot;,
    &quot;Palm Pre&quot; =&gt; &quot;Mozilla/5.0 (webOS/1.0; .....&quot;
  }
  webrat.adapter.mechanize.user_agent = UA_ALIASES[browser]
end
</pre>
<p>With a little tweaking you could use both the included list and, if the string from your feature isn&#8217;t there, look in a custom list too.</p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/541/custom-user-agent-with-cucumber-tests-and-webrat-in-mechanize-mode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Complete List of Special Google Chrome URLs</title>
		<link>http://otaqui.com/blog/539/complete-list-of-special-google-chrome-urls/</link>
		<comments>http://otaqui.com/blog/539/complete-list-of-special-google-chrome-urls/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 20:12:54 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=539</guid>
		<description><![CDATA[Google Chrome has quite a lot of special URLs. Some of these are covered over at Lifehacker in their post on Chrome&#8217;s about pages, but the meta &#8220;about:&#8221; protocol isn&#8217;t the only one that Chrome uses. Waha, a user on the chromeplugins.org site posted a much more complete list of URL schemes that Chrome uses. [...]]]></description>
			<content:encoded><![CDATA[<p>Google Chrome has quite a lot of special URLs.  Some of these are covered over at Lifehacker in their <a href="http://lifehacker.com/5045164/google-chromes-full-list-of-special-about-pages">post on Chrome&#8217;s about pages</a>, but the meta &#8220;about:&#8221; protocol isn&#8217;t the only one that Chrome uses.</p>
<p>Waha, a user on the chromeplugins.org site posted <a href="http://www.chromeplugins.org/google/chrome-tips-tricks/about-chrome-more-internal-urls-7793.html">a much more complete list of URL schemes</a> that Chrome uses.  Waha was looking at the <a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/url_constants.cc">url_constants.cc</a> source file, along with some other stuff, to work this list out.</p>
<p>I&#8217;ve ignored the virtually universal set of protocols that are in just about every browser: http, https, ftp, file, data, feed and javascript, and also the URLs that cannot be entered into the address bar (not using Chrome 5 on OS X Snow Leopard anyway).</p>
<p>Without further ado, here&#8217;s the list:</p>
<ul>
<li><a href="about:blank">about:blank</a> &#8211; the empty page</li>
<li><a href="about:cache">about:cache</a> &#8211; disk and memory cache information</li>
<li><a href="about:net-internals">about:net-internals</a> &#8211; network information including Proxy, HostResolver, URLRequest, HTTPCache and SocketStream</li>
<li><a href="about:crash">about:crash</a> &#8211; the page shown when a tab process crashes</li>
<li><a href="about:credits">about:credits</a> &#8211; list of libraries and other code used in Chrome, with links</li>
<li>about:hang &#8211; this seems to kill a tab for me (I haven&#8217;t linked for that reason &#8211; use at your own risk)</li>
<li><a href="about:memory">about:memory</a> &#8211; memory usage of the various processes</li>
<li>about:shorthang &#8211; see about:hang above</li>
<li><a href="about:terms">about:terms</a> &#8211; Google Chrome Terms of Service</li>
<li>about:inducebrowsercrashforrealz &#8211; not many lolz here</li>
<li><a href="chrome://extensions/">chrome://extensions/</a> &#8211; installed extensions</li>
<li><a href="chrome://history/">chrome://history/</a> &#8211; your browsing history</li>
<li><a href="chrome://newtab">chrome://newtab</a> &#8211; the new tab page</li>
<li><a href="chrome://thumb/http://www.google.com/">chrome://thumb/http://www.google.com/</a> &#8211; thumbnail for a page you&#8217;ve visited</li>
<li><a href="chrome://favicon/http://www.google.com/">chrome://favicon/http://www.google.com/</a> &#8211; favicon for a page you&#8217;ve visited</li>
<li><a href="view-source:http://otaqui.com/blog/539/complete-list-of-special-google-chrome-urls">view-source:http://otaqui.com/blog/539/complete-list-of-special-google-chrome-urls</a> &#8211; view the source of a web page</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/539/complete-list-of-special-google-chrome-urls/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>BBC Standards Ruby Gem</title>
		<link>http://otaqui.com/blog/526/bbc-standards-ruby-gem/</link>
		<comments>http://otaqui.com/blog/526/bbc-standards-ruby-gem/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 22:19:52 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[bbc]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=526</guid>
		<description><![CDATA[Thanks to some brilliant tidying up of my work by my good friend <a href="http://www.metade.org/">Patrick</a>, there is now a <a href="http://github.com/metade/bbc_standards">bbc_standards ruby gem</a> which you can use to validate pages against some of the <a href="http://www.bbc.co.uk/guidelines/futuremedia/technical/">BBC Technical Guidelines</a>]]></description>
			<content:encoded><![CDATA[<p>Thanks to some brilliant tidying up of my work by my good friend <a href="http://www.metade.org/">Patrick</a>, there is now a <a href="http://github.com/metade/bbc_standards">bbc_standards ruby gem</a> which you can use to validate pages against some of the <a href="http://www.bbc.co.uk/guidelines/futuremedia/technical/">BBC Technical Guidelines</a> (more specifically the &#8220;Semantic Mark-up&#8221; and &#8220;XHTML Integrity&#8221; standards).</p>
<p>This gem was originally designed to work with Cucumber, and initially was intended to just validate pages against the XHTML Strict doctype that BBC pages are usually required to use.  Since it uses Nokogiri for validation &#8211; against the XML Schema rather than the Doctype for what it&#8217;s worth &#8211; the testing is a) strict and b) *fast*.  There are no external webservice calls, so it is fine to test all page loads within Cucumber, even testing the same URI many times over (since the bottleneck will almost certainly be your app by some margin.</p>
<p>I&#8217;m currently working on a post about using the gem for the <a href="http://www.bbc.co.uk/blogs/webdeveloper/">BBC Web Developer blog</a>, but I thought I&#8217;d point any interested parties at the code here and now.</p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/526/bbc-standards-ruby-gem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create A Custom CakePHP Console Application Using Shells, Tasks, Models and Controllers</title>
		<link>http://otaqui.com/blog/448/create-a-custom-cakephp-console-application-using-shells-tasks-models-and-controllers/</link>
		<comments>http://otaqui.com/blog/448/create-a-custom-cakephp-console-application-using-shells-tasks-models-and-controllers/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 14:43:54 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=448</guid>
		<description><![CDATA[CakePHP doesn&#8217;t just come with its own console applications for baking code, managing ACL, inspecting classes, manipulating the schema, internationalisation and running the testsuite (whew!) it also lets you write your own console applications. [NB: I always have an external cake core directory, for easy swapping. The code examples all assume you have done this, [...]]]></description>
			<content:encoded><![CDATA[<p>CakePHP doesn&#8217;t just come with its own console applications for baking code, managing ACL, inspecting classes, manipulating the schema, internationalisation and running the testsuite (whew!) it also lets you write your own console applications.</p>
<p><em>[NB: I always have an external cake core directory, for easy swapping.  The code examples all assume you have done this, or at least created an alias in your terminal to point to the core cake directory with something like: alias cake='../cake/console/cake'</em></p>
<p>First off, to find out about the current console applications you are running jump into a terminal and cd to your app directory, then simple run the &#8220;cake&#8221; command to see what you have available:</p>
<pre class="brush: bash">
app_dir $ cake
</pre>
<p>This will output a list of available shells in the core cake library and the two &#8220;vendors&#8221; directories.</p>
<p>So how do you go about creating your own?  The <a href="http://book.cakephp.org/view/110/Creating-Shells-Tasks">CakePHP documentation on creating Shells &amp; Tasks</a> is a good place to start.</p>
<p>An application I&#8217;ve needed to automate with a cron-job, and also have available as an in-app, on-demand function is the sending of emails.  I&#8217;m not talking about writing a mass mailer here, but rather just sending out course information to users who are booked to attend &#8211; and doing so both automatically and on-demand when an administrator decides it is necessary.  This is an obvious instance where you don&#8217;t want to duplicate the code in the controller and the shell.</p>
<p>In my case, I have several kinds of email I want to send, so I set up a generalised Task, used by several different Shells.  The advantage of doing things this way around is that any other Shells can also make use of the emailer Task in the fututre.</p>
<p>Here&#8217;s some simplified code from one of the Shells, a &#8220;booking reminder&#8221; for delegates:</p>
<pre class="brush: php">
// file app/vendors/shells/booking_reminder.php
&lt;?php
class BookingReminderShell extends Shell {
  var $uses = array(&quot;Booking&quot;,&quot;User&quot;,&quot;Course&quot;);
  var $tasks = array(&quot;Emailer&quot;);
  public function main() {
    // use $this-&gt;Booking etc as if we were in a controller
    // use $this-&gt;Emailer for the task
  }
}
</pre>
<p>And then we have the Task:</p>
<pre class="brush: php">
// file app/vendors/shells/tasks/emailer.php
&lt;?php
class Emailer extends Shell {
  public function execute() {
    // this method is called when the task is instantiated,
    // gives you a chance to setup
  }
  public function send($to,$from,$subject,$message,$attachments=null) {
    // called from shell with: $this-&gt;Emailer-&gt;send();
  }
}
</pre>
<p>Note how both Shells and tasks extend from the base &#8220;Shell&#8221; class.  Also note how Shells use a method called &#8220;main()&#8221; when they are run, whereas Tasks use &#8220;execute()&#8221; when they are created.</p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/448/create-a-custom-cakephp-console-application-using-shells-tasks-models-and-controllers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using a Proxy with Cucumber, Webrat and Mechanize</title>
		<link>http://otaqui.com/blog/458/using-a-proxy-with-cucumber-webrat-and-mechanize/</link>
		<comments>http://otaqui.com/blog/458/using-a-proxy-with-cucumber-webrat-and-mechanize/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 08:15:36 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=458</guid>
		<description><![CDATA[If you&#8217;re writing Cucumber tests using Webrat and Mechanize to test a site, and you are behind a proxy server, you can do something like this to tell mechanize about it in your webrat_steps.rb file: When /^I am on (.+)$/ do &#124;page_name&#124; webrat.adapter.mechanize.set_proxy('proxy.host.com',8080) visit path_to(page_name) end I&#8217;m sure there&#8217;s a tidier way to do this, [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re writing Cucumber tests using Webrat and Mechanize to test a site, and you are behind a proxy server, you can do something like this to tell mechanize about it in your webrat_steps.rb file:</p>
<p><code><br />
When /^I am on (.+)$/ do |page_name|<br />
    webrat.adapter.mechanize.set_proxy('proxy.host.com',8080)<br />
    visit path_to(page_name)<br />
end<br />
</code></p>
<p>I&#8217;m sure there&#8217;s a tidier way to do this, but it&#8217;s quick and it works with the following gem versions:</p>
<p>Cucumber 0.3.11<br />
Webrat 0.5.3<br />
Mechanize 0.9.3</p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/458/using-a-proxy-with-cucumber-webrat-and-mechanize/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Disable Debug Output for Ajax in CakePHP</title>
		<link>http://otaqui.com/blog/430/disable-debug-output-for-ajax-in-cakephp/</link>
		<comments>http://otaqui.com/blog/430/disable-debug-output-for-ajax-in-cakephp/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 09:15:46 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=430</guid>
		<description><![CDATA[If you are developing a CakePHP application and you have the debug value set to anything greater than 0 in your config/core.php file, you will find that Ajax requests will also get the extra information appended to the output. In order to circumvent this add this to your &#8220;app_controller.php&#8221; file (which sits directly inside the [...]]]></description>
			<content:encoded><![CDATA[<p>If you are developing a <a href="http://cakephp.org">CakePHP</a> application and you have the debug value set to anything greater than 0 in your config/core.php file, you will find that Ajax requests will also get the extra information appended to the output.</p>
<p>In order to circumvent this add this to your &#8220;app_controller.php&#8221; file (which sits directly inside the &#8220;app/&#8221; dir, rather than in &#8220;app/controllers&#8221;):</p>
<pre class="brush: php">
&lt;?php
class AppController extends Controller {
  var $components = array(&#039;RequestHandler&#039;);
  var $helpers = array(&#039;Html&#039;,&#039;Form&#039;,&#039;Ajax&#039;);
  function beforeFilter() {
    if ( $this-&gt;RequestHandler-&gt;isAjax() ) {
      Configure::write(&#039;debug&#039;,0);
    }
  }
}
?&gt;
</pre>
<p>Note that while this will disable the debugging output, it will also have other affects too (for the life of the Ajax Request) like extending the length of time that the &#8220;schema&#8221; is cached.  This should make little or no difference, but is worth remembering.</p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/430/disable-debug-output-for-ajax-in-cakephp/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Mozilla Fennec Alpha 2 Release</title>
		<link>http://otaqui.com/blog/428/mozilla-fennec-alpha-2-release/</link>
		<comments>http://otaqui.com/blog/428/mozilla-fennec-alpha-2-release/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 20:29:29 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[links]]></category>
		<category><![CDATA[mozilla]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/428/mozilla-fennec-alpha-2-release/</guid>
		<description><![CDATA[Mozilla has released the second alpha of Fennec, their mobile browser. There&#8217;s a short but sweet overview of Fennec on Vimeo which is worth checking out. I think almost regardless of it&#8217;s performance improvements the real game-changing potential here is the inevitable swathe of add-ons and extensions that will be, and in some cases such [...]]]></description>
			<content:encoded><![CDATA[<p>Mozilla has <a href="http://blog.mozilla.com/blog/2008/12/23/fennec-alpha-2-released/">released the second alpha of Fennec</a>, their mobile browser.  There&#8217;s a short but sweet <a href="http://www.vimeo.com/2577978">overview of Fennec on Vimeo</a> which is worth checking out.</p>
<p>I think almost regardless of it&#8217;s <a href="http://starkravingfinkle.org/blog/2008/12/fennec-alpha2-performance/">performance improvements</a> the real game-changing potential here is the inevitable swathe of add-ons and extensions that will be, and in some cases such as <a href="http://hackademix.net/2008/12/23/noscript-for-fennec-update/">NoScript</a> already are, available.</p>
<p>I don&#8217;t think that any web developer who has used it would want to go back to a world without <a href="http://getfirebug.com/">Firebug</a> and I also think that it&#8217;s influence on <a href="http://webkit.org">WebKit</a>&#8216;s developer tools is fairly clear to see.</p>
<p>So I really hope that support for Fennec spreads beyond the Nokia 810 soon, and that it&#8217;s as instrumental as Firefox was in re-igniting browser development, especially from a developer-tool perspective.</p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/428/mozilla-fennec-alpha-2-release/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Page Optimisation Technique &#8211; Build Two Rows For The Fold</title>
		<link>http://otaqui.com/blog/415/page-optimisation-technique-build-two-rows-for-the-fold/</link>
		<comments>http://otaqui.com/blog/415/page-optimisation-technique-build-two-rows-for-the-fold/#comments</comments>
		<pubDate>Sat, 07 Feb 2009 14:01:07 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[page-optimisation]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=415</guid>
		<description><![CDATA[Despite suggestions to the contrary, we web developers still very much have to work with the concept of a &#8220;fold&#8221; &#8211; that is the part of the page that is immediately visible when a user visits your site. This is usually considered to mean &#8220;before the user has to scroll down&#8221; but can also just [...]]]></description>
			<content:encoded><![CDATA[<p>Despite suggestions to the contrary, we web developers still very much have to work with the concept of a &#8220;fold&#8221; &#8211; that is the part of the page that is immediately visible when a user visits your site.</p>
<p>This is usually considered to mean &#8220;before the user has to scroll down&#8221; but can also just mean &#8220;the stuff they look at first&#8221; even if they have a really big monitor.  This gives us a slightly more useful thing to think about &#8211; the first &#8220;batch&#8221; of content that will be at the top of the page, and incidentally will be the entirety of what a considerable portion of our users see first.</p>
<p>So, I have a suggestion to all the web *designers* out there to mull over: introduce the idea of &#8220;Two Rows&#8221; in your design.  By having a single row that is for content &#8220;above the fold&#8221; and a second one for everything below, we can get the absolute minimum &#8220;perceived load time&#8221; of the page.</p>
<p>Let&#8217;s have a look at a fairly standard wireframe of a page:</p>
<div id="attachment_416" class="wp-caption aligncenter" style="width: 430px"><a href="http://otaqui.com/blog/wp-content/uploads/layout_normal.png"><img src="http://otaqui.com/blog/wp-content/uploads/layout_normal.png" alt="&quot;Normal&quot; three column page layout" title="Normal three column page layout" width="420" height="420" class="size-full wp-image-416" /></a><p class="wp-caption-text">Normal three column page layout</p></div>
<p>This will be more or less as you expect, a header and footer with 3 (or however many) columns in between.</p>
<p>Now let&#8217;s have a look at a wireframe designed for the fold:</p>
<div id="attachment_417" class="wp-caption aligncenter" style="width: 430px"><a href="http://otaqui.com/blog/wp-content/uploads/layout_optimised.png"><img src="http://otaqui.com/blog/wp-content/uploads/layout_optimised.png" alt="Optimised For the Fold Layout" title="Optimised For the Fold Layout" width="420" height="420" class="size-full wp-image-417" /></a><p class="wp-caption-text">Optimised For the Fold Layout</p></div>
<p>As you can see, I&#8217;ve changed the structure to split the main content completely into two distinct rows.</p>
<p>The advantage here is that we developers can do several things to make the first row appear as quickly as possible:</p>
<ol>
<li>Firstly we don&#8217;t have to do anything.  The source order itself will mean that the content of the first row is loaded first, meaning that you won&#8217;t have that all-to-common &#8220;pause for the right-hand-column&#8221; to load.</li>
<li>Place all styles at the top of the page, and all required scripts between the two rows &#8211; this will make the page appear correctly styled and have javascript-driven functionality available.</li>
<li>Taking the point above to a further degree, we could in fact *split* the javascript (and possibly even css) files, which is normally a abad idea, to provide only the functionality required for the &#8220;first row&#8221;, and then load other resources afterwards.  This is a rather extreme approach, but could help if your site really needs the content &#8220;above the fold&#8221; to be absolutely as fast as possible even at the cost of overall page performance.</li>
<li>With a dynamic site, we can flush the buffer after the first row, and leave any further processing overhead to happen after that much of the page has been sent to the browser.</li>
</ol>
<p>There is no real need for the actual design to exagerate the rows in the same way that the wireframe does &#8211; but you would need a horizontal split of the content at that point to make things as easy and flexible as possible.  This limitation can be overcome with CSS, and possibly javascript, but this will rapidly become fiddly and hard to maintain.</p>
<p>To demonstrate what I mean, I took the Guardian&#8217;s homepage, and reworked it (as a graphic) to have the horizontal split required for Two Rows, without really appearing much different to the current, pure-column structure.</p>
<p>Before:<br />
<div id="attachment_423" class="wp-caption aligncenter" style="width: 310px"><a href="http://otaqui.com/blog/wp-content/uploads/guardian_original.jpg"><img src="http://otaqui.com/blog/wp-content/uploads/guardian_original-300x231.jpg" alt="Original Guardian Homepage" title="Guardian Original" width="300" height="231" class="size-medium wp-image-423" /></a><p class="wp-caption-text">Original Guardian Homepage</p></div></p>
<p>And after (with the &#8220;second row&#8221; being slightly greyed out):<br />
<div id="attachment_422" class="wp-caption aligncenter" style="width: 310px"><a href="http://otaqui.com/blog/wp-content/uploads/guardian_modified.jpg"><img src="http://otaqui.com/blog/wp-content/uploads/guardian_modified-300x231.jpg" alt="Modified Guardian Page" title="Guardian Modified" width="300" height="231" class="size-medium wp-image-422" /></a><p class="wp-caption-text">Modified Guardian Page</p></div></p>
<p>This example worked fairly well in terms of &#8220;hiding&#8221; the row lines since some things are bumped right up to them and others have varying amounts of whitespace either side.</p>
<p>I must admit that I&#8217;ve never implemented this technique, but I certainly believe that it could have significant impact for a site like the Guardian that has a large amount of content &#8220;below the fold&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/415/page-optimisation-technique-build-two-rows-for-the-fold/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Model and Field Result Set in CakePHP</title>
		<link>http://otaqui.com/blog/402/custom-model-and-field-result-set-in-cakephp/</link>
		<comments>http://otaqui.com/blog/402/custom-model-and-field-result-set-in-cakephp/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 17:22:44 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=402</guid>
		<description><![CDATA[If you&#8217;re using CakePHP and want to perform a custom SQL query while forcing your results into an arbitrary Model-based array when they are given back to you, you could do a lot worse than using grigri&#8217;s (who is a fellow South Westerner and therefore obviously a good bloke ;) DboMysqlEx (Mysql Extended) Class, or [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re using CakePHP and want to perform a custom SQL query while forcing your results into an arbitrary Model-based array when they are given back to you, you could do a lot worse than using grigri&#8217;s (who is a fellow South Westerner and therefore obviously a good bloke ;) DboMysqlEx (Mysql Extended) Class, or at least this particular part of it:</p>
<pre class="brush: php">&lt;?php
require_once (LIBS . &#039;model&#039; . DS . &#039;datasources&#039; . DS . &#039;dbo&#039; . DS . &#039;dbo_mysql.php&#039;);
class DboMysqlEx extends DboMysql {
   var $description = &quot;MySQL DBO Driver - Extended&quot;;
   // Override resultSet to allow for Model__field type aliases
   function resultSet(&amp;$results) {
		if (isset($this-&gt;results) &amp;&amp; is_resource($this-&gt;results) &amp;&amp; $this-&gt;results != $results) {
			mysql_free_result($this-&gt;results);
		}
       $this-&gt;results =&amp; $results;
       $this-&gt;map = array();
       $num_fields = mysql_num_fields($results);
       $index = 0;
       $j = 0;
       while ($j &lt; $num_fields) {
           $column = mysql_fetch_field($results,$j);
           if (!empty($column-&gt;table)) {
               $this-&gt;map[$index++] = array($column-&gt;table, $column-&gt;name);
           } else {
               if (strpos($column-&gt;name, &#039;__&#039;)) {
                   $parts = explode(&#039;__&#039;, $column-&gt;name);
                   $this-&gt;map[$index++] = array($parts[0], $parts[1]);
               } else {
                   $this-&gt;map[$index++] = array(0, $column-&gt;name);
               }
           }
           $j++;
       }
   }
}
?&gt;
</pre>
<p>This code, which overrides the default MySQL DBO, allows you to SELECT something AS Modelname__Fieldname (with a double underscore) and will end up populating your result set as you would like it to ($results['Modelname']['Fieldname']).</p>
<p>In order to use a custom datasource, copy the code and save it as &#8220;/cake_dir/app/models/datasources/dbo/dbo_mysqlex.php&#8221; and edit your &#8220;/cake_dir/app/config/database.php&#8221; file so that it uses the &#8220;mysqlex&#8221; driver instead of plain old &#8220;mysql&#8221;.</p>
<p>This all came from a discussion on the excellent <a href="http://groups.google.com/group/cake-php/browse_thread/thread/f823cc7f168cd619?hl=en">CakePHP Google Group</a></p>
<p>Grigri posted <a href="http://bin.cakephp.org/view/1781729779">a copy of his modified MySQL Extended DBO</a> online if you want some more of his nice features like backtracing.</p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/402/custom-model-and-field-result-set-in-cakephp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Selecting a Different Table Column if the Original Record is NULL in MYSQL Using IFNULL</title>
		<link>http://otaqui.com/blog/398/selecting-a-different-table-column-if-the-original-record-is-null-in-mysql-using-ifnull/</link>
		<comments>http://otaqui.com/blog/398/selecting-a-different-table-column-if-the-original-record-is-null-in-mysql-using-ifnull/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 13:31:13 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=398</guid>
		<description><![CDATA[MySQL&#8217;s documentation is OK, but it&#8217;s examples are sometimes quite poor. I have a particular setup where values across two tables &#8211; a course table and a schedule table which relates to it &#8211; can be effectively &#8220;overridden&#8221;. The idea is that for any given course, one can set &#8220;default&#8221; values, and then these can [...]]]></description>
			<content:encoded><![CDATA[<p>MySQL&#8217;s documentation is OK, but it&#8217;s examples are sometimes quite poor.</p>
<p>I have a particular setup where values across two tables &#8211; a course table and a schedule table which relates to it &#8211; can be effectively &#8220;overridden&#8221;.  The idea is that for any given course, one can set &#8220;default&#8221; values, and then these can be overridden every time a course is actually scheduled to happen.</p>
<p>The courses table looks something like this:</p>
<p>COURSES<br />
id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY<br />
title VARCHAR(255) NOT NULL<br />
subtitle VARCHAR(255) NOT NULL<br />
description TEXT NOT NULL</p>
<p>SCHEDULES<br />
id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY<br />
course_id INT(11) NOT NULL<br />
subtitle VARCHAR(255) NULL<br />
description TEXT NULL</p>
<p>Hopefully you can see what I would want during a SELECT &#8211; to get the values from the schedules table if they aren&#8217;t null, or otherwise get the value from the courses table if they are.</p>
<p>This is achieved with the IFNULL built in function in MySQL.  IFNULL takes two arguments, and returns the first argument if it (the first argument that is) is not null, or the second argument if it is.  The actual SQL for my example looks like this:</p>
<p>SELECT courses.title, IFNULL(schedules.subtitle,courses.subtitle) AS subtitle, IFNULL(schedules.description,courses.description) AS description FROM schedules LEFT JOIN courses ON schedule.course_id=course.id;</p>
<p>This will give you the &#8220;subtitle&#8221; and &#8220;description&#8221; values from the linked table (schedules) if they exist, or the default values from the original table (courses) if they don&#8217;t.</p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/398/selecting-a-different-table-column-if-the-original-record-is-null-in-mysql-using-ifnull/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MySQL Data Files In MAMP Pro</title>
		<link>http://otaqui.com/blog/341/mysql-data-files-in-mamp-pro/</link>
		<comments>http://otaqui.com/blog/341/mysql-data-files-in-mamp-pro/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 07:32:21 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=341</guid>
		<description><![CDATA[It took me a little searching to find where MAMP Pro (I couldn't say whether MAMP is the same) puts its MySQL data files, so I thought I'd blog it]]></description>
			<content:encoded><![CDATA[<p>It took me a little searching to find where MAMP Pro (I couldn&#8217;t say whether MAMP is the same) puts its MySQL data files, so I thought I&#8217;d blog it:</p>
<p><code>
<pre>/Library/Application Support/living-e/MAMP PRO/db/mysql</pre>
<p></code></p>
<p>I had been looking in my User directory&#8217;s version of the same path (which is where MAMP Pro stores config files), but it makes perfect sense in this context that databases are shared while configuration isn&#8217;t.</p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/341/mysql-data-files-in-mamp-pro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

