<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0"><channel><title>Algorithms for the masses - julian m bucknall</title><link>http://blog.boyet.com/blog/</link><description /><generator>Graffiti CMS 1.3 (build 1.3.0.0)</generator><lastBuildDate>Wed, 15 May 2013 08:52:43 GMT</lastBuildDate><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/boyet/blog" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="boyet/blog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><title>CSS3 line height is important for drop caps</title><link>http://blog.boyet.com/blog/blog/css3-line-height-is-important-for-drop-caps/</link><pubDate>Sat, 11 May 2013 02:53:26 GMT</pubDate><guid isPermaLink="true">http://blog.boyet.com/blog/blog/css3-line-height-is-important-for-drop-caps/</guid><dc:creator>julian m bucknall</dc:creator><slash:comments>0</slash:comments><category domain="http://blog.boyet.com/blog/blog/">Blog</category><description>&lt;p&gt;
	Recently I was playing around and added drop caps to the blog posts on blog.boyet.com. I decided to go for a pure CSS3 version (so, you&amp;rsquo;ll have to view this site in a reasonably fresh browser to see the effect) rather than a hacky &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt; version that mixes presentation &amp;ldquo;hints&amp;rdquo; in the content. (For a brief discussion on the two possible methods, see Chris Coyier&amp;rsquo;s blog post &lt;a href="http://css-tricks.com/snippets/css/drop-caps/"&gt;here&lt;/a&gt;.) I certainly didn&amp;rsquo;t want to change all my posts to include spans on the first letter of the first paragraph.&lt;/p&gt;
&lt;p&gt;
	&lt;a href="http://blog.boyet.com/blog/files/media/image/Windows-Live-Writer/5ca7faf86a2c_11B78/Manuscript_2.jpg"&gt;&lt;img alt="Manuscript from the Book of Hours" height="159" src="http://blog.boyet.com/blog/files/media/image/Windows-Live-Writer/5ca7faf86a2c_11B78/Manuscript_thumb.jpg" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: right; padding-top: 0px; padding-left: 0px; margin: 0px 0px 0px 20px; display: inline; padding-right: 0px; border-top-width: 0px" title="Manuscript from the Book of Hours" width="240" /&gt;&lt;/a&gt;The way I implemented it was to add a class style to the surrounding div:&lt;/p&gt;
&lt;div class="jmbcodeblock"&gt;
	&lt;pre&gt;
&lt;span style="color: #800000"&gt;&lt;span style="background-color: #ffffff"&gt;.initialcap&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #800000"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #800000"&gt;p:first-child:first-letter&lt;/span&gt;&lt;span style="color: #000000"&gt; {
  &lt;/span&gt;&lt;span style="color: #ff0000"&gt;background&lt;/span&gt;&lt;span style="color: #000000"&gt;: &lt;/span&gt;&lt;span style="color: #0000ff"&gt;url(&amp;quot;images/classy_fabric.png&amp;quot;)&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #0000ff"&gt;repeat&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #0000ff"&gt;scroll&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #0000ff"&gt;0&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #0000ff"&gt;0&lt;/span&gt;&lt;span style="color: #000000"&gt;;
  &lt;/span&gt;&lt;span style="color: #ff0000"&gt;color&lt;/span&gt;&lt;span style="color: #000000"&gt;: &lt;/span&gt;&lt;span style="color: #0000ff"&gt;#efefef&lt;/span&gt;&lt;span style="color: #000000"&gt;;
  &lt;/span&gt;&lt;span style="color: #ff0000"&gt;font-size&lt;/span&gt;&lt;span style="color: #000000"&gt;: &lt;/span&gt;&lt;span style="color: #0000ff"&gt;48px&lt;/span&gt;&lt;span style="color: #000000"&gt;;
  &lt;/span&gt;&lt;span style="color: #ff0000"&gt;padding&lt;/span&gt;&lt;span style="color: #000000"&gt;: &lt;/span&gt;&lt;span style="color: #0000ff"&gt;8px&lt;/span&gt;&lt;span style="color: #000000"&gt;;
  &lt;/span&gt;&lt;span style="color: #ff0000"&gt;margin-right&lt;/span&gt;&lt;span style="color: #000000"&gt;: &lt;/span&gt;&lt;span style="color: #0000ff"&gt;3px&lt;/span&gt;&lt;span style="color: #000000"&gt;;
  &lt;/span&gt;&lt;span style="color: #ff0000"&gt;float&lt;/span&gt;&lt;span style="color: #000000"&gt;: &lt;/span&gt;&lt;span style="color: #0000ff"&gt;left&lt;/span&gt;&lt;span style="color: #000000"&gt;;
}&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
	The style makes reference to a paragraph child of the div, and uses the cd:first-child and cd:first-letter pseudo-classes. The initial letter is styled with a background image, a contrasting color, a larger size and relevant padding and margins. The whole lot is then floated left, so that the text wraps around it.&lt;/p&gt;
&lt;p&gt;
	&lt;img alt="Correct drop cap" height="146" src="http://blog.boyet.com/blog/files/media/image/Windows-Live-Writer/5ca7faf86a2c_11B78/CorrectDropcap_3.png" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" title="Correct drop cap" width="186" /&gt;&lt;/p&gt;
&lt;p&gt;
	Pretty good. I viewed it in Firefox, saw it was good, and went off to do something else.&lt;/p&gt;
&lt;p&gt;
	A few days later, I happened to run Chrome and immediately saw a problem, the drop cap was stretched vertically:&lt;/p&gt;
&lt;p&gt;
	&lt;img alt="Elongated drop cap" height="137" src="http://blog.boyet.com/blog/files/media/image/Windows-Live-Writer/5ca7faf86a2c_11B78/ElongatedDropCap_3.png" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" title="Elongated drop cap" width="162" /&gt;&lt;/p&gt;
&lt;p&gt;
	The same problem happened in IE10, too. What was going on? Firefox still showed the initial capital just fine.&lt;/p&gt;
&lt;p&gt;
	It turned out that I&amp;rsquo;d missed off a line-height clause from my style, and this was affecting the display in Chrome and IE, but not, for some unknown reason, in Firefox. So I changed the style to this:&lt;/p&gt;
&lt;div class="jmbcodeblock"&gt;
	&lt;pre&gt;
&lt;span style="color: #800000"&gt;&lt;span style="background-color: #ffffff"&gt;.initialcap&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #800000"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #800000"&gt;p:first-child:first-letter&lt;/span&gt;&lt;span style="color: #000000"&gt; {
  &lt;/span&gt;&lt;span style="color: #ff0000"&gt;background&lt;/span&gt;&lt;span style="color: #000000"&gt;: &lt;/span&gt;&lt;span style="color: #0000ff"&gt;url(&amp;quot;images/classy_fabric.png&amp;quot;)&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #0000ff"&gt;repeat&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #0000ff"&gt;scroll&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #0000ff"&gt;0&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #0000ff"&gt;0&lt;/span&gt;&lt;span style="color: #000000"&gt;;
  &lt;/span&gt;&lt;span style="color: #ff0000"&gt;color&lt;/span&gt;&lt;span style="color: #000000"&gt;: &lt;/span&gt;&lt;span style="color: #0000ff"&gt;#efefef&lt;/span&gt;&lt;span style="color: #000000"&gt;;
  &lt;/span&gt;&lt;span style="color: #ff0000"&gt;font-size&lt;/span&gt;&lt;span style="color: #000000"&gt;: &lt;/span&gt;&lt;span style="color: #0000ff"&gt;48px&lt;/span&gt;&lt;span style="color: #000000"&gt;;
  &lt;/span&gt;&lt;span style="color: #ff0000"&gt;line-height&lt;/span&gt;&lt;span style="color: #000000"&gt;: &lt;/span&gt;&lt;span style="color: #0000ff"&gt;32px&lt;/span&gt;&lt;span style="color: #000000"&gt;; &lt;/span&gt;&lt;span style="color: #006400"&gt;/*&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #006400"&gt;that is, 48px font size - padding top&amp;amp;bottom&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #006400"&gt;*/&lt;/span&gt;&lt;span style="color: #000000"&gt;
  &lt;/span&gt;&lt;span style="color: #ff0000"&gt;padding&lt;/span&gt;&lt;span style="color: #000000"&gt;: &lt;/span&gt;&lt;span style="color: #0000ff"&gt;8px&lt;/span&gt;&lt;span style="color: #000000"&gt;;
  &lt;/span&gt;&lt;span style="color: #ff0000"&gt;margin-right&lt;/span&gt;&lt;span style="color: #000000"&gt;: &lt;/span&gt;&lt;span style="color: #0000ff"&gt;3px&lt;/span&gt;&lt;span style="color: #000000"&gt;;
  &lt;/span&gt;&lt;span style="color: #ff0000"&gt;float&lt;/span&gt;&lt;span style="color: #000000"&gt;: &lt;/span&gt;&lt;span style="color: #0000ff"&gt;left&lt;/span&gt;&lt;span style="color: #000000"&gt;;
}
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
	As you can see, I added a comment for myself to explain how I&amp;rsquo;d calculated the value since it&amp;rsquo;s a little bit &amp;ldquo;magic&amp;rdquo;. If you now visit this blog in Chrome and IE (and Safari for that matter) the drop caps are displayed correctly.&lt;/p&gt;
