<?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>wheresrhys &#187; Javascript</title>
	<atom:link href="http://wheresrhys.co.uk/category/computers-and-all-that/web/javascript-web/feed/" rel="self" type="application/rss+xml" />
	<link>http://wheresrhys.co.uk</link>
	<description>on the internet</description>
	<lastBuildDate>Fri, 06 Jan 2012 11:59:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Updating plugins to use the new jQuery.on event binding method in a backwards compatible way</title>
		<link>http://wheresrhys.co.uk/2012/01/updating-plugins-to-use-the-new-jquery-on-event-binding-method-in-a-backwards-compatible-way/</link>
		<comments>http://wheresrhys.co.uk/2012/01/updating-plugins-to-use-the-new-jquery-on-event-binding-method-in-a-backwards-compatible-way/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 11:59:12 +0000</pubDate>
		<dc:creator>wheresrhys</dc:creator>
				<category><![CDATA[Computers and all that]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://wheresrhys.co.uk/?p=1482</guid>
		<description><![CDATA[I&#8217;m going through all my written/half-written/never really gonna get written properly probably jQuery plugins to ready them for the new jQuery plugins site. While I&#8217;m at it I&#8217;m updating as many event handlers as I can to use the new $.on method (as other event binding methods are likely to be deprecated in future). This [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m going through all my written/half-written/never really gonna get written properly probably jQuery plugins to ready them for the new <a href="http://plugins.jquery.com/">jQuery plugins site</a>. While I&#8217;m at it I&#8217;m updating as many event handlers as I can to use the new <a href="http://api.jquery.com/on/">$.on</a> method (as other event binding methods are <a href="http://blog.jquery.com/2011/11/03/jquery-1-7-released/">likely to be deprecated in future</a>).</p>
<p>This presents a problem as I would like to achieve backwards compatibility too. A simple solution for the bind method is:</p>
<pre>var binder = $.fn.on ? "on": "bind";
$(this)[binder]("click", handler);</pre>
<p>But I&#8217;ve also put together this more generic solution (this is <em>completely</em> untested, but something like this should work)</p>
<pre>if(!$.fn.on) {
   $.fn.on = function(events, selector, data, handler) {
       if(typeof selector == "function") {
           return $.fn.bind.call(this, selector);
       } else if(typeof selector == "object"){
           return $.fn.bind.call(this, selector, data)
       } else {
           return $.fn.delegate.call(this, selector, data, handler)
       }
   }

   $.fn.off = function(events, selector, handler) {
       if(typeof selector == "function") {
           return $.fn.unbind.call(this, selector);
       } else {
           return $.fn.undelegate.call(this, selector, handler)
       }
   }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://wheresrhys.co.uk/2012/01/updating-plugins-to-use-the-new-jquery-on-event-binding-method-in-a-backwards-compatible-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Two small but useful javascript facts</title>
		<link>http://wheresrhys.co.uk/2011/02/two-small-but-useful-javascript-facts/</link>
		<comments>http://wheresrhys.co.uk/2011/02/two-small-but-useful-javascript-facts/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 13:32:15 +0000</pubDate>
		<dc:creator>wheresrhys</dc:creator>
				<category><![CDATA[Computers and all that]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://wheresrhys.co.uk/?p=1476</guid>
		<description><![CDATA[Passing parameters into setTimeout callbacks setTimeout (and setInterval too perhaps?) accepts a third parameter, an array of parameters to pass in to your callback function, so setTimeout(function() { myFunction(need, to, pass, these, in); }, 200); Can far more efficiently be written setTimeout(myFunction, 200, [need,to,pass,these,in]); Firebug&#8217;s console still works when you&#8217;re at a breakpoint (and can [...]]]></description>
			<content:encoded><![CDATA[<h2><a href="http://www.flickr.com/photos/dragonblog/254318049/"><img class="alignright" src="http://farm1.static.flickr.com/89/254318049_758420677d_m.jpg" alt="Bees knees" width="214" height="240" /></a>Passing parameters into setTimeout callbacks</h2>
<p>setTimeout (and setInterval too perhaps?) accepts a third parameter, an array of parameters to pass in to your callback function, so</p>
<pre>setTimeout(function() {</pre>
<pre>myFunction(need, to, pass, these, in);</pre>
<pre>}, 200);</pre>
<p>Can far more efficiently be written</p>
<pre>setTimeout(myFunction, 200, [need,to,pass,these,in]);</pre>
<h2>Firebug&#8217;s console still works when you&#8217;re at a breakpoint (and can be very useful for debugging jQuery)</h2>
<p>When debugging using firebug  and you set a breakpoint, when your code stops at that breakpoint</p>
<ul>
<li>you can still use firebug&#8217;s console to run any code you like</li>
<li>&#8220;this&#8221; in firebug&#8217;s console is always set to what &#8220;this&#8221; is set to in your code</li>
</ul>
<p>This means that you can play around with your variables at will at any given point in your code. It may be that I was a dunce for not knowing this, but I&#8217;ve never seen anybody I work with take advantage of these facts, so maybe it&#8217;s news to more people than just me&#8230;. and it&#8217;s bloody useful so I feel no shame in shouting about it.</p>
<p>For instance jQuery, for all its benefits, can be a pain to debug due to the fact that so much work is done by a single string (your selector) and on a single line of code (using chaining), and that jQuery often doesn&#8217;t give very helpful error messages. This means if you wnat to debug a certain line you have to either a) keep stepping in and out of the murky world of jQuery&#8217;s inner methods in order to find out where and why the unexpected bug is happening; or b) add temporary lines to your code which carry out only part of the single jQuery line, then reload the page to observe if they succeed or fail.</p>
<p>Not so if you set a breakpoint and then use the console. For instance, say a fairly complex line of jQuery misfires.</p>
<pre>$("&gt;p input:focus", myContainer).css("height", adjustHeight).children(".shrinker").remove().end().wrapAll("&lt;div class=\"done\"&gt;");
</pre>
<p>By setting a breakpoint in my code on this line, and then copying the line into the console and running it, I can progressively remove/tweak bits until the error no longer appears; I never have to step through jQuery&#8217;s code and I never have to reload the page. Easy peasy.</p>
]]></content:encoded>
			<wfw:commentRss>http://wheresrhys.co.uk/2011/02/two-small-but-useful-javascript-facts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eventful times</title>
		<link>http://wheresrhys.co.uk/2010/10/eventful-stuff/</link>
		<comments>http://wheresrhys.co.uk/2010/10/eventful-stuff/#comments</comments>
		<pubDate>Fri, 22 Oct 2010 08:45:09 +0000</pubDate>
		<dc:creator>wheresrhys</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://wheresrhys.co.uk/?p=1463</guid>
		<description><![CDATA[I&#8217;ve just started delving into using jQuery&#8217;s custom events. They&#8217;ve been around for a while, but I never really saw the point of using them before; I&#8217;d read one or two nice examples of how they can be used, but I kept hitting a mental block when trying to think of ways to use them [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/31420447@N04/2944088120/"><img class="alignright" title="An event (schematic)" src="http://farm4.static.flickr.com/3155/2944088120_65f106de36_m.jpg" alt="" width="160" height="240" /></a>I&#8217;ve just started delving into using <a href="http://api.jquery.com/trigger/">jQuery&#8217;s custom events</a>. They&#8217;ve been around for a while, but I never really saw the point of using them before; I&#8217;d read one or two nice examples of how they can be used, but I kept hitting a mental block when trying to think of ways to use them in my own work. I think, like the great leap forward you have to take when realising an object can be as abstract as you want (eg a process that exists only fleetingly, such as an ajax call, can be an object), programming using events as a central aspect of your style requires a big change in the way you think about problems.</p>
<p>As an example, previously I was always saving references to objects that a given object might need to interact with, e.g.</p>
<pre>function Obj1() {
   this.container = $("#container");
   this.child = new Obj2(this);

   this.method = function() {
         //do something
   }
}();

function Obj2(parent) {
   var that = this;
   this.parent = parent;
   this.container = $("#childContainer");
   $(this.container).click(function(){
       that.alter();
   });

   this.alter = function() {
      this.altered = true;
      this.parent.method();
   }
}

var obj1 = new Obj1();
</pre>
<p>So what&#8217;s wrong with this? It&#8217;s difficult to say, but it always jarred with me that you had to pass in &#8220;this&#8221; as a parameter in order to make it easy to track back to the parent. And there will be circumstances where you&#8217;re creating an object that has to interact with lots of other objects and you have to either pass in lots of parameters when creating the object or do some on the fly processing to find the objects that need to be affected.</p>
<p>Now, here&#8217;s the same thing achieved using custom events</p>
<pre>function Obj1() {
   var that = this;
   this.container = $("#container");
   this.child = new Obj2();
   $("#childContainer").altered(function(){
       that.method();
   });
   this.method = function() {
         //do something
   }
};

function Obj2() {
   var that = this;
   this.container = $("#childContainer");
   $(this.container).click(function(){
      that.alter();
   });

   this.alter = function() {
      this.altered = true;
      this.container.trigger("altered");
   }
}

var obj1 = new Obj1();
</pre>
<p>Ok, so what&#8217;s so good about this? It may even use more lines of code. But crucially it gets rid of having to store references to objects, freeing you up to create ever more complicated applications without having to create a web of dependencies that is difficult to maintain*. A good analogy I think is to think of an object triggering an event as a child shouting. If the child shouts when it needs something then it doesn&#8217;t have to constantly hold its parent&#8217;s hand; it&#8217;s parent comes to it on hearing the shout. And this gives the child freedom to explore the world on its own terms, and develop into a more rounded, unstifled human being&#8230; but I think I&#8217;m straying off the point.</p>
<p>So to sum up, javascript/jQuery custom events are a very useful feature.</p>
<p>And don&#8217;t smother your progeny.</p>
<p>*I&#8217;ve just re-read the <a href="http://api.jquery.com/trigger/">API</a> and found out that you can attach all manner of data to the event as extra parameters, which will also be very useful for this.</p>
]]></content:encoded>
			<wfw:commentRss>http://wheresrhys.co.uk/2010/10/eventful-stuff/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Batch including headscripts and links in Zend Framework</title>
		<link>http://wheresrhys.co.uk/2010/09/batch-including-headscripts-and-links-in-zend-framework/</link>
		<comments>http://wheresrhys.co.uk/2010/09/batch-including-headscripts-and-links-in-zend-framework/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 11:44:25 +0000</pubDate>
		<dc:creator>wheresrhys</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://wheresrhys.co.uk/?p=1459</guid>
		<description><![CDATA[A bit of a dull post to break my silence with, but after a summer away, it&#8217;s back to the grindstone of earning a living through programming. Fingers crossed I&#8217;ll be given the opportunity to work again on a website I finished ages ago, fixing all the things I did badly and adding some enhancements. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/rhysickle/4776734399/"><img class="alignright" title="bus stops here" src="http://farm5.static.flickr.com/4137/4776734399_5d5ff8ce40_m.jpg" alt="" width="240" height="160" /></a>A bit of a dull post to break my silence with, but after a summer away, it&#8217;s back to the grindstone of earning a living through programming. Fingers crossed I&#8217;ll be given the opportunity to work again on a website I finished ages ago, fixing all the things I did badly and adding some enhancements.</p>
<p>I used Zend framework for the back-end of the site and first time around I had a very rudimentary grasp of how to use it, but no real in depth understanding of its finer points. I&#8217;m now finding that I did a lot of things the long way round (eg typing out JSONs by hand  rather than using the Zend_JSON class to build them automatically). One major bugbear I had was that I was adding all my javascript and css files individually to the document head, and that the syntax for doing so in Zend wasn&#8217;t really any more concise than just hard coding &lt;link rel=&#8221;stylesheet&#8221; &#8230;.</p>
<p>So now I&#8217;m revisiting Zend the first thing I&#8217;ve done is write a couple of view helpers to batch add javascript and css files, which I thought I&#8217;d share here.</p>
<pre>&lt;?php

class Zend_View_Helper_IncludeStyles extends Zend_View_Helper_Abstract {

   public function includeStyles($folder)
   {
     $results = array();
     $handler = opendir(getenv("DOCUMENT_ROOT") . "/css/" . $folder);
     while ($file = readdir($handler)) {
       if ($file != "." &amp;&amp; $file != "..") {
         $this-&gt;view-&gt;headLink()-&gt;appendStylesheet('/css/' . $folder . '/' . $file);
       }
     }
     closedir($handler);
   }
}</pre>
<pre>&lt;?php

class Zend_View_Helper_IncludeScripts extends Zend_View_Helper_Abstract {

  public function includeScripts($folder)
  {
    $results = array();
    $handler = opendir(getenv("DOCUMENT_ROOT") . "/js/" . $folder);
    while ($file = readdir($handler)) {
      if ($file != "." &amp;&amp; $file != "..") {
        $this-&gt;view-&gt;headScript()-&gt;appendFile('/js/' . $folder . '/' . $file);
      }
    }
    closedir($handler);
  }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://wheresrhys.co.uk/2010/09/batch-including-headscripts-and-links-in-zend-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>It&#8217;s not what you say, it&#8217;s which font you say it in</title>
		<link>http://wheresrhys.co.uk/2010/03/process-for-choosing-font/</link>
		<comments>http://wheresrhys.co.uk/2010/03/process-for-choosing-font/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 22:36:21 +0000</pubDate>
		<dc:creator>wheresrhys</dc:creator>
				<category><![CDATA[Computers and all that]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[My resources]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[comparison]]></category>
		<category><![CDATA[fonts]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[switcher]]></category>

		<guid isPermaLink="false">http://wheresrhys.co.uk/?p=1001</guid>
		<description><![CDATA[I&#8217;m redesigning this site at the moment and one thing I wanted to pay closer attention to this time around was choice of fonts. Notwithstanding the fact that web browsers were, until recently, pretty shoddy at allowing you to use the fonts you wanted to, the main reason I hadn&#8217;t paid much attention to fonts [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/russell-higgs/4397586937/"><img class="alignright" title="Suck my Goldman Sachs" src="http://farm5.static.flickr.com/4069/4397586937_9349cbc67c_m.jpg" alt="" width="240" height="180" /></a>I&#8217;m redesigning this site at the moment and one thing I wanted to pay closer attention to this time around was choice of fonts. Notwithstanding the fact that web browsers were, until recently, pretty shoddy at allowing you to use the fonts you wanted to, the main reason I hadn&#8217;t paid much attention to fonts in the past was that it&#8217;s so darn hard picking one, for a number of reasons:</p>
<ol>
<li>There&#8217;s so damn many of them</li>
<li>There&#8217;s no relation between names and appearance (as opposed to, say, #f60283 being guessable as a garish pink, closer to red than to mauve)</li>
<li>They&#8217;re difficult to preview and compare</li>
</ol>
<p>So in the interests of productivity, quality and, dare I say it, working smarter, not harder, I&#8217;ve devoted some time to sorting out how I choose fonts, reduced to the following four steps:</p>
<ol>
<li>Organise your fonts in themed folders</li>
<li>Find a good stand alone font previewer i.e. don&#8217;t rely on photoshop and windows&#8217; poor tools</li>
<li>Narrow down to a short list</li>
<li><a href="#the-javascript-bit">Use javascript to make quick comparisons easy</a></li>
</ol>
<p>Read on if your curiosity is piqued.</p>
<h3>1. Organising the fonts</h3>
<p>Windows&#8217;s default font collection (and, I imagine, Apple&#8217;s too) and the collection of 2000 fonts I also use are organised alphabetically which is rubbish. Unless you have web design OCD you&#8217;re unlikely to want to narrow down your choice of font by it&#8217;s first-letter. But, on the other hand, it is difficult to categorise fonts; I&#8217;m yet to see a website do it effectively, and I&#8217;m not entirely happy with my choice. But in the end I plumped for the following: serif, sans-serif, script, stylised, symbol, stencil.</p>
<p>Stencil could easily fall within stylised, and stylised could easily be split into subfolders (Art Deco, Gothic, Celtic &#8230;), and I realised part way through that I should have a subfolder within symbol for fonts depicting alphabets other than Roman, but I think a minimal folder system would be serif, sans-serif and other. In the serif and sans-serif folders I included only sensible fonts you could print a book not aimed at children in, which I think is a useful distinction to make; often the hardest task when picking fonts is to find the one which is subtly different to other ordinary fonts, but somehow suits the design better than almost indistinguishable alternatives. Cutting out all the fancy fonts makes this task a lot easier.</p>
<p>So once you have all these folders put a copy of each font you have in one of them, and you&#8217;re ready for the next step. You don&#8217;t need to bother with installing them yet.</p>
<h3>2. Previewing your fonts</h3>
<p>My criteria for a good font-previewer are:</p>
<ol>
<li>Choice of text to use for the preview</li>
<li>Choice of text-size and colour</li>
<li>Ability to organise fonts how you want them organised</li>
<li>Speed and ease of switching between one font and another</li>
<li>Ease of installing a font</li>
</ol>
<p>Windows&#8217; control panel fails to meet conditions 1 and 2, and Photoshop&#8217;s built-in font selector fails to meet 3 and 4, and they both force you to install a font before using it. The best free solution I&#8217;ve come across for Windows which meets all 5 conditions is <a href="http://www.lanmisoft.com/fastfontpreview.htm">Fast Font Preview</a>.</p>
<h3>3. Short-listing</h3>
<p>Once you&#8217;ve got Fast Font Preview installed you can start picking your shortlist. Simply browse to your organised font folders, click on settings to type in your sample text, adjust the font-size to what you want, and double click on any contenders. Once the font is opened you can install with one click. While the font is open you&#8217;ll also want to jot down its official font name.</p>
<h3 id="the-javascript-bit">4. Use javascript to make comparisons</h3>
<p>This is where I stop being pedantic and hopefully can be of some use. Insert the following script into the head of your web-page-in-need-of-a-font, substitute your list of font names and the id/tag name of the elements to be affected and, hey presto, a handy font-switcher should appear, making choosing exactly the right font much easier. If your web page already uses javascript then add the body of the function to your existing onload event. (NOTE: It tends to work better in Google Chrome than other browsers as Google Chrome seems to be a bit more forgiving when it comes to font names).</p>
<pre>window.onload = function() {
 var body = document.getElementsByTagName('body')[0];
 var id = '';
 var tagName = '';
 var fonts = 'Comma,separated,list,of font,names';
 fonts = fonts.split(',');
 var elements = (id)      ? [document.getElementById(id)] :
                (tagName) ? document.getElementsByTagName(tagName):
                            [body];
 var switcher = document.createElement('DIV');
 switcher.setAttribute('style','position:absolute;top:0;right:0;background:white;z-index:200;padding:10px;');
 for(var i=0, il = fonts.length;i&lt;il;i++){
   createButton(i);
 }
 body.appendChild(switcher);
 var buttons = switcher.childNodes
 loadFont(0);

 function createButton(pos) {
   var button = document.createElement('a');
   button.innerHTML = fonts[pos];
   button.setAttribute('style','display:block;padding:2px;');
   button.setAttribute('href','#');
   button.onclick = function() {loadFont(pos);};
   switcher.appendChild(button);
 }

 function loadFont(pos) {
   for (var i=0,il=elements.length;i&lt;il;i++)
   {
     elements[i].style.fontFamily = fonts[pos];
   }
   for (var j=0,jl=buttons.length;j&lt;jl;j++) {
     buttons[j].style.backgroundColor='';
   }
   buttons[pos].style.backgroundColor='yellow';
   return false;
 };
};</pre>
]]></content:encoded>
			<wfw:commentRss>http://wheresrhys.co.uk/2010/03/process-for-choosing-font/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How I&#8217;d teach myself programming, if I could do it all over again</title>
		<link>http://wheresrhys.co.uk/2010/02/how-id-teach-myself-programming-if-i-could-do-it-all-over-again/</link>
		<comments>http://wheresrhys.co.uk/2010/02/how-id-teach-myself-programming-if-i-could-do-it-all-over-again/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 16:37:58 +0000</pubDate>
		<dc:creator>wheresrhys</dc:creator>
				<category><![CDATA[Computers and all that]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[autodidact]]></category>
		<category><![CDATA[beginner's guide]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[libraries]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[self-taught]]></category>

		<guid isPermaLink="false">http://wheresrhys.co.uk/?p=1063</guid>
		<description><![CDATA[As I , web development as a career is rare in that you can just pick it up off the internet unlike, say, luxury pet grooming. But it took me a while to find good strategies to learn what I wanted to learn. If I had a time machine I&#8217;d go back and tell myself [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/criminalintent/97078946/"><img class="alignright" title="Searching for the right way" src="http://farm1.static.flickr.com/32/97078946_00d1f55cd3_m.jpg" alt="" width="240" height="180" /></a>As I <a href="http://wheresrhys.co.uk/2010/02/your-friendly-office-idiot/">mentioned the other day</a>, web development as a career is rare in that you can just pick it up off the internet unlike, say, luxury pet grooming. But it took me a while to find good strategies to learn what I wanted to learn. If I had a time machine I&#8217;d go back and tell myself the following*.</p>
<h3>Don&#8217;t buy beginners guide programming books</h3>
<p>I bought a couple of these on php/mysql and javascript. I won&#8217;t say they were a complete waste of money as I did learn the basics from them, but there are several good reasons not to rely on them for your starting point:</p>
<ol>
<li>These books are almost always a long-winded, incomplete version of the programming language&#8217;s documentation (which is normally available for free online) structured around building an example application which probably bears little resemblance to something you would like to build, e.g a quiz about the Simpsons</li>
<li>Unlike online resources these books are not searchable with lots of easy to follow cross-references</li>
<li>Online tutorials are more up to date</li>
</ol>
<h3>Find a good online tutorial</h3>
<p>For any programming language there will be loads of beginner&#8217;s tutorials online; just search Google for &#8220;[language name] beginner&#8217;s tutorial&#8221;. the top results won&#8217;t however generally be the best, so open up lots of tutorials in lots of tabs, narrow it down to a few of the best and then bookmark them, before starting to follow one of them. If you get stuck on a section you can always try the explanatiosn given in your other bookmarked tutorials or search google for &#8220;[programming language] [topic] explained&#8221;. Below are some of my favourite tutorials:</p>
<ul>
<li>php &#8211; <a href="http://devzone.zend.com/article/627-PHP-101-PHP-For-the-Absolute-Beginner">http://devzone.zend.com/article/627-PHP-101-PHP-For-the-Absolute-Beginner</a></li>
<li>html/css &#8211; <a href="http://htmldog.com">http://htmldog.com</a></li>
<li>javascript &#8211; can&#8217;t say I have any recommendations</li>
<li>zend framework &#8211; <a href="http://www.zendcasts.com/archives">http://www.zendcasts.com/archives</a></li>
</ul>
<h3>Learn to use documentation</h3>
<p>It took me a long time to realise that most programming language documentation follows  the same structure, and once you understand this you are able to teach yourself any language. Roughly, a programming language (at least, the ones I know) is a collection of types of thing (objects, strings, arrays, numbers etc&#8230;) and processes (loops, conditionals, functions) for manipulating things, and some things have built in sub-things (properties) and their own dedicated processes (methods), and most processes will only work on certain types of thing (arguments of the correct type).</p>
<p>Well written documentation will list all the above information systematically (together with the basic syntax and rules of the language), so that if you create a variable of a certain type you can find out what you are able to do to it, or if you want to use a function you can find out what conditions its arguments need to meet. An understanding of <a href="http://en.wikipedia.org/wiki/Object-oriented_programming">object oriented programming</a> also goes a long way to being able to grasp documentation, but isn&#8217;t essential for a beginner.</p>
<h3>Use libraries&#8230; lots of libraries</h3>
<p>Not the ones with books. A library (sometimes called a framework) is a collection of software written by somebody else that takes care of some tedious/difficult processes for you. The classic example at the moment would have to be <a href="http://jquery.com">jQuery</a>. Without jQuery the differences between browsers&#8217; implementations of javascript would make developing javascript web applications a specialised and difficult task with unreliable results. Because jQuery is a collection of code that thinks about all the cross-browser differences for you (as well as doing lots of other useful tasks) creating reliable javascript applications is now something even beginners can take on. Some libraries also have thriving communities that build plug-ins to extend the functionality further.</p>
<p>And to make use of all this all you have to do is include a file (or collection of files) and get to grips with the library&#8217;s documentation (often called an API &#8211; Application Programming Interface) which, no matter how daunting it may seem at first, is guaranteed to be easier than writing all the code yourself.</p>
<h3>Invest in some expert/advanced books</h3>
<p>Beginner&#8217;s guides may have been made redundant by the internet, but there is still room for more advanced books. Yes, the information is probably on the internet somewhere but structured tutorials aimed at more advanced users are far less common than beginner&#8217;s tutorials. I won&#8217;t recommend any books myself as I don&#8217;t consider myself enough of an expert to judge, and I also don&#8217;t own many yet, but the ones I do have are full of techniques I couldn&#8217;t have worked out for myself.</p>
<p><strong>And that&#8217;s how I should have done it!</strong></p>
<p>*Like hell I would. Straight to the bookies it&#8217;d be.</p>
]]></content:encoded>
			<wfw:commentRss>http://wheresrhys.co.uk/2010/02/how-id-teach-myself-programming-if-i-could-do-it-all-over-again/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Remove text nodes function</title>
		<link>http://wheresrhys.co.uk/2010/02/remove-text-nodes-function/</link>
		<comments>http://wheresrhys.co.uk/2010/02/remove-text-nodes-function/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 12:29:41 +0000</pubDate>
		<dc:creator>wheresrhys</dc:creator>
				<category><![CDATA[Computers and all that]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[childNodes]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[text nodes]]></category>

		<guid isPermaLink="false">http://wheresrhys.co.uk/?p=1101</guid>
		<description><![CDATA[Here&#8217;s a fairly useful function for when you&#8217;re using javascript in a web page without using  library like jQuery to take care of the nitty gritty. It tackles problems that occur when you get the child nodes (eg myList.childNodes) of a DOM node, but there is whitespace in the html. Each of these whitespaces gets [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/texasforums/2099498774/"><img class="alignright" title="Too many children" src="http://farm3.static.flickr.com/2048/2099498774_34aeff085e_m.jpg" alt="" width="240" height="180" /></a>Here&#8217;s a fairly useful function for when you&#8217;re using javascript in a web page without using  library like jQuery to take care of the nitty gritty.</p>
<p>It tackles problems that occur when you get the child nodes (eg myList.childNodes) of a DOM node, but there is whitespace in the html. Each of these whitespaces gets counted as a DOM node of its own, a text node, so if you run code to iterate through eg all the children of a &lt;ul&gt; you will find that your code throws an error as not every node is an &lt;li&gt; as you expected.</p>
<pre>function removeTextNodes(nodeList) {
  list = Array.prototype.slice.apply(nodeList);
  for(var i=0, il=list.length;i&lt;il;i++)
  {
    if(list[i].nodeType == 3)
    {
      list.splice(i,1);
      i--;
      il--;
    }
  }
  return list;
}

var myUL = document.getElementById('myUl');
var myLIs = removeTextNodes(myUL.childNodes);</pre>
<p>I haven&#8217;t tested it in any browsers apart from firefox as I&#8217;m a bit busy, but if you find it&#8217;s buggy in Internet Explorer or elsewhere leave a comment.</p>
<p>(By the way, if you&#8217;re wondering about eth relevance of the image, if you search for &#8220;too many children&#8221; in flickr it throws up<a href="http://www.flickr.com/photos/texasforums/sets/72157600267190021/"> lots of photos of a very serious looking texas school board meeting</a>. Too many children in Texas, apparently!).</p>
]]></content:encoded>
			<wfw:commentRss>http://wheresrhys.co.uk/2010/02/remove-text-nodes-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deletious</title>
		<link>http://wheresrhys.co.uk/2010/02/deletious/</link>
		<comments>http://wheresrhys.co.uk/2010/02/deletious/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 17:24:12 +0000</pubDate>
		<dc:creator>wheresrhys</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Life in general]]></category>
		<category><![CDATA[My resources]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[delete]]></category>
		<category><![CDATA[deletious]]></category>
		<category><![CDATA[delicious]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://wheresrhys.co.uk/?p=1258</guid>
		<description><![CDATA[Well, this has to be the quickest I&#8217;ve ever gone from to publishable (albeit limited functionality) website. Deletious is my new site for simultaneously viewing a page bookmarked in Delicious and deciding whether to keep or delete the bookmark. I&#8217;ve had quite a lot of fun using it the last few days, rediscovering all sorts [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://wheresrhys.co.uk/wp-content/uploads/2010/02/deletious_logo1.gif"><img class="alignright size-full wp-image-1260" title="deletious logo" src="http://wheresrhys.co.uk/wp-content/uploads/2010/02/deletious_logo1.gif" alt="" width="200" height="200" /></a>Well, this has to be the quickest I&#8217;ve ever gone from <a href="http://wheresrhys.co.uk/2010/02/delicious-though-not-so-easy-to-swallow/">idea</a> to publishable (albeit limited functionality) website.</p>
<p><a href="http://deletious.wheresrhys.co.uk">Deletious</a> is my new site for simultaneously viewing a page bookmarked in Delicious and deciding whether to keep or delete the bookmark. I&#8217;ve had quite a lot of fun using it the last few days, rediscovering all sorts of articles, games, tools and other long forgotten sites. As well as wasting a lot of time reacquainting myself with all these I&#8217;ve also managed to de-clutter my Delicious account; all the CSS articles from 2-3 years ago giving an introduction to topics I now know inside out are gone from my bookmarks, as are all those gimmicky websites I can&#8217;t believe i found funny at one time.</p>
<p>Disappointingly, I&#8217;m having problems uploading the logo to the website&#8217;s folder, but it&#8217;ll be sorted sometime soon I hope.</p>
<p>So please do <a href="http://deletious.wheresrhys.co.uk">give it a go</a> and let me know what you think.</p>
<p><strong>EDIT &#8211; There&#8217;s a bug that pops up every now and then (something to do with caching) which leads Deletious to show zero bookmarks for your account. I&#8217;ll fix the bug when I get time, but waiting a few hours seems to clear the cache (at least, it works for my account) and then you can access your bookmarks again.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://wheresrhys.co.uk/2010/02/deletious/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Delicious, though not so easy to swallow</title>
		<link>http://wheresrhys.co.uk/2010/02/delicious-though-not-so-easy-to-swallow/</link>
		<comments>http://wheresrhys.co.uk/2010/02/delicious-though-not-so-easy-to-swallow/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 18:12:28 +0000</pubDate>
		<dc:creator>wheresrhys</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Life in general]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[usability]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[delete]]></category>
		<category><![CDATA[delicious]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://wheresrhys.co.uk/?p=1235</guid>
		<description><![CDATA[For a long time I&#8217;ve wanted to work with the Delicious API. Initially it was because the Delicious website not only had the difficult to remember del.icio.us url, but was also very badly designed. If you compared its progress &#8211; addition of new features, cleaning up of design, making use of new techniques suchas AJAX [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/diffuse/1207154579/"><img class="alignright" title="Hard to swallow" src="http://farm2.static.flickr.com/1004/1207154579_d53dab7d0c_m.jpg" alt="" width="240" height="191" /></a>For a long time I&#8217;ve wanted to work with the <a href="http://delicious.com/help/api">Delicious API</a>. Initially it was because the Delicious website not only had the difficult to remember del.icio.us url, but was also very badly designed. If you compared its progress &#8211; addition of new features, cleaning up of design, making use of new techniques suchas AJAX &#8211; with its web2.0 compatriots (Flickr, Digg, <a href="http://www.boriswatch.co.uk">boris-johnson.com</a>) it lagged way behind.</p>
<p>So I initially planned to build a new front-end for it, making it easier to work with your bookmarks, but before I could progress far enough in my coding abilities they completely redesigned the site; a <em>vast </em>improvement.</p>
<p>Though still not perfect. For a while I&#8217;ve found it frustrating that there is no easy way to simultaneously see the content of a bookmarked page and delete the bookmark if you deem it no longer useful, so my delicious account gradually got more and more cluttered. Well, this afternoon I decided to do something about it (and not just because I&#8217;m avoiding doing more important stuff).</p>
<p>But I was foiled for a long time by the laziness of the Delicious developers. My initial plan was to use javascript to get a JSON of all my bookmarks (or alternatively request one at a time) and go through them one by one, displaying the webpage in an iframe, and offering the option to discard or keep the bookmark. However, delicious only publish this data as XML which means, due to cross-domain restrictions on AJAX, you can&#8217;t just use javascript. I may be a bit hasty in pinning this on developer laziness, but I imagine creating alternate templates (because that&#8217;s all the difference between JSON and XML really) wouldn&#8217;t be too time consuming, and would greatly enhance the versatility of the API.</p>
<p>Anyway, I realised I would have to use a bit of PHP to get the XML and create pages from which my javascript would be able to access the data. Luckily, before I dived straight in I came across <a href="http://www.phpdelicious.com/">phpdelicious</a> (which, appropriately, I have now bookmarked in Delicious) , a very easy to use php class for wrapping the Delicious API, which is very handy indeed. Less than an hour later I had built exactly what I wanted.</p>
<p>I reckon a few more hours development and I can make it a publicly available service.  All I need to do is include a form for other users to be able to login, and (ideally) preload websites in the iframe to speed things up (though this is problematic as <a href="http://stackoverflow.com">some</a> <a href="http://alistapart.com">sites</a> force the whole web page to be redirect if you try and put them in an iframe).</p>
]]></content:encoded>
			<wfw:commentRss>http://wheresrhys.co.uk/2010/02/delicious-though-not-so-easy-to-swallow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sorted</title>
		<link>http://wheresrhys.co.uk/2010/02/sorted/</link>
		<comments>http://wheresrhys.co.uk/2010/02/sorted/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 11:55:43 +0000</pubDate>
		<dc:creator>wheresrhys</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://wheresrhys.co.uk/?p=1218</guid>
		<description><![CDATA[One of the problems I had to solve when writing my new was sorting an array of arrays/multidimensional array by one given column, eg testArray = [[a, b], [b, a]]; How would you sort by the second column of the array? I&#8217;m not sure if mine is the best solution, but here it is (it [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/davidgutierrez/3641153740/"><img class="alignright" title="columns" src="http://farm4.static.flickr.com/3396/3641153740_88448706d3_m.jpg" alt="" width="240" height="159" /></a>One of the problems I had to solve when writing my new <a href="http://wheresrhys.co.uk/2010/02/jquery-listsplitter-plugin/">jQuery listSplitter plugin</a> was sorting an array of arrays/multidimensional array by one given column, eg</p>
<pre>testArray = [[a, b], [b, a]];</pre>
<p>How would you sort by the second column of the array?</p>
<p>I&#8217;m not sure if mine is the best solution, but here it is (it also works for an array of objects as well as an array of arrays):</p>
<pre>/**
* sorts an array of arrays or objects using a specified column/property
*
* @param column (str/int) - the name/index of the column to use for sorting
* @param sortFunction (func) - the sort function to use for sorting (sort functions
*                             that can be used by array.sort() will also work here)
* @return array
*/
Array.prototype.sortByColumn = function(column, sortFunction) {
  return this.sort(function(a,b) {
    var testArray = [a[column], b[column]];
    testArray = (sortFunction) ? testArray.sort(sortFunction) : testArray.sort();
    return (testArray[0] == a[column]) ? -1 : 1;
  });
}
</pre>
<p>And to apply it to an array use it similarly to the array.sort() method, eg</p>
<pre>myArray.sortByColumn(5);//sort alphabetically by column 5 of the array
myArray.sortByColumn('title', sortByLength); //sort by length of title attribute
function sortByLength(a,b) {
   return a.length - b.length;
}
myArray.sortByColumn('price',function(a,b){return a - b}); // sort by price
</pre>
<h3>How it works</h3>
<p>It runs the normal array.sort() method, but uses as its sort function a clever little function which picks out the values to be sorted by, creates a new test array out of these values and sorts it. Using the <a href="http://wheresrhys.co.uk/2009/12/ternary-gets-a-turn/">ternary operator</a>, it checks if the test array is unchanged after this sort. If it is unchanged it means that the items in the original array are already in the right order so no change is made, otherwise they are swapped in the original array too.</p>
]]></content:encoded>
			<wfw:commentRss>http://wheresrhys.co.uk/2010/02/sorted/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

