<?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>Barryvan &#187; tips</title>
	<atom:link href="http://www.barryvan.com.au/tag/tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.barryvan.com.au</link>
	<description>Music, Programming, Design</description>
	<lastBuildDate>Wed, 23 Jun 2010 04:18:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Limiting the contents of a string via RegEx</title>
		<link>http://www.barryvan.com.au/2009/12/limiting-the-contents-of-a-string-via-regex/</link>
		<comments>http://www.barryvan.com.au/2009/12/limiting-the-contents-of-a-string-via-regex/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 08:10:49 +0000</pubDate>
		<dc:creator>Barry van Oudtshoorn</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.barryvan.com.au/?p=332</guid>
		<description><![CDATA[Often, you will need to prevent users from entering data that doesn&#8217;t conform to a specific pattern. For example, you may want to allow users to enter only numbers or only valid email addresses. To this end, I&#8217;ve written a little utility function that returns the &#8220;standardised&#8221; version of a string, according to the regex [...]]]></description>
			<content:encoded><![CDATA[<p>Often, you will need to prevent users from entering data that doesn&#8217;t conform to a specific pattern. For example, you may want to allow users to enter only numbers or only valid email addresses. To this end, I&#8217;ve written a little utility function that returns the &#8220;standardised&#8221; version of a string, according to the regex you supply.</p>
<pre class="brush: javascript">String.implement({
	limitContent: function(allowedRegex) {
		return $splat(this.match(allowedRegex)).join(&#039;&#039;);
	}
});</pre>
<p>Basically, the function takes the result of evaluating the regular expression on the string, converts it into an array if it isn&#8217;t one, and then joins the array&#8217;s elements together with an empty string.</p>
<h2>Examples:</h2>
<pre class="brush: javascript">console.log(&quot;12345&quot;.limitContent(/.{4}/)); // Only allow four characters
console.log(&quot;joe@mail.com&quot;.limitContent(/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}/)); // Only allow email addresses
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.barryvan.com.au/2009/12/limiting-the-contents-of-a-string-via-regex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Wave &amp; iPhone</title>
		<link>http://www.barryvan.com.au/2009/11/google-wave-iphone/</link>
		<comments>http://www.barryvan.com.au/2009/11/google-wave-iphone/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 06:10:54 +0000</pubDate>
		<dc:creator>Barry van Oudtshoorn</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[wave]]></category>

		<guid isPermaLink="false">http://www.barryvan.com.au/?p=301</guid>
		<description><![CDATA[I just tried out Google Wave on the iPhone. Interestingly, despite an initial &#8220;your browser is not supported&#8221; message, the actual system sports a rather snazzy app-like interface on the iPhone. I&#8217;ll be interested to see what kind of support Wave will &#8216;officially&#8217; have on mobile platforms, and perhaps even more interested in what &#8216;unofficial&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p>I just tried out Google Wave on the iPhone. Interestingly, despite an initial &#8220;your browser is not supported&#8221; message, the actual system sports a rather snazzy app-like interface on the iPhone.</p>
<p>I&#8217;ll be interested to see what kind of support Wave will &#8216;officially&#8217; have on mobile platforms, and perhaps even more interested in what &#8216;unofficial&#8217; support there&#8217;ll be. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.barryvan.com.au/2009/11/google-wave-iphone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS Columns</title>
		<link>http://www.barryvan.com.au/2009/10/css-columns/</link>
		<comments>http://www.barryvan.com.au/2009/10/css-columns/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 13:01:09 +0000</pubDate>
		<dc:creator>Barry van Oudtshoorn</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.barryvan.com.au/?p=295</guid>
		<description><![CDATA[In this post, I will walk through the new columns specification that arrived in CSS 3. I will show you the current implementation state of columns in the four major rendering engines: Gecko (Firefox), Webkit (Safari &#038; Chrome), Trident (Internet Explorer), and Presto (Opera). Before we get on to platform-specific issues and workarounds, though, we&#8217;ll [...]]]></description>
			<content:encoded><![CDATA[<p>In this post, I will walk through the new columns specification that arrived in CSS 3. I will show you the current implementation state of columns in the four major rendering engines: Gecko (Firefox), Webkit (Safari &#038; Chrome), Trident (Internet Explorer), and Presto (Opera).</p>
<p>Before we get on to platform-specific issues and workarounds, though, we&#8217;ll look at the various CSS properties available for working with columns.</p>
<p>For more in-depth information on columns, you should check out the <a href="http://www.w3.org/TR/css3-multicol/">W3C working draft</a> and Mozilla&#8217;s <a href="https://developer.mozilla.org/en/CSS3_Columns">MDC page on columns</a>. The Webkit blog <a href="http://webkit.org/blog/88/css3-multi-column-support/">also has an article</a>, but it&#8217;s not particularly informative.</p>
<h2>Contents</h2>
<ul>
<li>
		<a href="#capabilities">Browser capabilities</a>
	</li>
<li>
		<a href="#bugs">Browser bugs</a></p>
<ul>
<li><a href="#gecko-bugs">Gecko</a></li>
<li><a href="#webkit-bugs">Webkit</a></li>
</ul>
</li>
<li>
		<a href="#properties">Properties</a></p>
<ul>
<li><a href="#column-count">column-count</a></li>
<li><a href="#column-width">column-width</a></li>
<li><a href="#columns">columns</a></li>
<li><a href="#column-gap">column-gap</a></li>
<li><a href="#column-rule-color">column-rule-color</a></li>
<li><a href="#column-rule-style">column-rule-style</a></li>
<li><a href="#column-rule-width">column-rule-width</a></li>
<li><a href="#column-rule">column-rule</a></li>
<li><a href="#column-span">column-span</a></li>
<li><a href="#column-fill">column-fill</a></li>
</ul>
</li>
</ul>
<p>I will add more to this entry as I discover more about columns &#8212; the goal is to make it an easy-to-understand reference.</p>
<h2><a name="capabilities" href="#capabilities">Browser capabilities</a></h2>
<table class="capabilities" cellspacing="0" cellpadding="0">
<thead>
<tr>
<td>Property</td>
<td>Gecko</td>
<td>Webkit</td>
<td>Trident</td>
<td>Presto</td>
</tr>
</thead>
<tbody>
<tr>
<td class="property"><a href="#column-count">column-count</a></td>
<td class="full">-moz-column-count</td>
<td class="full">-webkit-column-count</td>
<td class="none">&#10007;</td>
<td class="none">&#10007;</td>
</tr>
<tr>
<td class="property"><a href="#column-width">column-width</a></td>
<td class="full">-moz-column-width</td>
<td class="full">-webkit-column-width</td>
<td class="none">&#10007;</td>
<td class="none">&#10007;</td>
</tr>
<tr>
<td class="property"><a href="#columns">columns</a></td>
<td class="none">&#10007;</td>
<td class="full">-webkit-columns</td>
<td class="none">&#10007;</td>
<td class="none">&#10007;</td>
</tr>
<tr>
<td class="property"><a href="#column-gap">column-gap</a></td>
<td class="full">-moz-column-gap</td>
<td class="full">-webkit-column-gap</td>
<td class="none">&#10007;</td>
<td class="none">&#10007;</td>
</tr>
<tr>
<td class="property"><a href="#column-rule-color">column-rule-color</a></td>
<td class="partial"><a href="#gecko-bugs">-moz-column-rule-color</a></td>
<td class="full">-webkit-column-rule-color</td>
<td class="none">&#10007;</td>
<td class="none">&#10007;</td>
</tr>
<tr>
<td class="property"><a href="#column-rule-style">column-rule-style</a></td>
<td class="partial"><a href="#gecko-bugs">-moz-column-rule-style</a></td>
<td class="full">-webkit-column-rule-style</td>
<td class="none">&#10007;</td>
<td class="none">&#10007;</td>
</tr>
<tr>
<td class="property"><a href="#column-rule-width">column-rule-width</a></td>
<td class="partial"><a href="#gecko-bugs">-moz-column-rule-width</a></td>
<td class="full">-webkit-column-rule-width</td>
<td class="none">&#10007;</td>
<td class="none">&#10007;</td>
</tr>
<tr>
<td class="property"><a href="#column-rule">column-rule</a></td>
<td class="partial"><a href="#gecko-bugs">-moz-column-rule</a></td>
<td class="full">column-rule</td>
<td class="none">&#10007;</td>
<td class="none">&#10007;</td>
</tr>
<tr>
<td class="property"><a href="#column-span">column-span</a></td>
<td class="none">&#10007;</td>
<td class="none">&#10007;</td>
<td class="none">&#10007;</td>
<td class="none">&#10007;</td>
</tr>
<tr>
<td class="property"><a href="#column-fill">column-fill</a></td>
<td class="none">&#10007;</td>
<td class="none">&#10007;</td>
<td class="none">&#10007;</td>
<td class="none">&#10007;</td>
</tr>
<tr>
<td class="property">break-before</a></td>
<td class="none">&#10007;</td>
<td class="none">&#10007;</td>
<td class="none">&#10007;</td>
<td class="none">&#10007;</td>
</tr>
<tr>
<td class="property">break-inside</a></td>
<td class="none">&#10007;</td>
<td class="none">&#10007;</td>
<td class="none">&#10007;</td>
<td class="none">&#10007;</td>
</tr>
</tbody>
</table>
<p>Browsers used for testing: Firefox 3.5.4 (Windows), Safari 4.0.2 (Windows), Internet Explorer 8.0.6001, Opera 10.00 (Windows)</p>
<p>Please let me know if this table is inaccurate, and I will update it.</p>
<h2><a name="bugs" href="#bugs">Browser bugs</a></h2>
<p>These are the bugs that I have encountered using CSS columns &#8212; if you know of more, please let me know, and I&#8217;ll add them to these lists.</p>
<h3><a name="gecko-bugs" href="#gecko-bugs">Gecko bugs</a></h3>
<ul>
<li>Specifying an &#8220;overflow&#8221; (or &#8220;overflow-x&#8221; or &#8220;overflow-y&#8221;) property on an element with columns prevents the column rule from being rendered at all.</li>
<li>Column rules occasionally don&#8217;t render, regardless of the &#8220;overflow&#8221; property.</li>
<li>There is no way to break columns.</li>
</ul>
<h3><a name="webkit-bugs" href="#webkit-bugs">Webkit bugs</a></h3>
<ul>
<li>Pixel creep: Pixels from a later column can creep back to the bottom of the previous column. This can happen with plain text, but it is much more noticeable when you use a non-layout altering effect like text-shadow or box-shadow.</li>
<li>Text that overflows the column horizontally is chopped off</li>
<li>There is no way to break columns.</li>
</ul>
<h2><a name="properties" href="#properties">Properties</a></h2>
<h3><a name="column-count" href="#column-count">column-count</a></h3>
<p><strong>Value:</strong> <integer> | auto<br />
<strong>Initial value:</strong> auto</p>
<p>If you don&#8217;t set the <a href="#column-width">column-width</a> property, <a href="#column-count">column-count</a> specifies the number of columns into which the content should be flowed.</p>
<p>If you specify <a href="#column-width">column-width</a>, <a href="#column-count">column-count</a> imposes a limit on the maximum number of columns to be rendered if you supply a numeric value.</p>
<h3><a name="column-width" href="#column-width">column-width</a></h3>
<p><strong>Value:</strong> <length> | auto<br />
<strong>Initial value:</strong> auto</p>
<p>This property indicates the <em>optimal</em> column width &#8212; columns may be rendered narrower or wider by the UA, according to the available space.</p>
<p>If <a href="#column-width">column-width</a> has the value &#8220;auto&#8221;, then the width of the columns is determined by other means (for example, <a href="#column-count">column-count</a>).</p>
<h3><a name="columns" href="#columns">columns</a></h3>
<p><strong>Value:</strong> <a href="#column-width">column-width</a> &#038;&#038; <a href="#column-count">column-count</a></p>
<p>The <a href="#columns">columns</a> property is a short-hand property, used to set both <a href="#column-width">column-width</a> and <a href="#column-count">column-count</a> simultaneously.</p>
<h3><a name="column-gap" href="#column-gap">column-gap</a></h3>
<p><strong>Value:</strong> <length> | normal<br />
<strong>Initial value:</strong> normal</p>
<p>Use <a href="#column-gap">column-gap</a> to specify the size of the gutter that lies between columns. Most UAs will render &#8220;normal&#8221; as 1em.</p>
<h3><a name="column-rule-color" href="#column-rule-color">column-rule-color</a></h3>
<p><strong>Value:</strong><br />
<color>
<p>When a <a href="#column-rule">column-rule</a> is specified, you may use <a href="#column-rule-color">column-rule-color</a> to set the colour for the line drawn between columns. This property is approximately equivalent to the various border-(?)-color properties.</p>
<h3><a name="column-rule-style" href="#column-rule-style">column-rule-style</a></h3>
<p><strong>Value:</strong> <border-style></p>
<p>By using <a href="#column-rule-style">column-rule-style</a>, you may determine how the line between columns is to be rendered, if at all. Similar to border-(?)-style.</p>
<h3><a name="column-rule-width" href="#column-rule-width">column-rule-width</a></h3>
<p><strong>Value:</strong> <border-width><br />
<strong>Initial value:</strong> medium</p>
<p><a href="#column-rule-width">column-rule-width</a> sets the width of the line rendered in the gutter between columns. Basically, it&#8217;s the same as the border-(?)-width properties.</p>
<h3><a name="column-rule" href="#column-rule">column-rule</a></h3>
<p><strong>Value:</strong> <a href="#column-rule-width">column-rule-width</a> &#038;&#038; <a href="#column-rule-style">column-rule-style</a> &#038; &#038; <a href="#column-rule-color">column-rule-color</a></p>
<p>Shorthand for setting all three column-rule properties.</p>
<h3><a name="column-span" href="#column-span">column-span</a></h3>
<p><strong>Value:</strong> 1 | all<br />
<strong>Initial value:</strong> 1</p>
<p>By using <a href="#column-span">column-span</a>, you can allow an element to span either the entire set of columns, or none at all.</p>
<p>Note that you cannot set an arbitrary number of columns to span &#8212; this property essentially &#8216;interrupts&#8217; the column flow and restarts it below the spanned element.</p>
<h3><a name="column-fill" href="#column-fill">column-fill</a></h3>
<p><strong>Value:</strong> auto | balance<br />
<strong>Initial value:</strong> balance</p>
<p>If you have set a height for your columnified element, setting <a href="#column-fill">column-fill</a> to &#8216;auto&#8217; will cause the columns to be &#8216;filled&#8217; in turn, rather than have the content balanced equally between them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.barryvan.com.au/2009/10/css-columns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apple Keyboard &amp; Windows</title>
		<link>http://www.barryvan.com.au/2009/09/apple-keyboard-windows/</link>
		<comments>http://www.barryvan.com.au/2009/09/apple-keyboard-windows/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 10:55:42 +0000</pubDate>
		<dc:creator>Barry van Oudtshoorn</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[keyboard]]></category>
		<category><![CDATA[multimedia keys]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.barryvan.com.au/?p=243</guid>
		<description><![CDATA[At work, I recently moved to one of the slim aluminium Apple keyboards, and I love it. Linux and the keyboard play nicely together without any hassles whatsoever. So, emboldened by this success, I bought another one for use at home &#8212; with my Windows machine. The results were, well, less than dazzling. Whilst the [...]]]></description>
			<content:encoded><![CDATA[<p>At work, I recently moved to one of the slim aluminium Apple keyboards, and I love it. Linux and the keyboard play nicely together without any hassles whatsoever. So, emboldened by this success, I bought another one for use at home &#8212; with my Windows machine. The results were, well, less than dazzling.</p>
<p>Whilst the keyboard&#8217;s basic functions pose no problem to Windows &#8212; it is, after all, just a USB keyboard &#8212; there were some problems, especially with the Function keys. Basically, the [fn] key doesn&#8217;t seem to generate a recognisable keycode for Windows, which meant that I didn&#8217;t have access to all the spiffy multimedia controls and so on.</p>
<p>After much googling and installation of keyboard drivers originally distributed with Apple&#8217;s Boot Camp, I eventually stumbled across a great little utility by <a href="http://petr.lastovicka.sweb.cz/others.html">Petr Laštovička</a>, which allows a fairly clean and simple remapping of keys to functions. [For the Googlers who've arrived here looking for a solution to the Mac Keyboard + Windows problem, it beats out Sharpkeys for me because it can handle key combos.]</p>
<p>So, ultimately, I have ended with a very good-looking, nice-feeling keyboard that works 99% of the way I want it to. My biggest gripe is that changing the volume now requires me to press [Command]+[Fn]+[F10/F11/F12], rather than just [Fn]+[F10/F11/F12], as I can in Linux. I&#8217;m quite happy with this keyboard &#8212; although it&#8217;s not 100%, it&#8217;s definitely much better than most similarly-priced keyboards (at $69AUD).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.barryvan.com.au/2009/09/apple-keyboard-windows/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Quicksort an array of objects</title>
		<link>http://www.barryvan.com.au/2009/08/quicksort-an-array-of-objects/</link>
		<comments>http://www.barryvan.com.au/2009/08/quicksort-an-array-of-objects/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 07:14:51 +0000</pubDate>
		<dc:creator>Barry van Oudtshoorn</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.barryvan.com.au/?p=225</guid>
		<description><![CDATA[Often, you will need to sort an array of objects in Javascript. The inbuilt sort() function can&#8217;t do this, but here is a Quicksort implementation for doing just this. Parameters array The array to be sorted. (See below for an implementation on the Array Native itself, which makes this variable unnecessary). key The key to [...]]]></description>
			<content:encoded><![CDATA[<p>Often, you will need to sort an array of objects in Javascript. The inbuilt <em>sort()</em> function can&#8217;t do this, but here is a Quicksort implementation for doing just this.</p>
<h2>Parameters</h2>
<p><strong>array</strong> The array to be sorted. (See below for an implementation on the Array Native itself, which makes this variable unnecessary).</p>
<p><strong>key</strong> The key to sort by. Make sure every object in your array has this key.</p>
<h2>Examples</h2>
<pre class="brush: javascript">
var objs = [
	{fruit:&quot;cherry&quot;},
	{fruit:&quot;apple&quot;},
	{fruit:&quot;banana&quot;}
];

console.log(objs.sortObjects(&#039;fruit&#039;));
// Logs [{fruit:&quot;apple&quot;},{fruit:&quot;banana&quot;},{fruit:&quot;cherry&quot;}] to the console
</pre>
<h2>The code</h2>
<pre class="brush: javascript">
sortObjects: function(array, key) {
	for (var i = 0; i &lt; array.length; i++) {
		var currVal = array[i][key];
		var currElem = array[i];
		var j = i - 1;
		while ((j &gt;= 0) &amp;&amp; (array[j][key] &gt; currVal)) {
			array[j + 1] = array[j];
			j--;
		}
		array[j + 1] = currElem;
	}
}
</pre>
<h3>Implemented on the Array native:</h3>
<pre class="brush: javascript">
Array.implement({
	sortObjects: function(key) {
		for (var i = 0; i &lt; this.length; i++) {
			var currVal = this[i][key];
			var currElem = this[i];
			var j = i - 1;
			while ((j &gt;= 0) &amp;&amp; (this[j][key] &gt; currVal)) {
				this[j + 1] = this[j];
				j--;
			}
			this[j + 1] = currElem;
		}
	}
});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.barryvan.com.au/2009/08/quicksort-an-array-of-objects/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Javascript string ellipsising</title>
		<link>http://www.barryvan.com.au/2009/08/javascript-string-ellipsising/</link>
		<comments>http://www.barryvan.com.au/2009/08/javascript-string-ellipsising/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 07:03:17 +0000</pubDate>
		<dc:creator>Barry van Oudtshoorn</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[string manipulation]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.barryvan.com.au/?p=217</guid>
		<description><![CDATA[Putting ellipses into strings that are too long has been around for a very long time. Unfortunately, Javascript doesn&#8217;t offer a native method of doing this, so below is a little function that&#8217;ll do it for you. This function returns a copy of the string it&#8217;s called on, ellipsised, and takes three parameters: toLength (required) [...]]]></description>
			<content:encoded><![CDATA[<p>Putting ellipses into strings that are too long has been around for a very long time. Unfortunately, Javascript doesn&#8217;t offer a native method of doing this, so below is a little function that&#8217;ll do it for you.</p>
<p>This function returns a copy of the string it&#8217;s called on, ellipsised, and takes three parameters:</p>
<p><strong>toLength</strong> (required) The number of characters to truncate the string to (or 0 to disable ellipsising)</p>
<p><strong>where</strong> (optional, default &#8216;end&#8217;) A string representing where the ellipsis should be placed &#8212; &#8216;front&#8217;, &#8216;middle&#8217;, or &#8216;end&#8217;</p>
<p><strong>ellipsis</strong> (option, default &#8216;\u2026&#8242;) A string to be used as the ellipsis.</p>
<h2>Examples</h2>
<pre class="brush: javascript">
// Our clichéd string
var s = &#039;Jackdaws love my great big sphinx of quartz&#039;;

alert(s.ellipsise(10));
// Alerts &quot;Jackdaws l…&quot;

alert(s.ellipsise(10, &#039;front&#039;));
// Alerts &quot;… of quartz&quot;

alert(s.ellipsise(10, &#039;middle&#039;, &#039;pony&#039;));
// Alerts &quot;Jackdponyuartz&quot;</pre>
<h2>The code</h2>
<pre class="brush: javascript">String.implement({
	ellipsise: function(toLength, where, ellipsis) { // Where is one of [&#039;front&#039;,&#039;middle&#039;,&#039;end&#039;] -- default is &#039;end&#039;
		if (toLength &lt; 1) return this;
		ellipsis = ellipsis || &#039;\u2026&#039;;
		if (this.length &lt; toLength) return this;
		switch (where) {
			case &#039;front&#039;:
				return ellipsis + this.substr(this.length - toLength);
				break;
			case &#039;middle&#039;:
				return this.substr(0, toLength / 2) + ellipsis + this.substr(this.length - toLength / 2)
				break;
			case &#039;end&#039;:
			default:
				return this.substr(0, toLength) + ellipsis;
				break;
		}
	}
});</pre>
<p>If you&#8217;re not using MooTools, you can use this variant instead:</p>
<pre class="brush: javascript">String.prototype.ellipsise = function(toLength, where, ellipsis) { // Where is one of [&#039;front&#039;,&#039;middle&#039;,&#039;end&#039;] -- default is &#039;end&#039;
	if (toLength &lt; 1) return this;
	ellipsis = ellipsis || &#039;\u2026&#039;;
	if (this.length &lt; toLength) return this;
	switch (where) {
		case &#039;front&#039;:
			return ellipsis + this.substr(this.length - toLength);
			break;
		case &#039;middle&#039;:
			return this.substr(0, toLength / 2) + ellipsis + this.substr(this.length - toLength / 2)
			break;
		case &#039;end&#039;:
		default:
			return this.substr(0, toLength) + ellipsis;
			break;
	}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.barryvan.com.au/2009/08/javascript-string-ellipsising/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Avoid Javascript&#8217;s &#8216;with&#8217; keyword</title>
		<link>http://www.barryvan.com.au/2009/05/avoid-javascripts-with-keyword/</link>
		<comments>http://www.barryvan.com.au/2009/05/avoid-javascripts-with-keyword/#comments</comments>
		<pubDate>Tue, 12 May 2009 00:06:10 +0000</pubDate>
		<dc:creator>Barry van Oudtshoorn</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[best practices]]></category>
		<category><![CDATA[syntax]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.barryvan.com.au/?p=162</guid>
		<description><![CDATA[Javascript is a fantastic language &#8212; in fact, it&#8217;s become the language that I do most of my programming in nowadays. It&#8217;s flexible, fast, and powerful. Unfortunately, though, it suffers from a few flaws, which, although not critical, can be frustrating. One of the potentially most confusing features is the with keyword, which promises a [...]]]></description>
			<content:encoded><![CDATA[<p>Javascript is a fantastic language &#8212; in fact, it&#8217;s become the language that I do most of my programming in nowadays. It&#8217;s flexible, fast, and powerful. Unfortunately, though, it suffers from a few flaws, which, although not critical, can be frustrating. One of the potentially most confusing features is the <em>with</em> keyword, which promises a lot, but can really just make life difficult.</p>
<p>The <em>with</em> keyword might appear to be harmless enough: it allows you to avoid typing long references; instead of</p>
<pre class="brush: javascript">ah.woom.ba.weh.lyric = &#039;In the jungle&#039;;</pre>
<p>we can type</p>
<pre class="brush: javascript">with (ah.woom.ba.weh) {
  lyric = &#039;In the jungle&#039;;
}</pre>
<p>But what happens if we happen to have a global variable named <em>lyric</em>? In the example below, which <em>lyric</em> should be modified?</p>
<pre class="brush: javascript">lyric = &#039;In the jungle&#039;;
with (ah.woom.ba.weh) {
  lyric = &#039;The mighty jungle&#039;;
}</pre>
<p>The simplest way to deal with this issue is to use a variable:</p>
<pre class="brush: javascript">var a = ah.woom.ba.weh;
a.lyric = &#039;The mighty jungle&#039;;</pre>
<p>Now there is no ambiguity.</p>
<p><em>Based on a <a href="http://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/">post by Douglas Crockford</a> at the YUI Blog.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.barryvan.com.au/2009/05/avoid-javascripts-with-keyword/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Internet Explorer DOMDocument &amp; XPath</title>
		<link>http://www.barryvan.com.au/2009/04/internet-explorer-domdocument-xpath/</link>
		<comments>http://www.barryvan.com.au/2009/04/internet-explorer-domdocument-xpath/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 04:10:38 +0000</pubDate>
		<dc:creator>Barry van Oudtshoorn</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[internet explorer]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xpath]]></category>
		<category><![CDATA[xslt]]></category>

		<guid isPermaLink="false">http://www.barryvan.com.au/?p=144</guid>
		<description><![CDATA[I discovered a couple of interesting things about Internet Explorer&#8217;s MSXML2.DOMDocument object. It turns out that there are essentially two &#8220;production-quality&#8221; versions of it available: 3.0 and 6.0. Version 6.0 is much the better version, but it&#8217;s quite new, and not available on all systems. This means that in IE7 and IE8, instantiating a new [...]]]></description>
			<content:encoded><![CDATA[<p>I discovered a couple of interesting things about Internet Explorer&#8217;s MSXML2.DOMDocument object. It turns out that there are essentially two &#8220;production-quality&#8221; versions of it available: 3.0 and 6.0. Version 6.0 is much the better version, but it&#8217;s quite new, and not available on all systems. This means that in IE7 and IE8, instantiating a new MSXML2.DOMDocument object gives you version 3.0.</p>
<p>Now most of the time, this isn&#8217;t a problem. Today, though, I was constructing an XPath expression that used the substring() function; something like this:</p>
<pre class="brush: xml">//Element[substring(Child, 1, 3)=&#039;abc&#039;]</pre>
<p>This will pull all Elements with a Child element whose value&#8217;s first three characters are &#8220;abc&#8221;. Not particularly complex. It turns out, though, that version 3.0 or the DOMDocument doesn&#8217;t actually use XPath as its default language: it uses a bastardised version of XPath called &#8220;XSLPatterns&#8221;, which just so happens to not support the substring() function at all.</p>
<p>So how do we deal with this situation? One way is to always instantiate version 6.0 of the DOMDocument:</p>
<pre class="brush: javascript">xd = new ActiveXObject(&#039;msxml2.DOMDocument.6.0&#039;)</pre>
<p>The problem with this approach is that, like I mentioned earlier, you can&#8217;t always be guaranteed that your users will have version 6.0 installed (even though it&#8217;s a free download). The safer way to deal with this problem is to switch the expression language to XPath in your 3.0 object:</p>
<pre class="brush: javascript">xd = new ActiveXObject(&#039;msxml2.DOMDocument&#039;);
xd.setProperty(&quot;SelectionLanguage&quot;, &quot;XPath&quot;);</pre>
<p>The advantage of this approach is that you&#8217;re not specifying a version, so when MS eventually changes the default to 7.0 (or whatever), your code will work without a problem.</p>
<p>For more information on this, check out  <a title="Microsoft XML Team's WebLog: Using the right version of MSXML in Internet Explorer" href="http://blogs.msdn.com/xmlteam/archive/2006/10/23/using-the-right-version-of-msxml-in-internet-explorer.aspx">this blog post</a> from Microsoft&#8217;s XML team, which goes into a little bit more detail.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.barryvan.com.au/2009/04/internet-explorer-domdocument-xpath/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript-generated tables and rowspan</title>
		<link>http://www.barryvan.com.au/2009/04/javascript-generated-tables-and-rowspan/</link>
		<comments>http://www.barryvan.com.au/2009/04/javascript-generated-tables-and-rowspan/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 10:24:43 +0000</pubDate>
		<dc:creator>Barry van Oudtshoorn</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.barryvan.com.au/?p=130</guid>
		<description><![CDATA[At work, I&#8217;ve recently been putting together a nice little calendar-like utility using Javascript. Basically, it has to generate a table consisting of cells which may span multiple rows. Surely the solution is simple enough: just set the rowspan on each td as we create it. Unfortunately, that doesn&#8217;t work, at least not in Firefox. [...]]]></description>
			<content:encoded><![CDATA[<p>At work, I&#8217;ve recently been putting together a nice little calendar-like utility using Javascript. Basically, it has to generate a table consisting of cells which may span multiple rows. Surely the solution is simple enough: just set the <em>rowspan</em> on each <em>td</em> as we create it. Unfortunately, that doesn&#8217;t work, at least not in Firefox.</p>
<p>It appears that in Firefox, if you create a <em>td</em> and set its <em>rowspan</em> to some value <strong>when there are no rows for it to expand into</strong>, the attribute will be completely ignored, <strong>even if you add rows afterwards</strong>! Needless to say, this is very annoying. The solution? Build your table backwards.</p>
<p>The code I have now is something like this (note that I&#8217;m developing using the Mootools framework):</p>
<pre class="brush: javascript">var tbl = new Element(&#039;table&#039;);
var trs = new Array();

for (var i = 0; i &lt; 4; i++) {
  var tr = new Element(&#039;tr&#039;);
  tr.grab(new Element(&#039;td&#039;, {
    &#039;html&#039;: &#039;Cell &#039; + i
  }));
  if (i % 2 == 0) {
    tr.grab(new Element(&#039;td&#039;, {
      &#039;rowspan&#039;: 2,
      &#039;html&#039;: &#039;Span &#039; + (i / 2)
    }));
  }
  trs.push(tr);
}

for (var i = trs.length - 1; i &gt;= 0; i--) {
  tbl.grab(trs[i], &#039;top&#039;);
}</pre>
<p>What does this code do? Well basically, we&#8217;re creating a table with ten rows and two columns; the cells in the right-hand column each occupy two rows. The result will be something like this:</p>
<table style="border:solid 1px blue;width:50%;">
<tr>
<td style="border:solid 1px black;">Cell 1</td>
<td rowspan="2" style="border:solid 1px red;">Span 1</td>
</tr>
<tr>
<td style="border:solid 1px black;">Cell 2</td>
</tr>
<tr>
<td style="border:solid 1px black;">Cell 3</td>
<td rowspan="2" style="border:solid 1px red;">Span 2</td>
</tr>
<tr>
<td style="border:solid 1px black;">Cell 4</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.barryvan.com.au/2009/04/javascript-generated-tables-and-rowspan/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ubuntu and sudo</title>
		<link>http://www.barryvan.com.au/2009/03/ubuntu-and-sudo/</link>
		<comments>http://www.barryvan.com.au/2009/03/ubuntu-and-sudo/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 08:08:35 +0000</pubDate>
		<dc:creator>Barry van Oudtshoorn</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.barryvan.com.au/?p=95</guid>
		<description><![CDATA[Ubuntu disables access to the root account by default, for reasons which have never been particularly clear to me. They deem it preferable to give users sudo access, which is all well and good, but typing a series of commands, all prefixed by &#8216;sudo&#8217;, can be very tedious. Fortunately, there are a few ways around [...]]]></description>
			<content:encoded><![CDATA[<p>Ubuntu disables access to the root account by default, for reasons which have never been particularly clear to me. They deem it preferable to give users sudo access, which is all well and good, but typing a series of commands, all prefixed by &#8216;sudo&#8217;, can be very tedious.</p>
<p>Fortunately, there are a few ways around this.</p>
<p>The first is to use a super user shell. From a terminal or console, type:<br />
<code>sudo bash</code><br />
This will give you a shell with full root access, and save you needlessly typing &#8216;sudo&#8217;. (You can, of course, use other shell flavours, like zsh or csh if you prefer.)</p>
<p>A similar method is to run the &#8216;su&#8217; command with sudo, thusly:<br />
<code>sudo su</code><br />
which will also give you a shell with full root access, according to root&#8217;s preferred shell.</p>
<p>The third method is to alter the password protecting the root account. To do this, from a terminal or console, type:<br />
<code>sudo passwd root</code><br />
and enter a password for the root user. Now you will be able to log on to consoles (and, if you&#8217;re that way inclined, X sessions) as root.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.barryvan.com.au/2009/03/ubuntu-and-sudo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