&lt;p&gt;
	The moral of this tale is: test your websites in all four major desktop browsers. You&amp;rsquo;d be wrong in believing that they all render the same way, even in this day and age.&lt;/p&gt;
&lt;p&gt;
	Now playing on Pandora:&lt;br /&gt;
	Groove Armada &amp;ndash; &lt;strong&gt;Inside My Mind (Blue Skies)&lt;/strong&gt; on &lt;a href="http://www.pandora.com/groove-armada/vertigo-import"&gt;Vertigo (Import)&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/boyet/blog/~4/TkRxZl2Tnn8" height="1" width="1"/&gt;</description><author>Algorithms for the masses - julian m bucknall &lt;julianb@boyet.com&gt;</author></item><item><title>Weird XML bug on iPad when displaying this site</title><link>http://blog.boyet.com/blog/blog/weird-xml-bug-on-ipad-when-displaying-this-site/</link><pubDate>Thu, 09 May 2013 03:09:22 GMT</pubDate><guid isPermaLink="true">http://blog.boyet.com/blog/blog/weird-xml-bug-on-ipad-when-displaying-this-site/</guid><dc:creator>julian m bucknall</dc:creator><slash:comments>2</slash:comments><category domain="http://blog.boyet.com/blog/blog/">Blog</category><description>&lt;p&gt;The call came though the batphone from &lt;a href="http://www.mehulharry.com/"&gt;Mehul Harry&lt;/a&gt;: he was seeing an issue displaying blog posts from this site on an iPad. It was a new one on me and I quickly checked on my iPad using Safari: no problem.&lt;/p&gt; &lt;p&gt;&lt;img title="HTML5 Badge" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: right; padding-top: 0px; padding-left: 0px; margin: 0px 0px 0px 20px; display: inline; padding-right: 0px; border-top-width: 0px" alt="HTML5 Badge" src="http://blog.boyet.com/blog/files/media/image/Windows-Live-Writer/ef12d48ed998_11D35/HTML5_Badge_128_3.png" width="128" height="128"&gt;After a bit of back-and-forth, we’d nailed it down. If you navigated to a blog post via the Facebook app, the iPad displayed an XML error (due to the missing schema, essentially). If you navigated to the exact same blog post using Safari, it displayed fine. The weird thing is that this site doesn’t use XML; it’s HTML5, not XHTML.&lt;/p&gt; &lt;p&gt;Although this was news to me on the iPad, it was something I’d run into before: when I try and validate the site with the W3C HTML5 validator, it complains of exactly the same problem: bad XML. At least with the W3C validator, I could glean a little more information: in its response the web server was sending the Content-Type as &lt;code&gt;application/xhtml+xml&lt;/code&gt; in the response header, not &lt;code&gt;text/html&lt;/code&gt; (which is what I was expecting and which is what I would get in the browser). Why would the web server (IIS7 as it happens) send this erroneous Content-Type?&lt;/p&gt; &lt;p&gt;By default, ASPX files (which this site serves up; it’s a big old .NET program) are assumed to be &lt;code&gt;text/html&lt;/code&gt; by both IIS and ASP.NET. Since the same page gets the correct Content-Type when it’s a browser making the requests, I can only assume that ASP.NET 3.5 was miscategorizing the user-agent of the request when it’s a UIWebView (what the Facebook app is using) or the W3C validator and assuming that it required XHTML. (This is the job of the &lt;code&gt;machine.config&lt;/code&gt; file, in essence; something that, in a shared hosting environment, I have no access to in order to change it.)&lt;/p&gt; &lt;p&gt;Time to be clear-cut since the default was wrong. I altered the ancestor page class’s &lt;code&gt;OnLoad()&lt;/code&gt; method (it’s the &lt;code&gt;TemplatedThemePage&lt;/code&gt; class if you’re interested) to explicitly state that the pages returned by GraffitiCMS were &lt;code&gt;text/html&lt;/code&gt;:&lt;/p&gt; &lt;div class="jmbcodeblock"&gt;&lt;pre&gt;Response.AppendHeader("Content-Type", "text/html");&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;I recompiled, uploaded the new assemblies, and – zing – the problem was solved both on the iPad and for the validator. 
&lt;p&gt;Now playing on Pandora:&lt;br&gt;IIO – &lt;strong&gt;Runaway&lt;/strong&gt; on &lt;a href="http://www.pandora.com/iio/runaway-maxi-single"&gt;Runaway [Maxi-Single]&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/boyet/blog/~4/Q2sxXqmak4Q" height="1" width="1"/&gt;</description><author>Algorithms for the masses - julian m bucknall &lt;julianb@boyet.com&gt;</author></item><item><title>Adventures with JSONP and jQuery</title><link>http://blog.boyet.com/blog/javascriptlessons/adventures-with-jsonp-and-jquery/</link><pubDate>Mon, 06 May 2013 20:50:15 GMT</pubDate><guid isPermaLink="true">http://blog.boyet.com/blog/javascriptlessons/adventures-with-jsonp-and-jquery/</guid><dc:creator>julian m bucknall</dc:creator><slash:comments>0</slash:comments><category domain="http://blog.boyet.com/blog/javascriptlessons/">JavaScriptLessons</category><description>&lt;p&gt;This whole thing started out as a nice-to-have. I have a blog (you’re reading it). I have a URL shortener (jmbk.nl). They are separate apps on separate domains. When I publish a post here, I diligently create the short URL for it manually in order to publish that short URL on social sites (the URL shortener has some minimalist stats associated with each short URL; so minimal, it’s only a count of the number of times it was used). Yeah, I know, silly, huh: why can’t each post generate its own short URL? &lt;/p&gt;  &lt;p&gt;&lt;img title="Compass on old map" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: right; padding-top: 0px; padding-left: 0px; margin: 0px 0px 0px 20px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="Compass on old map" align="right" src="http://blog.boyet.com/blog/files/media/image/Windows-Live-Writer/Adventures-with-JSONP-and-jQuery_A296/Compass%20on%20old%20map_3.jpg" width="240" height="174" /&gt;Now I could have done this in C# and .NET as a plug-in to the blogging software I use, but where’s the fun in that? Let’s do it in JavaScript!&lt;/p&gt;  &lt;p&gt;What I want is some code that will get the URL of a blog post when that post is displayed in the browser (easy!), call my URL shortener service with it via good-old AJAX, and receive the short URL as a reply. The big issue about this simple plan is the so-called “&lt;a href="http://en.wikipedia.org/wiki/Same_origin_policy"&gt;Same-Origin Policy&lt;/a&gt;”. In essence, getting data from the same site (that is, protocol, domain/host, and port number) via JavaScript is smiled upon, but getting data from another site entirely is frowned upon to the point it doesn’t work. Since my pages are on blog.boyet.com, I can only get data from blog.boyet.com. It’s all to do with maintaining strict security boundaries (think of cookies as a big example).&lt;/p&gt;  &lt;p&gt;Nevertheless, sometimes it might be advantageous for your code to get some data from another site. An example might be to display the top ten most recent of your tweets from Twitter in your blog webpage. The problem here is that twitter.com is not the domain of your personal blog, so what can be done?&lt;/p&gt;  &lt;p&gt;If you think about it, the one thing you can get from other sites is JavaScript code inside script elements. Here as an example is how this site gets jQuery:&lt;/p&gt;  &lt;div class="jmbcodeblock"&gt;   &lt;pre&gt;&lt;span style="color: #0000ff"&gt;&lt;span style="background-color: #ffffff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;script&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;text/javascript&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #ff0000"&gt;src&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://ajax.microsoft.com/ajax/jQuery/jquery-1.9.1.min.js&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;script&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;When the browser encounters a script element likes this, two things happen: first, the JavaScript file referenced by that URL is downloaded (via HTTP GET), and second, the script thus downloaded is executed. Hmm.&lt;/p&gt;

&lt;p&gt;Let’s continue this thought experiment. These days we get our data in the JSON format; that is, code that defines a JavaScript object. Here’s an example of a JSON object that is relevant to my discussion:&lt;/p&gt;

&lt;div class="jmbcodeblock"&gt;
  &lt;pre&gt;&lt;span style="color: #000000"&gt;&lt;span style="background-color: #ffffff"&gt;{
    shortURL: &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;http://jmbk.nl/j6Q2K&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;,
    requestCount: 42
}&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Running before I can walk, I could construct the source URL I need in a &amp;lt;script&amp;gt; tag, say something like “&lt;code&gt;http://jmbk.nl/MakeUrl/?shorten=http://blog.boyet.com/&lt;/code&gt;” (that isn’t the real URL I use for this operation, by the way, so there’s no point in trying it), and the browser would GET the URL, which would return the above JSON. Which would then be executed and crash with some kind of syntax error: it’s not executable code.&lt;/p&gt;

&lt;p&gt;OK, then, let’s alter the URL shortener’s code to return this instead:&lt;/p&gt;

