<?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>captured sparks</title>
	<atom:link href="http://capturedsparks.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://capturedsparks.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Tue, 25 Oct 2011 08:31:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Metrics</title>
		<link>http://capturedsparks.com/2011/02/metrics/</link>
		<comments>http://capturedsparks.com/2011/02/metrics/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 10:26:47 +0000</pubDate>
		<dc:creator>Robin Fisher</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://capturedsparks.com/?p=258</guid>
		<description><![CDATA[Inspired by Ryan Carson&#8217;s post on tracking campaign effectiveness, I&#8217;ve open-sourced the beginnings of a starter app called Metrics.
]]></description>
			<content:encoded><![CDATA[<p>Inspired by <a href="http://thinkvitamin.com/business/marketing/how-to-get-more-customers/">Ryan Carson&#8217;s post on tracking campaign effectiveness</a>, I&#8217;ve open-sourced the beginnings of <a href="https://github.com/robinjfisher/Metrics">a starter app called Metrics</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://capturedsparks.com/2011/02/metrics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Favourtweets</title>
		<link>http://capturedsparks.com/2010/06/favourtweets/</link>
		<comments>http://capturedsparks.com/2010/06/favourtweets/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 15:25:28 +0000</pubDate>
		<dc:creator>Robin Fisher</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://capturedsparks.com/2010/06/favourtweets/</guid>
		<description><![CDATA[Just a short note to publicise the launch of Favourtweets. This new service from captured sparks, allows you to tag and organise your favourite tweets.
No login is needed as it connects directly to Twitter.  Let me know what you think.
]]></description>
			<content:encoded><![CDATA[<p>Just a short note to publicise the launch of <a href="http://favourtweets.com/">Favourtweets</a>. This new service from captured sparks, allows you to tag and organise your favourite tweets.</p>
<p>No login is needed as it connects directly to Twitter.  Let me know what you think.</p>
]]></content:encoded>
			<wfw:commentRss>http://capturedsparks.com/2010/06/favourtweets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Text shadow bug in Safari 4.0.5</title>
		<link>http://capturedsparks.com/2010/06/text-shadow-bug-in-safari-4-0-5/</link>
		<comments>http://capturedsparks.com/2010/06/text-shadow-bug-in-safari-4-0-5/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 14:45:46 +0000</pubDate>
		<dc:creator>Robin Fisher</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://capturedsparks.com/?p=245</guid>
		<description><![CDATA[It looks like Safari 4.0.5 has introduced a bug in its rendering of the text-shadow property.  This image is from my site as rendered in Chrome (and also as rendered in Safari 4.0.4):


This image is now my site rendered in Safari 4.0.5:


Has anybody else come across this?
]]></description>
			<content:encoded><![CDATA[<p>It looks like Safari 4.0.5 has introduced a bug in its rendering of the <span class="inline-code">text-shadow</span> property.  This image is from my site as rendered in Chrome (and also as rendered in Safari 4.0.4):</p>
<p><img src="http://capturedsparks.com/wp-content/uploads/2010/06/chrome-text.png" alt="Chrome screenshot showing text shadow rendering" title="Screenshot from Chrome showing text shadow rendering" width="284" height="107" class="alignleft size-full wp-image-246" style="border:10px solid rgb(51,51,51)" /></p>
<p><br class="clear" /></p>
<p>This image is now my site rendered in Safari 4.0.5:</p>
<p><img src="http://capturedsparks.com/wp-content/uploads/2010/06/safari-text.png" alt="Screenshot of text shadow rendering in Safari" title="Screenshot of text shadow rendering in Safari" width="253" height="103" class="alignleft size-full wp-image-247" style="border:10px solid rgb(51,51,51)" /></p>
<p><br class="clear" /></p>
<p>Has anybody else come across this?</p>
]]></content:encoded>
			<wfw:commentRss>http://capturedsparks.com/2010/06/text-shadow-bug-in-safari-4-0-5/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sharerplane</title>
		<link>http://capturedsparks.com/2010/06/sharerplane/</link>
		<comments>http://capturedsparks.com/2010/06/sharerplane/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 20:38:46 +0000</pubDate>
		<dc:creator>Robin Fisher</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://capturedsparks.com/?p=242</guid>
		<description><![CDATA[I&#8217;d just like to announce the launch of my new website, Sharerplane. It enables people who share an aircraft to book and reserve the aircraft using an easy calendar interface.
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;d just like to announce the launch of <a href="http://sharerplane.com/">my new website, Sharerplane</a>. It enables people who share an aircraft to book and reserve the aircraft using an easy calendar interface.</p>
]]></content:encoded>
			<wfw:commentRss>http://capturedsparks.com/2010/06/sharerplane/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lessons from my first video tutorial</title>
		<link>http://capturedsparks.com/2010/05/lessons-from-my-first-video-tutorial/</link>
		<comments>http://capturedsparks.com/2010/05/lessons-from-my-first-video-tutorial/#comments</comments>
		<pubDate>Tue, 04 May 2010 20:03:56 +0000</pubDate>
		<dc:creator>Robin Fisher</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://capturedsparks.com/?p=228</guid>
		<description><![CDATA[So, I&#8217;ve now posted my two-part video tutorial on building a todo list application with Rails 3 (Part 1 and Part 2).  What have I learned?
Firstly, increase the text size in everything &#8211; TextMate, Terminal and the browser. Whilst easily legible on my screen, it is not so good when encoded and compressed at [...]]]></description>
			<content:encoded><![CDATA[<p>So, I&#8217;ve now posted my two-part video tutorial on building a todo list application with Rails 3 (<a href="http://capturedsparks.com/2010/05/building-a-todo-list-with-rails-3-part-one/">Part 1</a> and <a href="http://capturedsparks.com/2010/05/building-a-todo-list-with-rails-3-part-two/">Part 2</a>).  What have I learned?</p>
<p>Firstly, increase the text size in everything &#8211; TextMate, Terminal and the browser. Whilst easily legible on my screen, it is not so good when encoded and compressed at a smaller resolution. Thankfully, the code is still legible (just) but I don&#8217;t want my viewers to be squinting.</p>
<p>Secondly, <a href="http://www.ambrosiasw.com/utilities/snapzprox/">Snapz Pro X</a>, the MacBook&#8217;s built in microphone and iMovie are fine for recording video tutorials. I don&#8217;t think it&#8217;s necessary to invest in a separate microphone at the moment.</p>
<p>Finally, have a rough idea of what you will say, when you will say it and how much time you will need to say it. On a couple of occasions, I found myself needing more time to explain something and on other occasions, having too much time. Whilst a complete script might not be necessary, you might want to consider what particular areas need a detailed level of exposition and ensure you leave enough time to do so.</p>
]]></content:encoded>
			<wfw:commentRss>http://capturedsparks.com/2010/05/lessons-from-my-first-video-tutorial/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Building a todo list with Rails 3 &#8211; Part Two</title>
		<link>http://capturedsparks.com/2010/05/building-a-todo-list-with-rails-3-part-two/</link>
		<comments>http://capturedsparks.com/2010/05/building-a-todo-list-with-rails-3-part-two/#comments</comments>
		<pubDate>Tue, 04 May 2010 14:03:18 +0000</pubDate>
		<dc:creator>Robin Fisher</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://capturedsparks.com/?p=226</guid>
		<description><![CDATA[EDIT: The source code is now on Github.
Welcome to Part 2 of the video tutorial on building a todo list with Rails 3. Part One of the video tutorial is here.
Please leave comments and your suggestions for future topics to cover.






Active Record Query Interface
The new routing in Rails 3

]]></description>
			<content:encoded><![CDATA[<p>EDIT: The <a href="https://github.com/robinjfisher/todoodly">source code</a> is now on Github.</p>
<p>Welcome to Part 2 of the video tutorial on building a todo list with Rails 3. <a href="http://capturedsparks.com/2010/05/building-a-todo-list-with-rails-3-part-one/">Part One of the video tutorial is here</a>.</p>
<p>Please leave comments and your suggestions for future topics to cover.</p>
<p></wrapper></p>
<div id="video-holder">
<object width="640" height="360"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=11435163&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=11435163&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="640" height="360"></embed></object>
</div>
<p><wrapper></p>
<ul>
<li><a href="http://m.onkey.org/2010/1/22/active-record-query-interface">Active Record Query Interface</a></li>
<li><a href="http://guides.rails.info/3_0_release_notes.html#action-dispatch">The new routing in Rails 3</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://capturedsparks.com/2010/05/building-a-todo-list-with-rails-3-part-two/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Building a todo list with Rails 3 &#8211; Part One</title>
		<link>http://capturedsparks.com/2010/05/building-a-todo-list-with-rails-3-part-one/</link>
		<comments>http://capturedsparks.com/2010/05/building-a-todo-list-with-rails-3-part-one/#comments</comments>
		<pubDate>Tue, 04 May 2010 06:00:58 +0000</pubDate>
		<dc:creator>Robin Fisher</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://capturedsparks.com/?p=221</guid>
		<description><![CDATA[EDIT: The source code is now on Github.
In this video tutorial, we&#8217;ll be building a todo list application in Rails 3 that allows the user to have multiple todo lists with multiple tasks. Part 1 will cover setting up the lists and part 2 will deal with adding tasks to those lists and completing tasks.
This [...]]]></description>
			<content:encoded><![CDATA[<p>EDIT: The <a href="https://github.com/robinjfisher/todoodly">source code</a> is now on Github.</p>
<p>In this video tutorial, we&#8217;ll be building a todo list application in Rails 3 that allows the user to have multiple todo lists with multiple tasks. Part 1 will cover setting up the lists and part 2 will deal with adding tasks to those lists and completing tasks.</p>
<p>This is my first video tutorial so please leave constructive comments. If there is anything you&#8217;d like to see me cover, let me know.  Further reading material is after the video.<br />
</wrapper></p>
<div id="video-holder">
<object width="640" height="360"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=11436026&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=11436026&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="640" height="360"></embed></object>
</div>
<p><wrapper></p>
<ul>
<li><a href="http://guides.rails.info/3_0_release_notes.html#upgrading-to-rails-3">Upgrading to Rails 3</a></li>
<li><a href="http://guides.rails.info/3_0_release_notes.html#script-replaced-by-scriptrails">script/* replaced by script/rails</a></li>
<li><a href="http://ryandaigle.com/articles/2009/8/6/what-s-new-in-edge-rails-cleaner-restful-controllers-w-respond_with">Cleaner controllers with respond_with</a></li>
<li><a href="http://guides.rails.info/3_0_release_notes.html#validations">New validations</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://capturedsparks.com/2010/05/building-a-todo-list-with-rails-3-part-one/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>Pure CSS3 Buttons</title>
		<link>http://capturedsparks.com/2010/05/pure-css3-buttons/</link>
		<comments>http://capturedsparks.com/2010/05/pure-css3-buttons/#comments</comments>
		<pubDate>Sun, 02 May 2010 16:39:51 +0000</pubDate>
		<dc:creator>Robin Fisher</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://capturedsparks.com/?p=218</guid>
		<description><![CDATA[If you need to produce stunning buttons for use in modern browsers, use Pure CSS3 buttons.
They are designed to work in Safari 4, Chrome and Firefox 3.6. WebKit browsers also get transition effects on the hover state.
Why not check them out?
]]></description>
			<content:encoded><![CDATA[<p>If you need to produce stunning buttons for use in modern browsers, use <a href="http://capturedsparks.com/pure-css3-buttons/">Pure CSS3 buttons</a>.</p>
<p>They are designed to work in Safari 4, Chrome and Firefox 3.6. WebKit browsers also get transition effects on the hover state.</p>
<p>Why not <a href="http://capturedsparks.com/pure-css3-buttons/">check them out</a>?</p>
]]></content:encoded>
			<wfw:commentRss>http://capturedsparks.com/2010/05/pure-css3-buttons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick debugging of validations with Rails</title>
		<link>http://capturedsparks.com/2010/04/quick-debugging-of-validations-with-rails/</link>
		<comments>http://capturedsparks.com/2010/04/quick-debugging-of-validations-with-rails/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 19:31:07 +0000</pubDate>
		<dc:creator>Robin Fisher</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://capturedsparks.com/?p=194</guid>
		<description><![CDATA[In an application I&#8217;m building, I have a tricky validation that needs to ensure that a booking created by the user:

is not entirely within an existing booking
does not have a start time within an existing booking
does not have an end time within an existing booking
does not span an existing booking

While testing the validation, it was [...]]]></description>
			<content:encoded><![CDATA[<p>In an application I&#8217;m building, I have a tricky validation that needs to ensure that a booking created by the user:</p>
<ol>
<li>is not entirely within an existing booking</li>
<li>does not have a start time within an existing booking</li>
<li>does not have an end time within an existing booking</li>
<li>does not span an existing booking</li>
</ol>
<p>While testing the validation, it was really useful to add the following to the validation code:</p>
<pre class="brush: ruby;">
existing_bookings.each do |b|
  Rails.logger.debug(&quot;#{b.id} - #{b.from} - #{b.to}&quot;)
end
</pre>
<p>This was valuable in identifying what bookings my AR query was pulling out during the validation.</p>
]]></content:encoded>
			<wfw:commentRss>http://capturedsparks.com/2010/04/quick-debugging-of-validations-with-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building an AJAX style calendar with Rails and Prototype</title>
		<link>http://capturedsparks.com/2010/04/building-an-ajax-style-calendar-with-rails-and-prototype/</link>
		<comments>http://capturedsparks.com/2010/04/building-an-ajax-style-calendar-with-rails-and-prototype/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 19:01:18 +0000</pubDate>
		<dc:creator>Robin Fisher</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://capturedsparks.com/?p=188</guid>
		<description><![CDATA[In this tutorial, I&#8217;m going to show you how to build an AJAX style multi-day calendar with Ruby on Rails and Prototype. The code assumes that you have a number of multi-day bookings or events that you need to display on a calendar.  The final result looks like this:

We&#8217;ll start with the code for [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial, I&#8217;m going to show you how to build an AJAX style multi-day calendar with Ruby on Rails and Prototype. The code assumes that you have a number of multi-day bookings or events that you need to display on a calendar.  The final result looks like this:</p>
<p><img src="http://capturedsparks.com/wp-content/uploads/2010/04/calendar-one.png" alt="Screenshot of calendar" title="Screenshot of calendar" width="540" height="352" class="aligncenter size-full wp-image-192" /></p>
<p>We&#8217;ll start with the code for the controller. I&#8217;ve removed some of the code where I create the <span class="inline-code">@hours</span> variable. In my case, the calendar is displaying bookings relating to a particular aircraft:</p>
<pre class="brush: ruby;">
def index
  @plane = Plane.find(params[:plane_id])
  @booking = @plane.bookings.new
  @hours = [&quot;06:00&quot;,&quot;07:00&quot;,&quot;08:00&quot;...]
  @date = Time.parse(&quot;#{params[:start_date]} || Time.now.utc&quot;)
  @start_date = Date.new(@date.year, @date.month, @date.day)
  @bookings = @plane.bookings.where('bookings.from BETWEEN ? and ? OR bookings.to BETWEEN ? and ?', @start_date, @start_date + 1, @start_date, @start_date + 1).order('bookings.from ASC').all
  if params[:start_date] &amp;&amp; request.xhr?
    render :json =&gt; @bookings
  end
end
</pre>
<p>This retrieves all bookings for a particular aircraft on a given day: either today or the day passed in as a query string.  The following HTML is used to display the calendar:</p>
<pre class="brush: xml;">
&lt;section id=&quot;calendar&quot;&gt;

  &lt;ul id=&quot;dates-menu&quot;&gt;
    &lt;% for date in @start_date..@start_date + 6 %&gt;
      &lt;li&gt;&lt;a href=&quot;/planes/&lt;%= @plane.id %&gt;/bookings?start_date=&lt;%= Date.new(date.year,date.month,date.day) %&gt;&quot; class=&quot;dates-link&quot;&gt;&lt;%= date.strftime(&quot;%d %B&quot;) %&gt;&lt;/a&gt;&lt;/li&gt;
    &lt;% end %&gt;
  &lt;/ul&gt;&lt;!-- #dates-menu --&gt;

  &lt;br class=&quot;clear&quot; /&gt;

  &lt;div class=&quot;day&quot;&gt;
    &lt;div id=&quot;bookings&quot;&gt;
      &lt;img src=&quot;/images/ajax-loader.gif&quot; id=&quot;ajax-loader&quot;/&gt;
    &lt;/div&gt;&lt;!-- #bookings --&gt;
    &lt;div id=&quot;hours&quot;&gt;
      &lt;% @hours.each do |hour| %&gt;
        &lt;div class=&quot;hour&quot;&gt;&lt;%= hour %&gt;&lt;/div&gt;
      &lt;% end %&gt;
    &lt;/div&gt;&lt;!-- #hours --&gt;
  &lt;/div&gt;&lt;!-- .day --&gt;
&lt;/section&gt;
</pre>
<p>You&#8217;ll notice that the <span class="inline-code">div</span> with the id of <span class="inline-code">bookings</span> is populated with an AJAX-style loader.</p>
<p>Moving on to the javascript. I am no Javascript expert so it may be possible to refactor some of this to make it leaner.  The first part of the code applies an <span class="inline-code">active</span> class to the first <span class="inline-code">li</span> element in the dates menu.</p>
<pre class="brush: jscript;">
if ($('dates-menu')) {
  $('dates-menu').down(1).addClassName('active');
  var firstLink = $('dates-menu').down(1);
  if (firstLink.hasClassName('active')) {
    grabBookings(firstLink);
  };
};
</pre>
<p>The <span class="inline-code">grabBookings</span> function gets the bookings for a particular day using Prototype&#8217;s <span class="inline-code">Ajax.Request</span>.</p>
<pre class="brush: jscript;">
function grabBookings(date) {
  $$(&quot;.booking&quot;).each(function(b) {
    b.remove();
  });
  if (!$('ajax-loader')) {
    $('bookings').insert(&quot;&lt;img src='/images/ajax-loader.gif' id='ajax-loader' /&gt;&quot;);
  }
  new Ajax.Request(date.readAttribute(&quot;href&quot;), {method:&quot;get&quot;, evalJS:true, onSuccess:function(transport) {
    var bookings = transport.responseJSON;
    $('ajax-loader').remove();
    bookings.each(function(b) {
      var item = &quot;&lt;a href='/planes/&quot; + b.plane_id +&quot;/bookings/&quot; + b.id + &quot;'&lt;div id='booking-&quot; + b.id + &quot;' class='booking' style='height:&quot; + calculateBookingHeight(b.from,b.to) + &quot;px;top:&quot; + calculateBookingPosition(b.from,b.to) + &quot;px;'&gt;&lt;p&gt;&lt;strong&gt;From: &lt;/strong&gt;&quot; + formatTime(b.from) + &quot;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;To: &lt;/strong&gt;&quot; + formatTime(b.to) + &quot;&lt;/p&gt;&lt;/div&gt;&lt;/a&gt;&quot;;
    $('bookings').insert(item);
    });
  }});
}
</pre>
<p>I&#8217;ve added this as a <a href="http://gist.github.com/379721">gist</a>.  In summary, this obtains the bookings for a particular day and the controller returns the bookings in JSON format. I then iterate over each booking and insert it into the calendar.  The two key functions used in the code are to calculate the position of the booking to ensure it aligns with the appropriate time and the height of the booking to ensure it covers the appropriate time period.  Looking at the function to calculate the height first:</p>
<pre class="brush: jscript;">
function calculateBookingHeight(from, to) {
  var today = new Date();
  var end = new Date(today.getUTCFullYear(),today.getUTCMonth(),today.getUTCDate(),23);
  var start = new Date(today.getUTCFullYear(),today.getUTCMonth(),today.getUTCDate(),6);
  var from = parseDate(from);
  var fromUTC = new Date(from[0],(from[1] - 1),from[2],from[3],from[4],from[5])
  var to = parseDate(to);
  var toUTC = new Date(to[0],(to[1] - 1),to[2],to[3],to[4],to[5])
  if (fromUTC &gt; start &amp;&amp; toUTC &lt; end) {
    var difference = (toUTC - fromUTC) / 120000;
  } else if (fromUTC &gt; start &amp;&amp; toUTC &gt; end) {
    var difference = (end - fromUTC) / 120000;
  } else if (fromUTC &lt; start &amp;&amp; toUTC &lt; end) {
    var difference = (toUTC - start) / 120000
  } else {
    var difference = 510
  }
  return difference;
}
</pre>
<p>The key elements here are the use of the figure 120000 and the multiple if statements. The height of 1 hour on the calendar is 30px. Thus, if a booking is 1 hour long, that is equivalent to 3,600,000 milliseconds.  When divided by 120000, this produces a result of 30 i.e. 30px. The if statement is to deal with the situation where bookings either take up the whole day or cross with the previous or next day. The height is adjusted accordingly.</p>
<pre class="brush: jscript;">
function calculateBookingPosition(from, to) {
  var today = new Date();
  var today = new Date(today.getFullYear(),today.getMonth(),today.getDate(),6,0,0)
  var start = parseDate(from);
  var fromUTC = new Date(start[0],(start[1] - 1),start[2],start[3],start[4],start[5])
  var from_hours = (parseFloat(giveMeTime(from).split(&quot;:&quot;)[0]) - 6) * 30
  var from_minutes = (parseFloat(giveMeTime(from).split(&quot;:&quot;)[1]) / 60)
  var minutes = parseInt(from_minutes * 30)
  if (fromUTC &gt; today) {
    var top = parseInt(from_hours + minutes)
  } else {
    var top = 0
  }
  return top
}
</pre>
<p>Again, based on the height of 30px per hour, this function calculates the absolute position from the top of the calendar at which the booking needs to be displayed.</p>
<p>You will note a number of functions within these 2 functions that are used to extract certain aspects of the date and time of the booking. Based on an input in the format of <span class="inline-code">2010-04-25T12:00Z</span>, I use the following function to extract the time in format <span class="inline-code">12:00</span>.</p>
<pre class="brush: jscript;">
function giveMeTime(time) {
  var time = time.split(&quot;T&quot;)[1].gsub(/[A-Za-z]/,&quot;&quot;)
  return time
}
</pre>
<p>Leave a comment if you spot any obvious flaws in my design or with suggestions for improving the code. I&#8217;m also considering releasing this as a plugin for Rails if there is any interest?</p>
]]></content:encoded>
			<wfw:commentRss>http://capturedsparks.com/2010/04/building-an-ajax-style-calendar-with-rails-and-prototype/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

