<?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>HiddenTao &#187; Mobile</title>
	<atom:link href="http://www.hiddentao.com/archives/tag/mobile/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hiddentao.com</link>
	<description>software, websites, mobile, technology</description>
	<lastBuildDate>Fri, 27 Jan 2012 13:11:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>How to write a custom widget for jQuery Mobile</title>
		<link>http://www.hiddentao.com/archives/2011/11/07/how-to-write-a-custom-widget-for-jquery-mobile/</link>
		<comments>http://www.hiddentao.com/archives/2011/11/07/how-to-write-a-custom-widget-for-jquery-mobile/#comments</comments>
		<pubDate>Mon, 07 Nov 2011 10:28:06 +0000</pubDate>
		<dc:creator>ram</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Mobile]]></category>

		<guid isPermaLink="false">http://www.hiddentao.com/?p=1307</guid>
		<description><![CDATA[I needed to write a custom widget for the jQuery Mobile library but couldn&#8217;t find any step-by-step documentation on how to do it in the official docs. A search on Google didn&#8217;t result in any better luck. In the end it turned out to be quite easy to do &#8211; I was able to figure [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to write a custom widget for the <a href="http://jquerymobile.com/" class="link-external">jQuery Mobile</a> library but couldn&#8217;t find any step-by-step documentation on how to do it in the official docs. A search on Google didn&#8217;t result in any better luck. In the end it turned out to be quite easy to do &#8211; I was able to figure it out by looking at the source code of jQuery Mobile and that of the excellent <a href="http://dev.jtsage.com/jQM-DateBox/" class="link-external">DateBox</a> plugin. In this post I outline the essentials to adding your own custom widget to jQuery Mobile.
<span id="more-1307"></span></p>

<p>Ideally place all your widget code into its own file. Here is the basic code structure:</p>

<div><pre class="brush: jscript; title: ; notranslate">
(function($){
  $.widget(&quot;mobile.mywidget&quot;, $.mobile.widget, {
    /** Available options for the widget are specified here, along with default values. */
    options: {
      inline: false,
      mode: &quot;default&quot;,
      height: 200
    },
    /** Mandatory method - automatically called by jQuery Mobile to initialise the widget. */
    _create: function() {
      var inputElement = this.element;
      var opts = $.extend(this.options, inputElement.data(&quot;options&quot;));
      $(document).trigger(&quot;mywidgetcreate&quot;);
      ...
      inputElement.after(&quot;&lt;button&gt;&quot; + inputElement.val() + &quot;&lt;/button&gt;&quot;);
      ...
    },
    /** Custom method to handle updates. */
    _update: function() {
      var inputElement = this.element;
      var opts = $.extend(this.options, inputElement.data(&quot;options&quot;));
      $(document).trigger(&quot;mywidgetupdate&quot;);
      ...
      inputElement.siblings(&quot;button&quot;).text(inputElement.val());
      ...
    },
    /* Externally callable method to force a refresh of the widget. */
    refresh: function() {
      return this._update();
    }
  });
  /* Handler which initialises all widget instances during page creation. */
  $(document).bind(&quot;pagecreate&quot;, function(e) {
    $(document).trigger(&quot;mywidgetbeforecreate&quot;);
    return $(&quot;:jqmData(role='mywidget')&quot;, e.target).mywidget();
  });
})(jQuery);
</pre></div>

<p>In the HTML we can trigger use of the widget as follows:</p>

<div><pre class="brush: xml; title: ; notranslate">
  &lt;input type=&quot;text&quot; val=&quot;test&quot; data-role=&quot;mywidget&quot; data-height=&quot;100&quot; data-inline=&quot;true&quot; /&gt;
</pre></div>

<p>In the example above our widget is known as a <em>mywidget</em>. We first define the widget and then follow it with a handler for the <a href="http://jquerymobile.com/test/docs/api/events.html" class="link-external"><code>pagecreate</code> event</a>. This handler ensures that all HTML elements with the attribute <strong>data-role=&#8221;mywidget&#8221;</strong> are processed. <em>Note that you should use the <code>jqmData</code> filter in case you&#8217;re not using the standard <code>data-</code> prefix for widget attributes</em>.</p>

<p>Any number of options can be provided to your widget with no restrictions on option type. Per-widget-instance options can be specified as HTML attributes or as dictionary keys if initializing a widget directly in Javascript. Default values for options are provided within the widget itself (as you can see above).</p>

<p>The <code>_create()</code> method gets automatically called by jQuery Mobile when we call <code>mywidget()</code> from the <code>pagecreate</code> handler. This method is responsible for setting up the initial widget display. In the example above we simply add a button after the input element with its label set to the value within the text field.</p>

<p>There is also a <code>refresh()</code> method available for the widget which can be invoked through Javascript as follows:</p>

<p><code lang="js">
$(":jqmData(role='mywidget')").mywidget("refresh");
</code></p>

<p>This in turn calls the <code>_update()</code> method which in turn refreshes the button label with the current value of the text input field. You can add as many such methods as you like to the widget. For example, most of the standard jQuery Mobile widgets also come with <code>enable()</code> and <code>disable()</code> methods.</p>

<p>You&#8217;ll also notice that we trigger widget-specific events within the functions, e.g. <code>mywidgetcreate</code>. These aren&#8217;t strictly necessary but are useful to include, especially if you want the rest of your application to know when these events take place within the widget.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hiddentao.com/archives/2011/11/07/how-to-write-a-custom-widget-for-jquery-mobile/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>wuPlay &#8211; real-time multiplayer web gaming on your mobile</title>
		<link>http://www.hiddentao.com/archives/2011/07/15/wuplay-real-time-multiplayer-web-gaming-on-your-mobile/</link>
		<comments>http://www.hiddentao.com/archives/2011/07/15/wuplay-real-time-multiplayer-web-gaming-on-your-mobile/#comments</comments>
		<pubDate>Fri, 15 Jul 2011 16:14:56 +0000</pubDate>
		<dc:creator>ram</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Gaming]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Tornado]]></category>
		<category><![CDATA[Websockets]]></category>
		<category><![CDATA[wuPlay]]></category>

		<guid isPermaLink="false">http://www.hiddentao.com/?p=1238</guid>
		<description><![CDATA[Introducing wuPlay.com, an experiment in real-time multiplayer gaming on a mobile-friendly website. wuPlay is a web-based multiplayer implementation of the excellent Connect6 game that works well on desktops, tablets as well as on most good mobile devices (so far I&#8217;ve tested on Android 2.3 and iOS 4.2 devices). I started working on wuPlay mainly as [...]]]></description>
			<content:encoded><![CDATA[<p>Introducing <a href="wuPlay.com" class="liinternal">wuPlay.com</a>, an experiment in real-time multiplayer gaming on a mobile-friendly website. wuPlay is a web-based multiplayer implementation of the excellent <a href="http://en.wikipedia.org/wiki/Connect6" rel="nofollow" class="liwikipedia">Connect6</a> game that works well on desktops, tablets as well as on most good mobile devices (so far I&#8217;ve tested on Android 2.3 and iOS 4.2 devices).
<span id="more-1238"></span></p>

<p>I started working on wuPlay mainly as a way of learning <a href="http://www.tornadoweb.org/" class="link-external">Tornado</a>. Tornado was still quite new then and I was very interested in the idea of a non-blocking event-driven server and what it could do. I was also learning about Websockets and AJAX long-polling and other techniques of simulating a &#8220;push&#8221; from server to client. At the same time I was also wanting to make a multiplayer game from my droid device and figured that it would be better to build it as a web app so that it straight away ran on all devices. Finally, I wanted to improve my Javascript skills so all the client-side code is written in an object-oriented fashion.</p>

<p>For the rest of this post I&#8217;m going to talk about the implementation behind wuPlay and some of the design decisions I took.</p>

<h2>Overall architecture</h2>

<p>wuPlay is served via a single Tornado instance sat behind nginx. I put nginx in front so that I could load balance in future if necessary. One of my main aims was to make wuPlay load very quickly and minimize both the size and number of assets which need to be downloaded for it. So all the Javascript and CSS assets are minified using <a href="http://cjohansen.no/en/ruby/juicer_a_css_and_javascript_packaging_tool">Juicer</a> and compressed at build time, and then served using the <a href="http://wiki.nginx.org/HttpGzipStaticModule" class="link-external">HttpGzipStaticModule</a> module. So Tornado only serves the HTML.</p>

<p>I wanted it to be as fast as possible on mobile devices, even ones with a 2G connection. Browsing a site normally on a mobile is slow so I opted for a completely Javascript-driven client-side UI. The <a href="http://jquerymobile.com/" class="link-external">jQuery Mobile</a> project was in development at the time but I found it to be too slow and heavyweight so I rolled my own Javascript UI kit (more on that below).</p>

<p><a href="http://en.wikipedia.org/wiki/WebSockets" rel="nofollow" class="liwikipedia">Websockets</a> wasn&#8217;t fully supported in browsers when I started building this so I opted for <a href="http://en.wikipedia.org/wiki/Comet_(programming)#Ajax_with_long_polling" rel="nofollow" class="liwikipedia">AJAX long-polling</a>. This restricted the kind of games I could build but my initial goal was simply Connect6, for which it was more than adequate. There&#8217;s no need to sign up for the site &#8211; you just enter a nickname and immediately join the game lobby where you can both send and receive &#8220;challenges&#8221; to and from other players in the lobby.</p>

<p>The app is resilient to sudden losses in your internet connection as well as temporary increases in latency. On desktops and on Wifi none of this is an issue but on 2.5/3G on a mobile device these sorts of things happen regularly. In order to be resilient the back-end has to be very quick and responsive. I opted for <a href="http://www.mongodb.org/" class="link-external">MongoDB</a> as my datastore (for session data too) since most of the database activity involves high-speed writes.</p>

<h2>Back-end database</h2>

<p>In wuPlay the majority of the data consists of event notifications such as when a user leaves the lobby, enters the lobby, makes a move in the game, etc. They are stored in the db as a way of allowing other users to be notified of said events. In short wuPlay is based on a <a href="http://en.wikipedia.org/wiki/Publish/subscribe" rel="nofollow" class="liwikipedia">publish-subscribe</a> model.</p>

<p>I needed a high speed database and it didn&#8217;t need to be relational since the data model is so simple. And I didn&#8217;t mind if data occasionally got lost. So I opted for MongoDB. This also gave me an opportunity to learn what it was about and how to use it. I&#8217;d only ever used relation data models before so this was certainly a new way of looking at things. Still, as I built the app I ended up writing a database abstraction layer which mimicked Mongo&#8217;s API but left it open for me to swap out the actual back-end from MongoDB to something else in future if and when such a time arises.</p>

<h2>How clients receive updates from the server</h2>

<p>MongoDB automatically creates unique ids for every row it inserts. These IDs are essentially based on a timestamp and I use these to keep track of which events a client hasn&#8217;t yet been notified of. Thus, when a client first enters a lobby this is what it (i.e. the Javascript code running in the browser) do:</p>

<ol>
<li>It asks the server for the full state of the lobby (i.e. the full list of users along with their stats) as well as the timestamp of the last lobby event &#8211; it stores this as <code>last_timestamp</code>. </li>
<li>It then opens a persistent connection to the server and asks for events newer than <code>last_timestamp</code>. AJAX long-polling is used to query the server, thus ensuring that it only need to do something if the server returns with new data.</li>
<li>When new events are found it processes these (by updating the lobby display according to what happened) and sets <code>last_timestamp</code> to equal the timestamp of the newest event.</li>
<li>It then repeats from step 2 onwards.</li>
</ol>

<p>If the internet connection drops then the client will go back to step 1 and start from there.</p>

<p>The event notification process described above is also used for when a client is in a game. In fact, it&#8217;s architected in such a way as to make it re-usable for any type of event we may want to do in future, e.g. instant messaging.</p>

<p>As outlined above, every client maintains a long-polling connection to the server in order to receive event updates. Thankfully, browsers allow for upto <a href="http://stackoverflow.com/questions/2069562/2-connections-per-server" class="link-external">2 simultaneous connections</a> to a given domain name so the client can still send messages to the server.</p>

<h2>Javascript-driven UI</h2>

<p>The client UI is completely Javascript-driven. All the popup dialogs and message boxes are also re-usable Javascript &#8220;classes&#8221; which get used throughout. Once you load the initial <a href="wuPlay.com" class="liinternal">wuPlay.com</a> site from there on in all subsequent page changes are driven through Javascript. You&#8217;ll notice this by virtue of the loading graphic which shows for a moment or two whenever you click on a link. If something takes longer than a second or so to load you&#8217;ll see a &#8220;Waiting for server&#8221; message in the top right part of the page. All these notifications are coded in a re-usable fashion such that every AJAX request can be made with such progress notification if necessary.</p>

<p>There is a page loader which is responsible for loading a given page from the server. It passes the name of a page to the server and is given back a JSON object similar to the following representing <em>meta data</em> about the page:</p>

<pre><code>{"html" : ..., "js" : ...., "css" : ...}
</code></pre>

<p>The <code>html</code> entry is the HTML to show for the page. The <code>js</code> entry is a list of scripts to load using the <code>&lt;script&gt;</code> tag. The <code>css</code> entry is a list of stylesheets to load. When the page loader wishes to display a given page it first calls the server to obtain the above meta data. It then adds the specified stylesheets to the document <code>head</code> and then loads each of the Javascript files one at a time until they&#8217;re all loaded. Once these assets are loaded it replaces the webpage&#8217;s main content section with the HTML returned above.</p>

<p>A given page may have an associated <code>PageModule</code>, usually defined in one of its associated scripts. A <code>PageModule</code> is a Javascript object which exposes the following methods:</p>

<ul>
<li><code>preshow</code> &#8211; called just before the page gets shown. The module may choose to show another page instead at this point.</li>
<li><code>show</code> &#8211; called just after the page gets shown so that the module can do any required initialisation.</li>
<li><code>hide</code> &#8211; called just after the page gets hidden so that the module can do any required de-initialisation.</li>
</ul>

<p>For example, the lobby page as an associated <code>LobbyModule</code> which ensures that the lobby display gets reset and re-populated whenever the lobby page gets shown. Likewise, when the user leaves the lobby and switches to a different page this module ensures that any pending AJAX requests (e.g. the long-polling connection to the server) get cleanly aborted.</p>

<p>The <code>preshow</code> method on the <code>PageModule</code> may seem unnecessary but is actually very useful. When a user first visits wuPlay the <code>HomepageModule</code> can check in <code>preshow</code> to see if they&#8217;ve already visited the site before and have a nickname. If so it can take them straight to the lobby page rather than forcing them to re-submit a nickname. This mechanism is also handy if the user ever decides to refresh the webpage in their browser, thus allowing us to take them swiftly back to the page they were on.</p>

<h2>Device detection</h2>

<p>wuPlay uses the excellent <a href="http://wurfl.sourceforge.net/" class="link-external">WURFL</a> database to detect the user&#8217;s device type at the server level. So no need to mobile-specific URLs. Users type in the same URL (<a href="http://wuplay.com/" class="link-external">http://wuplay.com/</a>) on whatever device they&#8217;re on and the wuPlay back-end works out which stylesheets to use based on their device type. The device type detection takes a little bit of time because the code has to search through the WURFL database which, even when optimised for Python using <a href="http://celljam.net/" class="link-external">pywurfl</a>, takes up megabtyes. So once detected the device type gets saved in the session.</p>

<p>In addition to selecting the right stylesheet the device type is used in the Javascript game logic to determine how the game UI should work. When you hover over a square in the game grid you see a popup near the mouse cursor showing a magnified view of what&#8217;s underneath it. On the desktop version of the game the user cannot interact with this popup. However, they can on the mobile version &#8211; this stops users who have fat fingers from selecting the wrong squares!</p>

<h2>Cheating in the game</h2>

<p>The server is responsible for checking if a given move is valid and also for checking if and when somebody has won the game. This ensures that it&#8217;s impossible to cheat by intercepting and modifying the AJAX calls being made from the client to the server. The downside to this is that game logic is split between server and client. What&#8217;s more, this setup will only work efficently for turn-based games like Connect6. For anything real-time this isn&#8217;t really possible without having beefy servers to handle scale.</p>

<p>I did ponder having the clients themselves verifying validity and correctness of moves. So, one client would make a move and then the other client would verify the move and work out the result of it and inform the server of the result. The server would only accept the move if both clients accepted the move. This approach assumes that the &#8220;cheater&#8221; doesn&#8217;t control both clients in the game and that there&#8217;s no collusion between to the two players if they are indeed separate people. Game stats don&#8217;t get stored permanently in wuPlay so at the moment this approach is feasible. But once stats matter you wouldn&#8217;t want to leave a loophole like this in there.</p>

<p>Perhaps another approach would be to have every move vetted by a random selection of clients currently playing the game. This increase the workload of each client as well as the bandwidth utilisation and might not be viable for anything faster than turn-base games.</p>

<h2>Final thoughts and future work items</h2>

<p>As my first foray into mobile-friendly multiplayer web games I think wuPlay is ok.</p>

<p>Now that I&#8217;ve had some time to think about it and develop my skills further here are the things I would change and add:</p>

<ol>
<li>Refactor all the Javascript code to make better use of clojures. Perhaps use <a href="http://jashkenas.github.com/coffee-script/" class="link-external">CoffeeScript</a> to simplify coding? Also use <a href="http://requirejs.org/" class="link-external">RequireJS</a> rather than Juicer as I think it forces you to think in modular terms better.</li>
<li>Swap out Tornado for <a href="http://nodejs.org/" class="link-external">node</a>, thus making it easy to share code (particularly game logic) between front and back-ends.</li>
<li>Re-arcitect the back-end so that it&#8217;s is easy to add more games. Ideally wuPlay should be a platform providing users, lobbies and reward system with an API anyone can write games to.</li>
<li>Implement games using Websockets. iOS 4 devices already support this.</li>
<li>Implement canvas games. Though note that in mobile browsers you can&#8217;t currently do any finger dragging detection inside pages, thus ruling out certain games for these platforms.</li>
<li>Get more people involved. There&#8217;s a lot of cool stuff to build here and an opportunity for something special, particularly with the idea of the platform API (see point 3).</li>
<li>Add more games!</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.hiddentao.com/archives/2011/07/15/wuplay-real-time-multiplayer-web-gaming-on-your-mobile/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple online calculator using HTML and Javascript</title>
		<link>http://www.hiddentao.com/archives/2010/11/25/simple-online-calculator/</link>
		<comments>http://www.hiddentao.com/archives/2010/11/25/simple-online-calculator/#comments</comments>
		<pubDate>Thu, 25 Nov 2010 11:45:53 +0000</pubDate>
		<dc:creator>ram</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Calculator]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Mobile]]></category>

		<guid isPermaLink="false">http://www.hiddentao.com/?p=1028</guid>
		<description><![CDATA[Last Friday I was looking for a simple online calculator which I could use via a web browser and which was mobile friendly. The best ones I could find were all done in Flash which I though kinda sucked since it was perfectly possible to build one using HTML and Javascript. Not to mention that [...]]]></description>
			<content:encoded><![CDATA[<p>Last Friday I was looking for a simple online calculator which I could use via a web browser and which was mobile friendly. The best ones I could find were all done in <a href="http://www.adobe.com/products/flashplayer/" class="link-external">Flash</a> which I though kinda sucked since it was perfectly possible to build one using HTML and Javascript. Not to mention that Flash doesn&#8217;t work on iPhones/iPads. As I was feeling a little creative I decided to build one myself, which you can now see at <a href="http://calc8.com/" class="link-external">calc8.com</a>.
<span id="more-1028"></span>
These were my requirements:</p>

<ol>
<li>It must be built using open web standards, ideally HTML 5, CSS 2/3 and Javascript.</li>
<li>It should be usable from any modern mobile web browser which supported Javascript. </li>
<li>It must be quick to load.</li>
</ol>

<h2>Evaluating arithmetic expresssions</h2>

<p>I decided to model the functioning of my calculator on the stock one which came with my HTC Hero Android phone. Unlike most ordinary calculators this handily displays the full set of operations that you&#8217;ve punched in:</p>

<p><a href="http://www.flickr.com/photos/91055277@N00/5205983509/" class="imglink" title="htc_hero_21_calculator by little_ram, on Flickr"><img src="http://farm5.static.flickr.com/4145/5205983509_07c51b87b0.jpg" width="320" height="480" alt="htc_hero_21_calculator" /></a></p>

<p>What this meant was my calculator had to be able to parse such an input string (which is using <em>Infix</em> notation in mathematical terms), convert it to <em>Postfix</em> (also known as <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" rel="nofollow" class="liwikipedia">Reverse Polish</a>) notation &#8211; a format which makes it easier to evaluate algorithmically, notifying the user if there were any errors in the input. So for example, the following input expression in <em>Infix</em> notation:</p>

<p><code>1-2÷2x6</code></p>

<p>would look as follows in <em>Postfix</em> notation:</p>

<p><code>122÷6x-</code></p>

<p>The difference between the two notations is simple. In <em>Infix</em> the operator (e.g. +) is written between its two operands. In <em>Postfix</em> the operator is written after its two operands. The benefit of <em>Postfix</em> is that the operators are in order of precedence according to <a href="http://en.wikipedia.org/wiki/BODMAS" rel="nofollow" class="liwikipedia">BODMAS</a> rules and a simple <a href="http://en.wikipedia.org/wiki/Stack_%28data_structure%29" rel="nofollow" class="liwikipedia">Stack</a>-based algorithm can be used to evaluate the final answer.</p>

<p>Luckily, converting from <em>Infix</em> to <em>Postfix</em> is a <a href="http://scriptasylum.com/tutorials/infix_postfix/algorithms/infix-postfix/index.htm" class="link-external">solved problem</a> utilising the <a href="http://en.wikipedia.org/wiki/Shunting-yard_algorithm" rel="nofollow" class="liwikipedia">Shunting Yard Algorithm</a>.</p>

<h2>Making the most of the browser window</h2>

<p>Once I had the arithmetic evaluation working I decided to tackle the layout of the calculator number pad. I wanted the calculator buttons to appear more square than rectangular even if the web page was in widescreen rather than portrait mode. After some playing around with CSS I eventually settled on a Javascript solution which detects when the browser window size gets changed and then redraws the calculator accordingly.</p>

<p>I admit that this isn&#8217;t as nice as doing it all in CSS, as it&#8217;s slightly slower than letting the browser do all this work. I&#8217;m still investigating a better way of doing this, <del datetime="2011-02-01T10:38:33+00:00">especially since the calculator buttons currently overflow to the right in Mobile Safari &#8211; sorry, iPhone and iPod Touch users (if you have any suggestions as to why this happens please let me know!)</del>  <strong>Update: now looks ok on iOS devices running 4.2.</strong></p>

<p>When you turn the phone into landscape mode there is currently space on either side of the calculator button pad. In future I plan to add other buttons here (e.g. the ones you usually get with scientific calculators) so that you can easily switch between simple and &#8216;advanced&#8217; mode by turning your phone.</p>

<h2>Other considerations</h2>

<p>I went with HTML 5 for the DOCtype. In order to minimize the loading times all the CSS and Javascript is contained within the single HTML file. I&#8217;ve not used any third-party Javascript libraries and have instead stuck to the built-in DOM APIs. The standard jQuery library (at ~26 KB) would have been too heavy for my needs. A quick web search revealed <a href="http://unverse.net/Unverse-javascript-library">Unverse</a>, a ~5 KB library which gives you most of the basics including Lightbox-style pop-ups. If I do add a Javascript library at some point it will most likely be this one.</p>

<p>The full source code is available in the single HTML file on the site and it&#8217;s licensed under GPL 3. And apologies for the uninspiring domain name!</p>

<h2>Known issues</h2>

<p><del datetime="2011-02-01T10:35:45+00:00">The calculator width issue on iPhones and iPod Touches mentioned above.</del> <strong>Update: Seems to be ok now in iOS 4.2.</strong></p>

<p>It works fine in the Android 2.1 browser though it&#8217;s a bit slow. Actually I see this on iPhones too. When I press a calculator button there is a slight delay before the display gets updated. Initially this was because I was using <code>eval</code> along with an abstracted button click handling system &#8211; turns out <code>eval</code> is a bad idea with slow Javascript engines. But even after changing this the button response still isn&#8217;t snappy enough. I&#8217;m not sure whether this is just due to slower Javascript processing than desktops. I&#8217;ve yet to try this on Froyo which has a faster Javascript engine. <strong>Update: I had a look at how Google do click handling and they seem to handle the click on the mousedown event. Copying this idea I was able to reduce the click handling delay though it&#8217;s still a little slow on Froyo.</strong>.</p>

<p>Another issue I&#8217;ve noticed on Android is that you can&#8217;t press the buttons in rapid succession because the <a href="http://code.google.com/p/android/issues/detail?id=4113" class="link-external">browser assumes you&#8217;re trying to zoom in</a>. I&#8217;m already using <a href="https://developer.mozilla.org/en/Mobile/Viewport_meta_tag" class="link-external"><code>meta</code> tags</a> to markup the the page as mobile-friendly but it would be nice be able to disable the zoom-in mechanism on mobile browsers.</p>

<p>Enjoy <img src='http://www.hiddentao.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<p><a href="http://calc8.com/" class="link-external">calc8.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hiddentao.com/archives/2010/11/25/simple-online-calculator/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>&#8220;You are now friends with Android&#8221;</title>
		<link>http://www.hiddentao.com/archives/2009/09/19/you-are-now-friends-with-android/</link>
		<comments>http://www.hiddentao.com/archives/2009/09/19/you-are-now-friends-with-android/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 21:35:43 +0000</pubDate>
		<dc:creator>ram</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Symbian]]></category>

		<guid isPermaLink="false">http://www.hiddentao.com/?p=529</guid>
		<description><![CDATA[Having worked at Symbian a few years ago and gotten to learn about mobile operating systems, I believe that Symbian have the best mobile OS kernel in terms of performance, responsiveness and robustness. Unfortunately almost the opposite can be said for the S60 UI layer (which Nokia makes) that sits on top of it. The [...]]]></description>
			<content:encoded><![CDATA[<p>Having worked at <a href="http://www.symbian.com" class="link-external">Symbian</a> a few years ago and gotten to learn about mobile operating systems, I believe that Symbian have the best mobile OS kernel in terms of performance, responsiveness and robustness. Unfortunately almost the opposite can be said for the S60 UI layer (which Nokia makes) that sits on top of it. The end result being that a lot of Symbian phones (a lot of which are Nokias) tend to feel slow and buggy more often than they should. Nevertheless, they do pack a lot of features and thus for the last 3 years I&#8217;ve happily moved around with a Nokia N73, running S60v3 on Symbian 9.1. 
<span id="more-529"></span>
Over the last year Symbian got bought outright by <a href="http://gizmodo.com/5019082/nokia-helps-buys-symbian-turns-it-open-source" class="link-external">Nokia</a> and they&#8217;ve now turned it into the <em>Symbian Foundation</em>, essentially mirroring what <a href="http://www.openhandsetalliance.com/" class="link-external">Google</a>, <a href="http://www.limofoundation.org/" class="link-external">LiMo</a> and others have done. Symbian (and consequentially Nokia) have a huge task ahead of them if they wish to remain competitive in the smartphone market.</p>

<p>After leaving Symbian I went to work a <a href="http://www.bluewhalesystems.com/" class="link-external">mobile software startup</a> whose primary concern was a mobile social networking app written in Java MIDP. Now, if you want to stay as true as you can to the &#8220;write once, run anywhere&#8221; principle for mobiles then Java is really the only choice since almost every phone out there has some sort of Java support, albeit each with its own various inconsistencies and quirks. Writing a mobile Java app was also a whole lot easier than writing one in Symbian C++. The availability of great development tools (Eclipse, JUnit, ProGuard, etc.) didn&#8217;t hurt either! Having worked on a mobile Java client I decided that if I was to build my own mobile app I&#8217;d have to do it in Java.</p>

<p>Then iPhone came along and 2 years later it&#8217;s now obvious that if you have a good idea for a mobile app and don&#8217;t mind learning to develop on the Mac then you might as well as write your app for the iPhone, thus giving yourself a real chance to earn a decent income from it. Many of my fellow engineers have had iPhones for a while and some of them are even starting to write apps for it, some lured by the prospect of <a href="http://www.wired.com/gadgetlab/2008/09/indie-developer/" class="link-external">making a killing</a>, others just wanting to do something cool for what is hailed as the &#8220;Jesus phone&#8221;.</p>

<p>My T-Mobile contract is about to expire and I started seriously thinking about whether to upgrade to an iPhone or an Android handset. After much deliberation, I bought myself a lovely little <a href="http://www.youtube.com/watch?v=QJN8cXyyEQM" class="link-external">T-Mobile G2 Touch</a> instead (also known as HTC Hero). It runs <a href="http://developer.android.com/sdk/android-1.5-highlights.html" class="link-external">Android 1.5</a>, the latest stable release of Google&#8217;s mobile OS. Android development is essentially done in Java (the bytecode format and VM varies) using APIs which are different to the MIDP ones. You can use Eclipse to code, test and debug your apps. It&#8217;s an open source OS, which means you&#8217;ll be able to find deployable versions of the OS on the web which even include features from the upcoming 2.0 release of Android (e.g. multi-touch) folded into the current stable release.</p>

<p>If you read around you&#8217;ll find that the Android Market and consequent ecosystem for paid apps is almost miniscule compared to the AppStore (see <a href="http://larvalabs.com/blog/iphone/android-market-sales/" class="link-external">article and comments</a> and <a href="http://larvalabs.com/blog/iphone/android-market-sales-follow-up/" class="link-external">follow-up</a>), but I&#8217;m hoping that this will improve in the near future. And anyway, if the Android app platform doesn&#8217;t really take off then atleast I&#8217;ll already have some mobile app development experience by the time I get my iPhone <img src='http://www.hiddentao.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>

<p><strong>Update (Sep19): I&#8217;ve shifted the instructions for updating the HTC Hero/T-Mobile G2 Touch firmware into a <a href="http://www.hiddentao.com/archives/2009/09/19/upgrading-your-htc-herot-mobile-g2-touch-to-the-latest-htc-firmware/" class="liinternal">new post</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hiddentao.com/archives/2009/09/19/you-are-now-friends-with-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why the Vodafone flat-rate data tariff is lacking</title>
		<link>http://www.hiddentao.com/archives/2008/03/27/why-the-vodafone-flat-rate-data-tariff-is-no-good/</link>
		<comments>http://www.hiddentao.com/archives/2008/03/27/why-the-vodafone-flat-rate-data-tariff-is-no-good/#comments</comments>
		<pubDate>Thu, 27 Mar 2008 20:27:15 +0000</pubDate>
		<dc:creator>ram</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Data tariffs]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Vodafone]]></category>

		<guid isPermaLink="false">http://www.hiddentao.net/archives/2008/03/27/why-the-vodafone-flat-rate-data-tariff-is-no-good/</guid>
		<description><![CDATA[Most households in the UK that are connected to the internet are have got a broadband connection. And the vast majority (if not all) broadband packages are charged at a fixed monthly rate &#8211; a flat-rate tariff. So UK consumers are quite used to the idea of paying a fixed monthly amount for copious amounts [...]]]></description>
			<content:encoded><![CDATA[<p>Most households in the UK that are connected to the internet are have got a broadband connection. And the vast majority (if not all) broadband packages are charged at a fixed monthly rate &#8211; a flat-rate tariff. So UK consumers are quite used to the idea of paying a fixed monthly amount for copious amounts of broadband bandwidth (we&#8217;re talking Gigabytes of data).</p>

<p>It is only in the last 2 years or so that mobile network operators have truly realised this and started to adjust their internet/data tariffs to bill in a similar way to home broadband packages. <span id="more-22"></span>So for example, <a href="http://www.three.co.uk/" class="link-external">3</a> give you &#8220;unlimited&#8221; &#8211; actually just <a href="http://www.three.co.uk/xseries/fair_use_policy.omp" class="link-external">upto 1 GB</a> &#8211; internet usage for Â£5 a month added onto your existing contract bill. Slowly but surely operators will come out with more offers like this, and eventually I think it will get to the point where every mobile tariff comes with internet usage charges &#8220;folded in&#8221; and taken care of (assuming that as time passes, higher numbers of consumers will demand ever more mobile internet; I think this is realistic).</p>

<p>Anyway, recently I&#8217;ve been keen to start using <a href="http://www.bluewhalemail.com/" class="link-external">email on my phone</a> and also do the occasional web browsing, although nothing too <a href="http://www.youtube.com/" class="link-external">heavy</a>. So I started looking around to see which operators offered the best data tariff to suit my needs. I found a <a href="http://www.pocketpicks.co.uk/latest/index.php/2007/06/25/a-pocket-picks-special-uk-data-plans-unravelled-and-uncovered/" class="link-external">blog article reviewing the various offerings</a> written last year &#8211; <a href="http://www.t-mobile.co.uk/" class="link-external">T-Mobile</a> and <a href="http://www.three.co.uk/" class="link-external">3</a> came out tops. But my existing provider &#8211; <a href="http://www.vodafone.co.uk" class="link-external">Vodafone</a> came rock bottom <img src='http://www.hiddentao.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>

<p>I decided to check out Vodafone&#8217;s offering and see why it wasn&#8217;t considered competitive.</p>

<p>A quick look at <a href="http://www.phones4u.co.uk/vodafone/terms-and-conditions.asp" class="link-external">Vodafone&#8217;s data rates</a> shows that for all customers who haven&#8217;t got a specific mobile internet related tariff or tariff add-on, the day-to-day rate is Â£1 for 15 MB in any given day. Beyond the 15 MB you get charged at Â£2 per MB. Their flat-rate monthly tariff gives you 120 MB for Â£7.50. Beyond the 120 MB you get charged at the normal day-to-day rate (i.e. Â£1 per 15 MB, and then Â£2 per MB after).</p>

<p>Think about this. If I only use upto 15 MB each day (highly probable since I&#8217;m mainly checking email) then it would take me 8 days to use up 120 MB. And so on the day-to-day rate I would pay Â£8 for that 120 MB. Whereas, on the flat-rate monthly tariff I&#8217;d pay Â£7.50.I save a whopping <strong>50p</strong> by moving to the flat-rate monthly tariff <img src='http://www.hiddentao.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>

<p>But it gets better. On the flat-rate monthly tariff I&#8217;d pay Â£7.50 even if I don&#8217;t use the internet at all in a given month. Whereas on the day-to-day rate I don&#8217;t pay anything if I don&#8217;t use it. Now lets be conservative and assume that on the day-to-day rate, even if you don&#8217;t use upto 15 MB you get charged Â£1 (might not be true, but bear with me). Even then it&#8217;s only worth going on the flat-rate monthly tariff if I use more than 105 MB per month (105 MB would cost Â£7 when calculated using the day-to-day rate).</p>

<p>But then you might say: what if I need to use more than 15 MB in a given day? Then yes, the flat-rate montly tariff will allow you to use upto 120 MB in a single day before hitting you with the Â£2 per MB charge. But lets be honest, if you are using more than 15 MB in any given day then it&#8217;s likely that you&#8217;ll be doing this on more than one day, and therefore, exceeding the 120 MB boundary in most months.</p>

<p>So what does this tell me? that if I know that I won&#8217;t be using more than 15 MB in a given day then it&#8217;s cheaper to stay on the day-to-day rate. Even if I will be using more than 105 MB in a given month is it really worth paying Â£7.50 per month for a 50p saving? I don&#8217;t think so.</p>

<p>Having done the analysis I promptly signed up for a contract with T-Mobile. They essentially offer 1 GB of data for as part of their <a href="http://www.t-mobile.co.uk/shop/mobile-phones/price-plans/pay-monthly/webnwalk/plans/" class="link-external">Web &#8216;n&#8217; Walk</a> plans, and it doesn&#8217;t really cost much. And I find it unlikely that I&#8217;ll ever exceed that limit &#8211; it&#8217;s nice to know that I can browse and email without thinking about how much data I&#8217;m using (just like my home broadband connection). I contacted Vodafone to cancel my account with them. When I informed the nice lady on the phone as to why I was leaving her explanation was:</p>

<p><em>&#8220;We only give you 120 MB because we compress all the data we send to you, meaning that you&#8217;re getting virtually 1 GB of bandwidth anyway&#8221;</em></p>

<p>Oh please. First of all, the &#8220;compression&#8221; you&#8217;re referring to is only for web pages. I&#8217;m checking email more than anything; unless you control which phone (and therefore which browser) I use or multiple users are going to be reading the exact same email as me from the exact same email server (obviously not the case) I don&#8217;t think compression matters. And finally, don&#8217;t tell me it&#8217;s only Vodafone who have this cool magical compression technology. I&#8217;m sure other operators also have this cost-saving feature.</p>

<p>So there. Till now I haven&#8217;t had a problem with Vodafone. They probably have the best network coverage from what I can tell and their SIM-only deals are good. But as far as data usage goes they&#8217;re really playing &#8220;catch up&#8221; (or atleast trying to) with the other networks.</p>

<hr />

<p><strong>Update: May 2nd</strong></p>

<p>Looks like <a href="http://www.theregister.co.uk/2008/05/02/bundled_data_vodafone/" class="link-external">Vodafone are finally realising</a> what a poor deal they were offering to customers. So now you get 500 MB for your Â£7.50 per month, which makes it more worth it. Still only half what T-Mobile give you though&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hiddentao.com/archives/2008/03/27/why-the-vodafone-flat-rate-data-tariff-is-no-good/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