&lt;div class="jmbcodeblock"&gt;
  &lt;pre&gt;&lt;span style="color: #000000"&gt;&lt;span style="background-color: #ffffff"&gt;foobar({ shortURL: &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;http://jmbk.nl/j6Q2K&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;, requestCount: 42 });&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;This time it’s real executable code, and the browser will call the &lt;code&gt;foobar()&lt;/code&gt; function for me once the AJAX request is done, passing the JSON object I want as a parameter. Except I don’t have a &lt;code&gt;foobar()&lt;/code&gt; function yet in my client code, so I have to write one and include its code in some kind of script tag. This function must take the JSON object and so something with it (like replace the &lt;code&gt;href&lt;/code&gt; attribute on an anchor element I have somewhere in my HTML markup).&lt;/p&gt;

&lt;p&gt;This, in essence, is this mysterious protocol called JSONP you may have heard of. JSONP stands for JSON with Padding, where the “padding” is wrapping the JSON object inside a function call as a parameter. &lt;/p&gt;

&lt;p&gt;Now it’s a real pain to have to have two different ways of getting JSON objects from servers: one for your “same origin” server (a simple AJAX get request) and one for everything else (adding a silly script element, having a special function that does something with the JSON object, yadda, yadda), so jQuery simplifies it in one function: &lt;code&gt;$.getJSON()&lt;/code&gt;. The code in this function looks at the origin for the URL that’s passed in. If it’s for the same site, the function issues an AJAX get request and the callback gets called normally on completion. In the other case, jQuery does some pretty fancy footwork in the background that creates a temporary script element on the fly with a slightly modified version of the URL you pass in, creates a callback function that saves the returned JSON object and that calls your callback with that object (and deletes the temporary script element). To you, the developer, it’s as if a ‘local’ and a ‘remote’ getJSON call just work in the same way: you specify the URL, and your callback is executed once the JSON object is returned.&lt;/p&gt;

&lt;p&gt;I mentioned that for a ‘remote’ call the URL is modified a little: jQuery adds a &lt;code&gt;callback&lt;/code&gt; query string to the end of the URL. This query string defines the name of the function that should wrap the returned JSON. For example, for “&lt;code&gt;http://jmbk.nl/MakeUrl/?shorten=someurl&lt;/code&gt;”, the URL actually used is something like “&lt;code&gt;http://jmbk.nl/MakeUrl/?shorten=someurl&amp;amp;callback=foobar&lt;/code&gt;”. The server is supposed to read this query string and construct the reply so that it becomes a call to this function. Better still is to be explicit about the callback function name: write the URL as “&lt;code&gt;http://jmbk.nl/MakeUrl/?shorten=someurl&amp;amp;callback=?&lt;/code&gt;” and jQuery will make up a function with a unique name on the fly. This is by far the preferred way to do it: jQuery will ensure the returned JSON is not cached for example.&lt;/p&gt;

&lt;p&gt;(Note: it does get a little confusing since there are two callbacks in play. There’s the callback function you write and pass to the &lt;code&gt;$.getJSON()&lt;/code&gt; function. This function has one parameter: the JSON object that is returned. This callback will get called by jQuery once the AJAX request has completed. The other callback is the function that is used by the server to return the JSON. The browser calls this callback by executing the code returned from the AJAX request.)&lt;/p&gt;

&lt;p&gt;Of course, in my case, since the URL I’m trying to shorten may itself have query strings, it behooves me to encode the long URL and for the server to decode it. Here’s the code I use on the client:&lt;/p&gt;

&lt;div class="jmbcodeblock"&gt;
  &lt;pre&gt;&lt;span style="color: #000000"&gt;&lt;span style="background-color: #ffffff"&gt;$(&lt;/span&gt;&lt;span style="color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="color: #000000"&gt; () {
    &lt;/span&gt;&lt;span style="color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="color: #000000"&gt; url = encodeURIComponent(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&lt;a href="http://blog.boyet.com/?foo=this&amp;amp;bar=that"&gt;http://blog.boyet.com/?foo=this&amp;amp;bar=that&lt;/a&gt;&lt;/span&gt;&lt;span style="color: #000000"&gt;);
    url = &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;http://jmbk.nl/MakeUrl/?shorten=&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt; + url + &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;&amp;amp;callback=?&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;;
    $.getJSON(url, &lt;/span&gt;&lt;span style="color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="color: #000000"&gt; (json) {
        $(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;#shortURL&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;).attr(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;href&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;, json.shortUrl);
    });
});&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;And here’s the (somewhat redacted) code on the server:&lt;/p&gt;

&lt;div class="jmbcodeblock"&gt;
  &lt;pre&gt;&lt;span style="color: #000000"&gt;&lt;span style="background-color: #ffffff"&gt;  &lt;/span&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #0000ff"&gt;void&lt;/span&gt;&lt;span style="color: #000000"&gt; ProcessRequest(&lt;/span&gt;&lt;span style="color: #2b91af"&gt;HttpContext&lt;/span&gt;&lt;span style="color: #000000"&gt; context) {
    &lt;/span&gt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&lt;span style="color: #000000"&gt; urlToShorten = context.Request.QueryString[&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;shorten&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;];
    &lt;/span&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="color: #000000"&gt; (!&lt;/span&gt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&lt;span style="color: #000000"&gt;.IsNullOrEmpty(urlToShorten)) {
      &lt;/span&gt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&lt;span style="color: #000000"&gt; jsonpCallback = context.Request.QueryString[&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;callback&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;];
      &lt;/span&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="color: #000000"&gt; (!&lt;/span&gt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&lt;span style="color: #000000"&gt;.IsNullOrEmpty(jsonpCallback)) {
        context.Response.ContentType = &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;;
        &lt;/span&gt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&lt;span style="color: #000000"&gt; responseFormat = jsonpCallback + &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;({{ shortUrl : '{0}', requestCount : {1} }})&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;;
        urlToShorten = &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Uri&lt;/span&gt;&lt;span style="color: #000000"&gt;.UnescapeDataString(urlToShorten);   

        ShortUrl shortUrl = &lt;/span&gt;&lt;span style="color: #0000ff"&gt;new&lt;/span&gt;&lt;span style="color: #000000"&gt; ShortUrl(urlToShorten);
        shortUrl.Save();

        context.Response.Write(&lt;/span&gt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&lt;span style="color: #000000"&gt;.Format(responseFormat, shortUrl.PublicShortenedUrl, shortUrl.UsageCount));
      }
    }
  }&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;And that’s about it. If you want to do more with JSONP, check out the relevant options for &lt;code&gt;&lt;a href="http://api.jquery.com/jQuery.ajax/"&gt;$.ajax&lt;/a&gt;&lt;/code&gt;.&lt;/p&gt;







&lt;div class="itunesnowplaying"&gt;
  &lt;p&gt;&lt;a href="http://www.amazon.com/Power-Suggestion-Karminsky-Experience-Inc/dp/B0000E332O%3FSubscriptionId%3D0KQPG62QR93J93SA2A02%26tag%3Djulianbucknallsw%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB0000E332O"&gt;&lt;img style="float: left; margin-right: 20px" alt="Album cover for The Power Of Suggestion" src="http://ecx.images-amazon.com/images/I/61W2T29M14L._SL75_.jpg" /&gt;&lt;/a&gt;Now playing:

    &lt;br /&gt;Karminsky Experience Inc. - &lt;strong&gt;Exploration&lt;/strong&gt;

    &lt;br /&gt;(from &lt;a href="http://www.amazon.com/Power-Suggestion-Karminsky-Experience-Inc/dp/B0000E332O%3FSubscriptionId%3D0KQPG62QR93J93SA2A02%26tag%3Djulianbucknallsw%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB0000E332O"&gt;&lt;em&gt;The Power Of Suggestion&lt;/em&gt;&lt;/a&gt;) &lt;/p&gt;

  &lt;br class="clear" /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/boyet/blog/~4/s5EvLyBciGo" height="1" width="1"/&gt;</description><author>Algorithms for the masses - julian m bucknall &lt;julianb@boyet.com&gt;</author></item><item><title>PCPlus 321: Tilt-shift photography</title><link>http://blog.boyet.com/blog/pcplus/pcplus-321-tilt-shift-photography/</link><pubDate>Sat, 04 May 2013 21:02:00 GMT</pubDate><guid isPermaLink="true">http://blog.boyet.com/blog/pcplus/pcplus-321-tilt-shift-photography/</guid><dc:creator>julian m bucknall</dc:creator><slash:comments>0</slash:comments><category domain="http://blog.boyet.com/blog/pcplus/">PCPlus</category><description>&lt;p&gt;
	This was one of those articles where I had to start from scratch with my research: I knew pretty much nothing about the subject. Sure, I was familiar enough with those photos of real buildings that looked as if they were made as a model on the kitchen table, but I had no idea how they were produced. I&amp;rsquo;d assumed that it might be some kind of digital post-processing of a photo, but I didn&amp;rsquo;t have any idea that you could purchase special tilt-shift lenses for DSLRs.&lt;/p&gt;
&lt;p&gt;
	&lt;img alt="PCPlus logo" src="http://s3.amazonaws.com/boyetblog/PCPlusLogo.gif" style="float: right; margin: 0px 0px 0px 20px; display: inline" title="PCPlus logo" /&gt;I start off with the universal problem of photographing tall buildings: in order to get the top of the building in along with the bottom, you are forced to angle your camera upwards to fit it in. And that leads to the vertical lines in the view converging upwards. Enter the old view cameras, where you could shift the lens up or down (or side-to-side) rather than the camera itself, the bellows that connected the camera to the lens ensuring ease of movement and the blocking of light. In fact for architectural photos these cameras are still in use today.&lt;/p&gt;
