<?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>David Chambers Design</title>
	<atom:link href="http://davidchambersdesign.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://davidchambersdesign.com</link>
	<description>It&#039;s where I share interesting info with other web geeks</description>
	<lastBuildDate>Mon, 08 Mar 2010 07:39:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Gorgeous CSS3 buttons inspired by Aqua</title>
		<link>http://davidchambersdesign.com/gorgeous-css3-buttons-inspired-by-aqua/</link>
		<comments>http://davidchambersdesign.com/gorgeous-css3-buttons-inspired-by-aqua/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 07:39:10 +0000</pubDate>
		<dc:creator>David Chambers</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Mac OS X]]></category>

		<guid isPermaLink="false">http://davidchambersdesign.com/?p=1581</guid>
		<description><![CDATA[<p>Modern browsers can display exciting visual effects such as drop shadows (without the use of background images). CSS3 makes it possible to turn submit inputs and even links into rich, Aqua-like buttons in these browsers (alternative style rules can be provided for older browsers).</p>
<img src="http://resources.davidchambersdesign.com/images/posts/start-game-hyperlink-and-button.png" alt="" class="block" />
]]></description>
			<content:encoded><![CDATA[<p>The two cornerstones of the Web as an interactive medium are the <a href="http://en.wikipedia.org/wiki/Form_(web)">form</a>, which facilitates the submission and retrieval of data, and the <a href="http://en.wikipedia.org/wiki/Hyperlink">hyperlink</a>, which facilitates navigation.</p>
<p>Since form submission buttons and hyperlinks <em>do</em> different things, it makes sense that browsers display them differently (by default).</p>
<dl class="border">
	<dt><img src="http://resources.davidchambersdesign.com/images/posts/unstyled-button-and-hyperlink.png" alt="Unstyled button and hyperlink" /></dt>
	<dd>Default appearance of buttons and hyperlinks in Safari on Mac OS X</dd>
</dl>
<p>Web applications, however, sometimes blur the line between doing things and going places; visually distinguishing links from buttons, therefore, is not always appropriate. As Stephen Anderson explains in his article <a href="http://www.alistapart.com/articles/indefenseofeyecandy">In Defense of Eye Candy</a> on <a href="http://www.alistapart.com/">A List Apart</a>, an element's appearance should suggest appropriate modes of interaction.</p>
<dl class="border">
	<dt><img src="http://resources.davidchambersdesign.com/images/posts/wordpress-publish-pane.png" alt="WordPress Publish pane" /></dt>
	<dd>In WordPress's <strong>Publish</strong> pane "Save Draft" is a submit input, "Preview" is a link; both are styled as buttons</dd>
</dl>
<h3>Styling links to look like buttons</h3>
<p><em><strong>Beware!</strong> There's quite a bit involved in styling form elements – be sure that there's a compelling reason to override default browser styling before doing so.</em></p>
<p>An unstyled submit input and an unstyled hyperlink are displayed below. One must declare a number of rules in order to have the two elements rendered in the same way.</p>
<dl class="border">
	<dt><img src="http://resources.davidchambersdesign.com/images/posts/start-game-button-and-hyperlink-unstyled.png" alt="Unstyled button and hyperlink" /></dt>
	<dd>Unstyled submit input and hyperlink</dd>
	<dt><img src="http://resources.davidchambersdesign.com/images/posts/start-game-button-and-hyperlink-border.png" alt="Button and hyperlink with border" /></dt>
	<dd>border: 1px solid #850; color: #850;</dd>
	<dt><img src="http://resources.davidchambersdesign.com/images/posts/start-game-button-and-hyperlink-background-color.png" alt="Button and hyperlink with background colour" /></dt>
	<dd>background: #fc6; text-decoration: none;</dd>
	<dt><img src="http://resources.davidchambersdesign.com/images/posts/start-game-button-and-hyperlink-padding-font.png" alt="Button and hyperlink with consistent padding and font properties" /></dt>
	<dd>padding: 0.25em 0.5em; font: bold 12px/15px "Lucida Grande", "Lucida Sans Unicode", sans-serif;</dd>
</dl>
<h4>Progressive enhancement</h4>
<p>The submit input and the link now look the same, and <em>somewhat</em> button-like. Even antiquated browsers such as Internet Explorer 6 understand the rules defined thus far. The next step is to make the elements more appealing and more button-like in modern browsers.</p>
<pre class="brush: css;">-webkit-border-radius: 1em;
-moz-border-radius: 1em;
border-radius: 1em;</pre>
<dl class="border">
	<dt><img src="http://resources.davidchambersdesign.com/images/posts/start-game-button-and-hyperlink-border-radius.png" alt="Button and hyperlink with rounded corners" /></dt>
	<dd>Rounded corners</dd>
</dl>
<pre class="brush: css;">background: -webkit-gradient(linear, left top, left bottom, from(#fc6), to(#fc6), color-stop(0.1, #fff), color-stop(0.2, #fc6), color-stop(0.5, #fc6), color-stop(0.5, #fa2));
background: -moz-linear-gradient(-90deg, #fc6 5%, #fff 15%, #fc6 25%, #fc6 50%, #fa2 50%, #fc6);</pre>
<dl class="border">
	<dt><img src="http://resources.davidchambersdesign.com/images/posts/start-game-button-and-hyperlink-background-gradient.png" alt="Button and hyperlink with background gradient" /></dt>
	<dd>Linear gradient with colour stops creates a sense of depth</dd>
</dl>
<h3>Styling different states</h3>
<p>It is important to consider the different states a button may have. Apple's <a href="http://en.wikipedia.org/wiki/Aqua_(user_interface)">Aqua</a> GUI provides three different effects, any or all of which may be applied to a button: a pulsating blue background indicates that <strong>return</strong> activates the button; a button with an outer glow can be activated via the space bar; and a static blue background is used for a button's "active" state (which occurs while the button is being clicked).</p>
<dl class="border">
	<dt><img src="http://resources.davidchambersdesign.com/images/posts/textedit-save-dialog.png" alt="TextEdit dialog featuring two different button states" /></dt>
	<dd>In Aqua, <strong>return</strong> activates the blue button; <strong>space bar</strong> activates the button with the outer glow</dd>
</dl>
<p>On the web, submit inputs and hyperlinks have several possible states, the most important of which are hover, focus, and active. When creating style rules for each of these states it's important to bear in mind that more than one state may apply at one time.</p>
<dl class="border">
	<dt><img src="http://resources.davidchambersdesign.com/images/posts/transmission-up-to-date.png" alt="Transmission dialog featuring a button with two states" /></dt>
	<dd>Here the OK button exhibits both a pulsating blue background and an outer glow</dd>
</dl>
<h4>Hover</h4>
<pre class="brush: css;">border-color: #740;
background: #fb4;
background: -webkit-gradient(linear, left top, left bottom, from(#fb4), to(#fb4), color-stop(0.1, #fea), color-stop(0.2, #fb4), color-stop(0.5, #fb4), color-stop(0.5, #f90));
background: -moz-linear-gradient(-90deg, #fb4 5%, #fea 15%, #fb4 25%, #fb4 50%, #f90 50%, #fb4);
color: #740;
cursor: pointer;</pre>
<dl class="border">
	<dt><img src="http://resources.davidchambersdesign.com/images/posts/start-game-button-and-hyperlink-hover.png" alt="Hover state" /></dt>
	<dd>Hover state (right) alongside default state</dd>
</dl>
<h4>Focus</h4>
<pre class="brush: css;">-webkit-box-shadow: #740 0 1px 0.75em;
-moz-box-shadow: #740 0 1px 0.75em;
color: #740;
outline: none;</pre>
<dl class="border">
	<dt><img src="http://resources.davidchambersdesign.com/images/posts/start-game-button-and-hyperlink-focus.png" alt="Focus state" /></dt>
	<dd>Focus state (right) alongside default state</dd>
	<dt><img src="http://resources.davidchambersdesign.com/images/posts/start-game-button-and-hyperlink-focus-hover.png" alt="Focus+hover state" /></dt>
	<dd>The focus and hover states play nicely together</dd>
</dl>
<h4>Active</h4>
<pre class="brush: css;">border-color: #630;
background: #f90;
background: -webkit-gradient(linear, left top, left bottom, from(#f90), to(#f90), color-stop(0.1, #fd8), color-stop(0.3, #fb4), color-stop(0.5, #fb4), color-stop(0.5, #f90));
background: -moz-linear-gradient(-90deg, #f90 5%, #fd8 15%, #fb4 35%, #fb4 50%, #f90 50%, #f90);
color: #630;</pre>
<dl class="border">
	<dt><img src="http://resources.davidchambersdesign.com/images/posts/start-game-button-and-hyperlink-active.png" alt="Active state" /></dt>
	<dd>Active state (right) alongside default state</dd>
</dl>
<h3>Demo</h3>
<p>Interact with the finished styled button on the <a href="/examples/hyperlinks-as-buttons/">Hyperlinks as buttons</a> demo page.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidchambersdesign.com/gorgeous-css3-buttons-inspired-by-aqua/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get attributes of Django model or instance</title>
		<link>http://davidchambersdesign.com/get-attributes-of-django-model-or-instance/</link>
		<comments>http://davidchambersdesign.com/get-attributes-of-django-model-or-instance/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 07:24:25 +0000</pubDate>
		<dc:creator>David Chambers</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://davidchambersdesign.com/?p=1597</guid>
		<description><![CDATA[What is the best way to get the attributes of a Django model or instance?
from django.db import models

class Musician(models.Model):
	first_name = models.CharField()
	last_name  = models.CharField()
	instrument = models.CharField()
One option is to use __dict__.keys():
&#62;&#62;&#62; m = Musician(first_name='Norah', last_name='Jones', instrument='piano')
&#62;&#62;&#62; print m.__dict__.keys()
&#62;&#62;&#62; ['last_name', 'instrument', 'first_name', 'id']
Another options is to use _meta.fields:
&#62;&#62;&#62; print [f.name for f in m._meta.fields]
&#62;&#62;&#62; ['id', 'first_name', [...]]]></description>
			<content:encoded><![CDATA[<p>What is the best way to get the attributes of a Django model or instance?</p>
<pre class="brush: python;">from django.db import models

class Musician(models.Model):
	first_name = models.CharField()
	last_name  = models.CharField()
	instrument = models.CharField()</pre>
<p>One option is to use <code>__dict__.keys()</code>:</p>
<pre class="brush: python;">&gt;&gt;&gt; m = Musician(first_name='Norah', last_name='Jones', instrument='piano')
&gt;&gt;&gt; print m.__dict__.keys()
&gt;&gt;&gt; ['last_name', 'instrument', 'first_name', 'id']</pre>
<p>Another options is to use <code>_meta.fields</code>:</p>
<pre class="brush: python;">&gt;&gt;&gt; print [f.name for f in m._meta.fields]
&gt;&gt;&gt; ['id', 'first_name', 'last_name', 'instrument']</pre>
<p>This approach also works on models directly:</p>
<pre class="brush: python;">&gt;&gt;&gt; print [f.name for f in Musician._meta.fields]
&gt;&gt;&gt; ['id', 'first_name', 'last_name', 'instrument']</pre>
<h3>Advantages of using <code>_meta.fields</code></h3>
<ul class="square">
	<li>items in returned list are correctly ordered</li>
	<li>applicable to both models and instances</li>
	<li>only <em>fields</em> are returned</li>
</ul>
<p>The fact that only fields are returned is extremely useful. Django appears to add its own attributes to instances in certain circumstances; using <code>_meta.fields</code> prevents these from interfering with one's own code.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidchambersdesign.com/get-attributes-of-django-model-or-instance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resize browser window to match iPhone viewport dimensions</title>
		<link>http://davidchambersdesign.com/resize-browser-window-to-match-iphone-viewport-dimensions/</link>
		<comments>http://davidchambersdesign.com/resize-browser-window-to-match-iphone-viewport-dimensions/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 14:20:16 +0000</pubDate>
		<dc:creator>David Chambers</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bookmarklets]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://davidchambersdesign.com/?p=1560</guid>
		<description><![CDATA[<p>I've recently become interested in optimizing sites for the iPhone and iPod touch. While nothing beats testing on the device itself, I often find it quicker to test changes on my Mac. Changing the user agent string is a piece of cake in Safari (Develop > User Agent > Mobile Safari) but what about adjusting the browser window's dimensions to match those of the iPhone?</p>
<p>I've created two bookmarklets to allow the current page to be loaded in an iPhone-sized window with a single click:</p>
<ul>
	<li><strong>Portrait</strong> (labelled "⁑") <pre class="brush: javascript;">javascript:open(location,'iPhone:portrait','innerWidth='+(320+15)+',innerHeight='+(480+15)+',scrollbars=yes');</pre></li>
	<li><strong>Landscape</strong> (labelled "**") <pre class="brush: javascript;">javascript:open(location,'iPhone:landscape','innerWidth='+(480+15)+',innerHeight='+(320+15)+',scrollbars=yes');</pre></li>
</ul>
<dl class="border">
	<dt><img src="http://resources.davidchambersdesign.com/images/posts/iphone-testing-bookmarklets.png" alt="iPhone testing bookmarklets" /></dt>
	<dd>iPhone testing bookmarklets: portrait and landscape</dd>
</dl>
]]></description>
			<content:encoded><![CDATA[<p>I've recently become interested in optimizing sites for the iPhone and iPod touch. While nothing beats testing on the device itself, I often find it quicker to test changes on my Mac. Changing the user agent string is a piece of cake in Safari (Develop > User Agent > Mobile Safari) but what about adjusting the browser window's dimensions to match those of the iPhone?</p>
<p>I've created two bookmarklets to allow the current page to be loaded in an iPhone-sized window with a single click:</p>
<ul>
	<li><strong>Portrait</strong> (labelled "⁑") <pre class="brush: javascript;">javascript:open(location,'iPhone:portrait','innerWidth='+(320+15)+',innerHeight='+(480+15)+',scrollbars=yes');</pre></li>
	<li><strong>Landscape</strong> (labelled "**") <pre class="brush: javascript;">javascript:open(location,'iPhone:landscape','innerWidth='+(480+15)+',innerHeight='+(320+15)+',scrollbars=yes');</pre></li>
</ul>
<dl class="border">
	<dt><img src="http://resources.davidchambersdesign.com/images/posts/iphone-testing-bookmarklets.png" alt="iPhone testing bookmarklets" /></dt>
	<dd>iPhone testing bookmarklets: portrait and landscape</dd>
	<dt><img src="http://resources.davidchambersdesign.com/images/posts/safari-window-iphone-dimensions-portrait.png" alt="Safari window resized to iPhone portrait dimensions" /></dt>
	<dd>320x480: iPhone portrait dimensions</dd>
	<dt><img src="http://resources.davidchambersdesign.com/images/posts/safari-window-iphone-dimensions-landscape.png" alt="Safari window resized to iPhone landscape dimensions" /></dt>
	<dd>480x320: iPhone landscape dimensions</dd>
</dl>
<p>It appears that I need to rework this site's style sheet to better present content in these smaller viewports!</p>
]]></content:encoded>
			<wfw:commentRss>http://davidchambersdesign.com/resize-browser-window-to-match-iphone-viewport-dimensions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shockingly simple URL shortening</title>
		<link>http://davidchambersdesign.com/shockingly-simple-url-shortening/</link>
		<comments>http://davidchambersdesign.com/shockingly-simple-url-shortening/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 14:34:32 +0000</pubDate>
		<dc:creator>David Chambers</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://davidchambersdesign.com/?p=1523</guid>
		<description><![CDATA[<p>URL shortening is something that's been at the back of my mind since listening to <a href="http://www.sitepoint.com/blogs/2009/08/22/podcast-24-those-frames-are-ironic/">SitePoint Podcast #24</a> which discussed the near closure of <a href="http://tr.im/">tr.im</a>.</p>
<p><strong><em>Why are short URLs required?</em> Twitter.</strong> Tweets are limited to 140 characters, and URLs often seem recklessly long in this context. Of course, Twitter could simply allow us to apply short, meaningful labels to our links as we've been doing in HTML for years. Instead, each time one includes a link in a tweet one must either:</p>
<ul class="square">
	<li>spend a large number of characters on the full URL; or</li>
	<li>use a short URL generated by a service such as <a href="http://bit.ly/">bit.ly</a></li>
</ul>
]]></description>
			<content:encoded><![CDATA[<p>URL shortening is something that's been at the back of my mind since listening to <a href="http://www.sitepoint.com/blogs/2009/08/22/podcast-24-those-frames-are-ironic/">SitePoint Podcast #24</a> which discussed the near closure of <a href="http://tr.im/">tr.im</a>.</p>
<p><strong><em>Why are short URLs required?</em> Twitter.</strong> Tweets are limited to 140 characters, and URLs often seem recklessly long in this context. Of course, Twitter could simply allow us to apply short, meaningful labels to our links as we've been doing in HTML for years. Instead, each time one includes a link in a tweet one must either:</p>
<ul class="square">
	<li>spend a large number of characters on the full URL; or</li>
	<li>use a short URL generated by a service such as <a href="http://bit.ly/">bit.ly</a></li>
</ul>
<p>I'm opposed to short URLs for several reasons. First, I believe that every reference to a resource should use that resource's Uniform Resource Identifier (if it has one) in its normalized form. In other words, we should <em>not</em> use <strong>http://www.wikipedia.org/</strong> to refer to <strong>http://wikipedia.org/</strong>, and we should <em>certainly not</em> use <strong>http://bit.ly/8RTk</strong>. Having multiple URLs for a resource is a maintenance nightmare (unless one is willing to accept URLs being temporal).</p>
<p>Secondly, I have a simple rule: <strong>meaningful &gt; meaningless</strong>. Meaningful markup is wonderful, and meaningful URLs offer similar benefits (to both people and search engines).</p>
<p>Finally — and this point relates to URL shortening services rather than to short URLs themselves — there's no guarantee that sites which <em>currently</em> provide a service will continue to do so indefinitely.</p>
<h3>Enter John Gruber</h3>
<p>I noticed one day that <a href="http://daringfireball.net/">Daring Fireball</a> now has its own <a href="http://sites.google.com/a/snaplog.com/wiki/short_url">shorturl</a>s, using the incredibly cool domain name ✪df.ws. This got me thinking that perhaps I should procure a short domain name and do something similar. Well, last week I did.</p>
<p>With dċd.ws safely registered in my name I began looking for an open source URL shortener to run on that domain. I then struck upon a <strong>simple, elegant solution</strong> which took all of ten minutes to implement.</p>
<pre class="brush: plain;">RewriteEngine On
RewriteRule ^(.*)$ http://davidchambersdesign.com/$1 [R=301,L]</pre>
<p>The code above forms the entirety of the <strong>.htaccess</strong> file on the dċd.ws server. All it does is redirect every request to the corresponding davidchambersdesign.com URL. The key word being <em>every</em>. As a result, existing pages on this site gained short<em>er</em> (though not necessarily short) URLs automatically, and new pages gain a short URL the instant they are published. <strong>No maintenance, no fuss. Nice!</strong></p>
<p>So, for example, <strong>http://dċd.ws/twitter/</strong> → <strong>http://davidchambersdesign.com/twitter/</strong> (a 17 character saving).</p>
<p>If you're interested in acquiring your own short domain name, I suggest trying .ws as it's one of the few top level domains to allow virtually any Unicode character in its domain names. As a result, there are plenty of short .ws domain names available. I don't suggest this approach for normal use, however, as browsers will display something like <strong>http://xn--dd-7la.ws/</strong> in their address bars.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidchambersdesign.com/shockingly-simple-url-shortening/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Duplicating arrays in JavaScript</title>
		<link>http://davidchambersdesign.com/duplicating-arrays-in-javascript/</link>
		<comments>http://davidchambersdesign.com/duplicating-arrays-in-javascript/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 06:26:36 +0000</pubDate>
		<dc:creator>David Chambers</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://davidchambersdesign.com/?p=1466</guid>
		<description><![CDATA[Many of those who write JavaScript do not come from programming backgrounds (while I've written plenty of PHP, Python, and JavaScript, I don't have much experience with "real" programming languages*). As a result, a significant portion of JavaScript coders do not think of variables as pointers to memory addresses. This leads to confusion in cases [...]]]></description>
			<content:encoded><![CDATA[<p>Many of those who write JavaScript do not come from programming backgrounds (while I've written plenty of PHP, Python, and JavaScript, I don't have much experience with "real" programming languages<a href="#footnote">*</a>). As a result, a significant portion of JavaScript coders do not think of variables as pointers to memory addresses. This leads to confusion in cases such as this:</p>
<pre class="brush: javascript;">var fruits = ['orange', 'lime'];
var colours = fruits; // naïve attempt to duplicate array
colours.append('yellow');</pre>
<p>One might be surprised to learn that <code>fruits</code> now contains not just "orange" and "lime" but also "yellow". Oops! Here's how it went wrong:</p>
<pre class="brush: javascript;">var fruits = ['orange', 'lime']; // fruits points to array containing "orange" and "lime"
var colours = fruits; // colours now points to that same array!</pre>
<p>How, then, does one create a copy of the original array? <em>Slice!</em></p>
<pre class="brush: javascript;">var colours = fruits.slice();</pre>
<aside id="footnote">* Languages such as C. Like <a href="http://www.quirksmode.org/about/">ppk</a>, I take care to include quotation marks. ;)</aside>
]]></content:encoded>
			<wfw:commentRss>http://davidchambersdesign.com/duplicating-arrays-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Accessing MySQL shell via Terminal</title>
		<link>http://davidchambersdesign.com/accessing-mysql-shell-via-terminal/</link>
		<comments>http://davidchambersdesign.com/accessing-mysql-shell-via-terminal/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 00:49:28 +0000</pubDate>
		<dc:creator>David Chambers</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Terminal]]></category>

		<guid isPermaLink="false">http://davidchambersdesign.com/?p=1453</guid>
		<description><![CDATA[Certain things are extremely well documented on the Web; certain other things, however, seem to appear only deep in the comments of obscure blog entries.
The problem I encountered a few minutes ago fell squarely in the latter category. I simply wanted to know how to access the MySQL shell from the OS X Terminal. I [...]]]></description>
			<content:encoded><![CDATA[<p>Certain things are extremely well documented on the Web; certain other things, however, seem to appear only deep in the comments of obscure blog entries.</p>
<p>The problem I encountered a few minutes ago fell squarely in the latter category. I simply wanted to know how to access the MySQL shell from the OS X Terminal. I expected my Google search for <code>MySQL console Terminal "OS X"</code> to return several useful results, but this was not the case.</p>
<p>I managed to find the solution in a thread with subject <a href="http://www.oreillynet.com/cs/user/view/cs_msg/7078#id_7118">error 1044 and 1045</a>:</p>
<pre class="brush: bash;">mysql -u root -p mysql</pre>
]]></content:encoded>
			<wfw:commentRss>http://davidchambersdesign.com/accessing-mysql-shell-via-terminal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Auto-populating input fields with Prototype</title>
		<link>http://davidchambersdesign.com/autopopulating-input-fields-with-prototype/</link>
		<comments>http://davidchambersdesign.com/autopopulating-input-fields-with-prototype/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 09:03:56 +0000</pubDate>
		<dc:creator>David Chambers</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[UX]]></category>

		<guid isPermaLink="false">http://davidchambersdesign.com/?p=1414</guid>
		<description><![CDATA[<p>Yesterday I wrote a simple class which auto-populates input fields, and thought it worth sharing. I was originally inspired to write this code by Roger Johansson's post titled <a href="http://www.456bereastreet.com/archive/200710/autopopulating_text_input_fields_with_javascript/">Autopopulating text input fields with JavaScript</a>. While I approached the problem from a slightly different angle, I made sure to avoid the pitfalls mentioned.</p>
]]></description>
			<content:encoded><![CDATA[<p>Yesterday I wrote a simple class which auto-populates input fields, and thought it worth sharing. I was originally inspired to write this code by Roger Johansson's post titled <a href="http://www.456bereastreet.com/archive/200710/autopopulating_text_input_fields_with_javascript/">Autopopulating text input fields with JavaScript</a>. While I approached the problem from a slightly different angle, I made sure to avoid the pitfalls mentioned.</p>
<h3>Contents</h3>
<ul class="square">
	<li><a href="#behaviour">Behaviour</a></li>
	<li><a href="#html5-placeholder-text">HTML5 placeholder text</a></li>
	<li><a href="#markup">Markup</a></li>
	<li><a href="#styling">Styling</a></li>
	<li><a href="#placeholder-class">Placeholder class</a></li>
	<li><a href="#usage">Usage</a></li>
</ul>
<h3 id="behaviour">Behaviour</h3>
<ul class="square">
	<li>Placeholder text should be inserted into input field upon page load.</li>
	<li>Placeholder text should be targetable via CSS.</li>
	<li>Clicking or tabbing into input field should remove placeholder text.</li>
	<li>Placeholder text should be reinserted if input field is empty when it loses focus.</li>
</ul>
<h3 id="html5-placeholder-text">HTML5 placeholder text</h3>
<p>HTML5 allows placeholder text to be specified in the markup through the <code>placeholder</code> attribute. In supporting browsers (currently Chrome and Safari) this produces the behaviour described above with no reliance on JavaScript.</p>
<h3 id="markup">Markup</h3>
<pre class="brush: html;">&lt;input type="search" id="s" name="s" placeholder="search..." /&gt;</pre>
<h3 id="styling">Styling</h3>
<pre class="brush: css;">input.placeholder { color: #a9a9a9 !important; }</pre>
<p>I decided to use <code>#a9a9a9</code> as Safari uses this colour for placeholder text.</p>
<h3 id="placeholder-class">Placeholder class</h3>
<pre class="brush: javascript;">var Placeholder = Class.create({
	initialize: function (element) {
		this.element = element;
		this.placeholder = element.readAttribute('placeholder');
		this.blur();
		Event.observe(this.element, 'focus', this.focus.bindAsEventListener(this));
		Event.observe(this.element, 'blur', this.blur.bindAsEventListener(this));
	},
	focus: function () {
		if (this.element.hasClassName('placeholder'))
			this.element.clear().removeClassName('placeholder');
	},
	blur: function () {
		if (this.element.value == '')
			this.element.addClassName('placeholder').value = this.placeholder;
	},
});</pre>
<p>The Placeholder class requires <a href="http://prototypejs.org/">Prototype</a>.</p>
<h3 id="usage">Usage</h3>
<p>To create a new instance of the Placeholder class, simply pass the constructor a Prototype extended element:</p>
<pre class="brush: javascript;">new Placeholder($('s'));</pre>
<p>Ensure that the DOM is ready by wrapping everything in Prototype's <code>dom:loaded</code> event listener. This also avoids polluting the global namespace.</p>
<pre class="brush: javascript;">document.observe('dom:loaded', function () {
	var Placeholder = Class.create({
		...
	});
	$$('#s', '#contactform #name', '#contactform #email').each(function (input) {
		new Placeholder(input);
	});
});</pre>
<p><strong>This site's search field shows the code in action.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://davidchambersdesign.com/autopopulating-input-fields-with-prototype/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Prototype and script.aculo.us, combined and compressed</title>
		<link>http://davidchambersdesign.com/prototype-and-scriptaculous-combined-and-compressed/</link>
		<comments>http://davidchambersdesign.com/prototype-and-scriptaculous-combined-and-compressed/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 10:14:03 +0000</pubDate>
		<dc:creator>David Chambers</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[script.aculo.us]]></category>

		<guid isPermaLink="false">http://davidchambersdesign.com/?p=1390</guid>
		<description><![CDATA[Nothing new here. I've combined Prototype 1.6.1 and the various files that make up script.aculo.us 1.8.3 (except unittest.js) into one file, which I've minified using the YUI Compressor. Further compression has been achieved by gzipping the minified file. All three versions are available for download:

	prototype+scriptaculous.js (≈260.6 KB)
	prototype+scriptaculous.min.js (≈154.6 KB)
	prototype+scriptaculous.min.js.gz (≈43.6 KB)

I suggest including the Prototype [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Nothing new here.</strong> I've combined <a href="http://prototypejs.org/2009/9/1/prototype-1-6-1-released">Prototype 1.6.1</a> and the various files that make up <a href="http://script.aculo.us/downloads">script.aculo.us 1.8.3</a> (except unittest.js) into one file, which I've minified using the <a href="http://developer.yahoo.com/yui/compressor/">YUI Compressor</a>. Further compression has been achieved by gzipping the minified file. All three versions are available for download:</p>
<ul class="square">
	<li><a href="http://resources.davidchambersdesign.com/scripts/prototype+scriptaculous.js?p=1.6.1&amp;s=1.8.3">prototype+scriptaculous.js</a> <span class="filesize">(≈260.6 KB)</span></li>
	<li><a href="http://resources.davidchambersdesign.com/scripts/prototype+scriptaculous.min.js?p=1.6.1&amp;s=1.8.3">prototype+scriptaculous.min.js</a> <span class="filesize">(≈154.6 KB)</span></li>
	<li><a href="http://resources.davidchambersdesign.com/scripts/prototype+scriptaculous.min.js.gz?p=1.6.1&amp;s=1.8.3">prototype+scriptaculous.min.js.gz</a> <span class="filesize">(≈43.6 KB)</span></li>
</ul>
<p>I suggest including the Prototype and script.aculo.us version numbers in the <code>src</code>:</p>
<pre class="brush: html; toolbar: false;">&lt;script type="text/javascript" src="/scripts/prototype+scriptaculous.min.js?p=1.6.1&amp;amp;s=1.8.3"&gt;&lt;/script&gt;</pre>
<p>This prevents caching issues that might otherwise arise upon updating to a newer version of prototype+scriptaculous (I'll update the three files — and this post — each time a new version of Prototype is released).</p>
]]></content:encoded>
			<wfw:commentRss>http://davidchambersdesign.com/prototype-and-scriptaculous-combined-and-compressed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using HTML5 time element in WordPress themes</title>
		<link>http://davidchambersdesign.com/using-html5-time-element-in-wordpress-themes/</link>
		<comments>http://davidchambersdesign.com/using-html5-time-element-in-wordpress-themes/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 13:04:24 +0000</pubDate>
		<dc:creator>David Chambers</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://davidchambersdesign.com/?p=1371</guid>
		<description><![CDATA[I've begun retrofitting this site with HTML5 elements. I'm thoroughly enjoying the process (I love meaningful markup).
One of the first HTML5 elements I've introduced is the time element which, through its datetime attribute, provides a machine-readable version of dates and times.
&#60;time datetime="2009-11-01T16:41:53+13:00"&#62;1 November 2009&#60;/time&#62;
I wrote a function to generate the machine-readable dates and times for [...]]]></description>
			<content:encoded><![CDATA[<p>I've begun retrofitting this site with HTML5 elements. I'm thoroughly enjoying the process (I love meaningful markup).</p>
<p>One of the first HTML5 elements I've introduced is the <strong>time</strong> element which, through its <strong>datetime</strong> attribute, provides a machine-readable version of dates and times.</p>
<pre class="brush: html; toolbar: false;">&lt;time datetime="2009-11-01T16:41:53+13:00"&gt;1 November 2009&lt;/time&gt;</pre>
<p>I wrote a function to generate the machine-readable dates and times for blog comments.</p>
<pre class="brush: php;">/**
 * echoes comment's date and time in format 2009-11-01T03:41:53+13:00
 */
function comment_datetime()
{
	$comment = get_comment($comment);
	$local = strtotime($comment->comment_date);
	$gmt = strtotime($comment->comment_date_gmt);
	$seconds = abs($local - $gmt);
	$hours = (int) ($seconds / 3600);
	$minutes = (int) (($seconds - $hours * 3600) / 60);
	$output = get_comment_time('Y-m-d\TH:i:s');

	if ($local == $gmt)
		$output .= 'Z';
	else
		$output .= ($local > $gmt ? '+' : '-')
		        . str_pad($hours, 2, '0', STR_PAD_LEFT) . ':'
		        . str_pad($minutes, 2, '0', STR_PAD_LEFT);

	echo $output;
}</pre>
<p>While looping through comments in your WordPress theme, call the above function to print a valid datetime string.</p>
<pre class="brush: php; html-script: true;">&lt;time datetime="&lt;?php comment_datetime(); ?&gt;"&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://davidchambersdesign.com/using-html5-time-element-in-wordpress-themes/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>CSS fixed-position headers</title>
		<link>http://davidchambersdesign.com/css-fixed-position-headers/</link>
		<comments>http://davidchambersdesign.com/css-fixed-position-headers/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 05:25:49 +0000</pubDate>
		<dc:creator>David Chambers</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Prototype]]></category>

		<guid isPermaLink="false">http://davidchambersdesign.com/?p=871</guid>
		<description><![CDATA[<p>I began this post three months ago, got stuck, and put it in the too hard basket. I wanted to devise a workable solution to my stumbling block before publishing this information. I'm getting ahead of myself, though. First, the background.</p>
<p>As I began writing this post, I had just completed a redesign of this site. The new design removed unnecessary distractions to allow readers to focus on the clearly presented content. I moved site navigation from the sidebar (which I axed altogether) to the header. I decided to fix the header in place so that the navigation and search form would always be visible. This required very little effort, but overcoming the <a href="http://css-tricks.com/forums/viewtopic.php?t=3496">problem posed by fixed-position headers</a> took a great deal of trial and error. To save others from going through this tortuous process I'll describe my various approaches, and list the benefits and drawbacks of each.</p>
]]></description>
			<content:encoded><![CDATA[<p>I began this post three months ago, got stuck, and put it in the too hard basket. I wanted to devise a workable solution to my stumbling block before publishing this information. I'm getting ahead of myself, though. First, the background.</p>
<p>As I began writing this post, I had just completed a redesign of this site. The new design removed unnecessary distractions to allow readers to focus on the clearly presented content. I moved site navigation from the sidebar (which I axed altogether) to the header. I decided to fix the header in place so that the navigation and search form would always be visible. This required very little effort, but overcoming the <a href="http://css-tricks.com/forums/viewtopic.php?t=3496">problem posed by fixed-position headers</a> took a great deal of trial and error. To save others from going through this tortuous process I'll describe my various approaches, and list the benefits and drawbacks of each.</p>
<h3>Requirements</h3>
<ul class="square">
	<li>An additional vertical scrollbar must not be introduced.</li>
	<li>Appending <strong>#example</strong> to a URL should result in the element whose id is "example" being displayed at the top of the content area (not hidden behind the header).</li>
	<li>Additional markup may be used only if the requirements above cannot be met without extra markup.</li>
</ul>
<p>The CSS for the header initially looked like this:</p>
<pre class="brush: css; class-name: css;">#header
{
	position: fixed;
	top: 0;
	left: 0;
	height: 160px;
}</pre>
<h3>Approach 1: positive top padding + negative bottom margins</h3>
<p>Here's the CSS:</p>
<pre class="brush: css; class-name: css;">h1, h2, h3, h4, h5, h6, p
{
	padding-top: 160px;
	margin-bottom: -160px;
}</pre>
<p>This approach adds top padding (equal to the height of the header) to each of the block-level elements in the content area. This ensures that elements are in the correct position when jumped to using #id. An equal and opposite bottom margin is also applied to prevent the padding from adding unwanted white space between elements.</p>
<ul>
	<li class="pro">No additional markup is required.</li>
	<li class="pro">Straightforward CSS.</li>
	<li class="con">The CSS selector needs to contain all block-level elements that may have ids in some instances. This is likely to include elements such as divs and forms. Since it is hard to foresee all the situations in which a link may direct a user to a uniquely identified element, it is difficult to ensure that this approach will work in all cases.</li>
	<li class="con"><strong>The negative bottom margin causes each block-level element to overlap the preceding element, making "overlapped" links unclickable!</strong></li>
</ul>
<h3>Approach 2: preceding divs</h3>
<p>Again, the CSS:</p>
<pre class="brush: css; class-name: css;">div.id
{
	position: relative;
	top: -160px;
}</pre>
<p>This approach introduces meaningless markup. Where previously we may have had something like this:</p>
<pre class="brush: html; class-name: html;">&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc faucibus volutpat risus nec mollis. Integer dapibus dictum ultrices. Aenean vel lectus odio. Nam a mi ligula. Nam in dolor quis metus pretium imperdiet sit amet sed elit.&lt;/p&gt;
&lt;h3 id="example"&gt;Example&lt;/h3&gt;
&lt;p&gt;Suspendisse potenti. Proin convallis lacinia nibh, nec auctor ligula mattis consectetur. Mauris vel elit sit amet nibh volutpat varius id vel sem. Pellentesque id purus ligula. Vivamus vel nulla vel justo tempor ultricies.&lt;/p&gt;</pre>
<p>We now have the following:</p>
<pre class="brush: html; class-name: html; highlight: 2;">&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc faucibus volutpat risus nec mollis. Integer dapibus dictum ultrices. Aenean vel lectus odio. Nam a mi ligula. Nam in dolor quis metus pretium imperdiet sit amet sed elit.&lt;/p&gt;
&lt;div id="example" class="id"&gt;&lt;/div&gt;
&lt;h3&gt;Example&lt;/h3&gt;
&lt;p&gt;Suspendisse potenti. Proin convallis lacinia nibh, nec auctor ligula mattis consectetur. Mauris vel elit sit amet nibh volutpat varius id vel sem. Pellentesque id purus ligula. Vivamus vel nulla vel justo tempor ultricies.&lt;/p&gt;</pre>
<p>With this approach, each uniquely identified block-level element within the content area gives its id to a div which appears immediately before it in the html. Each of these divs is offset by the height of the header, ensuring that the element of interest is not obscured by the header.</p>
<ul>
	<li class="pro">Straightforward CSS.</li>
	<li class="pro">Links are always clickable!</li>
	<li class="con">Additional markup is required, necessitating that existing content be updated (or JavaScript used to insert the additional elements dynamically).</li>
	<li class="con">Not only is this extra markup meaningless, but it actually removes ids from the elements to which they were additionally assigned. Any existing CSS selectors that refer to one of these elements will need to be updated. (For example, <code>h3#comments</code> would need to change to <code>div#comments + h3</code>.</li>
</ul>
<p>This approach does not have any fatal flaws, but it may require template files, static html files, style sheets, and database records to be updated. Additionally, it is inelegant. In other words, it <em>is</em> as option, but not a good one.</p>
<h3>Approach 3: JavaScript trickery</h3>
<p>The previous approach got the job done, but introduced meaningless elements. This task is best performed with JavaScript.</p>
<pre class="brush: javascript;">// accommodate fixed-position header
document.observe('dom:loaded', function () {
	$$('h2[id]', 'h3[id]', 'h4[id]', 'h5[id]', 'h6[id]').each(function (e) {
		var div = new Element('div', { id: e.id });
		e.writeAttribute({ id: null });
		e.addClassName('unidentified');
		e.insert({ 'top': div });
	})
});</pre>
<p>The above snippet locates all the h2, h3, h4, h5, and h6 elements on the page that have an id attribute. It then loops through this collection of elements and inserts an empty div element into each one. This div "steals" its parent's id.</p>
<p>CSS can be used to position these empty divs in such a way that headings are visible when jumped to:</p>
<pre class="brush: css;">h2.unidentified div, h3.unidentified div
{
	float: left;
	margin: -160px 0 0 0;
}</pre>
<ul>
	<li class="pro">No additional markup is required.</li>
	<li class="pro">Straightforward CSS.</li>
	<li class="pro">Links are always clickable.</li>
	<li class="con">JavaScript (and in this case <a href="http://prototypejs.org/">Prototype</a>) required.</li>
	<li class="con">Association between an id and the element it identifies is broken.</li>
</ul>
<h3>Summary</h3>
<p>I have implemented the JavaScript approach, and it works nicely. I am still hopeful that there exists a simpler and/or more universal solution to the problem posed by fixed-position headers. Please let me know if you have any ideas or suggestions.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidchambersdesign.com/css-fixed-position-headers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.601 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-03-10 22:08:47 -->
