<?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>Big Ideas by Jezen Thomas</title>
	<atom:link href="http://jezenthomas.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://jezenthomas.co.uk</link>
	<description>I design and develop digital things like websites and iOS applications.</description>
	<lastBuildDate>Thu, 26 Apr 2012 15:30:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Scalable CSS Strategy</title>
		<link>http://jezenthomas.co.uk/scalable-css-strategy/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=scalable-css-strategy</link>
		<comments>http://jezenthomas.co.uk/scalable-css-strategy/#comments</comments>
		<pubDate>Thu, 26 Apr 2012 15:30:24 +0000</pubDate>
		<dc:creator>Jezen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://jezenthomas.co.uk/?p=308</guid>
		<description><![CDATA[Smashing Magazine recently published an article entitled 'A New Front-End Methodology: BEM'. In the article, some Russians argued that we should give classes to everything. That sounds alright, doesn't it? Well actually, they even went so far as saying that every HTML element should be given a class that is the element's type. This sounds like madness to me. <a href="http://jezenthomas.co.uk/scalable-css-strategy/"><br /><br />Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Smashing Magazine recently published an article entitled <a href="http://coding.smashingmagazine.com/2012/04/16/a-new-front-end-methodology-bem/">A New Front-End Methodology: BEM</a>. In the article, some Russians argued that we should give classes to everything. That sounds alright, doesn&#8217;t it? Well actually, they even went so far as saying that every HTML element should be given a class that is the element&#8217;s type. For example, paragraph tags should be notated as:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;p class=&quot;paragraph&quot;&gt;&lt;/p&gt;
</pre>
<p>This sounds like madness to me. I&#8217;ll quote their most plausible reason for this:</p>
<blockquote><p>Browsers parse CSS rules from right to left. That means, that selector “.menu a” browsers apply that way: 1. Select all ‘a’ nodes of the page. 2. Filter that ‘a’ nodes and keep only those of them that has ‘.menu’ as ancestor.<br />
If you have two or more rules ending with “a”, a browser would try to apply every rule to every link of the page. That could slow your page rendering speed, as it takes a lot of excess time.</p></blockquote>
<p>A <a href="http://bittersmann.de/">very smart German man</a> made some very strong counter-arguments, and pointed out that <em>to give every element a class is to miss the point of CSS</em>. Furthermore, he linked to an article demonstrating that <a href="http://www.stevesouders.com/blog/2009/03/10/performance-impact-of-css-selectors/">the named performance issues are so small that it&#8217;s not worth trying to optimise CSS selectors</a>.</p>
<p>That&#8217;s enough about BEM. It&#8217;s a drop in the ocean of over-complicated CSS strategies. Some people are pre-processing CSS (which isn&#8217;t so bad, really), and some people are even trying to coin a term like &#8220;Object-Oriented CSS&#8221; (WTF?!). Writing CSS shouldn&#8217;t be complicated. The beauty is in the simplicity. Over the past year or so, I&#8217;ve experimented with different ways of organising my stylesheets in such a way as to minimise repetitive code. I&#8217;ve tried really large comment banners:</p>
<pre class="brush: css; title: ; notranslate">
/*--------------------------------------------------
                        Header
	-------------------------------------------------- */

header {
	position: absolute;
	width: 920px;
	padding: 20px;
	background: #f0f0f0;
}

#logo {
	display: block;
	background: transparent url(logo.png) no-repeat 0 0;
}

/*--------------------------------------------------
                         Body
	-------------------------------------------------- */

#content {
	/* 

	Some more styles, ad infinitum.... 

	*/
}
</pre>
<p>&#8230;And this seems alright. At a quick glance, I can see which rules apply to which part of the document. That&#8217;s one way of keeping a document organised, but I&#8217;m not sure it&#8217;s quite <em>enough</em>. There&#8217;s still one fairly serious problem. The stylesheet is going to grow, and grow, and <strong>grow</strong>! You&#8217;ll be merrily coding away, pushing margin values around and building your interface, until suddenly your stylesheet is over a thousand lines long!</p>
<h2>My solution</h2>
<p>Since I have the luxury of working with a large display, I now place all my rules on one line. Is that crazy?! No. Check it out:</p>
<pre class="brush: css; title: ; notranslate">
header {background: transparent url(../img/header-bg.png) repeat-x 0 0; height: 141px;}
header a.logo {display: block; background: transparent url(../img/logo.png) no-repeat 0 0; width: 222px; height: 51px; margin: 37px 0 0 38px;}
header .logo h1, header .logo h2  {text-indent: -9999px; line-height: 0; height: 0; width: 0; margin: 0; padding: 0;}