&lt;p&gt;
	For SLRs and DSLRs, there is no such thing as bellows between the camera and lens, and so there&amp;rsquo;s evolved a similar setup where the lens will rotate or slide in front of the film plane. Compared to normal prime and zoom lenses, they tend to be expensive. I must admit that, while I was writing this article, I thought about finding and buying a secondhand one for my Canon DSLR. But, even secondhand, they command a steep price. (As an example, the 24mm Canon TS-E L Mark II lens is around $1500 secondhand, which, for a lens I&amp;rsquo;d probably not use all that much, is a little out of my price range. But maybe one day.)&lt;/p&gt;
&lt;p&gt;
	&lt;a data-rel="prettyPhoto" href="http://blog.boyet.com/blog/files/media/image/Windows-Live-Writer/PCPlus_C17F/tiltshiftbeachhuts_2_2.jpg"&gt;&lt;img alt="Beach huts at Wells-next-the-Sea, tilt-shifted" height="160" src="http://blog.boyet.com/blog/files/media/image/Windows-Live-Writer/PCPlus_C17F/tiltshiftbeachhuts_2_thumb.jpg" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: left; padding-top: 0px; padding-left: 0px; margin: 0px 20px 0px 0px; display: inline; padding-right: 0px; border-top-width: 0px" title="Beach huts at Wells-next-the-Sea, tilt-shifted" width="240" /&gt;&lt;/a&gt;So if the physical accessories are so expensive, is there any way to fake it? The answer is yes, and you can see an example alongside. This is a normal photo I&amp;rsquo;d taken on one of our vacations to England, and is ideal for a fake tilt-shift effect: the area of interest is a small band in the middle of the image. Enter Gaussian blur, especially a derived specialized algorithm that applies more blur the further away from the area of interest. This gives the effect of the foreground and the background being out of focus, providing the illusion of a tiny scale. I quickly discuss the mathematics behind Gaussian blur, including a quick way to calculate an approximation to it.&lt;/p&gt;
&lt;p&gt;
	(While I was writing this article, I wrote a &lt;a href="http://blog.boyet.com/blog/blog/tilt-shift-on-the-cheap/"&gt;blog post about tilt-shift&lt;/a&gt; here, further expanding ideas for digital processing of photos.)&lt;/p&gt;
&lt;p&gt;
	This article first appeared in issue 321, May 2013.&lt;/p&gt;
&lt;p&gt;
	You can read the PDF &lt;a href="http://boyetblog.s3.amazonaws.com/PCPlus/321.TiltShift.pdf"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;
	(I used to write a monthly column for PCPlus, a computer news-views-n-reviews magazine in the UK, which sadly is no longer published. The column was called &lt;em&gt;Theory Workshop&lt;/em&gt; and appeared in the &lt;em&gt;Make It&lt;/em&gt; section of the magazine. When I signed up, my editor and the magazine were gracious enough to allow me to reprint the articles here after say a year or so.)&lt;/p&gt;
&lt;p&gt;
	Now playing on Pandora:&lt;br /&gt;
	Jose Padilla &amp;ndash; &lt;strong&gt;Lontano (TripHop Mix)&lt;/strong&gt; on &lt;a href="http://www.pandora.com/jose-padilla/navigator-extra-tracks"&gt;Navigator&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/boyet/blog/~4/F_HFSh9qgo0" height="1" width="1"/&gt;</description><author>Algorithms for the masses - julian m bucknall &lt;julianb@boyet.com&gt;</author></item><item><title>Buying a sleeve for the Dell XPS 12</title><link>http://blog.boyet.com/blog/blog/buying-a-sleeve-for-the-dell-xps-12/</link><pubDate>Fri, 03 May 2013 03:08:00 GMT</pubDate><guid isPermaLink="true">http://blog.boyet.com/blog/blog/buying-a-sleeve-for-the-dell-xps-12/</guid><dc:creator>julian m bucknall</dc:creator><slash:comments>0</slash:comments><category domain="http://blog.boyet.com/blog/blog/">Blog</category><description>&lt;p&gt;
My new XPS 12&lt;a href="http://www.speckproducts.com/trimsleeve-for-macbook-air.html"&gt;&lt;img alt="Speck Trim Sleeve for MacBook Air" height="102" src="http://blog.boyet.com/blog/files/media/image/Windows-Live-Writer/Buying-a-sleeve-for-the-Dell-XPS-12_12EE7/SpeckTrimSleeve_6.jpg" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: right; padding-top: 0px; padding-left: 0px; margin: 0px 0px 0px 20px; display: inline; padding-right: 0px; border-top-width: 0px" title="Speck Trim Sleeve for MacBook Air" width="240" /&gt;&lt;/a&gt; is a pretty nice machine. Small (0.8&amp;rdquo; &amp;times; 12.5&amp;rdquo; &amp;times; 8.5&amp;rdquo;) and light (3.35 lbs), despite the intricacies of the flip screen and the touch capability. The top and bottom are covered in some kind of black matt surface that&amp;rsquo;s easy to grip and doesn&amp;rsquo;t seem to mark that easily. Yet, I&amp;rsquo;d prefer having something to protect it. Unfortunately it&amp;rsquo;s not such a bestseller like, say, the 13&amp;rdquo; MacBook Air that a whole accessories industry has grown around it.&lt;/p&gt;
&lt;p&gt;
	Dell sell a couple of cases (too big and unwieldy for an ultrabook like this in my view), and a sleeve at $45. The sleeve at least has a flap with magnetic clasp, but is a smidge expensive.&lt;/p&gt;
&lt;p&gt;
	&lt;a href="http://www.incipio.com/cases/macbook-cases/macbook-air-13in-cases/macbook-air-13in-slim-sleeve-case.html"&gt;&lt;img alt="Incipio Slim Sleeve for MacBook Air" height="190" src="http://blog.boyet.com/blog/files/media/image/Windows-Live-Writer/Buying-a-sleeve-for-the-Dell-XPS-12_12EE7/IncipioSlimSleeve_6.jpg" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: left; padding-top: 0px; padding-left: 0px; margin: 0px 20px 0px 0px; display: inline; padding-right: 0px; border-top-width: 0px" title="Incipio Slim Sleeve for MacBook Air" width="240" /&gt;&lt;/a&gt;My wife has an XPS 13 for which I purchased a &lt;a href="http://www.speckproducts.com/trimsleeve-for-macbook-air.html"&gt;Speck TrimSleeve&lt;/a&gt;. This was ostensibly for a 13&amp;rdquo; MacBook Air (the two machines have very similar dimensions). The XPS 12 fits in it nicely: what it gains in height, it loses in width and depth and so just glides into the sleeve. Unfortunately it seems Speck don&amp;rsquo;t sell it any more: (a) it&amp;rsquo;s out of stock, and (b) you can&amp;rsquo;t even get to the product page from the home page. This is a shame since it works extremely well and is pretty stylish too.&lt;/p&gt;
&lt;p&gt;
	Since this mini-experiment showed that a 13&amp;rdquo; MacBook Air sleeve would be ideal, I did some research and found the &lt;a href="http://www.incipio.com/cases/macbook-cases/macbook-air-13in-cases/macbook-air-13in-slim-sleeve-case.html"&gt;Slim Sleeve from Incipio&lt;/a&gt; at $30. It looks to be very well made and classy. There are eight possible colors, but I wimped out and got black. It was delivered today, and I&amp;rsquo;m glad to say the XPS 12 fits it just right. The only issue is that the device could slip out since there&amp;rsquo;s no flap or clasp to hold it in, but I can&amp;rsquo;t see that as being a problem with the way I use the machine. We&amp;rsquo;ll see.&lt;/p&gt;
