<?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>Cuneyt Karul&#039;s Blog</title>
	<atom:link href="http://karul.org/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://karul.org/blog</link>
	<description></description>
	<lastBuildDate>Thu, 19 Jan 2012 02:39:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Thread safety issues with Java SimpleDateFormat class</title>
		<link>http://karul.org/blog/2012/01/thread-safety-issues-with-java-simpledateformat-clas/</link>
		<comments>http://karul.org/blog/2012/01/thread-safety-issues-with-java-simpledateformat-clas/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 02:39:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://karul.org/blog/?p=634</guid>
		<description><![CDATA[<p>One of the common programming practices is to define a static SimpleDateFormat instance and use it in your application whenever you need to parse and/or format Java dates. It actually does perfect sense, because parsing and formatting in general is a computationally expensive  operation and rather than creating the object over and over again, [...]]]></description>
			<content:encoded><![CDATA[<p>One of the common programming practices is to define a static SimpleDateFormat instance and use it in your application whenever you need to parse and/or format Java dates. It actually does perfect sense, because parsing and formatting in general is a computationally expensive  operation and rather than creating the object over and over again, it is a lot more efficient to create one and to reuse it. After all converting one object to another is quite a trivial task, or is it?</p>
<p>One of the applications I developed was corrupting data every now and then, and I always assumed it is a temporary system failure or unavailable database. When this became a real issue I bothered to investigate further and the problem turned out to be one of the most common (well not common enough for me to pay attention I  guess) thread safety issues of core Java classes. If you&#8217;re thinking your  code is not multi-threaded and you don&#8217;t need to care about this, think again  because most application servers (Tomcat, JBoss, etc.) create multiple threads without you even knowing about it.</p>
<p>As this is a pretty easy mistake to make, I decided to document the solution here&#8230;</p>
<p><strong>The mistake</strong>:</p>
<p>I had a static variable to define a central date format, which I used through out my application.</p>
<blockquote>
<pre>public static final SimpleDateFormat DEFAULT_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");</pre>
</blockquote>
<p>So when I need to parse a date, or format it I simple make a single line call to:</p>
<blockquote>
<pre>Constants.DEFAULT_FORMAT.parse(date);</pre>
</blockquote>
<div id=":tt">
<p>It is nice and clean, and when in doubt I can always go to the Constants class to see what the date format looked like.</p>
<p><strong>The problem:</strong></p>
<p>The above should work fine in a single threaded application, or even in a multi-threaded application if the date formatting and parsing is not very heavily used. That&#8217;s what makes it elusive. The problem is not that it always throws an exception,  but when two or more threads try to use the same static variable at the same time,  the method returns some arbitrary date, so your code has no way of knowing if the date is wrong or not.</p>
<p><strong>The solution:</strong></p>
<p>Whatever I&#8217;ve documented so far is actually well publicized. The consensus on the solution is essentially:</p>
<ol>
<li>Don&#8217;t use it. Create a new SimpleDateFormat instance whenever you need it. This doesn&#8217;t work me as latency is very critical and can&#8217;t effort to have the object recreated every single time. I also hate to lose the centrally managed, well documented repository of all date formats in my Constants class.</li>
<li>Synchronize it, which essentially will make your threads wait for  each other to access this class, potentially creating a big bottleneck. So this is a no go as well.</li>
<li>Use ThreadLocal, which is what I did. As there are not many examples  out there to demonstrate how to use it I wanted to document a simple  example for your convenience.</li>
</ol>
<p>You better refer to Java documentation for a better description of ThreadLocal  class, but it essentially creates one static variable per thread rather  than per application. You&#8217;ll need to slightly change both your  variable definition and how you access it, but the change is quite  systematic, and you can do it safely with the help of a good IDE and the good old find/replace utility.</p>
<p>First replace your static variable with the following:</p>
<blockquote>
<pre>// public static final SimpleDateFormat DEFAULT_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
public static final ThreadLocal&lt;SimpleDateFormat&gt; DEFAULT_FORMAT = new ThreadLocal&lt;SimpleDateFormat&gt;() {
  @Override
  protected SimpleDateFormat initialValue() {
    return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  }
};</pre>
</blockquote>
<p>Note  that this method is will no longer return you SimpleDateFormat, but  rather the ThreadLocal instance which contains it. So you&#8217;ll have to  make a minor modification to all references to your old variable:</p>
<blockquote>
<pre>//Constants.DEFAULT_FORMAT.parse(date);
Constants.DEFAULT_FORMAT.get().parse(date);</pre>
</blockquote>
<p>And  that&#8217;s pretty much it. A good IDE should highlight all references once  you change the static variable so it&#8217;s not hard to find them.</p>
<p>While you are at it, I would check if there are other static  variables that are known to be non-thread-safe and replace them as well.<br />
In my case I also needed to convert some other decimal formatters.</p>
<blockquote>
<pre>//public static final DecimalFormat TWO_DIGIT_MONEY_FORMAT = new DecimalFormat("#,##0.00");
public static final ThreadLocal&lt;DecimalFormat&gt; TWO_DIGIT_MONEY_FORMAT = new ThreadLocal&lt;DecimalFormat&gt;() {
  @Override
  protected DecimalFormat initialValue() {
    return new DecimalFormat("#,##0.00");
  }
};</pre>
</blockquote>
<p>PS: One of the online bloggers commented  that this solution would have issues in thread pools. I&#8217;m not sure what  his/her rationale was, but I&#8217;ve been using it with pooled threads  quite a while now and didn&#8217;t have any problems so far. I profiled the  application memory for half a day just to make sure that I&#8217;m not leaking any  memory. I&#8217;ll update this entry if I encounter any issues.</p>
</div>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://karul.org/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://karul.org/blog/2012/01/thread-safety-issues-with-java-simpledateformat-clas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing music.isallicare.com</title>
		<link>http://karul.org/blog/2010/01/introducing-music-isallicare-com/</link>
		<comments>http://karul.org/blog/2010/01/introducing-music-isallicare-com/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 02:03:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Dijit]]></category>
		<category><![CDATA[Dojo]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[chords]]></category>
		<category><![CDATA[Java Script]]></category>
		<category><![CDATA[music theory]]></category>
		<category><![CDATA[Scales]]></category>
		<category><![CDATA[Web 2.0]]></category>

		<guid isPermaLink="false">http://karul.org/blog/?p=578</guid>
		<description><![CDATA[<p>A while back I blogged about music theory for geeks and got a lot of feedback from my fellow musicians (some geek some not). Then I blogged for over a month about a new technology named Dojo Toolkit, which essentially is a JavaScript toolkit to create really cool looking AJAX/Web 2.0 applications. As a pet [...]]]></description>
			<content:encoded><![CDATA[<p>A while back I blogged about <strong>music theory for geeks</strong> and got a lot of feedback from my fellow musicians (some geek some not). Then I blogged for over a month about a new technology named Dojo Toolkit, which essentially is a JavaScript toolkit to create really cool looking AJAX/Web 2.0 applications. As a pet project I developed an elementary music application which shows the notes that constitute a specific key and scale/chord combination. I frankly didn&#8217;t intend to make anything out of this application and it was a simple example to experiment with certain Dojo features.</p>
<p>Turns out there are many geeks out there who were looking for something like this and I started to get requests for new features and bug fixes. More interestingly I started to use it myself in music projects. So I decided to take my simple <strong>Musician&#8217;s Helper</strong> application and promote it to its own web page, fix up a number obvious issues and make it available to anyone who is willing to use it. Now an enhanced version of Musician&#8217;s Helper is available at:</p>
<p><a title="http://music.isallicare.com" href="http://music.isallicare.com" target="_blank">http://music.isallicare.com</a></p>
<p>As you might have noticed, I changed the name from &#8220;Musician&#8217;s Helper&#8221; to &#8220;music.isallicare.com&#8221;, because I already owned this domain and it made sense to recycle it rather than inventing another name. After all I registered this domain name to keep track of things I care about, and music is no exception.</p>
<p>I want to go over the application a bit today and give you an overview of its features, information about how you can get started to use it and what you might expect in the future in terms of new functionality. If you have been following my earlier blogs about music theory, most musical theory concepts can be modeled with the simple set theory, because there are essentially twelve notes and all scales and chords can be defined as a subset of these 12 notes. <a title="http://music.isallicare.com" href="http://music.isallicare.com" target="_blank">Music.isallicare.com</a> is a tool that performs these calculations and shows the user the notes that make up a chord or a scale in a number of different views.</p>
<p>Currently the application supports a &#8220;Notation View&#8221; and a &#8220;Table View&#8221;, in which the notes that belong to a scale or chord are shown for a specific key. When you first load the application, the initial key is set to &#8220;C&#8221; and the scale/chord is set to a &#8220;Major Scale&#8221; (see Figure below, and feel free to click on it to visit the web site).</p>
<div id="attachment_580" class="wp-caption aligncenter" style="width: 310px"><a href="http://music.isallicare.com"><img class="size-medium wp-image-580  " title="music.isallicare.com" src="http://karul.org/blog/wp-content/uploads/2009/12/music.isallicare.com1_-300x205.jpg" alt="music.isallicare.com" width="300" height="205" /></a><p class="wp-caption-text">Music.IsAllICare.com initial page screenshot</p></div>
<p style="text-align: center;">
<p>The above screenshot is from a &#8220;Notation View&#8221;, with which most musicians are probably are familiar with. If you click on the tab that says &#8220;Table View&#8221;, you&#8217;ll see the same scale in a Table View as shown below. This view, which I kind of invented, is nothing more than a linear version of a common degrees circle. It shows the degrees on top and corresponding notes at the bottom. The notes of the scale or chord are highlighted with blue. As you can see, the C Major Scale is composed of C,D,E,F,G,A and B.</p>
<p style="text-align: center;">
<div id="attachment_595" class="wp-caption aligncenter" style="width: 440px"><a href="http://music.isallicare.com?key=C&amp;sc=Major_scale&amp;tab=tableView"><img class="size-large wp-image-595  " title="Screen Shot for Table View" src="http://karul.org/blog/wp-content/uploads/2010/01/table-view-1024x485.jpg" alt="Screen Shot for Table View" width="430" height="204" /></a><p class="wp-caption-text">Screen Shot for Table View</p></div>
<p>Now let&#8217;s change the key, or in proper music lingo, let&#8217;s transpose to another key. You can transpose to another key, say to F, by simply clicking on the F on the left panel, or by choosing the &#8220;Transpose Menu&#8221; and clicking on F.</p>
<p style="text-align: center;">
<div id="attachment_596" class="wp-caption aligncenter" style="width: 310px"><a href="http://karul.org/blog/wp-content/uploads/2010/01/transpose.jpg"><img class="size-medium wp-image-596  " title="Transposing the Key" src="http://karul.org/blog/wp-content/uploads/2010/01/transpose-300x148.jpg" alt="Transposing the Key" width="300" height="148" /></a><p class="wp-caption-text">Transposing the Key</p></div>
<p>After you click on F, the notes on both Views are updated to reflect the changes. The F Major Scale is composed of F, G, A, Bb (B flat), C and D.</p>
<div id="attachment_599" class="wp-caption aligncenter" style="width: 310px"><a href="http://music.isallicare.com?key=F&amp;sc=Major_scale&amp;tab=tableView"><img class="size-medium wp-image-599" title="F Major Scale" src="http://karul.org/blog/wp-content/uploads/2010/01/transposed-to-f-300x140.jpg" alt="F Major Scale" width="300" height="140" /></a><p class="wp-caption-text">F Major Scale</p></div>
<p>You obviously can repeat the same for any of the available 12 keys to immediately see which notes belong to your major scale.</p>
<p>The other important feature of the application is to show different scales or chords. If you click on the accordion panel on the left side of the screen titled &#8220;Scales&#8221;, it will show you a list of most commonly used scales. Currently the application supports the following 8 scales:</p>
<p><span style="font-family: Myriad,Helvetica,Tahoma,Arial,clean,sans-serif; font-size: 12px;"> </span></p>
<li id="Major_scale" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom; background-color: #ffffff;" onclick="updateScaleChord('Major_scale');"><span>Major</span></li>
<li id="MajorPentatonic_scale" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('MajorPentatonic_scale');"><span>Major Pentatonic</span></li>
<li id="NaturalMinor_scale" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('NaturalMinor_scale');"><span>Minor (Natural)</span></li>
<li id="HarmonicMinor_scale" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('HarmonicMinor_scale');"><span>Minor (Harmonic)</span></li>
<li id="MinorPentatonic_scale" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('MinorPentatonic_scale');"><span>Minor Pentatonic</span></li>
<li id="Diminished_scale" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom; background-color: #ffffff;" onclick="updateScaleChord('Diminished_scale');"><span>Diminished</span></li>
<li id="WholeNote_scale" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('WholeNote_scale');"><span>Whole Note</span></li>
<li id="Chromatic_scale" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Chromatic_scale');"><span>Chromatic</span></li>
<p>As in the case of the keys, simply click on the scale you want to select and all views and titles will be updated dynamically. For example, to see which notes are in the F Diminished Scale, simply click on &#8220;Diminished Scale&#8221; link on the left.</p>
<p style="text-align: center;">
<div id="attachment_601" class="wp-caption aligncenter" style="width: 310px"><a href="http://music.isallicare.com?key=F&amp;sc=Diminished_scale&amp;tab=tableView"><img class="size-medium wp-image-601 " title="F Diminished Scale (Table View)" src="http://karul.org/blog/wp-content/uploads/2010/01/f-diminished-scale-300x141.jpg" alt="F Diminished Scale" width="300" height="141" /></a><p class="wp-caption-text">F Diminished Scale (Table View)</p></div>
<p>The F Diminished Scale has the notes F, G, Ab, Bb, B, Db, D and E. Needless to say you can view the Notation View by clicking on the appropriate tab as well.</p>
<div id="attachment_602" class="wp-caption aligncenter" style="width: 310px"><a href="http://music.isallicare.com?key=F&amp;sc=Diminished_scale&amp;tab=notationView"><img class="size-medium wp-image-602" title="F Diminished Scale (Notation View)" src="http://karul.org/blog/wp-content/uploads/2010/01/f-diminished-scale2-300x141.jpg" alt="F Diminished Scale (Notation View)" width="300" height="141" /></a><p class="wp-caption-text">F Diminished Scale (Notation View)</p></div>
<p>The Chords Tab on the Left Panel works pretty much the same way the Scales Tab does. I included most of the commonly used Chords and all you have to do to see the notes contained in that chord is just to click on it.</p>
<p><span style="font-family: Myriad,Helvetica,Tahoma,Arial,clean,sans-serif; font-size: 12px;"> </span></p>
<li id="Major_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Major_chord');"><span><strong>Major</strong></span></li>
<li id="Major_dominant_seventh_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Major_dominant_seventh_chord');"><span>Major Dominant Seventh</span></li>
<li id="Major_major_seventh_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Major_major_seventh_chord');"><span>Major Major Seventh</span></li>
<li id="Major_dominant_ninth_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Major_dominant_ninth_chord');"><span>Major Dominant Ninth</span></li>
<li id="Major_dominant_eleventh_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Major_dominant_eleventh_chord');"><span>Major Dominant Eleventh</span></li>
<li id="Major_dominant_seventh_augmented_fifth_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Major_dominant_seventh_augmented_fifth_chord');"><span>Major Dominant Seventh Augmented Fifth</span></li>
<li id="Major_dominant_seventh_flat_ninth_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Major_dominant_seventh_flat_ninth_chord');"><span>Major Dominant Seventh Flat Ninth</span></li>
<li id="Major_dominant_seventh_sharp_ninth_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Major_dominant_seventh_sharp_ninth_chord');"><span>Major Dominant Seventh Sharp Ninth</span></li>
<li id="Major_sixth_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Major_sixth_chord');"><span>Major Sixth</span></li>
<li id="Major_fourth_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Major_fourth_chord');"><span>Major Fourth</span></li>
<li id="Major_added_ninth_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Major_added_ninth_chord');"><span>Major Added Ninth</span></li>
<li id="Major_sixth_ninth_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Major_sixth_ninth_chord');"><span>Major Sixth Ninth</span></li>
<li id="Suspended_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;"><span><strong>Suspended</strong></span></li>
<li id="Suspended_second_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Suspended_second_chord');"><span>Suspended Second</span></li>
<li id="Suspended_fourth_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Suspended_fourth_chord');"><span>Suspended Fourth</span></li>
<li id="Seventh_suspended_fourth_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Seventh_suspended_fourth_chord');"><span>Seventh Suspended Fourth</span></li>
<li id="Minor_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Minor_chord');"><span><strong>Minor</strong></span></li>
<li id="Minor_dominant_seventh_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Minor_dominant_seventh_chord');"><span>Minor Dominant Seventh</span></li>
<li id="Minor_major_seventh_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Minor_major_seventh_chord');"><span>Minor Major Seventh</span></li>
<li id="Minor_half_diminished_seventh_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Minor_half_diminished_seventh_chord');"><span>Minor Half Diminished Seventh</span></li>
<li id="Minor_sixth_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Minor_sixth_chord');"><span>Minor Sixth</span></li>
<li id="Minor_ninth_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Minor_ninth_chord');"><span>Minor Ninth</span></li>
<li id="Diminished_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Diminished_chord');"><span><strong>Diminished</strong></span></li>
<li id="Diminished_seventh_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Diminished_seventh_chord');"><span>Diminished Seventh</span></li>
<li id="Augmented_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Augmented_chord');"><span><strong>Augmented</strong></span></li>
<li id="Augmented_seventh_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Augmented_seventh_chord');"><span>Augmented Seventh</span></li>
<li id="Augmented_major_seventh_chord" style="border-style: solid; border-width: 1px; margin: 1px; padding: 5px; font-size: 10pt; color: #000000; cursor: pointer; list-style-type: none; vertical-align: bottom;" onclick="updateScaleChord('Augmented_major_seventh_chord');"><span>Augmented Major Seventh</span></li>
<p>Now that we covered the basics, I like to go over a couple of other features, you might want to have a look. One of them is the <strong>Link to this page</strong> feature. On any key scale/chord combination you can click this button to generate an HTML code that links directly to the page you are currently viewing. This might come in handy while you are blogging and need to refer to a Chord or a Scale.</p>
<div id="attachment_610" class="wp-caption aligncenter" style="width: 310px"><a href="http://karul.org/blog/wp-content/uploads/2010/01/link-to-this-page.jpg"><img class="size-medium wp-image-610" title="Link to this page Feature" src="http://karul.org/blog/wp-content/uploads/2010/01/link-to-this-page-300x214.jpg" alt="Link to this page Feature" width="300" height="214" /></a><p class="wp-caption-text">Link to this page Feature</p></div>
<p>Another new feature is the <strong>Alternate Names for Chords</strong>. There are a large number of names and/or symbols associated with different chords (which sometimes gets quite confusing), and now the application gives a list of commonly used alternate names and symbols, where they are available.</p>
<div id="attachment_611" class="wp-caption aligncenter" style="width: 310px"><a href="http://karul.org/blog/wp-content/uploads/2010/01/alternate-names.jpg"><img class="size-medium wp-image-611" title="Alternate Chord Names" src="http://karul.org/blog/wp-content/uploads/2010/01/alternate-names-300x198.jpg" alt="Alternate Chord Names" width="300" height="198" /></a><p class="wp-caption-text">Alternate Chord Names</p></div>
<p>Before  I conclude today&#8217;s Blog, I like to list some of the possible future feature enhancements and known issues. If you have other features in mind, have software bugs or content inaccuracies to report, please drop me a line and I&#8217;ll try to fix them.</p>
<ul>
<li>A Piano View</li>
<li>A Guitar Keyboard View</li>
<li>A Bass Keyboard View</li>
<li>Allow the use of sharps as well as flats</li>
<li>Use natural sign after a flat sign on the Notation View</li>
<li>Add modal scales</li>
</ul>
<p>In the distant future</p>
<ul>
<li>Allow to upload Lead Sheets and the ability to transpose them</li>
<li>Include common progressions and the ability to transpose them</li>
<li>Show chord inversions</li>
</ul>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://karul.org/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://karul.org/blog/2010/01/introducing-music-isallicare-com/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Book Review: Before the Big Bang by Brian Clegg</title>
		<link>http://karul.org/blog/2009/12/book-review-before-the-big-bang-by-brian-clegg/</link>
		<comments>http://karul.org/blog/2009/12/book-review-before-the-big-bang-by-brian-clegg/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 16:19:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Science]]></category>
		<category><![CDATA[Big Bang]]></category>
		<category><![CDATA[Book Review]]></category>
		<category><![CDATA[Brane]]></category>
		<category><![CDATA[Cosmology]]></category>
		<category><![CDATA[M-Theory]]></category>
		<category><![CDATA[String Theory]]></category>
		<category><![CDATA[Universe]]></category>

		<guid isPermaLink="false">http://karul.org/blog/?p=522</guid>
		<description><![CDATA[Before the Big Bang: The Prehistory of Our Universe by Brian Clegg
<p>ISBN 0-312-48547-1 $25.99 US/$32.99 CAD</p>
<p>I read a short review of this book in one of the magazines I am regular of, so I borrowed it from the library. As I often do, I took notes while I was reading the book and this blog [...]]]></description>
			<content:encoded><![CDATA[<h3>Before the Big Bang: The Prehistory of Our Universe by Brian Clegg</h3>
<p>ISBN 0-312-48547-1 $25.99 US/$32.99 CAD</p>
<p>I read a short review of this book in one of the magazines I am regular of, so I borrowed it from the library. As I often do, I took notes while I was reading the book and this blog entry is basically a summary of my notes.</p>
<p>Chapter 1 is the Big Bang primer, which summarizes the history of the Big Bang theory. Although I am quite familiar with the history of this theory,  I nevertheless enjoyed reading the story behind it again, especially the anecdotes about Hoyle. Hoyle was one of the biggest criticizers of the theory, yet he inadvertently coined the name &#8220;Big Bang&#8221;, reportedly to derogate the theory not to help it out. Ironically his simple and striking name helped the theory gain popularity and acceptance.</p>
<p>Chapter 2 is named &#8220;Enter the Creator&#8221; and dives into the philosophical aspects of the Big Bang theory, which, for some people implies that the universe was actually created [by something]. It didn&#8217;t really help as the scientist, Georges Lemaitre who suggested the theory was also a priest. Clegg nevertheless keeps a neutral tone and states different ideas rather than stating his own.</p>
<p>Chapter 3 is called &#8220;What and How Big?&#8221; and it is an overview of what people thought universe was and how they struggled to measure its size through history. His reference to the race between Achilles and a tortoise to explain the paradox of having an infinite series that adds up to a finite value reminded me one of my favorite books &#8220;Escher, Goedel and Bach&#8221; by Douglas Hofstadter, which I probably should read a third time.</p>
<p>Chapter 4 is called &#8220;How Old?&#8221; and is somewhat similar to the previous chapter in that it travels through history to tell the story of people&#8217;s interpretation of the universe&#8217;s age. As with the previous chapters, it has an easy-to-read popular-science style narrative, which is fun to read.</p>
<p>Chapter 5 is &#8220;A Bang or a Whimper?&#8221; and this is where Clegg starts to vocalize his discomfort about the Big Bang theory, and complains that it is almost accepted as a fact these days, even though there are significant problems with it.  He again delightfully goes over the history of discoveries which lead to the Big Band theory, most significantly the Hubble&#8217;s discovery of expanding universe (if something is expanding, it should have started somewhere). The tragicomic story of Alpher, Bethe and Gamov never gets old, no matter in how many different books I&#8217;ve read it in before. One interesting concept he stipulates in this chapter is the idea that gravity is actually is a form of negative energy. He reasons, instead of saying a falling object loses its potential energy and gains kinetic energy, one can say the object gains negative energy as it approaches a big mass due to gravity. As all matter is positive energy (i.e. E-mc2) and gravity is negative, he reasons, the universe actually can come out of nothing where positive and negative energy balances each other (or gravity balances matter).</p>
<p>Chapter 6 is &#8220;Keeping Things Steady&#8221; and is all about steady state theories of the universe, which were doomed by the Big Bang theory. This chapter is also about Hoyle, and his losing battle against the Big Bang theory.</p>
<p>Chapter 7 is called &#8220;Inflating the Truth&#8221; and starts talking about the problems about the Big Bang theory, which by now is the only viable theory after steady state theory is crushed. Some of the issues discussed are how universe expanded faster than the speed of night, considering nothing can travel that fast.  Clegg elaborates on Heisenberg&#8217;s uncertainty principle to set the stage for Wilson and Penzias&#8217; discovery of the cosmic background radiation, and of course the now famous pigeon droppings they had to clean in their struggle to eliminate noise. The recent mishap at the CERN accelerator because of a baguette dropped by a bird makes me wonder what&#8217;s with the birds and secrets of the universe. Clegg here again vocalizes his discomfort about the Dark Matter and Dark Energy, about which we have absolutely no scientific evidence but use them the explain the anomalies in the expansion of the universe. He likens them to the ether, that was invented by Victorian scientists to explain how light waves travel in empty space. He again compares Dark Energy to Einstein&#8217;s cosmological constant, which he kind of had to introduce into his equation for mathematical reasons even though there is no physical explanation to it. This chapter also talks about the gravitational waves, that should be created by the Big Bang, and the fact that we don&#8217;t have sensitive enough devices to measure them.</p>
<p>Chapter 8 is &#8220;Let there be time&#8221;, and sure enough talks about time. As any other text about time, this chapter has enough mind boggling questions like &#8220;Was there time before the Big Bang, or was it created with Big Bang?&#8221;. No wonder Clegg suggests the reader to go and grab a coffee before starting this chapter. Frankly he is not being fair to himself as I really enjoyed reading it. His analogy of Augustine questioning the idea of time before creation and how this is relevant to existence of time before the Big Bang is brilliant. Augustine&#8217;s idea of time was no different than Einstein&#8217;s relativistic universe, where time is just like another dimension of space and was created with the Big Bang just like the space; therefore there is no &#8220;before&#8221; the Big Bang.</p>
<p>Chapter 9 is interestingly called &#8220;Groundhog Universe&#8221; in reference to one of my, and apparently Clegg&#8217;s, favorite movies &#8220;The Groundhog Day&#8221; starring Bill Murray. This chapter investigates the possibility of a cyclic universe where the universe crunches and bangs periodically. This conveniently solves the problem of where the universe came from. Clegg introduces the string and m-theory in this chapter and gives a quick description of strings, branes, and speculations on what actually the &#8220;M&#8221; in the M-theory might stand for.  Although Clegg shows his enthusiasm about the M-theory, he also states that it doesn&#8217;t predict anything new, makes arbitrary assumptions and not even sure if it can be considered as a theory. It&#8217;s not the first time I&#8217;ve heard about crashing branes to explain Big Bang, but his narrative is quite interesting, especially the way he explains the dark matter as possibly being a brane to brane interaction. Clegg also speculates that if no gravitational waves are discovered after the technology advances enough to measure them, that will put a nail into Big Bang theory&#8217;s coffin. We&#8217;ll have to wait and see.</p>
<p>Chapter 10 is called &#8220;Living in a Bubble&#8221;. speculates that there are multiple universes bubbling up and ours is not probably the only one. Concepts such as evolution of universes and natural selection, phantom multiverses, quantum multiverses and wormholes are discussed here. One interesting point was the possibility of having a parallel universe as close as a millimeter apart (not sure how they measured this) in a dimension we can&#8217;t perceive, which might explain dark matter and dark energy as a leakage of gravity from one universe to another.</p>
<p>Chapter 11 is &#8220;Welcome to the Matrix&#8221;, is probably my favorite chapter of the entire book. Not just because he refers to one of my most favorite movies (again), the Matrix, but Clegg rightfully identifies the script issue where the matrix uses humans as a source of energy in an otherwise absolutely perfect story-line. I also enjoyed this chapter because my academic background is in simulation and modeling, especially probabilistic models, and Clegg does a good job of explaining the non-deterministic nature of the universe. The reference to Matrix leads to ideas of Universe as a computer, where every particle is an information bit and the fact that they constantly collide with each other is the action of information processing. From non-deterministic nature comes the qubits and a short reference to quantum cryptography, where he postulates the possibility of all cryptographic systems becoming useless (and me losing my career in cryptography &#8211; good thing quantum computers aren&#8217;t coming anytime soon).</p>
<p>Chapter 12, the final chapter, is called &#8220;Snapshot Universe&#8221;. It entertains the possibility of the Universe being a Hologram. It also talks about the problem of losing information when matter goes into a black hole, which apparently is against the second law of thermodynamics. With another jump to quantum physics and EPR experiments, Clegg discusses quantum entanglement and locality concepts to state the fact that invisible forces of nature travels at the speed of light, whereas quantum potential, a new force suggested by Bohm doesn&#8217;t have to.</p>
<p>Overall the book is a fun and easy read, with almost no technical lingo. The sections which summarize historical facts are interesting and well written. The book is not all about history and known dry facts one can find in an encyclopedia though. Clegg is not shy about expressing his own point of view against the Big Bang theory, albeit he does it as an objective way you would expect from a scientist. Although his argument against Big Bang did not convert me to the other side instantly, it sure re-ignited my interest in the string and m-theories and opened my eyes to the possibility that there might be other explanations for the expanding universe than the &#8220;Big Bang Theory&#8221;.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://karul.org/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://karul.org/blog/2009/12/book-review-before-the-big-bang-by-brian-clegg/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Outside the Box Look at Public Key Encryption III: Signing and Certification</title>
		<link>http://karul.org/blog/2009/11/an-outside-the-box-look-at-public-key-encryption-iii-signing/</link>
		<comments>http://karul.org/blog/2009/11/an-outside-the-box-look-at-public-key-encryption-iii-signing/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 05:00:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[PKI]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[decryption]]></category>
		<category><![CDATA[Public Key Encryption]]></category>
		<category><![CDATA[symmetric encryption]]></category>

		<guid isPermaLink="false">http://karul.org/blog/?p=518</guid>
		<description><![CDATA[<p>One very handy feature of public key encryption is that both the public or the private key can be used to encrypt something, which can then only be decrypted with the remaining key. If you remember from my previous Blog entry, I mainly focused on the case where someone encrypts a message with a public [...]]]></description>
			<content:encoded><![CDATA[<p>One very handy feature of public key encryption is that both the public or the private key can be used to encrypt something, which can then only be decrypted with the remaining key. If you remember from my <a title="An Outside the Box Look at Public Key Encryption II: Asymmetric Encryption" href="http://karul.org/blog/2009/11/an-outside-the-box-look-at-public-key-encryption-ii-asymmetric-encryption/" target="_blank">previous Blog entry</a>, I mainly focused on the case where someone encrypts a message with a public key, so it can only be decrypted with the corresponding private key. This time I&#8217;ll try to demonstrate that doing just the opposite, that is, encrypting something with your own private key serves as a way to digitally sign your message.</p>
<p>As private and public keys can be used interchangeably, when someone uses his private key to encrypt something, anyone should be able decrypt that message with the corresponding public key. At first this looks totally pointless, as why would someone like to encrypt something others can decrypt using a publicly available key after all? The answer is because by encrypting something with your private key, which can independently be verified to be yours (using your public key), you are essentially certifying that is was created and encrypted by you.</p>
<p>This is not very much different than ordinary ways of proving authenticity; such as sealing an envelope, signing a document with your hand writing, sealing a parchment with seal wax, etc. They all are some sort of, so called &#8220;temper evident&#8221; containers that provide the recipient some level of guarantee of its authenticity. &#8220;Temper Evidence&#8221; is a very important concept as certification wouldn&#8217;t mean anything if we were not able to verify &#8220;what&#8221; was actually signed or sealed as much as &#8220;who&#8221; it was signed by.</p>
<p>So how do we know that someone has not altered a message before we had a chance to view it? When a message (or any computer file for that matter) is encrypted with the originator&#8217;s private key, it can be decrypted by anyone who has access to the originator&#8217;s public key, which will automatically verify the authenticity of its origin. If the message has been changed even by a bit, the decryption will entirely fail, so the third party would know that the message was altered. There is however a practical issue here as the message recipient needs to decrypt the message to be able to read it. If the recipient doesn&#8217;t have the needed software to decrypt the message, or if the message has been corrupted because it was tempered with, or even in the case where the recipient simply isn&#8217;t willing to be bothered by decryption, s/he will not be able to read the message. Another issue is that encryption and decryption operations are CPU intensive, and it will get progressively longer to decrypt as the file size increases.</p>
<p>The hash algorithms (<a title="Cryptographic Hash Functions" href="http://karul.org/blog/2008/09/cryptographic-hash-functions/" target="_blank">see my related Blog Entry here</a>) can help solve both problems. A hash algorithm creates a small fixed-size digest of a file of any size and will squish the original file into a fixed, much smaller size. In other words, any file regardless of their size, will create a relatively small signature that is very hard to temper with. When this smaller version of the payload (i.e. the hash of the original document) is encrypted with the originator&#8217;s private key, the recipient can independently hash the original message again and compare it with the hash that comes with the message (of course after decrypting it with the sender&#8217;s public key first). This therefore both improves performance significantly by keeping the cryptographic operations to a fixed small size and also retains the original document in the clear, which enables anyone to be able to read it whether they have the infrastructure to validate signatures (i.e. able decrypt) or not.</p>
<p>Now we can go back to our &#8220;drop box&#8221; from my <a title="     An Outside the Box Look at Public Key Encryption I: Symmetric Encryption » An Outside the Box Look at Public Key Encryption II: Asymmetric Encryption" href="http://karul.org/blog/2009/11/an-outside-the-box-look-at-public-key-encryption-ii-asymmetric-encryption/" target="_blank">previous blog entry</a> to explain this better. We used the analogy of ordinary mail boxes to show how Public Key Encryption works.  Now take the same box, and topple it over so the top door is locked with your private key, and the key for the bottom door is attached on the lid with a chain (i.e. it is public), so anyone can open it. If you had an announcement to make, but wanted to make sure that everyone knew it came from you and not from some impostor pretending to be you, you can simply lock copies of your announcement in the top box. Assuming that there is a fancy mechanical mechanism to dispense one announcement at a time, and your audience cannot reach in to replace your original messages; you are essentially signing your announcements.</p>
<p>Not exactly used for security reasons, but vending machines are probably the closest examples of our box model. When you are buying a pop or a candy bar, because they come from a locked location, you have some level of comfort that the contents are not tempered with. The sealed bottle lid or candy bar packaging serves a similar purpose as any alteration in the packaging will alert you. Automated newspaper vending boxes are probably the closest in terms of functionality and appearance to our boxes. Someone locks the newspapers in the top box and newspapers are dispensed at the bottom one at a time.</p>
<div id="attachment_556" class="wp-caption aligncenter" style="width: 310px"><a href="http://karul.org/blog/wp-content/uploads/2009/11/newspaper-vending.jpg"><img class="size-medium wp-image-556" title="Newspaper Vending Machines" src="http://karul.org/blog/wp-content/uploads/2009/11/newspaper-vending-300x225.jpg" alt="Newspaper Vending Machines" width="300" height="225" /></a><p class="wp-caption-text">Newspaper Vending Machines</p></div>
<p>As is the case of PKI, we can build a box which will serve both functions at the same time:</p>
<ul>
<li> keep your inbound messages secure and secret (encryption)</li>
<li>sign your outbound messages so people believe that they are coming from you (non-repudiation)</li>
</ul>
<p>So our PKI box design now looks like this:</p>
<ol>
<li> The top door works like Canada Post boxes. It is locked by your public key, which is attached to the lid of the door. Anyone willing to give you a secret message can open the top door, drop the message in and close the door again. The message will drop to the middle section once the door is closed.</li>
<li>The middle door is locked with your private key. This is like a safe deposit box and serves two purposes. For one, it keeps the messages that were dropped for you through the top door. And it also keeps your announcements that will be received from the bottom door, which is explained in the next bullet point.</li>
<li>The bottom door is again locked with your public key which is attached to the door for convenience. Just like a newspaper vending box, the front door is probably transparent, so your friends can see that you have an announcement to make. As the only way to place these messages in the third box is to drop them from the second l(locked) evel, it gives them a level of confidence that you actually are the author of that announcement.</li>
</ol>
<div id="attachment_558" class="wp-caption aligncenter" style="width: 226px"><a href="http://karul.org/blog/wp-content/uploads/2009/11/pki-box.jpg"><img class="size-medium wp-image-558" title="Public Key Encryption Box" src="http://karul.org/blog/wp-content/uploads/2009/11/pki-box-216x300.jpg" alt="Public Key Encryption Box" width="216" height="300" /></a><p class="wp-caption-text">Public Key Encryption Box</p></div>
<p>Now there is only one problem. Even if we assume that the box is strong enough to withstand abuse, how do we know that someone didn&#8217;t replace the entire box? If someone did so and fooled your friends to believe that this is your box, he will be collecting your secret messages and even making certified announcements impersonating you. So &#8220;<span><span>Quis</span></span> <span><span>custodiet</span></span> <span><span>ipsos</span></span> <span><span>custodes</span></span>?&#8221; or &#8220;Who will watch the watchers?&#8221;.</p>
<p>This is not a technical problem, it is a fundamental issue of trust. Who do you really trust? Someone you know, the government, family and friends, or no one? Take a real life case where you are trying to get your passport, which is a document that makes a foreign country believe you are who you say you are. At the top level another country trusts your country. Then the government trusts a hierarchy of officers who are in charge of issuing passports. Then this government officer (or a number of them) views your application to decide to give you your passport or not. Once you receive your passport you now have a document that contains a &#8220;chain of trust&#8221; you can use to cross borders.</p>
<p>In the PKI world it is not much different. As anyone with the right software or mathematical background can generate two prime numbers, someone to have a public and private key pair doesn&#8217;t prove much about his identity (although they are perfectly OK to encrypt and decrypt). So the a similar <span>concept</span> of chain of trust exhibits itself in PKI as well, which is achieved by simply signing the public credentials of key owners (collectively <span>referred</span> to as a certificate). Such signing authorities are called Certification Authorities (CA) and their trustworthiness is somewhat warranted by the fact that they are either governments, huge companies or security solution vendors that are audited by independent third-party authorities. In practice, whether <span>someones</span> certificate will be trusted or not pretty much depends on whether your operating system, browser, or cell phone comes with the root certification authorities&#8217; certificate.  The software then climbs up your certificate chain to see if it can trust anyone who vouched for you.</p>
<p>It is also possible to emulate the chain of trust in the world of boxes. All you have to do is to put your boxes in bigger boxes, or rooms to make it a better example. Just like the safe deposit boxes at a bank, we can put our boxes in a room that has a locked entry. Simply because there is no free entry to the room, you are more likely to believe that the box you are getting a signed message from is authentic. It is a lot harder to swipe boxes now, and the message owner probably was escorted inside with the room key owner essentially vouching for the box owner. If you can envision many rooms in a building, each of which containing a number of boxes, you pretty much get how chain of trust works in PKI as well. The same question still remains though. How do you trust the top level entity? The answer is &#8220;you just do&#8221; because either top entity is too big or well known to suspect, or is trusted by another <span>entity</span> that is.</p>
<p>And this concludes my &#8220;An <span>Outside</span> the Look at Public Key Encryption&#8221; <span>trilogy</span>. Next time you need to deal with Public Key Encryption, remember that it is all that different than a post box screwed on a newspaper vending machine.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://karul.org/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://karul.org/blog/2009/11/an-outside-the-box-look-at-public-key-encryption-iii-signing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Outside the Box Look at Public Key Encryption II: Asymmetric Encryption</title>
		<link>http://karul.org/blog/2009/11/an-outside-the-box-look-at-public-key-encryption-ii-asymmetric-encryption/</link>
		<comments>http://karul.org/blog/2009/11/an-outside-the-box-look-at-public-key-encryption-ii-asymmetric-encryption/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 02:46:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[PKI]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[AES]]></category>
		<category><![CDATA[asymmetric encryption]]></category>
		<category><![CDATA[decryption]]></category>
		<category><![CDATA[DES]]></category>
		<category><![CDATA[Public Key Encryption]]></category>
		<category><![CDATA[public key infrastructure]]></category>
		<category><![CDATA[symmetric encryption]]></category>

		<guid isPermaLink="false">http://karul.org/blog/?p=482</guid>
		<description><![CDATA[<p>Last week I went through symmetric encryption, and explained why it is not accepted as a great fit for secure communication. Today I&#8217;ll talk about asymmetric encryption and public key infrastructure.</p>
<p>The invention of asymmetric encryption as we use it today is attributed to a publication by Whitfield Diffie and Martin Hellman in 1976, who were [...]]]></description>
			<content:encoded><![CDATA[<p><a title="An Outside the Box Look at Public Key Encryption I: Symmetric Encryption" href="http://karul.org/blog/2009/11/an-outside-the-box-look-at-public-key-encryption-i-symmetric-encryption/" target="_blank">Last week</a> I went through symmetric encryption, and explained why it is not accepted as a great fit for secure communication. Today I&#8217;ll talk about asymmetric encryption and public key infrastructure.</p>
<p>The invention of asymmetric encryption as we use it today is attributed to a publication by <strong>Whitfield Diffie </strong>and<strong> Martin Hellman</strong> in 1976, who were inspired by <strong>Ralph Merkle&#8217;s</strong> work. Their article was the first theoretical method to exchange keys in a non-secured communications channel without the knowledge of a previously agreed key, which later came to be known as <strong>Diffie-Hellman key exchange</strong>.</p>
<p>Diffie and Hellman&#8217;s work assumed a theoretical <strong>trap function</strong>, where one way calculation is easy and fast, where the inverse function is a lot harder and takes significantly longer to calculate. They didn&#8217;t describe exactly what this function could be, so their work didn&#8217;t become a practical solution until 3 MIT scientists <strong>Rivest</strong>, <strong>Shamir </strong>and <strong>Adleman</strong>, came up with a mathematical function that did exactly that a year after in 1977. This algorithm was published in 1978 and came to known as <strong>RSA </strong>(first letters of their last names), and involves the factoring of large prime numbers.</p>
<p>I will not go into details of how this works mathematically, but I&#8217;ll try to explain why it solves the key distribution problem. Think of RSA algorithm as a one way <strong>trap function</strong>, where calculating in one direction is much easier than calculating in the other way. There are a lot of examples for such trap functions in our daily life that works exactly as mathematical one-way functions.</p>
<p>The following subway station exit gate allows people to walk in one direction, but would not let them go the other way. I took this picture in my neighbourhood subway station and this particular gate is at the unattended side of the subway exit. It allows a commuter to push the rotating metal gates counterclockwise to get out (i.e. on the left side on the picture, on the right side when they are coming outside), but they cannot turn the gate clockwise. This design lets commuters go outside freely but won&#8217;t let them in as the right side is blocked with interlocking metal bars.</p>
<div id="attachment_505" class="wp-caption aligncenter" style="width: 310px"><a href="http://karul.org/blog/wp-content/uploads/2009/11/subway-door.jpg"><img class="size-medium wp-image-505" title="Subway Exit Door" src="http://karul.org/blog/wp-content/uploads/2009/11/subway-door-300x225.jpg" alt="Subway Exit Door" width="300" height="225" /></a><p class="wp-caption-text">Subway Exit Door</p></div>
<p>Following is another example, which my friends used to pull pranks with when I was a kid. If  you drop one of these in someone&#8217;s collar, it is almost impossible for them to reverse it and take it out. They can only push it forward because the wheat&#8217;s shape only allows motion in one direction and not in the opposite way. (Note that this is not a good joke and I&#8217;m not endorsing this by any means)</p>
<div id="attachment_506" class="wp-caption aligncenter" style="width: 166px"><a href="http://karul.org/blog/wp-content/uploads/2009/11/wheat-copy.jpg"><img class="size-full wp-image-506" title="Wheat" src="http://karul.org/blog/wp-content/uploads/2009/11/wheat-copy.jpg" alt="Wheat" width="156" height="226" /></a><p class="wp-caption-text">Wheat</p></div>
<p>But as we were talking about boxes last week, I&#8217;ll give you my favorite <strong>one-way trap function</strong> analogue. It is a box design used by Canada Post, and  a number of other charities for donation boxes. This ingenious design is a tall box which has two doors. The top door has a handle and opens about 45 degrees forward to let a person drop an object (mail, donation, etc.). The interior design creates a holding space to keep the object temporarily. When you close the lid, your object drops further down to the bottom section (where the second door is), and you can no longer reach in to get it back.</p>
<div id="attachment_500" class="wp-caption aligncenter" style="width: 130px"><a href="http://karul.org/blog/wp-content/uploads/2009/11/canada-post11.jpg"><img class="size-full wp-image-500" title="Canada Post Mail Box" src="http://karul.org/blog/wp-content/uploads/2009/11/canada-post11.jpg" alt="Canada Post Mail Box" width="120" height="240" /></a><p class="wp-caption-text">Canada Post Mail Box</p></div>
<p>Next time you open the top lid it is now empty and ready for your next package.  The bottom door is a regular door with a lock on it, similar to what we used for symmetric encryption example <a title="An Outside the Box Look at Public Key Encryption I: Symmetric Encryption" href="http://karul.org/blog/2009/11/an-outside-the-box-look-at-public-key-encryption-i-symmetric-encryption/" target="_blank">last week</a>. Whatever falls from the above chute is collected at the bottom compartment until someone with the key comes to pick them up. Canada Post uses this design to let people drop their mails and packages, without the possibility of other people to open the top door and reach in to steal them.</p>
<div id="attachment_502" class="wp-caption aligncenter" style="width: 170px"><a href="http://karul.org/blog/wp-content/uploads/2009/11/canada-post21.jpg"><img class="size-full wp-image-502" title="Canada Post Mail Box - Opened" src="http://karul.org/blog/wp-content/uploads/2009/11/canada-post21.jpg" alt="Canada Post Mail Box - Opened" width="160" height="120" /></a><p class="wp-caption-text">Canada Post Mail Box - Opened</p></div>
<p>The key to the bottom door is only available to a Canada Post employee who comes to pick up the mail every now and then. Larger boxes are often used by charities for people to drop unwanted clothing or food to help those in need.</p>
<p>As simple as it looks, this basic box design is almost identical to how RSA algorithm works. I&#8217;ll just make a simple change on the box design to make certain RSA terminology to make more sense, which will not effect the end result in any way.</p>
<p>Instead of having an unlocked lid, I&#8217;ll put another lock at the top door, but the key of that lock will be chained to the handle of the lid this time. In other words, instead of just reaching the handle to open the lid, now you&#8217;ll need to unlock the lid with the key that is hanging there and then drop your package in. This is kind of pointless, but in the end it doesn&#8217;t change the fact that anyone can drop a package because they can simply take the dangling key and open the top lid. If you really need a reason, assume this is a food-bank drop box and you want the raccoons out of your box.</p>
<div id="attachment_497" class="wp-caption aligncenter" style="width: 210px"><a href="http://karul.org/blog/wp-content/uploads/2009/11/box2.jpg"><img class="size-medium wp-image-497" title="Public Key Drop Box" src="http://karul.org/blog/wp-content/uploads/2009/11/box2-200x300.jpg" alt="Public Key Drop Box" width="200" height="300" /></a><p class="wp-caption-text">Public Key Drop Box</p></div>
<p>As you have noticed, we now have 2 keys on our box. The top key is hanging there and available to anyone who is willing to use it, therefore it is <strong>public</strong>. The bottom key belongs to a specific person and is kept secure, therefore it is <strong>private</strong>. Before going back to the 4 boys&#8217; secure communication problem we discussed <a title="An Outside the Box Look at Public Key Encryption I: Symmetric Encryption" href="http://karul.org/blog/2009/11/an-outside-the-box-look-at-public-key-encryption-i-symmetric-encryption/" target="_blank">last week</a>, let me briefly summarize how RSA algorithm works. The algorithm uses two prime numbers, where</p>
<ul>
<li>whatever information  is encrypted with one prime number can only be decrypted with the other one (works in both ways)</li>
<li>it is computationally infeasible (that is almost impossible) to derive one prime number using the other one</li>
</ul>
<p>The technical details of the algorithm can be found in MIT <a title="Cryptographic communications system and method" href="http://www.google.com/patents?vid=4405829" target="_blank">patent</a> by Rivest, Shamir and Adleman<a title="Cryptographic communications system and method" href="http://www.google.com/patents?vid=4405829" target="_blank"></a>.</p>
<p>What this means is that one can create a trap function that is easy to calculate in one direction, but it is almost impossible to go the other way. In this crypto-system once a message is encrypted with one of the prime numbers, say <strong>p</strong>, it can only be decrypted with the other one, say <strong>q</strong>. So if one person keeps one of the keys secret (<strong>private key</strong>) and give the other one to others, s/he can decrypt anything encrypted with the distributed key, which is sure enough called the <strong>public key</strong>.</p>
<p>Let&#8217;s go back to our drop box to explain what this really means in plain English. If I had one of these drop boxes, I would be the only person who has access to the key for the bottom box. If someone wanted give me a secret message, all they need to do is to open the top door with the public key and drop their messages in. To do that they don&#8217;t need to know me or I don&#8217;t need to distribute any keys. Their key is useless to open the bottom door to reach my private messages, including their very own message. The public key therefore doesn&#8217;t have to be secret, and that&#8217;s why we hang it to the handle for anyone to use. Once the message is in and the door is closed. there is no way for them to take it back. The recipient however can unlock the bottom door and read her/his messages.</p>
<p>The four boys in <a href="http://karul.org/blog/2009/11/an-outside-the-box-look-at-public-key-encryption-i-symmetric-encryption/" target="_blank">last week&#8217;s example</a> will benefit a lot from this setting. In this case each boy needs only a box and a private key. Each box will have a public key that is shared by all the others. When A needs to share a secret with B, he will simply drop it into B&#8217;s box. Same thing is valid for C and D.  As long as the boys know which box to put the secret replies in, all messages will be confidential.</p>
<div id="attachment_507" class="wp-caption aligncenter" style="width: 310px"><a href="http://karul.org/blog/wp-content/uploads/2009/11/4-boys-assymetric.jpg"><img class="size-medium wp-image-507" title="Example for Assymetric Encryption" src="http://karul.org/blog/wp-content/uploads/2009/11/4-boys-assymetric-300x149.jpg" alt="Example for Assymetric Encryption" width="300" height="149" /></a><p class="wp-caption-text">Example for Asymmetric Encryption</p></div>
<p>All of a sudden, instead of needing 21 boxes and 32 keys, the 4 boys now need only 4 boxes and 8 keys (4 private and 4 public). The difference gets bigger and bigger as more people are involved. Instead of growing exponentially as in symmetric encryption, asymmetric encryption box and key size grows linearly with the number of involved parties. So in theory everyone in the world can exchange secure messages if they had a box and two keys, one for them and one for the rest of the world to use.</p>
<p>The two major problems of symmetric encryption disappears in asymmetric encryption because:</p>
<ul>
<li>Key distribution is no longer an issue as public keys don&#8217;t need to be secret. You can just hang it on the box or send along with an email without exposing any sensitive information.</li>
<li>The exponential growth of number of boxes and keys is no longer an issue, because you need exactly one box and two keys per person.</li>
</ul>
<p>So next time you hear phrases like key generation, public key, private key, key exchange, key pair, key generation etc. don&#8217;t panic. All they are talking about is generating two random prime numbers, one to unlock your bottom box, and one to hang on the top handle for anyone else to use.</p>
<p>You&#8217;ll also hear phrases like signing, signing authority, certificates, certification authority, signature, etc. which is what I&#8217;ll talk about next week.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://karul.org/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://karul.org/blog/2009/11/an-outside-the-box-look-at-public-key-encryption-ii-asymmetric-encryption/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Outside the Box Look at Public Key Encryption I: Symmetric Encryption</title>
		<link>http://karul.org/blog/2009/11/an-outside-the-box-look-at-public-key-encryption-i-symmetric-encryption/</link>
		<comments>http://karul.org/blog/2009/11/an-outside-the-box-look-at-public-key-encryption-i-symmetric-encryption/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 17:57:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[PKI]]></category>
		<category><![CDATA[Science]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[decryption]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[Public Key Encryption]]></category>
		<category><![CDATA[symmetric encryption]]></category>

		<guid isPermaLink="false">http://karul.org/blog/?p=466</guid>
		<description><![CDATA[<p>PKI, or Public Key Infrastructure has been around for over 3 decades now, yet it is still an enigma for your average lay-person even though they use it regularly while they are shopping online, exchanging encrypted emails or using other security systems. Yet, only a fraction of users really understand what exactly a certificate is, [...]]]></description>
			<content:encoded><![CDATA[<p>PKI, or Public Key Infrastructure has been around for over 3 decades now, yet it is still an enigma for your average lay-person even though they use it regularly while they are shopping online, exchanging encrypted emails or using other security systems. Yet, only a fraction of users really understand what exactly a certificate is, should they trust it, or more accurately why they should trust it.</p>
<p>As part of my job I design and implement security software that uses PKI as its basis, and often end up giving crash courses to a wide variety of audiences; ranging from software developers to business people, or customers who are not necessarily well versed in the area of information security.</p>
<p>I won&#8217;t try to claim that the mathematics behind PKI is simple, just because it isn&#8217;t. But neither is the physics behind semi-conductors, yet very few of us have a problem using a flat screen television or a computer. I believe the real difficulty of understanding PKI originates from the fact that most people don&#8217;t have a visual analogue they can use as a reference point, which in many cases makes complex phenomena a lot easier to grasp.</p>
<p>At least that&#8217;s how it works for me. So when I started to work with cryptography and PKI in general, I started to look for objects that are analogous to certain cryptographic concepts. Over time I came up with a number of &#8220;boxes&#8221; that provide good physical representations for symmetric and asymmetric encryption, signing, trust chains, etc. which can sometimes get tricky to visualize.</p>
<p>When I&#8217;m working on a security system design, I visualize these boxes, often multiple boxes working together to solve one specific problem. So if you are trying to understand PKI and textbook definitions are not working for you, read on and my boxes might just help.</p>
<h2>Symmetric Encryption</h2>
<p>Let&#8217;s start with the simplest form of encryption. As I have explained in one of my earlier blog <a href="http://karul.org/blog/2008/09/cryptography-basics/" target="_blank">entries</a>, symmetric encryption means that the same key is used both to encrypt and decrypt the same object. This is analogous to a simple box with a lock on it. Not much different than a locker you&#8217;d find at a gym, or a locked room, or a safe deposit box.</p>
<p><a href="http://karul.org/blog/wp-content/uploads/2009/11/box1.jpg"><img class="aligncenter size-medium wp-image-473" title="box1" src="http://karul.org/blog/wp-content/uploads/2009/11/box1-275x300.jpg" alt="box1" width="275" height="300" /></a></p>
<p>It is a closed box, so nobody can open it unless they have the key. If you have something valuable and don&#8217;t want others to have a look at it, you just simply lock it up in your box and keep the key secret. Similarly, if you have a secret computer file, you encrypt it with your key and only those who have access to that key can decrypt it back. In either situation you use the same key to lock or unlock your secret.</p>
<p>As are symmetric cryptographic algorithms, some boxes are stronger than the others. Actual box keys and cryptographic keys have similar properties as well. Whether they are used by a cryptographic algorithm or a wooden box, the &#8220;keys&#8221; can be objects (a metal key or a X509 key file) or just some information (numbers you memorize to open a combination lock or your encryption password). Symmetric encryption is perfect to keep secrets, but has its limitations to &#8220;share secrets&#8221;.</p>
<p>Let me explain why locking and sharing doesn&#8217;t work well with a real life example where a group of people, say 4, are<br />
using these boxes to exchange secrets. Think of 4 school boys trading secret messages with each other. If everyone kept their secrets to themselves, they would need 4 boxes and 4 keys.</p>
<pre style="padding-left: 30px;">A
B
C
D</pre>
<p>That&#8217;s trivial enough, one box for each boy and a key to lock/unlock it.</p>
<p>If Boy A wants to trade secrets with Boy B, then they&#8217;ll need a separate box just for that, because they cannot give their own keys to the other boy, which will reveal their own personal secrets. If we assume each boy needs a separate box to share secrets with another boy now we need another 6 boxes and 12 keys.</p>
<pre style="padding-left: 30px;">A and B</pre>
<pre style="padding-left: 30px;">A and C</pre>
<pre style="padding-left: 30px;">A and D</pre>
<pre style="padding-left: 30px;">B and C</pre>
<pre style="padding-left: 30px;">B and D</pre>
<pre style="padding-left: 30px;">C and D</pre>
<p>It doesn&#8217;t even end there. What happens if 3 boys want to share secrets now? They cannot use their individual boxes, or their common boxes with either of the other two boys. So they will need 4 more boxes and 12 more keys:</p>
<pre style="padding-left: 30px;">A and B and C
A and B and D
A and C and D
B and C and D</pre>
<p>If these 4 boys want to share secrets among them (and keep the girls out), they need yet another box and 4 more keys for that</p>
<pre style="padding-left: 30px;">A and B and C and D</pre>
<p>Even with only 4 people trying to trade secrets we ended up with 21 boxes and 32 keys. Each boy has to manage 8 keys and 8 boxes if they want to share secrets with 3 other boys.</p>
<p><a href="http://karul.org/blog/wp-content/uploads/2009/11/4-boy-example2.jpg"><img class="aligncenter size-medium wp-image-474" title="Key Distribution Among 4 People" src="http://karul.org/blog/wp-content/uploads/2009/11/4-boy-example2-300x253.jpg" alt="Key Distribution Among 4 People" width="300" height="253" /></a></p>
<p>Try the same thing with 5 people and you&#8217;ll end up with 31 boxes, try it with 10 and you&#8217;ll need 1023 boxes. Before you reach anywhere close to the population of the town you&#8217;re living in, you&#8217;ll need more boxes than the stars in the sky.</p>
<p>This is why symmetric encryption can not be used as a reliable and scalable means to exchange confidential information among multiple people. In addition to the exponential growth of boxes and keys that are needed, there is another major reason why symmetric encryption is not a good fit for secure communication. These keys should somehow be distributed to individuals. In the above example, boys can simply swap them during their recess time. But in a real life scenario where parties are not physically at the same location, and in most cases, are not even acquainted with each other, distribution of keys is a major problem. Because the Internet is not secure (at least for now), they cannot send the keys via email. To secure an email you can use encryption, but before that you&#8217;ll have to agree on an encryption key, which takes you back to where they&#8217;ve started (i.e. you need to share that key to make your email secure). This paradox, sometimes referred to as &#8220;Key distribution Problem&#8221;, is the other major reason why symmetric encryption is not suited for securing a communication.</p>
<p>Public Key Infrastructure was invented to solve this problem, and I&#8217;ll show you how to build a PKI box next week.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://karul.org/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://karul.org/blog/2009/11/an-outside-the-box-look-at-public-key-encryption-i-symmetric-encryption/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Developing a Dojo Application 6 – Epilogue</title>
		<link>http://karul.org/blog/2009/10/developing-a-dojo-application-6-%e2%80%93-epilogue/</link>
		<comments>http://karul.org/blog/2009/10/developing-a-dojo-application-6-%e2%80%93-epilogue/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 23:59:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Dijit]]></category>
		<category><![CDATA[Dojo]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[chords]]></category>
		<category><![CDATA[dojox]]></category>
		<category><![CDATA[graphical user interface]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java Script]]></category>
		<category><![CDATA[music theory]]></category>
		<category><![CDATA[Scales]]></category>

		<guid isPermaLink="false">http://karul.org/blog/?p=434</guid>
		<description><![CDATA[<p>About 6 weeks ago I started a pet project  to experiment with Dojo Toolkit which I tentatively called  Musician&#8217;s Friend. My goal was to see whether this technology is really mature and stable enough to be used in an enterprise grade software project, and to create  an application that might one day [...]]]></description>
			<content:encoded><![CDATA[<p>About 6 weeks ago I started a pet project  to experiment with Dojo Toolkit which I tentatively called  <strong>Musician&#8217;s Friend</strong>. My goal was to see whether this technology is really mature and stable enough to be used in an enterprise grade software project, and to create  an application that might one day turn into something useful. After almost two months of on-and-off development, I have now enough information to write down my findings.</p>
<p>I believe a good GUI framework needs to accomplish a number of things:</p>
<ul>
<li>It should be easy to write and test</li>
<li>It should be well documented</li>
<li>It should look good out of the box</li>
<li>It should be robust and bug free, should work with all major browsers</li>
<li>It should be extensible</li>
</ul>
<p>Marketing presentations and demo applications can give you only so much information about a technology. After 6 weekends of development following are my observations  about the Dojo Toolkit:</p>
<p><strong>Coding and Debugging with Dojo</strong></p>
<p>Writing JavaScript code has always been hard. Maybe just because of the &#8220;script&#8221; in its name, this language has rarely been taken into consideration for any serious project. Part of its bad reputation can be attributed to haphazardly inserted script snippets into HTML, mostly by non-developers, which are responsible for many less than perfect examples of Javascripting  out there. As any other language though, if you spend enough time and effort to design your software and write it by abiding commonly accepted development practices,  I don&#8217;t think JavaScript is any worse  than other scripting languages. This experience taught me to take JavaScript more seriously and use a good IDE to work with it. To implement this project I used my favorite IDE,   Eclipse Galileo Edition with a number of extra optional HTML/JS plug-ins.  Eclipse is open source and free, so I highly recommend you to give it a shot if you intend to use Dojo Toolkit as part of your project. For your reference, I use the following Eclipse plug-ins and I am pretty happy with the real time syntax checking, dynamic highlighting and other usual features that come with any good IDE.</p>
<p><a href="http://karul.org/blog/wp-content/uploads/2009/10/eclipse-shot1.jpg"><img class="aligncenter size-medium wp-image-436" title="eclipse-shot" src="http://karul.org/blog/wp-content/uploads/2009/10/eclipse-shot1-300x105.jpg" alt="eclipse-shot" width="300" height="105" /></a>I don&#8217;t debug Javascript within the Eclipse platform, and I am not even sure if this is possible at all. I instead use Firebug plug-in on Mozilla Firefox. This combination however didn&#8217;t work that well for this project. So I experimented with Google Chrome debugger and recently IE 8&#8242;s debugger for Javascript. As no single debugger came close to satisfying my needs, I used all three. The cross-browser problem I experienced <a href="http://karul.org/blog/?p=405" target="_blank">last week</a> also taught me the hard way that, it probably is better to test the code on all three major browsers as you go.</p>
<p>In general coding with Dojo is quite simple and painless. Just be very careful with your HTML syntax and CSS styling as these sometimes prevent Dojo widgets to render correctly. I also recommend you to keep your Javascript in a separate file and not embed into your HTML code. These are my overall ratings for coding and debugging experience with Dojo Toolkit:</p>
<pre style="padding-left: 30px;">Ease of coding:                <strong>9</strong></pre>
<pre style="padding-left: 30px;">Ease of debugging</pre>
<pre style="padding-left: 60px;">with Firefox/Firebug:      <strong>5</strong></pre>
<pre style="padding-left: 60px;">with Chrome:               <strong>7</strong></pre>
<pre style="padding-left: 60px;">with IE 8:                 <strong>8</strong></pre>
<pre style="padding-left: 30px;">Ease of reading source code:   <strong>8
</strong></pre>
<p><strong>Dojo Documentation</strong></p>
<p>Dojo is reasonably well documented for the starter and  the online documentation covers most usual and common features. Two problems I had with the documentation in general were:</p>
<ol>
<li>They often are a bit sketchy and/or not complete, and at times they are not always in sync with the code. Examples do not always work.</li>
<li>Documentation is dispersed among many different sources and one needs to fish through tutorials, reference documentation and mailing lists to find what they are looking for.</li>
</ol>
<p>Being a new technology the available online sources for code samples, tutorials and examples are somewhat limited as compared to other technologies. Just to give you an example, my only weeks-old blog entries about Dojo show up on top ten of many Dojo related Google searches, which as flattering as it is, indicates how rare Dojo related online documentation actually is.</p>
<p>I personally figured out how to overcome some challenging  tasks, such as overwriting methods in core classes, changing the way certain widgets work, or debugging obscure errors by ether reading the source code or by analyzing the process flow in a debugger. As more people start to use this technology, I believe the documentation will improve both qualitatively and quantitatively.</p>
<pre style="padding-left: 30px;">Document availability:                         <strong>7</strong></pre>
<pre style="padding-left: 30px;">Document quality:                              <strong>7</strong></pre>
<pre style="padding-left: 30px;">Third party examples, tutorials, code samples: <strong>6

</strong></pre>
<p><strong>Looks</strong></p>
<p>Looks are important, and I believe this is where Dojo shines most. If it was not the sex-appeal of Dojo, I would probably have chosen other competitive technologies such as GWT by Google or YUI by Yahoo, which seem to be more mature and stable. What interests me more is to be able to do things in a web browser which people believe is not possible at all: such as dragging and dropping objects, having slider controls, animations, etc. What I like about Dojo&#8217;s UI design is that I don&#8217;t have to do anything extra to make it look good. As a matter of fact, the less you touch the default design theme, the better off you are.  Dojo comes with 3-4 decent themes you can choose from. You can use  third party themes or create one on your own as well.</p>
<p>The visual design is consistent among different browsers as the themes handle most of the cross-browser issues seamlessly. My favorite web sites which helped me a lot while working on  Dojo GUI visual designs were:</p>
<p><a href="http://dojocampus.org/explorer/" target="_blank">http://dojocampus.org/explorer/</a></p>
<p>and</p>
<p><a href="http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/themes/themeTester.html" target="_blank">http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/themes/themeTester.html</a></p>
<p>The former demonstrates most (unfortunately some widgets are missing on that page) available Dojo, Dijit and Dojox widgets  with links to relevant documentation. The latter is a theme tester, which again has most of the available features and lets the user switch the themes dynamically to allow them see how different controls look in different themes.</p>
<pre style="padding-left: 30px;">Looks:                    <strong>9</strong></pre>
<pre style="padding-left: 30px;">Available Themes:         <strong>7</strong></pre>
<pre style="padding-left: 30px;">Ease of extending Themes: <strong>7

</strong></pre>
<p><strong>Stability</strong></p>
<p>Frankly I haven&#8217;t come across a major bug so far which prevented me from doing what I intended to. Having said that, I had  hard time in a number of cases, most of which turned out to be  issues unrelated to Dojo libraries, but made it malfunction anyways. For instance some Dojo layout objects would not render on the screen if a hard-coded size is not provided. You might therefore end up with an empty page with no way of knowing why your perfectly working application disappeared after you only played with some CSS styling. In my opinion style should never break the code and objects should fall back to some default size if user doesn&#8217;t provide any. Another issue was where the order of loading scripts affected the way the page was rendered, which again was fixed by simply changing the scripts&#8217; location on the HTML  page. Last week&#8217;s issue with IE again is a good example of how not closing a simple &lt;span&gt; object can break the entire application on IE, whereas Chrome and Firefox can somehow handle it as if nothing happened.</p>
<p>In general though I would rate Dojo as a stable toolkit, yet one with a steep learning curve and not quite enough reference material to help you along the way.</p>
<pre style="padding-left: 30px;">Stability:                    <strong>8</strong></pre>
<pre style="padding-left: 30px;">Robustness:                   <strong>7</strong></pre>
<pre style="padding-left: 30px;">Cross-platform transparency:  <strong>8

</strong></pre>
<p><strong>Extensibility</strong></p>
<p>Although I haven&#8217;t written about this much (yet), I have been experimented with Dojo Drag and Drop functionality and was able to overwrite a couple of standard methods to change their behavior to suit my needs. Figuring out how to extend a class took me some time as I am used to more advanced object oriented languages such as Java. But once I got the hang of it, it is actually quite straight forward to extend existing functionality and overwrite it with your own implementation. I implemented my drag and drop methods for an earlier version of Dojo and when I upgraded to the newer version they just kept working without a glitch. I didn&#8217;t have to download the source code to extend the functionality either, so I am quite comfortable that one can tailor any existing object into their specific needs easily. The harder part is actually to read the source code of the original method and understand what it actually does.</p>
<pre style="padding-left: 30px;">Ease of extensibility: 9</pre>
<pre style="padding-left: 30px;">Flexibility:           9</pre>
<p>After this short evaluation of the Dojo Toolkit, I like to conclude this series with a run down of latest improvements of  Musician&#8217;s Helper, which gracefully served as a reference application for my experimentation over last couple of weeks. I made some final improvements this week, most of which are not directly related to Dojo technologies:</p>
<p><a href="http://karul.org/blog/wp-content/uploads/2009/10/mhelper6-shot.jpg"><img class="aligncenter size-medium wp-image-452" title="mhelper6-shot" src="http://karul.org/blog/wp-content/uploads/2009/10/mhelper6-shot-300x175.jpg" alt="mhelper6-shot" width="300" height="175" /></a></p>
<ul>
<li>I improved the left panel where I changed the visual design and enabled highlighting. So the user now knows which key and scale/chord combination is selected at any time.</li>
<li>I implemented the notation view with a little bit of HTML trickery and a lot of image processing. It still has a number of issues I  have to take care of, but it does what it is supposed to do: shows the notes of a scale or a chord for any given key.</li>
<li>I also implemented a custom initialization logic, where I can initialise the application with  a certain key-scale/chord combination directly through a URL. This is quite useful for someone who is talking about a certain chord or scale and needs a direct link to the correct key-chord/scale. For example if I like to draw your attention to a Ab Diminished chord, now I can provide the direct URL as:</li>
</ul>
<p><a href="http://karul.org/etc/mhelper/mhelper6.html?key=Ab&amp;sc=Diminished_chord" target="_blank">http://karul.org/etc/mhelper/mhelper6.html?key=Ab&amp;sc=Diminished_chord</a></p>
<p>or if you want to check out D Whole Note Scale you can click on:</p>
<p><a href="http://karul.org/etc/mhelper/mhelper6.html?key=D&amp;sc=WholeNote_scale" target="_blank">http://karul.org/etc/mhelper/mhelper6.html?key=D&amp;sc=WholeNote_scale</a></p>
<p>I&#8217;m planning to polish the Musician&#8217;s Helper a bit more, possibly rename it and move it to its own web page after I implement a proper back-end data layer. Until then enjoy this final alpha version and send me your comments if you have any bugs or recommendations.</p>
<p><a href="../../etc/mhelper/mhelper6.html" target="_blank">http://karul.org/etc/mhelper/mhelper6.html</a></p>
<blockquote>
<p><span style="color: #000080;">Some of the concepts discussed in this Blog has over the time evolved into an application you might want to check out:</span></p>
<p><span style="color: #000080;"><a title="http://music.isallicare.com" href="http://music.isallicare.com" target="_blank">http://music.isallicare.com</a></span></p>
<p><span style="color: #000080;">Thanks for visiting my Blog     &#8212; C. Karul Jan 3, 2010</span></p></blockquote>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://karul.org/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://karul.org/blog/2009/10/developing-a-dojo-application-6-%e2%80%93-epilogue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Developing a Dojo Application 5 – Cross-browser (IE) problems</title>
		<link>http://karul.org/blog/2009/10/developing-a-dojo-application-5-%e2%80%93-cross-browser-ie-problems/</link>
		<comments>http://karul.org/blog/2009/10/developing-a-dojo-application-5-%e2%80%93-cross-browser-ie-problems/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 02:26:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Dijit]]></category>
		<category><![CDATA[Dojo]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[cross browser problems]]></category>
		<category><![CDATA[dojox]]></category>
		<category><![CDATA[graphical user interface]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Internet Explorer compatibility]]></category>
		<category><![CDATA[Scales]]></category>
		<category><![CDATA[Web 2.0]]></category>

		<guid isPermaLink="false">http://karul.org/blog/?p=405</guid>
		<description><![CDATA[<p>I was hoping to wrap up our mini application  this week and move on to another project. Then I suddenly realised that the application stopped working for Microsoft Internet Explorer (IE) after version 3.  I pretty much spent my entire spare time trying to debug the problem with not much traction so far.</p>
<p>Documenting failures [...]]]></description>
			<content:encoded><![CDATA[<p>I was hoping to wrap up our mini application  this week and move on to another project. Then I suddenly realised that the application stopped working for Microsoft Internet Explorer (IE) after version 3.  I pretty much spent my entire spare time trying to debug the problem with not much traction so far.</p>
<p>Documenting failures is an important part of the learning process, so that&#8217;s what I&#8217;ve decided to do this week. I did achieve some minor improvements as well. I  figured out that you can actually encode musical symbols using plain HTML. I did some experimentation with positioning of quarter notes on an image of manuscript paper in an effort to dynamically write down musical notation on the fly. Again, this seemed to work but the results were not identical on different browsers. I&#8217;ll talk about this more at a future date, when I have more to discuss.</p>
<p>Going back to the IE issue, up until version 4 I was using the</p>
<pre>&lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.3.2/dojo/dojo.xd.js"
    djConfig="parseOnLoad: <span style="color: #ff0000;"><strong>true</strong></span>"&gt;&lt;/script&gt;</pre>
<p>statement at the top of my HTML page, which dynamically loaded the dojo.xd.js file from Google code repository. This code dynamically loads all the other libraries when needed. Note the last parameter</p>
<pre>djConfig="parseOnLoad: true"</pre>
<p>which essentially is telling Dojo to parse the page and process all other dojo objects when the page is loaded.  When this parameter is true, the application works for all the browsers I have:</p>
<ul>
<li>Mozilla Firefox 3.5.3</li>
<li>Google Chrome 3.0.195.27</li>
<li>Microsoft Internet Explorer 8.0.6001.18828</li>
</ul>
<p>Last week I made some changes to set this parameter false, and then added an extra function which parses the page contents after the actual loading is completed, essentially implementing a splash screen. This works nicely both for Firefox and Chrome. For IE, I get some various exceptions. First of all, dojo objects still partially work. If nothing had worked, I would assume that the loader I wrote is somehow not compatible with IE.</p>
<p>The splash screen shows fine</p>
<p><a href="http://karul.org/blog/wp-content/uploads/2009/10/ie-issue-1.jpg"><img class="aligncenter size-medium wp-image-407" title="IE loading splash screen" src="http://karul.org/blog/wp-content/uploads/2009/10/ie-issue-1-300x196.jpg" alt="IE loading splash screen" width="300" height="196" /></a></p>
<p>and it loads the page, with most of the Dojo objects on it as expected. Not all objects are rendered successfully though. The tabbed pane that should show up on the right panel is entirely missing (marked as a red rectangle below). It instead shows contents of the tabbed pane as if they are regular div objects, which makes me think that parsing of these  objects fail for some reason.</p>
<p><a href="http://karul.org/blog/wp-content/uploads/2009/10/ie-issue-2.jpg"><img class="aligncenter size-medium wp-image-408" title="Partially rendered Dojo objects" src="http://karul.org/blog/wp-content/uploads/2009/10/ie-issue-2-300x127.jpg" alt="Partially rendered Dojo objects" width="300" height="127" /></a>And it doesn&#8217;t stop there. When I click on anything on the left panel I get  the following exception</p>
<p><a href="http://karul.org/blog/wp-content/uploads/2009/10/ie-issue-3.jpg"><img class="aligncenter size-medium wp-image-410" title="ie-issue-3" src="http://karul.org/blog/wp-content/uploads/2009/10/ie-issue-3-300x196.jpg" alt="ie-issue-3" width="300" height="196" /></a></p>
<pre style="padding-left: 30px;">'dojo.byId(...)' is null or not an object  mhelper5.js, line 199 character 3</pre>
<p>for each cell of the table view.  In other words, IE can no longer find the table cell objects which have been marked with unique Id&#8217;s.</p>
<p><a href="http://karul.org/blog/wp-content/uploads/2009/10/ie-issue-4.jpg"><img class="aligncenter size-medium wp-image-411" title="ie-issue-4" src="http://karul.org/blog/wp-content/uploads/2009/10/ie-issue-4-300x57.jpg" alt="ie-issue-4" width="300" height="57" /></a></p>
<p>The interesting thing is that, dojo.byId function works fine for the title where both the key and the chord-scale name parameters are found and replaced exactly the same way.</p>
<pre style="padding-left: 30px;">dojo.byId('keySpan').innerHTML = currentKey;
dojo.byId('scaleChordSpan').innerHTML = currentScaleChordName;</pre>
<p>On the upside I discovered that as of version 8.0, IE now comes with a  pretty decent JavaScript debugger. I have been using Firefox as my main Web Browser since they came out, and FireBug Extension was my favorite JavaScript/HTML/CSS debugger. For some reason this combination is getting progressively  complicated and somewhat buggy. I can no longer get the Firebug debugger effectively run for any of the my recent Dojo applications. It either doesn&#8217;t load  the source code as it used to or doesn&#8217;t let me set breakpoints; and it crashes Firefox if I push it too hard. Google Chrome has a JavaScript debugger as well, which seems to perform better than Firebug for some tasks, but has its own quirks. So I was using both with mixed results. Being a hard-core Java/Unix guy I didn&#8217;t think I would ever say this, but IE 8&#8242;s JavaScript debugger worked (for me at least) like a charm so far.  It is quite intuitive and I still couldn&#8217;t manage to crash or hang it once.</p>
<p>Well my code still doesn&#8217;t work on IE but at least the debugger is not dying on me every 10 minutes. I&#8217;ll work on this and hopefully update this entry with a solution in the next couple of days.</p>
<p>If you want to play with version 5, which is known not to work on Internet Explorer here is the link:</p>
<p><a href="http://karul.org/etc/mhelper/mhelper5.html" target="_blank">http://karul.org/etc/mhelper/mhelper5.html</a></p>
<h2>UPDATE (21-Oct-2009)</h2>
<p>I finally figured out what the problem was. Turns out it was a simple HTML typo that somehow was ignored by all browsers when all dojo components are loaded during startup.</p>
<pre>&lt;h1&gt;&lt;span id="keySpan"&gt;C&lt;/span&gt; &lt;span id="scaleChordSpan"&gt;Major Scale<span style="color: #ff0000;"><strong>&lt;span/&gt;</strong></span>&lt;/h1&gt;</pre>
<p>For some reason, only when the dojo.parser.parse function was used to parse dojo objects, IE fails to create the DOM properly and that&#8217;s why the script was failing to find certain DOM objects (such as table cell Id&#8217;s).</p>
<p>The version 5 is now updated with the fix:</p>
<p><a href="../../etc/mhelper/mhelper5.html" target="_blank">http://karul.org/etc/mhelper/mhelper5.html</a></p>
<blockquote><p><span style="color: #000080;">Some of the concepts discussed in this Blog has over the time evolved into an application you might want to check out:</span></p>
<p><span style="color: #000080;"><a title="http://music.isallicare.com" href="http://music.isallicare.com" target="_blank">http://music.isallicare.com</a></span></p>
<p><span style="color: #000080;">Thanks for visiting my Blog     &#8212; C. Karul Jan 3, 2010</span></p></blockquote>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://karul.org/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://karul.org/blog/2009/10/developing-a-dojo-application-5-%e2%80%93-cross-browser-ie-problems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Developing a Dojo Application 4 – Splash Screen, TitlePane and Dialog</title>
		<link>http://karul.org/blog/2009/10/developing-a-dojo-application-4-%e2%80%93-splash-screen-titlepane-and-dialog/</link>
		<comments>http://karul.org/blog/2009/10/developing-a-dojo-application-4-%e2%80%93-splash-screen-titlepane-and-dialog/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 01:38:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Dijit]]></category>
		<category><![CDATA[Dojo]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[dojox]]></category>
		<category><![CDATA[graphical user interface]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[harmony]]></category>
		<category><![CDATA[Java Script]]></category>
		<category><![CDATA[music theory]]></category>
		<category><![CDATA[Scales]]></category>

		<guid isPermaLink="false">http://karul.org/blog/?p=372</guid>
		<description><![CDATA[<p>This week I&#8217;ll complete the chord and scale definitions and add some functionality to the application.</p>
<p>There is a large number of chords, most of which I believe is now included in our application. I omitted some rarely used chords which spread out to two octaves. Also note that some added notes, such as ninths, elevenths, [...]]]></description>
			<content:encoded><![CDATA[<p>This week I&#8217;ll complete the chord and scale definitions and add some functionality to the application.</p>
<p>There is a large number of chords, most of which I believe is now included in our application. I omitted some rarely used chords which spread out to two octaves. Also note that some added notes, such as ninths, elevenths, etc. are often played in the second octave, but they are technically equivalent to a second and a fourth respectively. How you play a chord is a different matter of music theory and right now this tool only shows you which notes are part of your scale or chord, and not necessarily in what order you are supposed to play them. I might extend the application to include common chord inversions in the future.</p>
<p>I will not elaborate on how I coded the chord definitions and hook them up with on-screen links, as I went through it <a href="http://karul.org/blog/?p=309" target="_blank">last week</a>. The chord screen now looks like this:</p>
<p style="text-align: center;">
<div id="attachment_374" class="wp-caption aligncenter" style="width: 213px"><a href="http://karul.org/blog/wp-content/uploads/2009/10/chords.jpg"><img class="size-full wp-image-374  " title="Chords" src="http://karul.org/blog/wp-content/uploads/2009/10/chords.jpg" alt="Chords" width="203" height="343" /></a><p class="wp-caption-text">Chords</p></div>
<p>When a link is clicked, it activates the function by passing the chord&#8217;s unique identifier as argument:</p>
<pre>...</pre>
<pre>&lt;p&gt;
 &lt;li onClick="<span style="color: #ff0000;"><strong>updateScaleChord('Major_chord')</strong></span>;"&gt;&lt;span&gt;&lt;b&gt;Major&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
 &lt;li onClick="<span style="color: #ff0000;"><strong>updateScaleChord('Major_dominant_seventh_chord')</strong></span>;"&gt;&lt;span&gt;Major Dominant Seventh&lt;/span&gt;&lt;/li&gt;
 &lt;li onClick="<strong><span style="color: #ff0000;">updateScaleChord('Major_major_seventh_chord')</span></strong>;"&gt;&lt;span&gt;Major Major Seventh&lt;/span&gt;&lt;/li&gt;
 &lt;li onClick="<span style="color: #ff0000;"><strong>updateScaleChord('Major_dominant_ninth_chord')</strong></span>;"&gt;&lt;span&gt;Major Dominant Ninth&lt;/span&gt;&lt;/li&gt;
 &lt;li onClick="<span style="color: #ff0000;"><strong>updateScaleChord('Major_dominant_eleventh_chord')</strong></span>;"&gt;&lt;span&gt;Major Dominant Eleventh&lt;/span&gt;&lt;/li&gt;</pre>
<pre>...</pre>
<p>In the mean time I reorganized the right panel a bit. First of all, I made the title dynamic, so whenever the key is transposed or a scale/chord is chosen, the title is automatically updated with accurate definition of the key-chord/scale combination.</p>
<div id="attachment_375" class="wp-caption aligncenter" style="width: 586px"><a href="http://karul.org/blog/wp-content/uploads/2009/10/title_shot.jpg"><img class="size-full wp-image-375 " title="Title" src="http://karul.org/blog/wp-content/uploads/2009/10/title_shot.jpg" alt="Dynamic Title" width="576" height="145" /></a><p class="wp-caption-text">Dynamic Title</p></div>
<p>To get this working I added new statements to the <strong><em>updateInformation()</em></strong> function, which simply update the two span objects I created for this purpose within the title of the right panel.</p>
<pre>function updateInformation() {
<span style="color: #ff0000;"><strong>  dojo.byId('keySpan').innerHTML = currentKey;
  dojo.byId('scaleChordSpan').innerHTML = currentScaleChordName;</strong></span>
  updateDegreesTable();
}</pre>
<p>The HTML code for that section now looks like this:</p>
<pre>&lt;h1&gt;&lt;span id="<span style="color: #ff0000;">keySpan</span>"&gt;C&lt;/span&gt; &lt;span id="<span style="color: #ff0000;">scaleChordSpan</span>"&gt;Major Scale&lt;span/&gt;&lt;/h1&gt;</pre>
<p>I also moved the little &#8220;How to use?&#8221; instructions to the bottom of the page, and placed them in a TitlePane object. This is a nice little Dijit Widget that hides the content and shows it only when someone clicks on the title. It looks like this when it is collapsed:</p>
<div id="attachment_379" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-379" title="TitlePane Collapsed" src="http://karul.org/blog/wp-content/uploads/2009/10/titlepane1-300x51.jpg" alt="TitlePane Collapsed" width="300" height="51" /><p class="wp-caption-text">TitlePane Collapsed</p></div>
<p>And it looks like this when it is exploded:</p>
<div id="attachment_380" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-380" title="TitlePane Exploded" src="http://karul.org/blog/wp-content/uploads/2009/10/titlepane2-300x83.jpg" alt="TitlePane Exploded" width="300" height="83" /><p class="wp-caption-text">TitlePane Exploded</p></div>
<p>To use the TitlePane in the application, I simply included the <em><strong>dijit.TitlePane</strong></em> library</p>
<pre>dojo.require("dijit.TitlePane");</pre>
<p>and added the following DIV object at the bottom of my right panel.</p>
<pre>&lt;div <strong>dojoType="<span style="color: #ff0000;">dijit.TitlePane</span>" title="<span style="color: #ff0000;">Need Help?</span>" open="<span style="color: #ff0000;">false</span>"</strong>&gt;
  Change Keys on the left panel to transpose this chart to another key.
  &lt;p&gt;
  Choose other Scales and Chords on the left panel to highlight the notes of these scales and charts below.&lt;br&gt;
&lt;/div&gt;</pre>
<p>I wanted to have the panel collapsed when the page is first loaded, so I added the parameter open=&#8221;false&#8221;.</p>
<p>Another widget I like a lot is the dijit.Dialog. As with TitlePane, all you need to do is to include the library and add a DIV object with the dojoType=&#8221;dijit.Dialog&#8221;. I added a simple <strong>About Page</strong> and  also added a dijit.form.Button object, which simply shows the dialog when someone clicks on it.</p>
<pre>...
dojo.require("dijit.form.Button");</pre>
<pre>dojo.require("dijit.Dialog");</pre>
<pre>...</pre>
<pre>&lt;button dojoType="<span style="color: #ff0000;"><strong>dijit.form.Button</strong></span>" onclick="dijit.byId('<span style="color: #ff0000;"><strong>aboutDialog</strong></span>').show()" style="align:right;"&gt;About&lt;/button&gt;
&lt;div dojoType="<span style="color: #ff0000;"><strong>dijit.Dialog</strong></span>" id="<span style="color: #ff0000;"><strong>aboutDialog</strong></span>" title="About"&gt;
  &lt;b&gt;Musician's Helper&lt;/b&gt; v 4.0 alpha
  &lt;p&gt;
  This is an application designed to help musicians learn &lt;br&gt;
  the relationships between degrees, scales and chords.
  &lt;p&gt;
  Build id: 200910091129&lt;br&gt;
  (c) Copyright Cuneyt Karul, 2009.  All rights reserved.&lt;br&gt;
  &lt;a href="http://karul.org"&gt;http://karul.org&lt;/a&gt;
  &lt;p&gt;
&lt;/div&gt;</pre>
<pre>...</pre>
<p>The button and the dialog box together looks like as shown in the screen-shot below. Note that the dialog box is modal, meaning that the user cannot click on anything else on the screen until they close the dialog box. Dijit Dialog implementation grays out the disabled screen to let the user know that they need to close the modal dialog before proceeding. I somehow couldn&#8217;t figure out how to align the About button to the right properly, but I&#8217;ll deal with this later.</p>
<div id="attachment_384" class="wp-caption aligncenter" style="width: 310px"><a href="http://karul.org/blog/wp-content/uploads/2009/10/aboutDialog.jpg"><img class="size-medium wp-image-384 " title="About Dialog" src="http://karul.org/blog/wp-content/uploads/2009/10/aboutDialog-300x185.jpg" alt="About Dialog" width="300" height="185" /></a><p class="wp-caption-text">About Dialog</p></div>
<p>And the final improvement for this week is something that was annoying me from day one. When you load a page that uses Dojo/Dijit components, it naturally takes a while before all libraries are loaded and the page is rendered. This creates a quite ugly view for about a second or so before the page parsing is completed:</p>
<p style="text-align: center;"><a href="http://karul.org/blog/wp-content/uploads/2009/10/nosplash.jpg"><img class="aligncenter size-medium wp-image-386" title="nosplash" src="http://karul.org/blog/wp-content/uploads/2009/10/nosplash-300x183.jpg" alt="nosplash" width="300" height="183" /></a></p>
<p>To solve this issue, I disabled the &#8220;parseOnLoad&#8221; parameter</p>
<pre>&lt;script type="text/javascript"
         src="http://ajax.googleapis.com/ajax/libs/dojo/1.3.2/dojo/dojo.xd.js"
    djConfig="<span style="color: #ff0000;"><strong>parseOnLoad: false</strong></span>"&gt;
&lt;/script&gt;</pre>
<p>and added a new function to show a temporary page while the browser is busy loading dojo libraries and parsing them. This function shows a temporary message until the Dojo parsing is completed, and when the parsing is done, it shows an animated transition to the actual application pages. (I  took  this function from  <a href="http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/themes/themeTester.html" target="_blank">Dijit Theme Tester </a>page).</p>
<pre>&lt;script type="text/javascript"&gt;
  dojo.addOnLoad(function() {
    var start = new Date().getTime();
    dojo.parser.parse(dojo.byId('container'));
    dojo.byId('loaderInner').innerHTML += " done.";
    setTimeout(function hideLoader(){
      var loader = dojo.byId('loader');
      dojo.fadeOut({ node: loader, duration:500,onEnd: function(){
          loader.style.display = "none";
        }
      }).play();
    }, 250);
  });
&lt;/script&gt;</pre>
<p>Now while the application is being loaded,  a small note is shown to let the user know what is going on and the ugly unprocessed view of the page is hidden.</p>
<div id="attachment_387" class="wp-caption aligncenter" style="width: 310px"><a href="http://karul.org/blog/wp-content/uploads/2009/10/splash.jpg"><img class="size-medium wp-image-387" title="Splash Screen" src="http://karul.org/blog/wp-content/uploads/2009/10/splash-300x198.jpg" alt="Splash Screen" width="300" height="198" /></a><p class="wp-caption-text">Splash Screen</p></div>
<p>The temporary page can sure be improved by adding images, etc., but it is already a huge improvement over what we had beore.</p>
<p>As usual, a working version of the application is available here:</p>
<p><a href="http://karul.org/etc/mhelper/mhelper4.html" target="_blank">http://karul.org/etc/mhelper/mhelper4.html</a></p>
<p>If you want to see  how initiation looked like before the splash screen, you can compare it to the previous version here.</p>
<p><a href="http://karul.org/etc/mhelper/mhelper3.html" target="_blank">http://karul.org/etc/mhelper/mhelper3.html</a></p>
<p>To be concluded next week. Happy Thanksgiving!</p>
<p>PS: If you see any chords or scales that seem to be wrong please drop me a line so I can fix them.</p>
<blockquote><p><span style="color: #000080;">Some of the concepts discussed in this Blog has over the time evolved into an application you might want to check out:</span></p>
<p><span style="color: #000080;"><a title="http://music.isallicare.com" href="http://music.isallicare.com" target="_blank">http://music.isallicare.com</a></span></p>
<p><span style="color: #000080;">Thanks for visiting my Blog     &#8212; C. Karul Jan 3, 2010</span></p></blockquote>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://karul.org/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://karul.org/blog/2009/10/developing-a-dojo-application-4-%e2%80%93-splash-screen-titlepane-and-dialog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Developing a Dojo Application 3 &#8211; Wiring it up</title>
		<link>http://karul.org/blog/2009/10/developing-a-dojo-application-3-wiring-it-up/</link>
		<comments>http://karul.org/blog/2009/10/developing-a-dojo-application-3-wiring-it-up/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 02:00:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Dijit]]></category>
		<category><![CDATA[Dojo]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[chords]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[keys]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[music theory]]></category>
		<category><![CDATA[Scales]]></category>
		<category><![CDATA[transpose]]></category>
		<category><![CDATA[ui design]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://karul.org/blog/?p=309</guid>
		<description><![CDATA[<p>I left it where we had a simple GUI that didn&#8217;t do much last week. This time I&#8217;ll try to implement a simple, but working version of our little Musician&#8217;s Helper application. My primary design goal is to make this really intuitive and useful for a musician who wants to  figure out or practice [...]]]></description>
			<content:encoded><![CDATA[<p>I left it where we had a simple GUI that didn&#8217;t do much last week. This time I&#8217;ll try to implement a simple, but working version of our little Musician&#8217;s Helper application. My primary design goal is to make this really intuitive and useful for a musician who wants to  figure out or practice the  notes that make up a scale or a chord  for a given key.</p>
<p>Once we figure out what notes belong to a key/scale-chord combination, we can show them to the end user in a number of ways. My initial implementation will be a table of <strong>Degrees</strong> vs. <strong>Note </strong>names, where notes for the given chord or scale are  highlighted. This is sort of the rectangular version of a magic circle as I described in my previous Blog entries Music Theory for Geeks <a href="http://karul.org/blog/?p=19" target="_blank">2</a> and <a href="http://karul.org/blog/?p=34" target="_blank">3</a>. I&#8217;ll call this the <strong>Table View</strong>.</p>
<p>I&#8217;ll start by developing a standard &#8220;data&#8221; representation of my application, which corresponds to the <strong>Model</strong> in a, so called, <strong>Model-View-Controller </strong>architectural pattern. The <strong>Table View</strong>, as you might have guessed,  will be one of my views. If I separate the model from the view now, I won&#8217;t need to change my core application logic in the future when I need to implement additional views (such as Notation View, Piano, Guitar, Bass view, etc.).</p>
<p>Because the degrees never change and they always have a length of 12, I&#8217;ll model them as a simple array. I&#8217;ll model the notes as an array as well, but this time I&#8217;ll use an array of size 24. There are 12 notes, but when I transpose a key, I rather start at the 11th degree and iterate up the array to get a list of my transposed list, instead of using an ugly if/then (i.e. if  position = 12 go back to 0) condition.</p>
<div class="im">
<p>So the first function will simply start at a certain point in the <strong>keys array</strong> and copy the array members to the <strong>degrees  array</strong>, where the 0th item will be 1st degree, 1st item will be flat second, 2nd item will be a second, etc. This function will accept the <strong>key name</strong> as an argument, to which we will transpose the key. This function simply calculates the starting point in the keys array and copies next 12 notes to the degrees array, effectively transposing (i.e. shifting) the key.</div>
<pre class="im">function transposeToKey(keyName) {
    switch(keyName){
        case "C":
            var startPoint = 0;
            break;
        case "Db":
            var startPoint = 1;
            break;
        case "D":
            var startPoint = 2;
            break;
        case "Eb":
            var startPoint = 3;
            break;
        case "E":
            var startPoint = 4;
            break;
        case "F":
            var startPoint = 5;
            break;
        case "Gb":
            var startPoint = 6;
            break;
        case "G":
            var startPoint = 7;
            break;
        case "Ab":
            var startPoint = 8;
            break;
        case "A":
            var startPoint = 9;
            break;
        case "Bb":
            var startPoint = 10;
            break;
        case "B":
            var startPoint = 11;
            break;
    }
    for (var i = 0; i &lt; 12 ; i++) {
        degrees[i] = keys[i+startPoint];
    }
    currentKey = keyName;
    updateInformation();
}</pre>
<div class="im">Now that we can  transpose, let&#8217;s try to implement a highlighting mechanism. This is trickier than the transposition algorithm, because we will have to deal with different types of <strong>views</strong>, each of which will potentially require a different approach. Even though I&#8217;ll only implement a simple table for now, I&#8217;ll take my time to think of the commonalities of different views and see if I can avoid re-work in the future by designing something more general.</div>
<div class="im">
<p>Before designing the view, let me elaborate on the <strong>data</strong>, or <strong>Model </strong>of our application a bit. For now, all  I care is what subset of my <strong>degrees</strong> <strong>array</strong> is part of the <strong>chord </strong>or <strong>scale</strong>. Even though Chords and Scales  are different beasts musically, in our case I&#8217;ll treat them the same, because they are programmatically nothing more  than a subset of my <strong>degrees </strong>array, which  always has exactly 12 members.</p>
<p>I can use any format to keep my static data, which is for now just the chord and scale definitions. I&#8217;ll go with a simple array of 12 members again, where  I&#8217;ll have a member &#8220;1&#8243; when the note is a scale/chord member, and &#8220;0&#8243; when it is not. For example, some  scale/chord definitions will look like this:</p>
<pre>Chromatic_scale:      111111111111
Diminished_chord:     100100100100
Major_chord:          100010010000
Major_scale:          101011010101</pre>
</div>
<p>Note that I appended the words <strong>_chord</strong> or <strong>_scale</strong> at the end of my scale/chord names as some chords and scales happen to have the same names, even though they represent entirely different things (i.e. a major chord and a major scale).</p>
<p>For now I&#8217;ll create associative arrays in my JavaScript code to keep these definitions. Moving forward, I&#8217;ll probably put all of them in  a simple file and load to memory during page initiation. JSON might be a pretty good fit considering Dojo has  built-in support for it and our data is pretty small in size. Eventually they&#8217;ll end up in a database. For now this is how my data definitions look like:</p>
<pre>var scaleChordData = new Array();
scaleChordData['Major_scale'] =            ['1','0','1','0','1','1','0','1','0','1','0','1'];
scaleChordData['NaturalMinor_scale'] =     ['1','0','1','1','0','1','0','1','1','0','1','0'];
scaleChordData['HarmonicMinor_scale'] =    ['1','0','1','1','0','1','0','1','1','0','0','1'];
scaleChordData['WholeNote_scale'] =        ['1','0','1','0','1','0','1','0','1','0','1','0'];
scaleChordData['Diminished_scale'] =       ['1','0','1','1','0','1','1','0','1','1','0','1'];
scaleChordData['MajorPentatonic_scale'] =  ['1','0','1','0','1','0','0','1','0','1','0','0'];
scaleChordData['MinorPentatonic_scale'] =  ['1','0','0','1','0','1','0','1','0','0','1','0'];
scaleChordData['Chromatic_scale'] =        ['1','1','1','1','1','1','1','1','1','1','1','1'];</pre>
<p>I also have another associative array to keep user friendly name, which I`ll use later to dynamically generate on screen information snippets. I kind of have to keep these two separate arrays in sync, as JavaSctipt doesn`t have a Hash Table or Hash Map that comes with most languages.</p>
<pre>var scaleChordName = new Array();
scaleChordName['Major_scale'] =             'Major Scale';
scaleChordName['NaturalMinor_scale'] =      'Minor (Natural) Scale';
scaleChordName['HarmonicMinor_scale'] =     'Minor (Harmonic) Scale';
scaleChordName['WholeNote_scale'] =         'Whole Note Scale';
scaleChordName['MajorPentatonic_scale'] =   'Major Pentatonic Scale';
scaleChordName['MinorPentatonic_scale'] =   'Minor Pentatonic Scale';
scaleChordName['Diminished_scale'] =        'Diminished Scale';
scaleChordName['Chromatic_scale'] =         'Chromatic Scale';</pre>
<p>And finally I can get to the part where we highlight scales and chords visually on the screen, so the user can quickly see which notes belong to the scale or chord, and which ones don`t.  For <strong>Table View</strong>,  highlighting is quite simple. All I need to do is to find the table cells that correspond members of  my scale or chord, and then change their style dynamically.</p>
<div class="im">
<p>The following function does just that. First it first iterates through the <strong>degrees </strong>array (which keeps my transposed scale) and updates the table cells with the array values.Then it iterates through currentScaleChordData (1s and 0s) and changes the background color of the cells; blue for 1s and white for 0s.</div>
<pre>function updateDegreesTable() {
    // Update notes
    for (var i = 1; i &lt; 13 ; i++) {
        var degree = degrees[i-1];
        dojo.byId('r2_c'+i).innerHTML = degree;
    }
    // Update highlighting
    for (var j = 1; j &lt; 13 ; j++) {
        var current = currentScaleChordData[j-1];
        if (current == 1) {
            document.getElementById('r2_c'+j).style.backgroundColor='#ddddff';
        }
        else {
            document.getElementById('r2_c'+j).style.backgroundColor='#ffffff';
        }
    }
}</pre>
<p>Finally I wire these two functions up with the keys and scales on the left panel. So when the user clicks on a key or scale link, the <strong>transposeToKey </strong>and <strong>updateDegreesTable </strong>functions are called, respectively.</p>
<pre>...
  &lt;li class="leftPanel" <span style="color: #ff0000;"><strong>onClick="transposeToKey('Bb')</strong>;"</span>&gt;&lt;span&gt;B-flat&lt;/span&gt;&lt;hr&gt;&lt;/li&gt;
  &lt;li class="leftPanel" <span style="color: #ff0000;"><strong>onClick="transposeToKey('B');"</strong></span>&gt;&lt;span&gt;B&lt;/span&gt;&lt;hr&gt;&lt;/li&gt;
&lt;/div&gt;
&lt;div dojoType="dijit.layout.AccordionPane" title="Scales"&gt;
  &lt;p&gt;
  &lt;li class="leftPanel" <span style="color: #ff0000;"><strong>onClick="updateScaleChord('Major_scale');"</strong></span>&gt;&lt;span&gt;Major&lt;/span&gt;&lt;/li&gt;
  &lt;li class="leftPanel" <span style="color: #ff0000;"><strong>onClick="updateScaleChord('MajorPentatonic_scale');"</strong></span>&gt;&lt;span&gt;Major Pentatonic&lt;/span&gt;&lt;/li&gt;
...</pre>
<p>Note that some code was omitted for brevity. And also note that the fisheye animations I used to decorate the left panel items last week didn&#8217;t seem to be a great idea anymore after a week of playing with them. So I ended up replacing them with simple text, which I will try to make nicer later.</p>
<p>The application now looks like this, which still has some more work to do but can now show the keys and chord/scale notes for scales as designed:</p>
<p><a href="http://karul.org/blog/wp-content/uploads/2009/10/mhelper3.jpg"><img class="aligncenter size-medium wp-image-321" title="Musician's Helper v3" src="http://karul.org/blog/wp-content/uploads/2009/10/mhelper3-300x207.jpg" alt="" width="300" height="207" /></a></p>
<p>A working version of the version 3 is available at <a href="http://karul.org/etc/mhelper/mhelper3.html" target="_blank">http://karul.org/etc/mhelper/mhelper3.html</a>.</p>
<blockquote><p><span style="color: #000080;">Some of the concepts discussed in this Blog has over the time evolved into an application you might want to check out:</span></p>
<p><span style="color: #000080;"><a title="http://music.isallicare.com" href="http://music.isallicare.com" target="_blank">http://music.isallicare.com</a></span></p>
<p><span style="color: #000080;">Thanks for visiting my Blog     &#8212; C. Karul Jan 3, 2010</span></p></blockquote>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://karul.org/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://karul.org/blog/2009/10/developing-a-dojo-application-3-wiring-it-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

