<?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>DaveOnCode</title>
	<atom:link href="http://www.daveoncode.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.daveoncode.com</link>
	<description>coder and technology lover</description>
	<lastBuildDate>Sun, 16 May 2010 16:55:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>iPhone applications&#8217; localization</title>
		<link>http://www.daveoncode.com/2010/05/15/iphone-applications-localization/</link>
		<comments>http://www.daveoncode.com/2010/05/15/iphone-applications-localization/#comments</comments>
		<pubDate>Sat, 15 May 2010 12:15:28 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[Objective-c and Cocoa]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[internalization]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=609</guid>
		<description><![CDATA[Well, it&#8217;s quite a lot since my first approach to Objective C, Cocoa and iPhone development and now I&#8217;m starting to move my first concrete steps into this beautiful world. Today I would like to face an important aspect of iPhone development (and application development generally), localization! Fortunately the excellent Cocoa framework and Objective C]]></description>
			<content:encoded><![CDATA[<p>Well, it&#8217;s quite a lot since my first approach to Objective C, Cocoa and iPhone development and now I&#8217;m starting to move my first concrete steps into this beautiful world. Today I would like to face an important aspect of iPhone development (and application development generally), localization! Fortunately the excellent Cocoa framework and Objective C ecosystem make internalization process easy, fast and clean, thus localize an application into several languages can be accomplished with a minimum effort by developers.<br />
Fundamentally there are three main steps to get a multi language app in action. The first is to create a special folder with the extension <strong>.lproj</strong> under application&#8217;s root for each language we want/can support. So, if we suppose to support english, italian and spanish languages, we will create those folders: <strong>en.lproj</strong>, <strong>it.lproj</strong>, <strong>es.lproj</strong>. &#8220;en&#8221;, &#8220;it&#8221; and &#8220;es&#8221; represent the <strong>ISO 639-1</strong> language designation (the same used in domain suffixes), it&#8217;s also possible to adopt the <strong>ISO 639-2</strong> convention and the folders would be renamed as &#8220;eng&#8221;, &#8220;ita&#8221; and &#8220;spa&#8221;, anyway first approach is the preferred and widely adopted. If you want to know all <strong>ISO 639-1</strong> and <strong>ISO 639-2</strong> designators, I suggest you this page: <a href="http://www.loc.gov/standards/iso639-2/php/code_list.php">http://www.loc.gov/standards/iso639-2/php/code_list.php</a>.<br />
Once we create all the necessary <strong>.lproj</strong> folders (using Finder or Terminal) we can switch to our beloved Xcode and create all the necessary resources that will keep the different localized strings. We must now select the logical &#8220;<strong>Resources</strong>&#8221; folder and add a new file by choosing &#8220;<strong>String file</strong>&#8221; under Mac OS X &#8220;<strong>Resource</strong>&#8220;, then click next and naming this file &#8220;<strong>Localizable.strings</strong>&#8220;, finally save it under previous created folders (we must repeat this operation for each folder).<br />
Those <strong>.strings</strong> file are just simple text file, where we can specify keys and values as the following example:</p>
<p>// en.lproj<br />
&#8220;hello&#8221; = &#8220;Hello&#8221;;</p>
<p>// it.lproj<br />
&#8220;hello&#8221; = &#8220;Ciao&#8221;;</p>
<p>// sp.lproj<br />
&#8220;hello&#8221; = &#8220;Hola&#8221;;</p>
<p>The basic approach is to use the english word as the key and assign it different values based on the localization file, but we can be more cryptic and use our custom conventions, for example by assigning incremental keys like: &#8220;k1&#8243;, &#8220;k2&#8243;, &#8220;k3&#8243; and so on. As last step, we can automatically read the right localized string version at runtime (based on user&#8217;s language setting) by using macro (<strong>NSLocalizedString</strong>, <strong>NSLocalizedStringFromTable</strong>, <strong>NSLocalizedStringFromTableInBundle</strong>, <strong>NSLocalizedStringWithDefaultValue</strong>) or class methods available in Apple&#8217;s framework. The simplest way to do that is to use the function <strong>NSLocalizedString()</strong>, which accepts two arguments: an <strong>NSString</strong> representing the key we are looking for and a second optional argument which has the mere purpose of serving as note for developers by trying to describe string&#8217;s context (*), for this reason this argument will be &#8220;<strong>nil</strong>&#8221; the most of times:</p>
<div class="codecolorer-container c mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// set myLabel's text using NSLocalizedString()</span><br />
myLabel.<span style="color: #202020;">text</span> <span style="color: #339933;">=</span> NSLocalizedString<span style="color: #009900;">&#40;</span>@<span style="color: #ff0000;">&quot;hello&quot;</span><span style="color: #339933;">,</span> nil<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Although this approach is very simple, it&#8217;s not recommendable in my opinion, because it doesn&#8217;t provide a way to handle missing keys and if a key can&#8217;t be found, it will print that key literally (and in case of a not human readable key like &#8220;k-15&#8243;, it would be very annoying for the user). Thus, a far better option is to use the <strong>NSLocalizedStringWithDefaultValue()</strong>, which accepts 5 arguments: an <strong>NSString</strong> for the key, an <strong>NSString</strong> for the table, an <strong>NSBundle</strong> reference, an <strong>NSString</strong> for a fallback string&#8217;s value, and an optional <strong>NSString</strong> for a comment (like <strong>NSLocalizedString()</strong>). The table argument refers to the name of <strong>.strings</strong> file (without extension), in fact we are not limited to &#8220;<strong>Localizable.strings</strong>&#8221; but we can create as many <strong>.strings</strong> files we need (&#8220;Menu.strings&#8221;, &#8220;InfoPanel.strings&#8221;&#8230;). &#8220;<strong>Localizable.strings</strong>&#8221; is only a conventional name used to specify a default file for localization that can be loaded without specify its name (<strong>NSLocalizedString()</strong> can read only that file). The bundle is a reference to the <strong>NSBundle</strong> where the <strong>.strings</strong> file is located (usually the main bundle).</p>
<div class="codecolorer-container c mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// set myLabel's text using NSLocalizedStringWithDefaultValue()</span><br />
myLabel.<span style="color: #202020;">text</span> <span style="color: #339933;">=</span> NSLocalizedStringWithDefaultValue<span style="color: #009900;">&#40;</span>@<span style="color: #ff0000;">&quot;MyKey&quot;</span><span style="color: #339933;">,</span> @<span style="color: #ff0000;">&quot;MyStringFile&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>NSBundle mainBundle<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> @<span style="color: #ff0000;">&quot;Missing key&quot;</span><span style="color: #339933;">,</span> nil<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>It&#8217;s also possible to use bundle&#8217;s method <strong>localizedStringForKey:value:table</strong>, which accepts an <strong>NSString</strong> as key, a second <strong>NSString</strong> as fallback value, and a third <strong>NSString</strong> for the table (or <strong>nil</strong> if you are lazy and want to use &#8220;<strong>Localizable.strings</strong>&#8221; without specifying it) :</p>
<div class="codecolorer-container c mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">NSBundle <span style="color: #339933;">*</span>bundle <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>NSBundle mainBundle<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
myLabel.<span style="color: #202020;">text</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>bundle localizedStringForKey<span style="color: #339933;">:</span>@<span style="color: #ff0000;">&quot;MyKey&quot;</span> value<span style="color: #339933;">:</span>@<span style="color: #ff0000;">&quot;Missing key :(&quot;</span> table<span style="color: #339933;">:</span>nil<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>An important point to understand is how localization process works, that is which steps are involved at runtime on the device. As far I know (by doing several experiment using iPhone simulator), the process is the following: </p>
<p>1. code is executed and a request for a localized string is found<br />
2. the system try to find the <strong>.strings</strong> file of the current locale (according to user language settings). The NSString represenitng current locale can be found using:</p>
<div class="codecolorer-container c mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>NSLocale currentLocale<span style="color: #009900;">&#93;</span> localeIdentifier<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>3. If the file is found, it will search for the requested key and it will return it&#8217;s value if found or a nil otherwise. If .strings file can&#8217;t be found, the system will try to find others <strong>.strings</strong> file sequentially, using <strong>preferredLanguages</strong>&#8216;s <strong>NSArray</strong>:</p>
<div class="codecolorer-container c mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">NSArray <span style="color: #339933;">*</span>preferredLanguages <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>NSLocale preferredLanguages<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>and it will stops as soon a file is found, by returning key&#8217;s value if found or <strong>nil</strong> otherwise.</p>
<p>So, considering the simple &#8220;hello&#8221; localization example into english, italian and spanish, our @&#8221;hello&#8221; key will be successfully translated if we use one of the three locales (en, it, sp) and it will be printed in english for extra locales (like german, french and so on).</p>
<p>Finally it&#8217;s also possible to generate strings file automatically from the source code by using Terminal&#8217;s command <strong>genstrings</strong>, see here for details:  <a href="http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/genstrings.1.html">http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/genstrings.1.html</a></p>
<p>* the comment parameter is also used to automatically generate a comment (/* comment */) in <strong>.strings</strong> files using <strong>genstrings</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2010/05/15/iphone-applications-localization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning shell scripting while trying to fix Snow Leopard local network issue :)</title>
		<link>http://www.daveoncode.com/2010/04/08/learning-shell-scripting-while-trying-to-fix-snow-leopard-local-network-issue/</link>
		<comments>http://www.daveoncode.com/2010/04/08/learning-shell-scripting-while-trying-to-fix-snow-leopard-local-network-issue/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 15:31:44 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[samba]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[smb]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=606</guid>
		<description><![CDATA[Mac OS X is a great system, but this doesn&#8217;t mean it&#8217;s perfect and without issues. One thing is not working as it would (in Snow Leopard 10.6.X), it&#8217;s the automatic discovering and mounting of local machines connected to the same network. This is especially true if the network includes a lot of Windows computers.]]></description>
			<content:encoded><![CDATA[<p>Mac OS X is a great system, but this doesn&#8217;t mean it&#8217;s perfect and without issues. One thing is not working as it would (in Snow Leopard 10.6.X), it&#8217;s the automatic discovering and mounting of local machines connected to the same network. This is especially true if the network includes a lot of Windows computers. Theoretically those machines should be automatically discovered and displayed in Finder under &#8220;SHARED&#8221; label, but often this is not the case. Anyway in such cases is fortunately possible to connect to a particular device from Finder (once we know its IP address) by choosing &#8220;Connect to server&#8230;&#8221; (cmd+K) and by using the Samba protocol (ie: smb://ip-address). This is however very annoying, because we have to know each ip we want to connect to and type several addresses, so I spent some time to find a way to make this process automatic (because I didn&#8217;t find a solution to the original OS X issue) and I realized a shell script which tries to do the job the Leopard should do :)<br />
I&#8217;m really a newbie when it comes to shell scripting (and networking too :P) and my script doesn&#8217;t work perfectly, anyway it does an acceptable work the most of times and although it doesn&#8217;t really solve the problem, it could help a lot.<br />
The script is the following:</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/bash</span><br />
<br />
<span style="color: #666666; font-style: italic;"># get user name</span><br />
<span style="color: #7a0874; font-weight: bold;">declare</span> <span style="color: #007800;">currentuser</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">whoami</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># get mac name</span><br />
<span style="color: #7a0874; font-weight: bold;">declare</span> <span style="color: #007800;">macname</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>scutil <span style="color: #660033;">--get</span> ComputerName<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># save arp command result</span><br />
<span style="color: #7a0874; font-weight: bold;">declare</span> <span style="color: #007800;">ipstring</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>arp -a<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># split ipstring into an array by using a regex to match ip addresses</span><br />
<span style="color: #7a0874; font-weight: bold;">declare</span> <span style="color: #660033;">-a</span> <span style="color: #007800;">iplist</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$ipstring</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-o</span> <span style="color: #660033;">-E</span> <span style="color: #ff0000;">&quot;([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># display addresses found</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${#iplist[*]}</span> ip addresses found&quot;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># switch directory to user dir</span><br />
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$currentuser</span><br />
<br />
<span style="color: #666666; font-style: italic;"># for each ip in list try to mount it using smbfs</span><br />
<span style="color: #000000; font-weight: bold;">for</span> ip <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${iplist[@]}</span> <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">do</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-d</span> link-to-<span style="color: #007800;">$ip</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;creating directory link-to-<span style="color: #007800;">$ip</span> under /Users/<span style="color: #007800;">$currentuser</span>&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mkdir</span> link-to-<span style="color: #007800;">$ip</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;trying to mount //<span style="color: #007800;">$macname</span>:@<span style="color: #007800;">$ip</span>/Public&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #660033;">-t</span> smbfs <span style="color: #000000; font-weight: bold;">//</span><span style="color: #007800;">$macname</span>:<span style="color: #000000; font-weight: bold;">@</span><span style="color: #007800;">$ip</span><span style="color: #000000; font-weight: bold;">/</span>Public <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$currentuser</span><span style="color: #000000; font-weight: bold;">/</span>link-to-<span style="color: #007800;">$ip</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'folder &quot;link-to-$ip&quot; already exists... skip'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span> <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">done</span><br />
<br />
<span style="color: #666666; font-style: italic;"># complete</span><br />
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></div></td></tr></tbody></table></div>
<p>Any comment and suggestion is really appreciated! Thanks</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2010/04/08/learning-shell-scripting-while-trying-to-fix-snow-leopard-local-network-issue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handling doubleclick on Flex components</title>
		<link>http://www.daveoncode.com/2010/04/07/handling-doubleclick-on-flex-components/</link>
		<comments>http://www.daveoncode.com/2010/04/07/handling-doubleclick-on-flex-components/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 10:34:53 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[flex]]></category>
		<category><![CDATA[actionscript]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=598</guid>
		<description><![CDATA[Handling a common event like a double click is not so simple as we may assume when it comes to Flex programming. In fact there are several critical aspects related to this event, first of all we have to set the attribute doubleClickEnabled to true in order to make our components double clickable, and this]]></description>
			<content:encoded><![CDATA[<p>Handling a common event like a double click is not so simple as we may assume when it comes to Flex programming.<br />
In fact there are several critical aspects related to this event, first of all we have to set the attribute <strong>doubleClickEnabled</strong> to <strong>true</strong> in order to make our components double clickable, and this sounds pretty silly to me. Why should I enable an object to receive an event which is so common and &#8220;natural&#8221;? This is incoherent from a software design perspective end totally unexpected by the user. Anyway this is not a real problem, because once we know about it we have just to use a setter, but double click is somehow buggy in the framework and its broadcasting can be blocked mysteriously when using certain components. I faced this issue by trying to handle a double click on a DataGrid which makes use of custom item renderers and I tested that by double clicking on the &#8220;special cells&#8221; (those rendered by my own renderers) the <strong>MouseEvent.DOUBLE_CLICK</strong> is not dispatched/cacthed. To solve the problem I had to draw an invisible rectangle using the underlying Actionscript graphics API! This is my workaround:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">this</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xffffff, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #0066CC;">this</span>.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #0066CC;">this</span>.<span style="color: #006600;">parent</span>.<span style="color: #0066CC;">width</span>, <span style="color: #0066CC;">this</span>.<span style="color: #006600;">parent</span>.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #0066CC;">this</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div></td></tr></tbody></table></div>
<p>Finally, it seems that double click is <strong>completely ignored</strong> by Firefox 3.6 on Mac OS X, but fortunately this seems to been fixed in the last release (3.6.3)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2010/04/07/handling-doubleclick-on-flex-components/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get hours, minutes and seconds from a number without maths operations</title>
		<link>http://www.daveoncode.com/2010/02/05/get-hours-minutes-and-seconds-from-number-without-maths-operations/</link>
		<comments>http://www.daveoncode.com/2010/02/05/get-hours-minutes-and-seconds-from-number-without-maths-operations/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 15:09:11 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=589</guid>
		<description><![CDATA[Today I&#8217;m gonna show you a secret ninja technique to extract hours, minutes and seconds from a number (representing an amount of seconds). In my example I will show an Actionscript code, but this can be implemented in JavaScript and maybe other languages too. So, the scenario is the following: we have a number representing]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;m gonna show you a secret ninja technique to extract hours, minutes and seconds from a number (representing an amount of seconds). In my example I will show an Actionscript code, but this can be implemented in JavaScript and maybe other languages too.<br />
So, the scenario is the following: we have a number representing seconds and we want to know how many hours this amount of seconds contains, how many minutes and how many remaining seconds. We know that a minute is composed by 60 seconds and an hour by 60 minutes and we could write a series of maths operations in order to accomplish our objective, but there is a way far simple and fast: use the Date class!<br />
Date class already implements all the methods we need:</p>
<ul>
<li><strong>getHours()</strong></li>
<li><strong>getMinutes()</strong></li>
<li><strong>getSeconds()</strong></li>
</ul>
<p>So, in order to take advantage of these useful methods, all we have to do is initialize a &#8220;fake&#8221; date using the amount of seconds we want to &#8220;split&#8221; into hours, minutes and seconds. The Date class has several OPTIONAL arguments that can be specified during its initializations, these are:</p>
<ul>
<li><strong>year</strong></li>
<li><strong>month</strong></li>
<li><strong>date</strong> (day number)</li>
<li><strong>hours</strong></li>
<li><strong>minutes</strong></li>
<li><strong>seconds</strong></li>
<li><strong>milliseconds</strong></li>
</ul>
<p>Because theme all are optional, we can create a date object by specifying only the know arguments (in our case seconds) and by assigning null or zero to the others:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">date</span>:<span style="color: #0066CC;">Date</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">9137</span><span style="color: #66cc66;">&#41;</span>;</div></td></tr></tbody></table></div>
<p>Then by calling getHours, getMinutes and getSeconds we will obtain what we expect:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;hours: &quot;</span>, <span style="color: #0066CC;">date</span>.<span style="color: #0066CC;">getHours</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// 2 hours</span><br />
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;minutes: &quot;</span>, <span style="color: #0066CC;">date</span>.<span style="color: #0066CC;">getMinutes</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// 32 minutes</span><br />
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;seconds: &quot;</span>, <span style="color: #0066CC;">date</span>.<span style="color: #0066CC;">getSeconds</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// 17 seconds</span></div></td></tr></tbody></table></div>
<p>Not sure about the result? Let&#8217;s test it:</p>
<p>60 * 60 * 2 = <strong>7200</strong>; (seconds contained in 2 hours)<br />
32 * 60 = <strong>1920</strong>; (seconds contained in 32 minutes)<br />
7200 + 1920 + 17 = <strong>9137</strong>; (original seconds!)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2010/02/05/get-hours-minutes-and-seconds-from-number-without-maths-operations/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Debugging PhoneGap applications using Xcode console</title>
		<link>http://www.daveoncode.com/2010/01/12/debugging-phonegap-applications-using-xcode-console/</link>
		<comments>http://www.daveoncode.com/2010/01/12/debugging-phonegap-applications-using-xcode-console/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 10:13:59 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[phonegap]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=580</guid>
		<description><![CDATA[When I started to play whit PhoneGap, my greatest issue was: &#8220;how can I debug my code?&#8221;, I use often tools such FireBug and JavaScript debugger included in Internet Explorer 8 (which is the first good thing IE has to offers!) but write and test my code on iPhone simulator is completely different. Fortunately PhoneGap]]></description>
			<content:encoded><![CDATA[<p>When I started to play whit <strong>PhoneGap</strong>, my greatest issue was: &#8220;how can I debug my code?&#8221;, I use often tools such <strong>FireBug</strong> and JavaScript debugger included in Internet Explorer 8 (which is the first good thing IE has to offers!) but write and test my code on iPhone simulator is completely different. Fortunately PhoneGap offers a way to access to <strong>Xcode</strong> console and print messages by choosing among three different levels: <strong>log</strong>, <strong>warn</strong> and <strong>error</strong>. In order to print a message, we have to use the <strong>debug</strong> object, which has scope <strong>window</strong> (it is a global object), in this way:</p>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">debug.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;my log message&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">// or</span><br />
debug.<span style="color: #660066;">warn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;my warning message&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">// or</span><br />
debug.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;my error message&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>To open Xcode console you have to choose &#8220;Run -> Console&#8221; from the toolbar (or CMD+SHIFT+R) and after a &#8220;Build and Run&#8221; (CMD+Enter), you will see your message appear in the console.<br />
Testing applications while developing using PhoneGap and Xcode, is an intense activity, because errors are not automatically notified (like in FireBug or similar), so it&#8217;s really important to make use of <strong>try/catch/finally</strong> blocks and logging calls:</p>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; mycommand.<span style="color: #660066;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; debug.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Error using mycommand: &quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #660066;">message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">finally</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// do something smart here :^)</span><br />
<br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Finally, in order to avoid problems related to Xcode cache, I suggest to always clean the cache by running &#8220;Build -> Clean&#8221; from the toolbar (or CMD+SHIFT+K) before doing a new build and eventually remove the application folder under &#8220;/Users/{your-name}/Library/Application Support/iPhone Simulator/User/Applications/{app-number}&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2010/01/12/debugging-phonegap-applications-using-xcode-console/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to solve CSS conflicts using jQTouch</title>
		<link>http://www.daveoncode.com/2010/01/02/jqtouch-how-to-solve-css-conflicts-using-jqtouch/</link>
		<comments>http://www.daveoncode.com/2010/01/02/jqtouch-how-to-solve-css-conflicts-using-jqtouch/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 16:55:40 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jqtouch]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=569</guid>
		<description><![CDATA[In these days I&#8217;m developing my first iPhone application, using frameworks like PhoneGap and jQTouch. This aims to be a powerful app, not a mere widget, so I&#8217;m writing a lot of code and I&#8217;m using several libraries and components in order to create a really native-like application. Unfortunately, due to a bad CSS approach,]]></description>
			<content:encoded><![CDATA[<p>In these days I&#8217;m developing my first iPhone application, using frameworks like <a href="http://phonegap.com/">PhoneGap</a> and <a href="http://www.jqtouch.com/">jQTouch</a>. This aims to be a powerful app, not a mere widget, so I&#8217;m writing a lot of code and I&#8217;m using several libraries and components in order to create a really native-like application.<br />
Unfortunately, due to a bad CSS approach, I faced an issue with the excellent <strong><a href="http://cubiq.org/spinning-wheel-on-webkit-for-iphone-ipod-touch/11">SpinningWheel</a></strong> component which won&#8217;t never be displayed unless you open and modify jQTouch CSS. The fact is that, jQTouch takes the body and use it as main container to hold all application&#8217;s pages and components and by default it hides all nodes inside the body except the current displayed content (active page/section) and this is a problem, because SpinningWheel create the ui object into the body and it won&#8217;t be displayed.<br />
Fortunately the solution is simple, we just need a wrapper, an html element which will holds all jQTouch stuff in place of body, so in my html I wrapped all inside this:</p>
<div class="codecolorer-container html4strict mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jqtouch-wrapper&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">&lt;!-- content --&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span></div></td></tr></tbody></table></div>
<p>Then I changed all jQTouch CSS, to reflect this approach (you can see the wrapper as a sandbox):</p>
<div class="codecolorer-container css mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">div<span style="color: #cc00cc;">#jqtouch-wrapper</span> <span style="color: #00AA00;">&gt;</span> <span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; -webkit-backface-<span style="color: #000000; font-weight: bold;">visibility</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; -webkit-box-sizing<span style="color: #00AA00;">:</span> border-box<span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; -webkit-transform<span style="color: #00AA00;">:</span> translate3d<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">&#41;</span> rotate<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">&#41;</span> scale<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">min-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">420px</span> !important<span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">/* ...and so on*/</span></div></td></tr></tbody></table></div>
<p>&#8230;and finally I changed jQuery selectors inside JavaScript code:</p>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;$body <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#jqtouch-wrapper'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">// ...and so on</span></div></td></tr></tbody></table></div>
<p>It&#8217;s also possible to solve the conflict by changing SpinningWheel code in order to put the dom node inside active jQTouch pages, but the problem of potential incompatibilities will remains. A CSS declaration, except reset statements and other rare cases, should NEVER refers directly to a whole set of nodes (ie: <strong>ul { color: red; })</strong>, but to a node type contained by a wrapper/sandbox (ie: <strong>#foo ul {color: red; }</strong>), thus conflicts will be avoided.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2010/01/02/jqtouch-how-to-solve-css-conflicts-using-jqtouch/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Google Closure&#8217;s idiocies: Ajax can&#8217;t be synchronous :(</title>
		<link>http://www.daveoncode.com/2009/12/31/google-closures-idiocies-ajax-cant-be-synchronous/</link>
		<comments>http://www.daveoncode.com/2009/12/31/google-closures-idiocies-ajax-cant-be-synchronous/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 11:02:08 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[google closure]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[closure]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=564</guid>
		<description><![CDATA[While I love Closure tools and the possibility to write a better organized and OOP based JavaScript, I&#8217;m facing some weakness and inexplicable choices in the library. The last discover is that is impossible to make synchronous ajax call using the provided classes, since I didn&#8217;t find nothing about synch/asynch options by reading API reference,]]></description>
			<content:encoded><![CDATA[<p>While I love Closure tools and the possibility to write a better organized and OOP based JavaScript, I&#8217;m facing some weakness and inexplicable choices in the library. The last discover is that is impossible to make synchronous ajax call using the provided classes, since I didn&#8217;t find nothing about synch/asynch options by reading API reference, I took a look to the source (xhrio.js), and I noticed this:</p>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">xhr_</span>.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span>method<span style="color: #339933;">,</span> url<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp;<span style="color: #006600; font-style: italic;">// Always async!</span></div></td></tr></tbody></table></div>
<p>that <strong>true</strong> should be a parametric value which developers can set to true or false. Why forcing it to true???<br />
I&#8217;m really disappointed :(</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2009/12/31/google-closures-idiocies-ajax-cant-be-synchronous/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>&#8220;Not authorized&#8221; error due to Safari &#8220;private browsing&#8221; mode! :P</title>
		<link>http://www.daveoncode.com/2009/12/27/not-authorized-error-due-to-safari-private-browsing-mode/</link>
		<comments>http://www.daveoncode.com/2009/12/27/not-authorized-error-due-to-safari-private-browsing-mode/#comments</comments>
		<pubDate>Sun, 27 Dec 2009 14:26:56 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[browsers]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=562</guid>
		<description><![CDATA[This is just a quick post to share my misadventure with Safari and the &#8220;private browsing&#8221; mode. I&#8217;m working on a small JavaScript library which has the goal to abstract SQLite database api and allow users to create table, insert, update and delete records easily&#8230; my code seems to work very well, but this morning]]></description>
			<content:encoded><![CDATA[<p>This is just a quick post to share my misadventure with Safari and the &#8220;private<br />
browsing&#8221; mode. I&#8217;m working on a small JavaScript library which has the goal to abstract  SQLite database api and allow users to create table, insert, update and delete<br />
records easily&#8230; my code seems to work very well, but this morning during some<br />
tests, I got the &#8220;not authorized&#8221; exception (error code n°1)  on every<br />
transaction. After hours of debugging I realized that my code was ok, but I forgot<br />
to disable the &#8220;private browsing&#8221; mode in Safari!<br />
So, bear in mind, if you want to play with database api and other client-related store capabilities (such cookies), remember to disable that option in Safari ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2009/12/27/not-authorized-error-due-to-safari-private-browsing-mode/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Extending Eclipse using JavaScript and Monkey Script engine</title>
		<link>http://www.daveoncode.com/2009/12/16/extending-eclipse-using-javascript-monkey-script-engine/</link>
		<comments>http://www.daveoncode.com/2009/12/16/extending-eclipse-using-javascript-monkey-script-engine/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 16:20:50 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[extensions]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=555</guid>
		<description><![CDATA[I was wondering how to wrap a string with quotes in Eclipse by using a shortcut, then I realized that there is not such command, so I started thinking for a solution and initially I created an Aptana&#8217;s snippet, but I was not satisfied, because I want to have an handy shortcut to invoke my]]></description>
			<content:encoded><![CDATA[<p>I was wondering how to wrap a string with quotes in Eclipse by using a shortcut, then I realized that there is not such command, so I started thinking for a solution and initially I created an Aptana&#8217;s snippet, but I was not satisfied, because I want to have an handy shortcut to invoke my snippet. By googling, I discovered Eclipse Monkey Script engine, that is an extremely powerful tool for every JavaScript developer who wants to extend Eclipse features by writing few lines of JavaScript code. In order to use the js engine, you must have the package org.eclipse.eclipsemonkey (which is installed by default by Aptana) installed. Unfortunately I can&#8217;t find a complete and exhaustive reference for this project, which seems forgotten by authors, so I learnt what I know reading different posts.<br />
Basically, Monkey Script allow developers to access editor&#8217;s instance, get selected test, get document content, edit it and update it. Moreover is possible to print text to consol, read and create files on the filesystem&#8230; and finally the scripts created will be accessible from Eclipse menu (under &#8220;Scripts&#8221;) and invokable through user defined shortcut&#8230; really nice!<br />
So, backing to my experiment, I created this monkey script:</p>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-style: italic;">/* <br />
* Key: M1+M2+C<br />
* Menu: Custom Scripts &gt; Wrap with double quotes<br />
* DOM: http://download.eclipse.org/technology/dash/update/org.eclipse.eclipsemonkey.lang.javascript<br />
* Kudos: Davide Zanotti<br />
*/</span><br />
<span style="color: #003366; font-weight: bold;">function</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// no editor... exit</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> editors.<span style="color: #660066;">activeEditor</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;undefined&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;No active editor&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// get a reference to the editor in use</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> editor <span style="color: #339933;">=</span> editors.<span style="color: #660066;">activeEditor</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// beginning of text selection</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> startOffset <span style="color: #339933;">=</span> editor.<span style="color: #660066;">selectionRange</span>.<span style="color: #660066;">startingOffset</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// end of text selection</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> endOffset <span style="color: #339933;">=</span> editor.<span style="color: #660066;">selectionRange</span>.<span style="color: #660066;">endingOffset</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// selected text</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> selection <span style="color: #339933;">=</span> editor.<span style="color: #660066;">source</span>.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span>startOffset<span style="color: #339933;">,</span> endOffset<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// surround selection with quotes</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;editor.<span style="color: #660066;">applyEdit</span><span style="color: #009900;">&#40;</span>startOffset<span style="color: #339933;">,</span> endOffset <span style="color: #339933;">-</span> startOffset<span style="color: #339933;">,</span> <span style="color: #3366CC;">'&quot;'</span> <span style="color: #339933;">+</span> selection <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Error &quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #660066;">code</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;: &quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #660066;">message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>It&#8217;s important to notice some points, first you MUST write an &#8220;header&#8221; using the comment syntax &#8220;/* */&#8221; into which you MUST declare at least 2 parameter: the &#8220;<strong>Menu</strong>&#8221; path (you can nest several menu items by writing several &#8220;&gt;&#8221;) and the &#8220;<strong>DOM</strong>&#8221; package (which allows you to access specific objects like &#8220;<strong>editors</strong>&#8220;). You can write several js functions, but you must provide a <strong>main()</strong> function, which is called automatically by Eclipse once you launch your script, otherwise you can call the main function as you like but you must then provide the &#8220;OnLoad&#8221; param in the header, specifying which function will be called.<br />
To define a shortcut you can use the &#8220;<strong>Key</strong>&#8221; parameter and define your own keys combination by choosing among the four modifiers: M1, M2, M3, M4, that are a platform-independent way of representing keys (these stand for ALT, COMMAND, CTRL, and SHIFT). The strange (at least to me) parameter &#8220;<strong>Kudos</strong>&#8221; is used to declare the author of the monkey script.<br />
To test my little script or create your own, you have simply to create a new project into Eclipse by calling it as you like (ie: &#8220;custom-extensions&#8221;), then create a &#8220;scripts&#8221; folder into which you will save your .js files&#8230; that&#8217;s all, try yourself and enjoy :)</p>
<p>This is how it looks:</p>
<div id="attachment_558" class="wp-caption alignnone" style="width: 519px"><img src="http://www.daveoncode.com/wp-content/uploads/2009/12/Screen-shot-2009-12-16-at-17.08.56.jpg" alt="eclipse monkey script menu" title="eclipse-monkey-script-menu" width="509" height="254" class="size-full wp-image-558" /><p class="wp-caption-text">eclipse monkey script menu</p></div>
<p>ps: I&#8217;m going to explore the Monkey Script API in order to write more complex and useful extensions :P</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2009/12/16/extending-eclipse-using-javascript-monkey-script-engine/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>.cjs (Compiled JavaScript): an idea for a new file extension</title>
		<link>http://www.daveoncode.com/2009/12/10/cjs-compiled-javascript-file-extension-idea/</link>
		<comments>http://www.daveoncode.com/2009/12/10/cjs-compiled-javascript-file-extension-idea/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 16:54:59 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=547</guid>
		<description><![CDATA[Due to the growing diffusion of tools to compress and optimize JavaScript files (such Google Closure), I feel the need of an introduction of a standard way to identify and differentiate them (compiled files) from other uncompressed files. Basically, I would adopt a different file extension like CJS (which stands for compiled/compressed JavaScript). In this]]></description>
			<content:encoded><![CDATA[<p>Due to the growing diffusion of tools to compress and optimize JavaScript files (such Google Closure), I feel the need of an introduction of a standard way to identify and differentiate them (compiled files) from other uncompressed files. Basically, I would adopt a different file extension like <strong>CJS</strong> (which stands for compiled/compressed JavaScript). In this way it would be easy to browse a directory of hundreds of js files and identify those which are ready to be used in our project because already compressed and optimized.<br />
What do you think about?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2009/12/10/cjs-compiled-javascript-file-extension-idea/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