&lt;p&gt;
	Now playing on Pandora:&lt;br /&gt;
	Zero 7 &amp;ndash; &lt;strong&gt;Red Dust&lt;/strong&gt; on &lt;a href="http://www.pandora.com/0-7/simple-things"&gt;&lt;em&gt;Simple Things&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/boyet/blog/~4/Iuax_ILdrEs" height="1" width="1"/&gt;</description><author>Algorithms for the masses - julian m bucknall &lt;julianb@boyet.com&gt;</author></item><item><title>Upgrading hardware: Dell XPS 15z and XPS 12</title><link>http://blog.boyet.com/blog/blog/upgrading-hardware-dell-xps-15z-and-xps-12/</link><pubDate>Thu, 02 May 2013 03:17:34 GMT</pubDate><guid isPermaLink="true">http://blog.boyet.com/blog/blog/upgrading-hardware-dell-xps-15z-and-xps-12/</guid><dc:creator>julian m bucknall</dc:creator><slash:comments>0</slash:comments><category domain="http://blog.boyet.com/blog/blog/">Blog</category><description>&lt;p&gt;We’re getting close to the conference season at work: in June I’m going to both &lt;a href="http://northamerica.msteched.com/"&gt;TechEd US in New Orleans&lt;/a&gt; and &lt;a href="http://www.buildwindows.com/"&gt;//build/ in San Francisco&lt;/a&gt;. Rather than cart around my very unloved Surface RT (haven’t used it in possibly two months), I’ve been dithering about buying an Intel Windows 8 machine, a touch device, say a convertible.I’ve had my eye on two possibilities, the Surface Pro and the Dell XPS 12. Since none of the touch machines available right now just aren’t powerful or expansive enough to be my main PC, I’ve been thinking of upgrading that too.&lt;/p&gt;  &lt;p&gt;&lt;img title="Dell XPS 15z" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: right; padding-top: 0px; padding-left: 0px; margin: 0px 0px 0px 20px; display: inline; padding-right: 0px; border-top-width: 0px" alt="Dell XPS 15z" src="http://blog.boyet.com/blog/files/media/image/Windows-Live-Writer/Hello_12740/Dell-XPS-15z_thumb.jpg" /&gt;First things first, my current machine is a Dell XPS 15z and I’ve already been on the upgrade path with it (&lt;a href="http://blog.boyet.com/blog/blog/bye-bye-macbook-pro-hello-dell-xps-15z/"&gt;one&lt;/a&gt;, &lt;a href="http://blog.boyet.com/blog/blog/hello-dell-xps-15z-part-deux/"&gt;two&lt;/a&gt;). This time, I had a problem that I was continually bumping into: I was running out of disk space. I had a 512GB Crucial M4 SSD in there, partitioned into two drives, both 256GB-ish, and twice in the past couple of months I’ve hit the dreaded “red bar” in the Windows Explorer drive list on both of them. Yes, sure, I was able to clean some stuff out (including the recycle bin) both times, but with an SSD you’ve got to allow some breathing space.&lt;/p&gt;  &lt;p&gt;I looked online and there’s a new Crucial 960GB SSD on the market (the Crucial M500) for about $600, but it’s been out of stock pretty well permanently. I’ve even had an email alert registered with &lt;a href="http://www.newegg.com/"&gt;Newegg&lt;/a&gt; to be notified immediately they got some. Still no response. Since Newegg had a 15% off coupon for the past couple of weeks, I finally decided to switch out my optical drive instead for another Crucial M4 512GB SSD. Saved $60 on the $400 price, which went immediately to a DVD replacement caddy (I got one from &lt;a href="http://www.newmodeus.com"&gt;newmodeus.com&lt;/a&gt; that fit the slimline 15z optical drive). That was the 15z taken care of – once I got the drive I merely copied one of the old partitions onto it (my data partition), removed it, and then expanded the other partition.&lt;/p&gt;  &lt;p&gt;&lt;img title="Dell XPS 12 " style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: left; padding-top: 0px; padding-left: 0px; margin: 0px 20px 0px 0px; display: inline; padding-right: 0px; border-top-width: 0px" alt="Dell XPS 12 " src="http://blog.boyet.com/blog/files/media/image/Windows-Live-Writer/c5de04e421e8_12CE7/Dell%20XPS%2012_3.jpg" width="240" height="204" /&gt;Once that was sorted out, a great deal came up on eBay for a nearly new XPS 12. It was the i7 version with 8GB memory and a 128GB SSD. New, they’re $1,400 in that configuration, but this one was a three-month-old buy-it-now from someone in Denver for $1,000. The SSD is too small (one reason I stopped thinking about the Surface Pro), but replacing it is even simpler than with the 15z – opening the 15z can be frustrating in the extreme. Since Newegg had a Crucial mSata 256GB SSD in stock (there are no 512GB mSata SSDs yet), and the coupon was still valid, I snagged one for $180. In essence, I got a top of the line XPS 12 for $1,180, whereas new, they’re $1,700. Not too shabby.&lt;/p&gt;  &lt;p&gt;In replacing the drive, the first thing to do was to create a recovery disk (or rather a recovery USB drive) from the partitions on the existing drive. This needs an 8GB drive for that – I had lots of spare USB drives of that size – and the process using the Dell recovery app was pretty painless, just lengthy. Of course I did not keep any of the existing data. Swapping the SSDs was easy too – removing the screws from the bottom of the Ultrabook causes the base to come off. The SSD is held in with one other screw. Next the reboot was simple: you just have to make sure the device boots from the USB drive. Half an hour later or so, I had a brand new repaved system. (And, man, it needs six partitions? I could work out which one is the recovery partition and delete and merge it, but to be honest, I can’t be bothered.)&lt;/p&gt;  &lt;p&gt;Since I’m going to be using the XPS 12 as a Windows 8 development system and also a demonstration system at conferences, I installed everything needed for that: Visual Studio 2012, SQL Server Standard, Sublime Text 2, Office 2013, Firefox, and, of course, all of DevExpress’ products. After doing all that, I’ve got 146GB free for projects and data. I’ll probably copy over some of my current projects as and when.&lt;/p&gt;  &lt;p&gt;Oh, and I installed a &lt;a href="http://startisback.com/"&gt;Start Menu replacement&lt;/a&gt;. Sorry, I just can’t stand the Start screen for normal work (just the flash of the Start screen as I type the name of an app to find it is irritating) and most of the apps I just installed are all desktop apps anyway.&lt;/p&gt;  &lt;p&gt;Now playing on Pandora:    &lt;br /&gt;Daft Punk - &lt;strong&gt;The Game Has Changed&lt;/strong&gt; on &lt;a href="http://www.pandora.com/daft-punk/tron-legacy"&gt;&lt;em&gt;Tron Legacy&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/boyet/blog/~4/tul_TKLvu-c" height="1" width="1"/&gt;</description><author>Algorithms for the masses - julian m bucknall &lt;julianb@boyet.com&gt;</author></item><item><title>PCPlus 320: Error detection and correction</title><link>http://blog.boyet.com/blog/pcplus/pcplus-320-error-detection-and-correction/</link><pubDate>Tue, 23 Apr 2013 00:41:56 GMT</pubDate><guid isPermaLink="true">http://blog.boyet.com/blog/pcplus/pcplus-320-error-detection-and-correction/</guid><dc:creator>julian m bucknall</dc:creator><slash:comments>0</slash:comments><category domain="http://blog.boyet.com/blog/pcplus/">PCPlus</category><description>&lt;p&gt;OK, I admit it. I&amp;rsquo;ve been in the programming industry for more years that I care to count, and although I&amp;rsquo;d vaguely considered error detection in the past, it wasn&amp;rsquo;t until I did some research for this next article that I finally got to have some understanding of it all. And not only error &lt;em&gt;detection&lt;/em&gt; but &lt;em&gt;correction&lt;/em&gt; too: now &lt;em&gt;that&lt;/em&gt; was pure magic. But, as with all these things, once you get the basic idea about how it works, all the magic gets stripped away.&lt;/p&gt;

&lt;p&gt;&lt;img alt="PC Plus logo" src="http://s3.amazonaws.com/boyetblog/PCPlusLogo.gif" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: right; padding-top: 0px; padding-left: 0px; margin: 0px 0px 0px 20px; display: inline; padding-right: 0px; border-top-width: 0px" title="PC Plus logo" /&gt;I suppose the first kind of error detection I&amp;rsquo;d come across was the &lt;em&gt;parity bit&lt;/em&gt;, especially with regard to the dodgy RAM and diskettes and trundling hard disks you used to have in the MSDOS days. Here we suppose that the storage medium is subject to some errors (either writing to the storage medium or reading it back again). What happened was that bytes were stored as 9 bits, the required eight bits in the byte and a parity bit. If there were an odd number of 1 bits in the byte, the parity bit would be set to 1 for &lt;em&gt;even parity&lt;/em&gt; or 0 for &lt;em&gt;odd parity&lt;/em&gt;. When the byte was retrieved the hardware could check that the 9 bits read had an even number of 1 bits or an odd number, depending on the parity scheme in place. It couldn&amp;rsquo;t do anything about it if it detected an error, of course.&lt;/p&gt;

&lt;p&gt;The next example of error detection I came across was a checksum calculation, such as credit card numbers: again, it detects errors but doesn&amp;rsquo;t help correct them. Mind you, with a credit card number you can just ask the customer for it again; it&amp;rsquo;s unlikely you&amp;rsquo;d have such a data storage problem that a credit card number gets corrupted. A more interesting checksum is &lt;em&gt;Cyclic Redundancy Check (CRC)&lt;/em&gt;, or cryptographic hashes like SHA-1 or MD5. These checksums try and identify cases where the input message is corrupted in a perhaps subtle way.&lt;/p&gt;

&lt;p&gt;Then there&amp;rsquo;s barcodes. Although linear barcodes tend to have error detection though some kind of checksum,&amp;nbsp; 2D barcodes generally have error correction as well since they can store more information per unit area. The familiar QR code uses the Reed-Solomon error correction algorithm. In the article I show how to calculate an earlier error correction algorithm, Hamming codes, and how they can be used to detect and correct errors. The (7,4) Hamming code I show is the best way to detect and correct single bit flips in 4 data bits.&lt;/p&gt;

&lt;p&gt;In essence, in any situation where you are trying to transmit data (a message) from point A to point B digitally (scanning barcodes, streaming from a DVD, reading SSD memory chips, etc) where there is a possibility that some physical damage will cause data corruption, there will be some error detection and correction algorithm in the background trying to make sure that we get what we expect. Like many things in the digital realm, it&amp;rsquo;s just invisibly working for us.&lt;/p&gt;