.searchbar {margin-top: 45px; background: url(../img/search-bg.png) no-repeat 0 0; width: 302px; height: 37px; margin-left: 392px;}
.searchbar *:focus {outline: none; box-shadow: none; -webkit-box-shadow: none;}
.searchbar input {color: #666; background: transparent; border: none; margin-top: 6px;}

.projects {width: 200px; height: 285px; position: absolute; right: 26px; top: 22px; overflow: hidden;}
.projects ul {list-style-type: none; overflow-x: hidden; overflow-y: scroll; max-height: 273px; width: 200px; margin: 0; background: transparent url(../img/project-bg.png) repeat 0 0;}
.projects li {width: 169px; height: 31px; background: transparent url(../img/projectsprite.png) no-repeat 0 0; display: block; margin: 3px auto 0; color: #9fa8b0; line-height: 31px; padding-left: 13px; font-size: 12px; text-shadow: 0px 1px 1px rgba(0,0,0,0.4); filter: dropshadow(color=#000000, offx=0, offy=1);}
.projects li:hover {background-position: 0 -31px; cursor: pointer; color: #eef2f5;}
.projects li.active:before {content: url(../img/goldarr.png);}
.projects span {display: block; width: 100%; height: 6px; background: transparent url(../img/project-rnd.png) no-repeat 0 0;}
.projects .btm {background-position: 0 -6px;}

.nav {height: 43px; background: #ccc; margin: 334px 0 12px;}
.nav li {display: block; float: left; height: 43px;}
.nav li a {display: block; height: 100%; text-align: center; line-height: 43px; text-indent: -9999px; background-image: url(../img/navsprite.jpg);}
.nav li a:hover {cursor: pointer;}
.nav .start {width: 106px;}
.nav .blogg {width: 116px;}
.nav .projekt {width: 137px;}
.nav .omoss {width: 131px;}
.nav .kunder {width: 134px;}
.nav .kontakt {width: 140px;}
.nav .nyheter {width: 176px;}
</pre>
<h4>Note: This code won&#8217;t look good on this blog. A large display is needed.</h4>
<p>Oh, it&#8217;s beautiful! It&#8217;s organised! I know which rules apply to which elements on the page, and I can see the entire stylesheet. It&#8217;s so simple; the first group of lines start with &#8216;header&#8217;, and so they correspond with the &#8216;header&#8217; element on the page. The &#8216;.nav&#8217; group of lines corresponds with the site&#8217;s navigation bar. You get the idea. I start each block with the most general rules, which are applied to the parent element. The lines that follow then become increasingly specific. This is basic CSS! It shouldn&#8217;t be more complicated than this. Let&#8217;s not stop. Let&#8217;s add some constants.</p>
<h2>Defining constants</h2>
<p>When I say &#8220;defining constants&#8221;, I mean adding some CSS rules that you know aren&#8217;t going to ever change. Most commonly, this means things like a CSS Reset, or some Font-Squirrel styles. When I define constant CSS rules, I like to stick them at the top of my stylesheet, and minify them. That way I know where they are, but they&#8217;re also out of my way so I can focus on the things that <em>do</em> need changing. Let&#8217;s combine our chunky comment banners with minified constants:</p>
<pre class="brush: css; title: ; notranslate">
/*--------------------------------------------------
              Avenir font | Font Squirrel
	-------------------------------------------------- */
@font-face{font-family:AvenirLTStd85Heavy;src:url(../fonts/avenirltstd-heavy-webfont.eot);src:url(../fonts/avenirltstd-heavy-webfont.eot?#iefix) format(embedded-opentype), url(../fonts/avenirltstd-heavy-webfont.woff) format(woff), url(../fonts/avenirltstd-heavy-webfont.ttf) format(truetype), url(../fonts/avenirltstd-heavy-webfont.svg#AvenirLTStd85Heavy) format(svg);font-weight:400;font-style:normal;}@font-face{font-family:AvenirLTStd35Light;src:url(../fonts/avenirltstd-light-webfont.eot);src:url(../fonts/avenirltstd-light-webfont.eot?#iefix) format(embedded-opentype), url(../fonts/avenirltstd-light-webfont.woff) format(woff), url(../fonts/avenirltstd-light-webfont.ttf) format(truetype), url(../fonts/avenirltstd-light-webfont.svg#AvenirLTStd35Light) format(svg);font-weight:400;font-style:normal;}@font-face{font-family:AvenirLTStd65Medium;src:url(../fonts/avenirltstd-medium-webfont.eot);src:url(../fonts/avenirltstd-medium-webfont.eot?#iefix) format(embedded-opentype), url(../fonts/avenirltstd-medium-webfont.woff) format(woff), url(../fonts/avenirltstd-medium-webfont.ttf) format(truetype), url(../fonts/avenirltstd-medium-webfont.svg#AvenirLTStd65Medium) format(svg);font-weight:400;font-style:normal;}
/*--------------------------------------------------
                   cssstickyfooter.com
	-------------------------------------------------- */
html,body{height:100%;}#wrap{min-height:100%;}#main{overflow:auto;padding-bottom:150px;}footer{position:relative;height:140px;margin-top:-140px;clear:both;}body:before{content:&quot;&quot;;height:100%;float:left;width:0;margin-top:-32767px;}
</pre>
<p>So far, I&#8217;m convinced that sticking with the basics is the way forward. The simpler the code is, the more semantic it can be. This means it&#8217;s leaner, faster, easier to understand, and easier to maintain. Why make it harder?</p>
]]></content:encoded>
			<wfw:commentRss>http://jezenthomas.co.uk/scalable-css-strategy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fibonacci in jQuery</title>
		<link>http://jezenthomas.co.uk/fibonacci-in-jquery/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fibonacci-in-jquery</link>
		<comments>http://jezenthomas.co.uk/fibonacci-in-jquery/#comments</comments>
		<pubDate>Tue, 24 Apr 2012 05:35:45 +0000</pubDate>
		<dc:creator>Jezen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://jezenthomas.co.uk/?p=300</guid>
		<description><![CDATA[Here is a quick learning exercise I set myself. I know a function that builds a Fibonacci sequence can be written in two lines of code as I've seen it elsewhere, but copying from someone else would be cheating and it's worth more to me if I actually try to figure it out myself. <a href="http://jezenthomas.co.uk/fibonacci-in-jquery/"><br /><br />Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here is a quick learning exercise I set myself. I know a function that builds a <a href="http://en.wikipedia.org/wiki/Fibonacci_number">Fibonacci sequence</a> can be written in two lines of code as I&#8217;ve seen it elsewhere, but copying from someone else would be cheating and it&#8217;s worth more to me if I actually try to figure it out myself. Here&#8217;s my first attempt:</p>
<pre class="brush: jscript; title: ; notranslate">
$(function(){
	var a = 0, b = 1, c, s = '&amp;nbsp;';
	$('body').append(a + s + b + s);
	for (i = 1; i &lt;= 20; i++) {
		c = a + b;
		$('body').append(c, s);
		a = b;
		b = c;
	}
});
</pre>
<p>That&#8217;s not bad. It works as it should, but I can&#8217;t help thinking that I can do better. I&#8217;m sure I can build the same but using only one <span class="light-code">append</span> method. I&#8217;ll try again&#8230;</p>
<pre class="brush: jscript; title: ; notranslate">
$(function(){
	var a = 0, b = 1, c, s = '&amp;nbsp;';
	for (i = 0; i &lt; 20; i++) {
		if (i &lt; 2) {
			c = i;
		} else {
			c = a + b;
			a = b;
			b = c;
		}
		$('body').append(c, s);
	}
});
</pre>
<p>That feels better. Kind of. At least now we&#8217;re not hard-coding the first two Fibonacci numbers. But somehow, this version is longer than the first. Maybe I could put that <span class="light-code">if</span> statement on a diet&#8230;</p>
<pre class="brush: jscript; title: ; notranslate">
$(function(){
	var a = 0, b = 1, c, s = '&amp;nbsp;';
	for (i = 0; i &lt; 20; i++) {
		c = (i &lt; 2) ? i : a + b;
		a = b;
		b = c;
		$('body').append(c, s);
	}
});
</pre>
<p>Much nicer! I&#8217;m sure it could be improved further (for a start, by removing the HTML non-breaking space), but I think that&#8217;s lean enough for now.</p>
]]></content:encoded>
			<wfw:commentRss>http://jezenthomas.co.uk/fibonacci-in-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detect IE with JavaScript</title>
		<link>http://jezenthomas.co.uk/detect-ie-with-javascript/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=detect-ie-with-javascript</link>
		<comments>http://jezenthomas.co.uk/detect-ie-with-javascript/#comments</comments>
		<pubDate>Thu, 19 Apr 2012 15:16:54 +0000</pubDate>
		<dc:creator>Jezen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://jezenthomas.co.uk/?p=290</guid>
		<description><![CDATA[Sometimes you want to animate things with jQuery, and it looks beautiful in all browsers except Internet Explorer. We all understand graceful degradation or progressive enhancement or whatever-the-crap-the-buzzword-is when we're talking CSS, but what about Javascript? Here's how to detect IE with JavaScript. Like a boss. <a href="http://jezenthomas.co.uk/detect-ie-with-javascript/"><br /><br />Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Sometimes you want to animate things with jQuery, and it looks beautiful in all browsers except Internet Explorer. We all understand graceful degradation or progressive enhancement or whatever-the-crap-the-buzzword-is when we&#8217;re talking CSS, but what about Javascript? Here&#8217;s how to detect IE with JavaScript. Like a boss.</p>
<p>First, a lovely piece of ingenuity from Paul Irish, the creator of HTML5 Boilerplate (among many other things):</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!doctype html&gt;
&lt;!--[if lt IE 7 ]&gt; &lt;html class=&quot;ie6&quot;&gt; &lt;![endif]--&gt;
&lt;!--[if IE 7 ]&gt;    &lt;html class=&quot;ie7&quot;&gt; &lt;![endif]--&gt;
&lt;!--[if IE 8 ]&gt;    &lt;html class=&quot;ie8&quot;&gt; &lt;![endif]--&gt;
&lt;!--[if IE 9 ]&gt;    &lt;html class=&quot;ie9&quot;&gt; &lt;![endif]--&gt;
&lt;!--[if (gt IE 9)|!(IE)]&gt;&lt;!--&gt; &lt;html class=&quot;&quot;&gt; &lt;!--&lt;![endif]--&gt;
&lt;head&gt;
</pre>
<p>Obviously, that&#8217;s how the beginning of your document should look. Using this technique means you can also have all your IE hacks in your main stylesheet (conditional stylesheets are so uncool). Now we can detect the browsers that we don&#8217;t like with a bit of jQuery when the page loads:</p>
<pre class="brush: jscript; title: ; notranslate">
$(function () {
	&quot;use strict&quot;;

	// Detecting IE
	var oldIE;
	if ($('html').is('.ie6, .ie7, .ie8')) {
		oldIE = true;
	}

	if (oldIE) {
		// Here's your JS for IE..
	} else {
		// ..And here's the full-fat code for everyone else
	}
</pre>
<p>Happy days!</p>
]]></content:encoded>
			<wfw:commentRss>http://jezenthomas.co.uk/detect-ie-with-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Disabling the Chrome Download Bar</title>
		<link>http://jezenthomas.co.uk/disabling-the-chrome-download-bar/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=disabling-the-chrome-download-bar</link>
		<comments>http://jezenthomas.co.uk/disabling-the-chrome-download-bar/#comments</comments>
		<pubDate>Sun, 11 Mar 2012 00:20:54 +0000</pubDate>
		<dc:creator>Jezen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://jezenthomas.co.uk/?p=278</guid>
		<description><![CDATA[Google Chrome is my standard everyday browser. It does everything I need it to do, and gracefully. I don't waste space with toolbars and favourites bars and this-that-whatever bars. It's just me, my tabs, and my glorious screen real-estate. It seems the most common gripe that Chrome users have is the download bar which appears every time you want to grab a file. <a href="http://jezenthomas.co.uk/disabling-the-chrome-download-bar/"><br /><br />Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Google Chrome is my standard everyday browser. It does everything I need it to do, and gracefully. I don&#8217;t waste space with toolbars and favourites bars and this-that-whatever bars. It&#8217;s just me, my tabs, and my glorious screen real-estate. It seems the most common gripe that Chrome users have is the download bar which appears every time you want to grab a file.</p>
<p>For those of us that care about screen real-estate, it seems like a real kick in the teeth that we can&#8217;t simply disable this &#8216;feature&#8217;. Or rather, we can, but the setting is not in the most obvious of places. Here&#8217;s how:</p>
<ol>
<li>Go to chrome://flags/</li>
<li>Scroll down to &#8216;New Downloads UI&#8217;</li>
<li>Click &#8216;Enable&#8217;</li>
</ol>
<p>Cool.</p>
]]></content:encoded>
			<wfw:commentRss>http://jezenthomas.co.uk/disabling-the-chrome-download-bar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chess with PHP</title>
		<link>http://jezenthomas.co.uk/chess-with-php/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=chess-with-php</link>
		<comments>http://jezenthomas.co.uk/chess-with-php/#comments</comments>
		<pubDate>Wed, 29 Feb 2012 10:10:01 +0000</pubDate>
		<dc:creator>Jezen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://jezenthomas.co.uk/?p=248</guid>
		<description><![CDATA[One of my colleagues at itiden was kind enough to set me some PHP challenges as homework so that I could work on my programming chops. The first two challenges involved reversing a string of dynamic length without using PHP's strrev. Apparently, the next step up from reversing strings is building a game of Chess. Sure, why not... <a href="http://jezenthomas.co.uk/chess-with-php/"><br /><br />Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of my colleagues at <a href="http://itiden.se">itiden</a> was kind enough to set me some PHP challenges as homework so that I could work on my programming chops. The <a href="http://jezenthomas.co.uk/lab/marco">first two challenges</a> involved reversing a string of dynamic length without using PHP&#8217;s <span class="light-code">strrev</span>. Apparently, the next step up from reversing strings is building a game of Chess. Sure, why not&#8230;</p>
<p>This article will document both my successes and fumblings with this project, so revisions will be included. First, I&#8217;ll outline the HTML and CSS, since it&#8217;s easy and doesn&#8217;t really have anything to do with this as a PHP project.</p>
<p>The initial markup:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!doctype html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Chess&lt;/title&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;link href='http://fonts.googleapis.com/css?family=Shadows+Into+Light+Two' rel='stylesheet' type='text/css'&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;style.css&quot; /&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;wrap&quot;&gt;
&lt;h1&gt;Chess&lt;/h1&gt;
&lt;?php 

// Code for building Chess goes here.

?&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>And the styles:</p>
<pre class="brush: css; title: ; notranslate">
* {margin: 0;padding: 0;} /* I normally wouldn't select elements in CSS with a wildcard operator like this, but stylistically, it's a small project*/

html, body {
	background: #fff url(i/tile.png) repeat 0 0;
	height: 100%;
	margin: 0;
	padding: 0;
	font-family: sans-serif;
}

#wrap {
	width: 800px;
	background: #fff;
	min-height: 100%;
	margin: auto;
	box-shadow: 0px 0px 3px 3px rgba(155,155,155,0.5);
}

h1 {
	font-family: 'Shadows Into Light Two', cursive;
	padding: 40px 0 20px 73px;
}

table {
	border-collapse: collapse;
	margin: auto;
}

table, td {border: 1px solid #404040;}

td {
	width: 80px;
	height: 80px;
	font-size: 45px;
	text-align: center;
	line-height: 80px;
}

.grey {background: #f0f0f0;}
</pre>
<p>So far, so good. My first attempt only involved programming the board. I knew the chessboard would be eight columns wide, and eight rows high, so I tried drawing it with a <span class="light-code">for</span> loop. I knew that each alternate cell in a row had to be a different colour, and that each alternating row had to offset its alternately coloured cells by one. With that in mind, I tried determining whether each cell and row had an even or odd index with the help of a couple of <span class="light-code">modulus (%)</span> operators.</p>
<pre class="brush: php; title: ; notranslate">
&lt;table&gt;
&lt;?php
for ($rows = 1; $rows &lt;= 8; $rows++) {
	echo '&lt;tr&gt;';
	if ($rows % 2 == 1) {
		for ($cells = 1; $cells &lt;= 8; $cells++) {
			if ($cells % 2 == 0) {
				echo '&lt;td class=&quot;grey&quot;&gt;&lt;/td&gt;';
			} else {
				echo '&lt;td&gt;&lt;/td&gt;';
			}
		}
	} else {
		for ($cells = 1; $cells &lt;= 8; $cells++) {
			if ($cells % 2 == 1) {
				echo '&lt;td class=&quot;grey&quot;&gt;&lt;/td&gt;';
			} else {
				echo '&lt;td&gt;&lt;/td&gt;';
			}
		}
	}
	echo '&lt;/tr&gt;';
}
?&gt;
&lt;/table&gt;
</pre>
<p>At first, I included a bunch of PHP <span class="light-code">\n</span> (new line) and <span class="light-code">\t</span> (tab) commands so my HTML source would look neater, but I&#8217;ve left it out now so the PHP is neater. <a href="http://jezenthomas.co.uk/lab/chess/i/progress/1.png">This is what the code outputs so far.</a></p>
<p>The next step is to plot out all the chess pieces on the chessboard. My colleague mentioned that the chess piece coordinates would ordinarily come from a database, but that I could use arrays to emulate that for now. I decided to create a multi-dimensional array, consisting of an array for each row of the chessboard. I could then simply plot my chess pieces manually in each array with variables that contain the HTML entity, or an empty string if there is no chess piece in a given cell.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$wKing		=	'&amp;#9812';
$wQueen		=	'&amp;#9813';
$wRook		=	'&amp;#9814';
$wBishop	=	'&amp;#9815';
$wKnight	=	'&amp;#9816';
$wPawn		=	'&amp;#9817';
$bKing		=	'&amp;#9818';
$bQueen		=	'&amp;#9819';
$bRook		=	'&amp;#9820';
$bBishop	=	'&amp;#9821';
$bKnight	=	'&amp;#9822';
$bPawn		=	'&amp;#9823';
$empty		=	'';

$c1 = array($bRook, $bKnight, $bBishop, $bKing, $bQueen, $bBishop, $bKnight, $bRook);
$c2 = array($bPawn, $bPawn, $bPawn, $bPawn, $bPawn, $bPawn, $bPawn, $bPawn);
$c3 = array($empty, $empty, $empty, $empty, $empty, $empty, $empty, $empty);
$c4 = array($empty, $empty, $empty, $empty, $empty, $empty, $empty, $empty);
$c5 = array($empty, $empty, $empty, $empty, $empty, $empty, $empty, $empty);
$c6 = array($empty, $empty, $empty, $empty, $empty, $empty, $empty, $empty);
$c7 = array($wPawn, $wPawn, $wPawn, $wPawn, $wPawn, $wPawn, $wPawn, $wPawn);
$c8 = array($wRook, $wKnight, $wBishop, $wKing, $wQueen, $wBishop, $wKnight, $wRook);
$cBoard = array($c1, $c2, $c3, $c4, $c5, $c6, $c7, $c8);
?&gt;
</pre>
<p>That looks great! <a href="http://jezenthomas.co.uk/lab/chess/i/ohcrap.png">But now how do I position my chess pieces on the chess board?</a></p>
<p>&#8220;That&#8217;s.. Not bad..&#8221; is my feedback from Marco.<br />
&#8220;Here&#8217;s how I would have done that array:&#8221; he continues.</p>
<pre class="brush: php; title: ; notranslate">
$cBoard = array(
	0 =&gt; array($bRook, $bKnight, $bBishop, $bKing, $bQueen, $bBishop, $bKnight, $bRook),
	1 =&gt; array($bPawn, $bPawn, $bPawn, $bPawn, $bPawn, $bPawn, $bPawn, $bPawn),
	2 =&gt; array($empty, $empty, $empty, $empty, $empty, $empty, $empty, $empty),
	3 =&gt; array($empty, $empty, $empty, $empty, $empty, $empty, $empty, $empty),
	4 =&gt; array($empty, $empty, $empty, $empty, $empty, $empty, $empty, $empty),
	5 =&gt; array($empty, $empty, $empty, $empty, $empty, $empty, $empty, $empty),
	6 =&gt; array($wPawn, $wPawn, $wPawn, $wPawn, $wPawn, $wPawn, $wPawn, $wPawn),
	7 =&gt; array($wRook, $wKnight, $wBishop, $wKing, $wQueen, $wBishop, $wKnight, $wRook)
);
</pre>
<p>Marco reviewed my loop and decided it&#8217;d be a little more elegant if I used <span class="light-code">foreach</span> loops. He also managed to draw the table and plot the chess pieces, using a similar modulus idea. He managed it in 17 lines of code, and admitted it wasn&#8217;t so great because a lot of code was repeated. It took a lot of staring at the chessboard before the penny finally dropped. My new idea was neatest, and worked! Eureka moment!</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
foreach ($cBoard as $y =&gt; $row) {
	echo '&lt;tr&gt;';
	foreach ($row as $x =&gt; $cell) {
		$class = (($x+$y) % 2 == 1) ? ' class=&quot;grey&quot;' : '';
		echo '&lt;td'.$class.'&gt;'.$cell.'&lt;/td&gt;';
	}
	echo '&lt;/tr&gt;';
}
?&gt;
</pre>
<p>To clarify, the code looks inside the <span class="light-code">$cBoard</span> array and for each index it finds, it spits out a pair of HTML table row tags (lines 2, 3 and 8). While it&#8217;s inside each table row, it runs through its respective array and assigns each value a variable name of <span class="light-code">$cell</span>. The cells know whether they are at an even or odd coordinate because I&#8217;m using a modulus against both the <span class="light-code">x</span> and <span class="light-code">y</span> values at the same time. The shorthand <span class="light-code">if</span> statement sets <span class="light-code">$class</span> depending on whether the <span class="light-code">if</span> statement returns true or false. I then simply <span class="light-code">echo</span> out the value of <span class="light-code">$class</span> and <span class="light-code">$cell</span>, and wrap them in some HTML table data tags. Simples!</p>
<p>So far, the result <a href="http://jezenthomas.co.uk/lab/chess/i/progress/2.png">looks like this</a>, and the code looks like this:</p>
<pre class="brush: php; collapse: true; light: false; title: ; toolbar: true; notranslate">
&lt;!doctype html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Chess&lt;/title&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;link href='http://fonts.googleapis.com/css?family=Shadows+Into+Light+Two' rel='stylesheet' type='text/css'&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;style.css&quot; /&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;wrap&quot;&gt;
&lt;h1&gt;Chess&lt;/h1&gt;
&lt;?php
$wKing		=	'&amp;#9812';
$wQueen		=	'&amp;#9813';
$wRook		=	'&amp;#9814';
$wBishop	=	'&amp;#9815';
$wKnight	=	'&amp;#9816';
$wPawn		=	'&amp;#9817';
$bKing		=	'&amp;#9818';
$bQueen		=	'&amp;#9819';
$bRook		=	'&amp;#9820';
$bBishop	=	'&amp;#9821';
$bKnight	=	'&amp;#9822';
$bPawn		=	'&amp;#9823';
$empty		=	'';

$cBoard = array(
	0 =&gt; array($bRook, $bKnight, $bBishop, $bKing, $bQueen, $bBishop, $bKnight, $bRook),
	1 =&gt; array($bPawn, $bPawn, $bPawn, $bPawn, $bPawn, $bPawn, $bPawn, $bPawn),
	2 =&gt; array($empty, $empty, $empty, $empty, $empty, $empty, $empty, $empty),
	3 =&gt; array($empty, $empty, $empty, $empty, $empty, $empty, $empty, $empty),
	4 =&gt; array($empty, $empty, $empty, $empty, $empty, $empty, $empty, $empty),
	5 =&gt; array($empty, $empty, $empty, $empty, $empty, $empty, $empty, $empty),
	6 =&gt; array($wPawn, $wPawn, $wPawn, $wPawn, $wPawn, $wPawn, $wPawn, $wPawn),
	7 =&gt; array($wRook, $wKnight, $wBishop, $wKing, $wQueen, $wBishop, $wKnight, $wRook)
);
?&gt;

	&lt;table&gt;
	&lt;?php
	foreach ($cBoard as $y =&gt; $row) {
		echo '&lt;tr&gt;';
		foreach ($row as $x =&gt; $cell) {
			$class = (($x+$y) % 2 == 1) ? ' class=&quot;grey&quot;' : '';
			echo '&lt;td'.$class.'&gt;'.$cell.'&lt;/td&gt;';
		}
		echo '&lt;/tr&gt;';
	}
	?&gt;
	&lt;/table&gt;

&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<h3>It doesn&#8217;t do anything</h3>
<p>So, I&#8217;ve coded myself what is essentially a picture of a chessboard. None of the pieces move, and I&#8217;d like to change that. At this stage, I imagine that trying to animate chess pieces with PHP is probably not such a fantastic idea. Even if I knew how to do that, my understanding is that every attempted chess move would initiate a server request. That&#8217;s probably fine for myself and a friend, but it&#8217;s not exactly scalable. If my chess game became popular, I&#8217;d have to start paying through the nose for hosting.</p>
<p>I&#8217;ll take a shot at this problem with jQuery. After many hours of shuffling code around, I came up with some ideas. The logic should play out roughly as follows:</p>
<ul>
<li>Select a chess piece, store its value, and make it invisible</li>
<li>Create a clone of the chess piece, so it can be animated</li>
<li>Insert the chess piece value into the destination cell, but don&#8217;t show it</li>
<li>Animate the clone to the destination cell</li>
<li>Show the chess piece value in its new cell, and destroy the clone</li>
</ul>
<p>And here&#8217;s what I came up with:</p>
<pre class="brush: jscript; title: ; notranslate">
$(function () {
	&quot;use strict&quot;;

	// Highlight cell
	$('td').hover(function () {
		$(this).css('background-color' , '#0ff');
	}, function () {
		$(this).css('background-color' , '');
	});

	var moving = 0, piece, depart, origin, x, y, clone;
	$('td').click(function(){
		if (moving === 0) {
			// Select chess piece
			if ($(this).text()) {
				piece = $(this).text();
				$(this).html('&lt;span class=&quot;ghost&quot;&gt;' + piece + '&lt;/span&gt;');
				clone = '&lt;span id=&quot;clone&quot;&gt;' + $(this).text() + '&lt;/span&gt;';
				x = $(this).offset().left + 1 + 'px';
				y = $(this).offset().top + 1 + 'px';
				$('body').append(clone);
				$('#clone').css({'color':'blue', 'top':y, 'left':x});
				origin = $(this);
				moving = 1;
			} else {
				return false;
			}
		} else {
			// Move chess piece
			if (!$(this).text()) {
				x = $(this).offset().left + 1 + 'px';
				y = $(this).offset().top + 1 + 'px';
				$(this).html($('.ghost').parent().html());
				origin.html('');
				$('#clone').animate({'left':x, 'top':y}, 800, 'swing', function(){
					$('.ghost').replaceWith($(this).text());
					$('span').remove();
					moving = 0;
				});
			} else {
				return false;
			}
		}
	});

});
</pre>
<p><span class="code-comment">### This article is a work in progress. I&#8217;ll update it as I find my way through the project.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://jezenthomas.co.uk/chess-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress and LESS</title>
		<link>http://jezenthomas.co.uk/wordpress-and-less/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wordpress-and-less</link>
		<comments>http://jezenthomas.co.uk/wordpress-and-less/#comments</comments>
		<pubDate>Tue, 28 Feb 2012 23:55:28 +0000</pubDate>
		<dc:creator>Jezen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://jezenthomas.co.uk/?p=215</guid>
		<description><![CDATA[I quite like the idea of using a CSS preprocessor, but I most certainly don't like the idea of obstructing my workflow by having to run a compiler or a terminal command each time I want to update my CSS. Furthermore, I don't want to have to use anyone else's LESS theme or plugin for WordPress. I'd much rather roll my own. <a href="http://jezenthomas.co.uk/wordpress-and-less/"><br /><br />Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I quite like the idea of using a CSS preprocessor, but I most certainly don&#8217;t like the idea of obstructing my workflow by having to run a compiler or a terminal command each time I want to update my CSS. Furthermore, I don&#8217;t want to have to use anyone else&#8217;s LESS theme or plugin for WordPress. I&#8217;d much rather roll my own.</p>
<p><a href="http://lesscss.org/">LESS</a> gives you a few compilation options, but I&#8217;m not too keen on most of them. There is a <a href="http://lesscss.googlecode.com/files/less-1.0.18.min.js">JavaScript compiler</a>, but why force the user to compile client-side? What if they have JS disabled? Everything is ruined. Also, the LESS documentation states that you should use a different <span class="light-code">rel</span> attribute, like this:</p>
<pre class="brush: xml; title: ; notranslate">&lt;link rel=&quot;stylesheet/less&quot; type=&quot;text/css&quot; href=&quot;styles.less&quot;&gt;</pre>
<p>I&#8217;m quite sure though, that this causes serious rendering problems for IE7 (which is still an important browser, as my colleagues have taught me).</p>
<p>That&#8217;s enough of the wrong way. Here&#8217;s the right way:</p>
<p>Your WordPress child theme should include:</p>
<ul>
<li>A <span class="light-code">header.php</span> file, for the compiler.</li>
<li>A <span class="light-code">style.css</span> file so WP recognises the child theme.</li>
<li>An <span class="light-code">input.less</span> file, for the LESS code.</li>
<li>The LESS PHP compiler file: <a href="http://leafo.net/lessphp/">lessc.inc.php</a>.</li>
</ul>
<p>The <span class="light-code">header.php</span> file should begin with:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php
require 'lessc.inc.php';

try {
    lessc::ccompile(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'input.less', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'output.css');
} catch (exception $ex) {
    exit('lessc fatal error:&lt;br /&gt;'.$ex-&gt;getMessage());
}
?&gt;</pre>
<p>&#8230;And the <span class="light-code">style.css</span> should only include something like this:</p>
<pre class="brush: css; title: ; notranslate">/*
Theme Name:     YourThemeName
Description:    This is a theme you built with LESS CSS
Author:         Jezen Thomas
Author URI:     http://jezenthomas.co.uk
Template:       twentyeleven
*/

@import url(&quot;output.css&quot;);</pre>
]]></content:encoded>
			<wfw:commentRss>http://jezenthomas.co.uk/wordpress-and-less/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More transcriptions!</title>
		<link>http://jezenthomas.co.uk/more-transcriptions/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=more-transcriptions</link>
		<comments>http://jezenthomas.co.uk/more-transcriptions/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 11:17:17 +0000</pubDate>
		<dc:creator>Jezen</dc:creator>
				<category><![CDATA[Music]]></category>

		<guid isPermaLink="false">http://jezenthomas.co.uk/?p=119</guid>
		<description><![CDATA[I have teamed up with Zsolt Korompay and Wolfgang Schüler to make Drums Notated the best resource for drum transcriptions. We now have performances by Vinnie Colaiuta, Peter Erskine, Gavin Harrison, Dave DiCenso, Dennis Chambers, Jojo Mayer, Omar Hakim, and more. So drummers, what are you waiting for? Check it out now.]]></description>
			<content:encoded><![CDATA[<p>I have teamed up with <em>Zsolt Korompay</em> and <em>Wolfgang Schüler</em> to make <a href="http://drumsnotated.com">Drums Notated</a> the best resource for drum transcriptions. We now have performances by <a href="http://drumsnotated.com/products/vinnies-half-time">Vinnie Colaiuta</a>, <a href="http://drumsnotated.com/products/pools">Peter Erskine</a>, <a href="http://drumsnotated.com/products/slippin-away">Gavin Harrison</a>, <a href="http://drumsnotated.com/products/dicenso-by-schuler">Dave DiCenso</a>, <a href="http://drumsnotated.com/products/half-time-shuffle">Dennis Chambers</a>, <a href="http://drumsnotated.com/products/groove-for-drummerworld">Jojo Mayer</a>, <a href="http://drumsnotated.com/products/mystic-glance">Omar Hakim</a>, and more.</p>
<p>So drummers, what are you waiting for? <a href="http://drumsnotated.com">Check it out now.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://jezenthomas.co.uk/more-transcriptions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Where are the drum transcriptions?</title>
		<link>http://jezenthomas.co.uk/where-are-the-drum-transcriptions/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=where-are-the-drum-transcriptions</link>
		<comments>http://jezenthomas.co.uk/where-are-the-drum-transcriptions/#comments</comments>
		<pubDate>Tue, 21 Jun 2011 14:32:19 +0000</pubDate>
		<dc:creator>Jezen</dc:creator>
				<category><![CDATA[Music]]></category>

		<guid isPermaLink="false">http://jezenthomas.co.uk/?p=94</guid>
		<description><![CDATA[I frequently receive emails from drummers around the world looking for my transcription of Gavin Harrison&#8217;s Slippin&#8217; Away performance from PASIC, 2008. That particular transcription – along with a few others – is available for instant download from http://drumsnotated.com. It&#8217;s a wonderful system; you choose the transcription you want, and it is automatically emailed to [...]]]></description>
			<content:encoded><![CDATA[<p>I frequently receive emails from drummers around the world looking for my transcription of Gavin Harrison&#8217;s <em>Slippin&#8217; Away</em> performance from PASIC, 2008.</p>
<p>That particular transcription – along with a few others – is available for instant download from <a title="Drums Notated" href="http://drumsnotated.com">http://drumsnotated.com</a>.</p>
<p>It&#8217;s a wonderful system; you choose the transcription you want, and it is automatically emailed to you immediately after purchase.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://jezenthomas.co.uk/where-are-the-drum-transcriptions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