&lt;p&gt;This article first appeared in issue 320, April 2012.&lt;/p&gt;

&lt;p&gt;You can read the PDF &lt;a href="http://boyetblog.s3.amazonaws.com/PCPlus/320.ErrorDetection.pdf"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;(I used to write a monthly column for PCPlus, a computer news-views-n-reviews magazine in the UK, which sadly is no longer published. The column was called &lt;em&gt;Theory Workshop&lt;/em&gt; and appeared in the &lt;em&gt;Make It&lt;/em&gt; section of the magazine. When I signed up, my editor and the magazine were gracious enough to allow me to reprint the articles here after say a year or so.)&lt;/p&gt;

&lt;div class="itunesnowplaying"&gt;
&lt;p&gt;&lt;a href="http://www.amazon.com/Raoul-Kings-Spain-Tears-Fears/dp/B0012GN39Q%3FSubscriptionId%3D0KQPG62QR93J93SA2A02%26tag%3Djulianbucknallsw%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB0012GN39Q"&gt;&lt;img alt="Album cover for Raoul and the Kings of Spain" src="http://ecx.images-amazon.com/images/I/51zUDiGol4L._SL75_.jpg" style="float: left; margin-right: 20px" /&gt;&lt;/a&gt;Now playing:&lt;br /&gt;
Tears for Fears - &lt;strong&gt;God&amp;#39;s Mistake&lt;/strong&gt;&lt;br /&gt;
(from &lt;a href="http://www.amazon.com/Raoul-Kings-Spain-Tears-Fears/dp/B0012GN39Q%3FSubscriptionId%3D0KQPG62QR93J93SA2A02%26tag%3Djulianbucknallsw%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB0012GN39Q"&gt;&lt;em&gt;Raoul and the Kings of Spain&lt;/em&gt;&lt;/a&gt;)&lt;/p&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/boyet/blog/~4/oEDhaxhUcNg" height="1" width="1"/&gt;</description><author>Algorithms for the masses - julian m bucknall &lt;julianb@boyet.com&gt;</author></item><item><title>Scientists in Paris</title><link>http://blog.boyet.com/blog/blog/scientists-in-paris/</link><pubDate>Sun, 14 Apr 2013 20:28:42 GMT</pubDate><guid isPermaLink="true">http://blog.boyet.com/blog/blog/scientists-in-paris/</guid><dc:creator>julian m bucknall</dc:creator><slash:comments>0</slash:comments><category domain="http://blog.boyet.com/blog/blog/">Blog</category><description>&lt;p&gt;We were vacationing in Paris last week in a hotel in the 16eme arrondissement, just outside the boundary of the 8eme. We&amp;rsquo;d stayed there before, but I noticed this time that several streets in the vicinity has names commemorating scientists and mathematicians. I thought it would be fun to take pictures of the ones I could find that were close and put them in a collage:&lt;/p&gt;

&lt;p&gt;&lt;a data-rel="prettyPhoto" href="http://blog.boyet.com/blog/files/media/image/Windows-Live-Writer/Scientists-in-Paris_C5FA/Collage_2.png"&gt;&lt;img alt="Collage of scientist street names in Paris" height="240" src="http://blog.boyet.com/blog/files/media/image/Windows-Live-Writer/Scientists-in-Paris_C5FA/Collage_thumb.png" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" title="Collage of scientist street names in Paris" width="240" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In order, they are:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;Augustin-Jean &lt;a href="http://en.wikipedia.org/wiki/Augustin-Jean_Fresnel"&gt;Fresnel&lt;/a&gt;. We also saw a lighthouse lens built on his principles in the Mus&amp;eacute;e Maritime.&lt;/li&gt;
	&lt;li&gt;Johannes &lt;a href="http://en.wikipedia.org/wiki/Kepler"&gt;Kepler&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;Leonhard &lt;a href="http://en.wikipedia.org/wiki/Euler"&gt;Euler&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;Isaac &lt;a href="http://en.wikipedia.org/wiki/Isaac_Newton"&gt;Newton&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;Galileo &lt;a href="http://en.wikipedia.org/wiki/Galileo_Galilei"&gt;Galilei&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;Nicolaus &lt;a href="http://en.wikipedia.org/wiki/Nicolaus_Copernicus"&gt;Copernicus&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;L&amp;eacute;on &lt;a href="http://en.wikipedia.org/wiki/L%C3%A9on_Foucault"&gt;Foucault&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I did also think that Avenue Raymond Poincar&amp;eacute; might have been named after the mathematician (I couldn&amp;rsquo;t remember his first name offhand), but it turned out to be for the President during the first World War and not Henri Poincar&amp;eacute;, he of the famous Conjecture.&lt;/p&gt;

&lt;div class="itunesnowplaying"&gt;
&lt;p&gt;&lt;a href="http://www.amazon.com/Corps-Et-Armes-Etienne-Daho/dp/B00004T99X%3FSubscriptionId%3D0KQPG62QR93J93SA2A02%26tag%3Djulianbucknallsw%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB00004T99X"&gt;&lt;img alt="Album cover for Corps et Armes" src="http://ecx.images-amazon.com/images/I/51ku%2BvCPBPL._SL75_.jpg" style="float: left; margin-right: 20px" /&gt;&lt;/a&gt;Now playing:&lt;br /&gt;
Daho, Etienne - &lt;strong&gt;La Baie&lt;/strong&gt;&lt;br /&gt;
(from &lt;a href="http://www.amazon.com/Corps-Et-Armes-Etienne-Daho/dp/B00004T99X%3FSubscriptionId%3D0KQPG62QR93J93SA2A02%26tag%3Djulianbucknallsw%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB00004T99X"&gt;&lt;em&gt;Corps et Armes&lt;/em&gt;&lt;/a&gt;)&lt;/p&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/boyet/blog/~4/TJuSLNHgqZM" height="1" width="1"/&gt;</description><author>Algorithms for the masses - julian m bucknall &lt;julianb@boyet.com&gt;</author></item><item><title>Inline scripts: sometimes the web is just screwed up</title><link>http://blog.boyet.com/blog/blog/inline-scripts-sometimes-the-web-is-just-screwed-up/</link><pubDate>Tue, 02 Apr 2013 01:49:04 GMT</pubDate><guid isPermaLink="true">http://blog.boyet.com/blog/blog/inline-scripts-sometimes-the-web-is-just-screwed-up/</guid><dc:creator>julian m bucknall</dc:creator><slash:comments>6</slash:comments><category domain="http://blog.boyet.com/blog/blog/">Blog</category><description>&lt;p&gt;I don’t know about you, but one of my favorite commands in the browser is “View Page Source”, especially on a site that’s modern, visually attractive, or shows off some clever interactions. After all, I’m a developer: I like to find out how things work so I can, if I want to, replicate on my own web sites.&lt;/p&gt;  &lt;p&gt;&lt;img title="Sculpture in New Orleans" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: right; padding-top: 0px; padding-left: 0px; margin: 0px 0px 0px 20px; display: inline; padding-right: 0px; border-top-width: 0px" alt="Sculpture in New Orleans" src="http://blog.boyet.com/blog/files/media/image/Windows-Live-Writer/Inline-scripts-sometimes-the-web-is-scre_F783/TechEd%20NOLA-2_3.jpg" width="240" height="160" /&gt;Some web pages though are really nasty when you look at their source. And one of the places they excel at nastiness is in their use of inline scripts. Now, don’t get me wrong, I’m not particularly objecting to inline scripts: sometimes they’re the biz when you just have some minor bit of JavaScript to execute, so minor it doesn’t seem efficient to create a brand new JS file and add the external script tag to the HTML on the page. And then sometimes you get web pages that can’t seem to decide how the heck they should represent inline scripts and throw everything but the kitchen sink at the problem.&lt;/p&gt;  &lt;p&gt;Let’s take a look at the three main ways you can insert inline scripts into your HTML. First, there’s the obvious way, just unadorned:&lt;/p&gt;  &lt;div class="jmbcodeblock"&gt;   &lt;pre&gt;&lt;span style="color: #0000ff"&gt;&lt;span style="background-color: #ffffff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;script&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000"&gt;
    $(&lt;/span&gt;&lt;span style="color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="color: #000000"&gt; () {
        &lt;/span&gt;&lt;span style="color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="color: #000000"&gt; inputText = $(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;#inputtext&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;),
            outputMath = $(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;#outputmath&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;),
            inlineMath = $(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;#inlinemath&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;);

        inputText.on(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;keyup&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;, &lt;/span&gt;&lt;span style="color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="color: #000000"&gt; () {
            &lt;/span&gt;&lt;span style="color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="color: #000000"&gt; expr = inputText.val();
            outputMath.text(&lt;/span&gt;&lt;span style="color: #a31515"&gt;'\\[ '&lt;/span&gt;&lt;span style="color: #000000"&gt; + expr + &lt;/span&gt;&lt;span style="color: #a31515"&gt;' \\]'&lt;/span&gt;&lt;span style="color: #000000"&gt;);
            inlineMath.text(&lt;/span&gt;&lt;span style="color: #a31515"&gt;'The expression is &amp;lt;\\( '&lt;/span&gt;&lt;span style="color: #000000"&gt; + expr + &lt;/span&gt;&lt;span style="color: #a31515"&gt;' \\)&amp;gt;.'&lt;/span&gt;&lt;span style="color: #000000"&gt;);
            MathJax.Hub.Queue([&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Typeset&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;, MathJax.Hub, &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;outputmath&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;]);
            MathJax.Hub.Queue([&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Typeset&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;, MathJax.Hub, &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;inlinemath&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;]);
        });

    });
&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;script&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Then, from way back when, there was the attempt to circumvent those browsers that didn’t support inline JavaScript by enclosing the code in HTML comments:&lt;/p&gt;

&lt;div class="jmbcodeblock"&gt;
  &lt;pre&gt;&lt;span style="color: #0000ff"&gt;&lt;span style="background-color: #ffffff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;script&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000"&gt;
    &lt;/span&gt;&lt;span style="background-color: #ffff91"&gt;&amp;lt;!--&lt;/span&gt;&lt;span style="background-color: #ffffff"&gt;
    $(&lt;/span&gt;&lt;span style="color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="color: #000000"&gt; () {
        &lt;/span&gt;&lt;span style="color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="color: #000000"&gt; inputText = $(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;#inputtext&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;),
            outputMath = $(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;#outputmath&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;),
            inlineMath = $(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;#inlinemath&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;);

        inputText.on(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;keyup&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;, &lt;/span&gt;&lt;span style="color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="color: #000000"&gt; () {
            &lt;/span&gt;&lt;span style="color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="color: #000000"&gt; expr = inputText.val();
            outputMath.text(&lt;/span&gt;&lt;span style="color: #a31515"&gt;'\\[ '&lt;/span&gt;&lt;span style="color: #000000"&gt; + expr + &lt;/span&gt;&lt;span style="color: #a31515"&gt;' \\]'&lt;/span&gt;&lt;span style="color: #000000"&gt;);
            inlineMath.text(&lt;/span&gt;&lt;span style="color: #a31515"&gt;'The expression is &amp;lt; \\( '&lt;/span&gt;&lt;span style="color: #000000"&gt; + expr + &lt;/span&gt;&lt;span style="color: #a31515"&gt;' \\) &amp;gt;.'&lt;/span&gt;&lt;span style="color: #000000"&gt;);
            MathJax.Hub.Queue([&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Typeset&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;, MathJax.Hub, &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;outputmath&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;]);
            MathJax.Hub.Queue([&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Typeset&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;, MathJax.Hub, &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;inlinemath&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;]);
        });

    });
    &lt;/span&gt;&lt;span style="background-color: #ffff91"&gt;// --&amp;gt;&lt;/span&gt;&lt;span style="background-color: #ffffff"&gt;
&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;script&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Notice that (1) the opening HTML comment tag is allowed to be “bare” (it’s not counted as part of the JavaScript code) but the closing end-comment tag must be itself commented out in the inline JavaScript. &lt;/p&gt;

&lt;p&gt;Finally there’s the CDATA approach, which just seems wacky until you understand why it’s used:&lt;/p&gt;

&lt;div class="jmbcodeblock"&gt;
  &lt;pre&gt;&lt;span style="color: #0000ff"&gt;&lt;span style="background-color: #ffffff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;script&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000"&gt;
    &lt;/span&gt;&lt;span style="background-color: #ffff91"&gt;// &amp;lt;![CDATA[&lt;/span&gt;&lt;span style="background-color: #ffffff"&gt;
    $(&lt;/span&gt;&lt;span style="color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="color: #000000"&gt; () {
        &lt;/span&gt;&lt;span style="color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="color: #000000"&gt; inputText = $(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;#inputtext&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;),
            outputMath = $(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;#outputmath&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;),
            inlineMath = $(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;#inlinemath&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;);

        inputText.on(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;keyup&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;, &lt;/span&gt;&lt;span style="color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="color: #000000"&gt; () {
            &lt;/span&gt;&lt;span style="color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="color: #000000"&gt; expr = inputText.val();
            outputMath.text(&lt;/span&gt;&lt;span style="color: #a31515"&gt;'\\[ '&lt;/span&gt;&lt;span style="color: #000000"&gt; + expr + &lt;/span&gt;&lt;span style="color: #a31515"&gt;' \\]'&lt;/span&gt;&lt;span style="color: #000000"&gt;);
            inlineMath.text(&lt;/span&gt;&lt;span style="color: #a31515"&gt;'The expression is &amp;lt; \\( '&lt;/span&gt;&lt;span style="color: #000000"&gt; + expr + &lt;/span&gt;&lt;span style="color: #a31515"&gt;' \\) &amp;gt;.'&lt;/span&gt;&lt;span style="color: #000000"&gt;);
            MathJax.Hub.Queue([&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Typeset&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;, MathJax.Hub, &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;outputmath&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;]);
            MathJax.Hub.Queue([&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Typeset&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;, MathJax.Hub, &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;inlinemath&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;]);
        });

    });
    &lt;/span&gt;&lt;span style="background-color: #ffff91"&gt;// ]]&amp;gt;&lt;/span&gt;&lt;span style="background-color: #ffffff"&gt;
&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;script&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;So what’s up with all this? Why the three different methods? &lt;/p&gt;

&lt;p&gt;The first point to recognize is that there are two characters that should never be used un-escaped in HTML: the less-than angle bracket (&lt;code&gt;&amp;lt;&lt;/code&gt;) and the ampersand (&lt;code&gt;&amp;amp;&lt;/code&gt;). In the inline code I’m showing in method 1, there’s a left angle bracket. Luckily, in HTML, text that appears in a script element can contain these two characters un-escaped. (The only thing that cannot appear in a script element is the string “&lt;code&gt;&amp;lt;/script&amp;gt;&lt;/code&gt;”, since that signals the end of the script.) So, with all modern day browsers, this kind of unadorned inline script is accepted in an HTML file without issues (except for one special case, which I’ll come to in a moment). &lt;/p&gt;

&lt;p&gt;&lt;img title="Batman slaps Robin about inline script" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: right; padding-top: 0px; padding-left: 0px; margin: 0px 0px 0px 20px; display: inline; padding-right: 0px; border-top-width: 0px" alt="Batman slaps Robin about inline script" src="http://blog.boyet.com/blog/files/media/image/Windows-Live-Writer/Inline-scripts-sometimes-the-web-is-scre_F783/BatmanSlapsRobinInlineScript_3.jpg" width="240" height="232" /&gt;Method 2 was used purely for those browsers that didn’t understand inline scripts. To be exact, the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag was introduced in HTML 3.2 as a placeholder and browsers from that point on would no longer display the inline code as text when displaying the page – which is what happened prior to that. If you can remember those days, more power to you; I certainly can’t. So, back in the dim and distant past the inline code had to be commented out HTML-wise to make sure it wasn’t displayed by a horse-drawn user agent. Fast forward to the 21st century where even – shock, horror – IE6 recognized inline script. Method 2 then is not required ever, anymore. Just say no. (Incidentally there’s another issue with the “commented out” inline script: the code could not contain dash-dash (&lt;code&gt;--&lt;/code&gt;), since it was that character sequence that officially denoted the end of the comment. So no post- or pre-decrements in your code, OK?)&lt;/p&gt;

&lt;p&gt;Method 3 is an interesting one. It’s the only allowed way to have general text embedded in an XML file that isn’t going to be parsed as XML. Hence it’s the only way to have valid un-escaped less-than signs or ampersands in the XML file. And, of course, an HTML file that is flagged as XHTML in the file’s DOCTYPE is supposed to be valid XML. However, that’s not the end of the story. Basically browsers have two parsers: an HTML parser and an XML parser, with the HTML parser being used the vast majority of the time. This is true even in the case of an HTML file flagged as XHTML in the DOCTYPE: the HTML parser will be used. Since the CDATA section is not part of the HTML spec, both the start and end CDATA tags are just ignored: and this is especially so since they are both commented out in the inline script. The &lt;em&gt;only&lt;/em&gt; time the CDATA section is parsed as such is if (a) the HTML file is flagged as XHTML, and (b) the HTTP response header sent by the web server marks the content as the “&lt;code&gt;application/xhtml+xml&lt;/code&gt;” MIME type. In this case, the XML parser is executed on the content and your inline script had better be in a CDATA section just in case.&lt;/p&gt;

&lt;p&gt;So, where does this leave you? &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;First, just avoid inline script. If you do, you don’t have to worry about any of this palaver. &lt;/li&gt;

  &lt;li&gt;Second, never use method 2. Never, ever, ever. It’s not been needed for years, and when even IE6 (&lt;em&gt;spit, spit&lt;/em&gt;) doesn’t need it, you are completely safe in avoiding it. &lt;/li&gt;

  &lt;li&gt;Third, if you are at the cutting edge of web development and are writing HTML5 pages or web sites or applications and you absolutely have to have inline JavaScript, just use method 1. All modern browsers will understand what you want and none will barf at your succinctness. &lt;/li&gt;

  &lt;li&gt;Fourth, only use method 3 if you are declaring your HTML as XHTML in the DOCTYPE, and you have set up your web server to declare these files as “&lt;code&gt;application/xhtml+xml&lt;/code&gt;”. If you are doing that, more power to you! &lt;/li&gt;

  &lt;li&gt;Fifth, use method 1 in all other cases. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now isn’t that all just simple?&lt;/p&gt;

&lt;div class="itunesnowplaying"&gt;
  &lt;p&gt;&lt;a href="http://www.amazon.com/Luck-Be-A-Weirdo-Tonight/dp/B0000247KS%3FSubscriptionId%3D0KQPG62QR93J93SA2A02%26tag%3Djulianbucknallsw%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB0000247KS"&gt;&lt;img style="float: left; margin-right: 20px" alt="Album cover for Luck Be A Weirdo Tonight" src="http://ecx.images-amazon.com/images/I/51HmUBsb-9L._SL75_.jpg" /&gt;&lt;/a&gt;Now playing: 

    &lt;br /&gt;Fila Brazillia - &lt;strong&gt;Pollo De Palo&lt;/strong&gt; 

    &lt;br /&gt;(from &lt;a href="http://www.amazon.com/Luck-Be-A-Weirdo-Tonight/dp/B0000247KS%3FSubscriptionId%3D0KQPG62QR93J93SA2A02%26tag%3Djulianbucknallsw%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB0000247KS"&gt;&lt;em&gt;Luck Be A Weirdo Tonight&lt;/em&gt;&lt;/a&gt;) &lt;/p&gt;

  &lt;br class="clear" /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/boyet/blog/~4/MbCayfGjoms" height="1" width="1"/&gt;</description><author>Algorithms for the masses - julian m bucknall &lt;julianb@boyet.com&gt;</author></item><item><title>Upgrading to jQuery 1.9.x</title><link>http://blog.boyet.com/blog/blog/upgrading-to-jquery-1-9-x/</link><pubDate>Sun, 24 Mar 2013 04:15:13 GMT</pubDate><guid isPermaLink="true">http://blog.boyet.com/blog/blog/upgrading-to-jquery-1-9-x/</guid><dc:creator>julian m bucknall</dc:creator><slash:comments>0</slash:comments><category domain="http://blog.boyet.com/blog/blog/">Blog</category><description>&lt;p&gt;Today it snowed. It started before we awoke and pretty much kept at it all day. Hence it was a day to do some work inside, and what better task than to clean up my blog? First port of call, and a major one at that, was to upgrade to jQuery 1.9. &lt;/p&gt;  &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px 0px 0px 20px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Cloud maintenance image" border="0" alt="Cloud maintenance image" align="right" src="http://blog.boyet.com/blog/files/media/image/Windows-Live-Writer/Upgrading-to-jQuery-1.9.x_12B07/Cloud%20maintenance_3.jpg" width="240" height="180" /&gt;Before you say, so what, just change the version number in the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag, consider this. jQuery 1.9 removes several APIs that “behaved inconsistently or inefficiently in the past” (&lt;a href="http://jquery.com/upgrade-guide/1.9/#overview"&gt;here&lt;/a&gt;), ones that have been deprecated for a while. So, replacing the version number willy-nilly &lt;em&gt;might&lt;/em&gt; break some code. Can’t have that.&lt;/p&gt;  &lt;p&gt;The jQuery team have mitigated the problem by providing the jQuery Migrate plugin. This has two main benefits: it firstly adds back the removed APIs so that you can continue as before (however, doing so comes with some caveats), and secondly, when you use the un-minified version instead of the production version, it not only does that but also writes warning diagnostic messages to the console if such APIs are used. You can then use these messages to work out which JavaScript code needs to be changed and, by using the &lt;a href="http://jquery.com/upgrade-guide/1.9/"&gt;Upgrade Guide&lt;/a&gt;, fix the problems. And, in general, the fixes are quite easy.&lt;/p&gt;  &lt;p&gt;After updating the jQuery version number ion my HTML and adding a new script tag to reference the uncompressed Migration plugin, I found I had one problem in my own code: the &amp;quot;&lt;code&gt;hover&lt;/code&gt;” pseudo-event &lt;a href="http://jquery.com/upgrade-guide/1.9/#hover-pseudo-event"&gt;no longer exists&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;This was my original code that triggered the warning:&lt;/p&gt;  &lt;div class="jmbcodeblock"&gt;   &lt;pre&gt;&lt;span style="color: #000000"&gt;&lt;span style="background-color: #ffffff"&gt;sidebarDiv.unbind(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;hover&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;In essence: unbind the hover event handler from the DOM element called &lt;code&gt;sidebarDiv&lt;/code&gt;. Now, although &lt;code&gt;bind()&lt;/code&gt; and &lt;code&gt;unbind()&lt;/code&gt; are still valid, the documentation for them explicitly state that the new &lt;code&gt;on()&lt;/code&gt; and &lt;code&gt;off()&lt;/code&gt; methods are preferred to add or remove event handlers. OK, then. The removal code was pretty simple to fix, especially as the new methods allow for a space-delimited list of events, instead of just one at a time:&lt;/p&gt;

&lt;div class="jmbcodeblock"&gt;
  &lt;pre&gt;&lt;span style="color: #000000"&gt;&lt;span style="background-color: #ffffff"&gt;sidebarDiv.off(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;mouseenter mouseleave&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;The setting of the hover event handler was a little more involved. The original API allowed for two callback functions to be defined in the one call:&lt;/p&gt;

&lt;div class="jmbcodeblock"&gt;
  &lt;pre&gt;&lt;span style="color: #000000"&gt;&lt;span style="background-color: #ffffff"&gt;sidebarDiv.hover(&lt;/span&gt;&lt;span style="color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="color: #000000"&gt; () {
    mouseInside = &lt;/span&gt;&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;&lt;span style="color: #000000"&gt;;
  },
&lt;/span&gt;&lt;span style="color: #0000ff"&gt;  function&lt;/span&gt;&lt;span style="color: #000000"&gt; () {
    mouseInside = &lt;/span&gt;&lt;span style="color: #0000ff"&gt;false&lt;/span&gt;&lt;span style="color: #000000"&gt;;
  }&lt;/span&gt;&lt;/span&gt;
&lt;span style="color: #000000"&gt;&lt;span style="color: #000000"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;but the new separate event types would either mean two separate calls to set the handlers, or a more clever handler. I went with the second route, using the passed in parameter to get at the event type:&lt;/p&gt;

&lt;div class="jmbcodeblock"&gt;
  &lt;pre&gt;&lt;span style="color: #000000"&gt;&lt;span style="background-color: #ffffff"&gt;sidebarDiv.on(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;mouseenter mouseleave&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;, &lt;/span&gt;&lt;span style="color: #0000ff"&gt;function&lt;/span&gt;&lt;span style="color: #000000"&gt; (event) {
  &lt;/span&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt;&lt;span style="color: #000000"&gt; (event.type === &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;mouseenter&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;) {
    mouseInside = &lt;/span&gt;&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;&lt;span style="color: #000000"&gt;;
  }
  &lt;/span&gt;&lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;span style="color: #000000"&gt; {
    mouseInside = &lt;/span&gt;&lt;span style="color: #0000ff"&gt;false&lt;/span&gt;&lt;span style="color: #000000"&gt;;
  }
});&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;After that I just modified the other (albeit still valid) calls to &lt;code&gt;bind()&lt;/code&gt; and &lt;code&gt;unbind()&lt;/code&gt; I had in the code to use the new APIs just to be consistent.&lt;/p&gt;

&lt;p&gt;And I’d have to say that was pretty much it for me. I had to update a third-party library I was using (a new version was available that supported jQuery 1.9), but nothing else was being flagged by the Migration plug-in. Score!&lt;/p&gt;

&lt;p&gt;(Oh, I also added a drop cap for the initial paragraph for each blog post. Just because. To find out how, go &lt;a href="http://css-tricks.com/snippets/css/drop-caps/"&gt;here&lt;/a&gt;. I used the second method, which requires CSS3 support in the browser.) &lt;/p&gt;

&lt;div class="itunesnowplaying"&gt;
  &lt;p&gt;&lt;a href="http://www.amazon.com/Up-Peter-Gabriel/dp/B00006F7S3%3FSubscriptionId%3D0KQPG62QR93J93SA2A02%26tag%3Djulianbucknallsw%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB00006F7S3"&gt;&lt;img style="float: left; margin-right: 20px" alt="Album cover for Up" src="http://ecx.images-amazon.com/images/I/312XRA4F2ML._SL75_.jpg" /&gt;&lt;/a&gt;Now playing: 

    &lt;br /&gt;Gabriel, Peter - &lt;strong&gt;The Drop&lt;/strong&gt; 

    &lt;br /&gt;(from &lt;a href="http://www.amazon.com/Up-Peter-Gabriel/dp/B00006F7S3%3FSubscriptionId%3D0KQPG62QR93J93SA2A02%26tag%3Djulianbucknallsw%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB00006F7S3"&gt;&lt;em&gt;Up&lt;/em&gt;&lt;/a&gt;) &lt;/p&gt;

  &lt;br class="clear" /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/boyet/blog/~4/ItgZUHLaBVs" height="1" width="1"/&gt;</description><author>Algorithms for the masses - julian m bucknall &lt;julianb@boyet.com&gt;</author></item></channel></rss>
