<?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>chris moos&#039;s blog</title>
	<atom:link href="http://chrismoos.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://chrismoos.com</link>
	<description>developer by day, developer by night</description>
	<lastBuildDate>Wed, 11 Aug 2010 15:41:00 +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>MoosTrax for Blackberry &#8212; Looking for&#160;testers</title>
		<link>http://chrismoos.com/2010/08/11/moostrax-for-blackberry-looking-for-testers/</link>
		<comments>http://chrismoos.com/2010/08/11/moostrax-for-blackberry-looking-for-testers/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 15:41:00 +0000</pubDate>
		<dc:creator>Chris Moos</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[moostrax]]></category>

		<guid isPermaLink="false">http://chrismoos.com/?p=871</guid>
		<description><![CDATA[I am finally going to work on updating MoosTrax for BlackBerry &#8212; as there are a few outstanding bugs that need to be addressed. The most important bug I will be working on is consistency of location updates in newer, post-4.2 OS BlackBerry devices.
If you are interested in helping test the upcoming version, please e-mail [...]]]></description>
			<content:encoded><![CDATA[<p>I am finally going to work on updating MoosTrax for BlackBerry &#8212; as there are a few outstanding bugs that need to be addressed. The most important bug I will be working on is consistency of location updates in newer, post-4.2 OS BlackBerry devices.</p>
<p>If you are interested in helping test the upcoming version, please e-mail <a href="mailto:moostraxsupport@gmail.com">moostraxsupport@gmail.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrismoos.com/2010/08/11/moostrax-for-blackberry-looking-for-testers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MoosTrax released for&#160;iPhone</title>
		<link>http://chrismoos.com/2010/07/29/moostrax-released-for-iphone/</link>
		<comments>http://chrismoos.com/2010/07/29/moostrax-released-for-iphone/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 04:01:59 +0000</pubDate>
		<dc:creator>Chris Moos</dc:creator>
				<category><![CDATA[moostrax]]></category>
		<category><![CDATA[app store]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[released]]></category>

		<guid isPermaLink="false">http://chrismoos.com/?p=859</guid>
		<description><![CDATA[I am happy to say that MoosTrax has been approved by Apple and is now available for download in the App Store. Thanks to everyone who helped with the beta testing &#8212; it was a great help.
Note: MoosTrax works on devices running iOS 4+.
iPhone Support/Help
MoosTrax iTunes Link
]]></description>
			<content:encoded><![CDATA[<p>I am happy to say that MoosTrax has been approved by Apple and is now available for download in the App Store. Thanks to everyone who helped with the beta testing &#8212; it was a great help.</p>
<p><strong>Note:</strong> MoosTrax works on devices running iOS 4+.</p>
<p><a href="http://trac.moostrax.com/trac/wiki/iPhone">iPhone Support/Help</a><br />
<a href="itms://itunes.apple.com/us/app/moostrax/id383812018?mt=8">MoosTrax iTunes Link</a></p>
]]></content:encoded>
			<wfw:commentRss>http://chrismoos.com/2010/07/29/moostrax-released-for-iphone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MoosTrax for iPhone Beta&#160;Updates</title>
		<link>http://chrismoos.com/2010/07/12/moostrax-for-iphone-beta-updates/</link>
		<comments>http://chrismoos.com/2010/07/12/moostrax-for-iphone-beta-updates/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 05:59:04 +0000</pubDate>
		<dc:creator>Chris Moos</dc:creator>
				<category><![CDATA[moostrax]]></category>
		<category><![CDATA[beta]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://chrismoos.com/?p=841</guid>
		<description><![CDATA[I&#8217;ve been working a lot on getting MoosTrax ready for the App Store and the latest beta adds a lot of great features.

View a list of all of your devices
View the current location of any device on your account.
Enhanced battery usage through the &#8220;Conserve Battery&#8221; feature.

The beta is still open, so send an e-mail to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working a lot on getting MoosTrax ready for the App Store and the latest beta adds a lot of great features.</p>
<ul>
<li>View a list of all of your devices</li>
<li>View the current location of any device on your account.</li>
<li>Enhanced battery usage through the &#8220;Conserve Battery&#8221; feature.</li>
</ul>
<p>The beta is still open, so send an e-mail to <a href="mailto:moostraxsupport@gmail.com">moostraxsupport@gmail.com</a> to join.</p>
<p><img src="http://chrismoos.com/wp-content/uploads/2010/07/settings.png" style="width: 300px;float:left;" /><img src="http://chrismoos.com/wp-content/uploads/2010/07/devices.png" style="width: 300px;float:right;"/><br style="clear:both;"/></p>
<p><img src="http://chrismoos.com/wp-content/uploads/2010/07/device_info.png" style="width: 300px;"/></p>
]]></content:encoded>
			<wfw:commentRss>http://chrismoos.com/2010/07/12/moostrax-for-iphone-beta-updates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MoosTrax for iPhone&#160;iOS4</title>
		<link>http://chrismoos.com/2010/06/27/moostrax-for-iphone-ios4/</link>
		<comments>http://chrismoos.com/2010/06/27/moostrax-for-iphone-ios4/#comments</comments>
		<pubDate>Mon, 28 Jun 2010 02:47:51 +0000</pubDate>
		<dc:creator>Chris Moos</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[moostrax]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://chrismoos.com/?p=829</guid>
		<description><![CDATA[I just got a new iPhone 4 with iOS4&#8230;and it supports background location updates! I&#8217;ve decided to bring MoosTrax back to the iPhone.
I&#8217;m looking for beta testers&#8230;and then soon I&#8217;ll be pushing it to the App Store.
Applying for the beta
Please e-mail moostraxsupport@gmail.com with your iPhone&#8217;s UDID. 
For information on finding the UDID, go here: http://www.geekology.co.za/blog/2009/07/how-to-check-your-iphones-udid-from-itunes/
Screenshots



]]></description>
			<content:encoded><![CDATA[<p>I just got a new iPhone 4 with iOS4&#8230;and it supports background location updates! I&#8217;ve decided to bring MoosTrax back to the iPhone.</p>
<p>I&#8217;m looking for beta testers&#8230;and then soon I&#8217;ll be pushing it to the App Store.</p>
<h2>Applying for the beta</h2>
<p>Please e-mail <a href="mailto:moostraxsupport@gmail.com">moostraxsupport@gmail.com</a> with your iPhone&#8217;s UDID. </p>
<p>For information on finding the UDID, go here: <a href="http://www.geekology.co.za/blog/2009/07/how-to-check-your-iphones-udid-from-itunes/">http://www.geekology.co.za/blog/2009/07/how-to-check-your-iphones-udid-from-itunes/</a></p>
<h2>Screenshots</h2>
<p><img src="http://www.moostrax.com/images/moostraxiphone2.png" style="float:left;"/><br />
<img src="http://www.moostrax.com/images/moostraxiphone.png" style="float:right;"/><br />
<br style="clear:both;"/></p>
]]></content:encoded>
			<wfw:commentRss>http://chrismoos.com/2010/06/27/moostrax-for-iphone-ios4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AsyncRecord: Non-blocking database access for&#160;Ruby</title>
		<link>http://chrismoos.com/2010/06/21/asyncrecord-non-blocking-database-access-for-ruby/</link>
		<comments>http://chrismoos.com/2010/06/21/asyncrecord-non-blocking-database-access-for-ruby/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 04:17:18 +0000</pubDate>
		<dc:creator>Chris Moos</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[eventmachine]]></category>
		<category><![CDATA[fastr]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://chrismoos.com/?p=809</guid>
		<description><![CDATA[Two weeks ago I developed my first event-driven web framework for Ruby, Fastr. It helped me understand why running a web framework in an event loop is so natural. 
As I continued to tackle more features in Fastr, it was time to tackle persistence &#8212; notably, database access. 
AsyncRecord is/will be an ORM, similar to [...]]]></description>
			<content:encoded><![CDATA[<p>Two weeks ago I developed my first event-driven web framework for Ruby, <a href="http://chrismoos.com/2010/06/08/fastr-ruby-web-framework/">Fastr</a>. It helped me understand why running a web framework in an event loop is so <em>natural</em>. </p>
<p>As I continued to tackle more features in Fastr, it was time to tackle persistence &#8212; notably, database access. </p>
<p>AsyncRecord is/will be an ORM, similar to ActiveRecord &#8212; with one major difference &#8212; it doesn&#8217;t block. AsyncRecord currently uses <a href="http://github.com/tmm1/em-mysql">em-mysql</a> to access a MySQL database.</p>
<h2>How it usually works</h2>
<p>In most ORMs, when you attempt to access the database, everything in that thread will block until a response is received. This means that you waste time &#8212; just waiting. The CPU may be idle, but you cannot handle any more requests. (Typically you start multiple instances of your application to get past this, unfortunately each instance requires more resources on your server)</p>
<h2>How AsyncRecord works</h2>
<p>When you access something in the database with AsyncRecord, the request is sent to the database server, but control returns to the application immediately after the packet(s) are sent. When the server responds, which could be 20ms or 200ms later, a callback that you specify is invoked. </p>
<p>One important thing about accessing a database asynchronously, especially in web frameworks, is the ability to defer a response. Fastr has built-in support for deferred responses, a-la EventMachine/Thin.</p>
<p> A deferred response is when you tell the web server that you will send data to the client some time in the future, and the server is free to handle more requests until you are ready to respond.</p>
<h2>Benchmarking</h2>
<p>As I was implementing AsyncRecord, I knew it would be faster &#8212; but I wasn&#8217;t sure by how much. I setup a very simple Rails 2.3.5 application, as well as a Fastr application (from the latest source).</p>
<p>My goal was to make an application that has a single page, which shows 5 usernames from the database.</p>
<p><b>Rails controller</b>:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> MainController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
  <span style="color:#9966CC; font-weight:bold;">def</span> index
    users = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
    User.<span style="color:#9900CC;">all</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:limit</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>user<span style="color:#006600; font-weight:bold;">|</span>
      users <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> user.<span style="color:#9900CC;">username</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    headers<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'Content-Type'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">'text/plain'</span>
    render<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:text</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> users.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p><b>Fastr controller:</b></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> MainController <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">Fastr::Controller</span>  
  <span style="color:#9966CC; font-weight:bold;">def</span> index
    defer_response<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">200</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;Content-Type&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;text/plain&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>response<span style="color:#006600; font-weight:bold;">|</span>
&nbsp;
      User.<span style="color:#9900CC;">all</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:limit</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>users<span style="color:#006600; font-weight:bold;">|</span>
        users.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>user<span style="color:#006600; font-weight:bold;">|</span>
          response.<span style="color:#9900CC;">send_data</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{user.username}<span style="color:#000099;">\n</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
        response.<span style="color:#9900CC;">succeed</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<h2>The Numbers</h2>
<h3>Fastr</h3>
<p>Average Latency: 123ms<br />
Requests per second: 385 r/s</p>
<p><img style="width: 600px;" src="http://chrismoos.com/wp-content/uploads/2010/06/fastr.png"/></p>
<h3>Rails</h3>
<p>Average Latency: 2040ms<br />
Requests per second: 42 r/s</p>
<p><img style="width: 600px;" src="http://chrismoos.com/wp-content/uploads/2010/06/rails.png"/></p>
<p>The tests were performed using JMeter. 100 concurrent requests (10 requests per connection).</p>
<p>I also ran some tests using apache bench, here are the results:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ab <span style="color: #660033;">-c</span> <span style="color: #000000;">100</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">1000</span> http:<span style="color: #000000; font-weight: bold;">//</span>127.0.0.1:<span style="color: #000000;">5000</span><span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<h3>Fastr</h3>
<p>Average Latency: 90ms<br />
Requests per second: 1100 r/s</p>
<h3>Rails</h3>
<p>Average Latency: 2235ms<br />
Requests per second: 44 r/s</p>
<h2>Conclusion</h2>
<p>I am extremely happy with what AsyncRecord can do &#8212; and I hope to make it even better. I will be moving it out of Fastr and into its own project soon.</p>
<p>Fastr GitHub: <a href="http://github.com/chrismoos/fastr">http://github.com/chrismoos/fastr</a></p>
]]></content:encoded>
			<wfw:commentRss>http://chrismoos.com/2010/06/21/asyncrecord-non-blocking-database-access-for-ruby/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Fastr &#8211; A Web Framework for&#160;Ruby</title>
		<link>http://chrismoos.com/2010/06/08/fastr-ruby-web-framework/</link>
		<comments>http://chrismoos.com/2010/06/08/fastr-ruby-web-framework/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 04:12:06 +0000</pubDate>
		<dc:creator>Chris Moos</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[web framework]]></category>

		<guid isPermaLink="false">http://chrismoos.com/?p=787</guid>
		<description><![CDATA[Foreword
Every month I go on a binge and learn something new. The most recent binge resulted in a new web framework, called fastr.
I&#8217;ve always used Rails when I needed to create a web application in Ruby, but despite how great it is to code in, the performance and concurrency is not up to par. 
Don&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<h2>Foreword</h2>
<p>Every month I go on a binge and learn something new. The most recent binge resulted in a new web framework, called <a href="http://github.com/chrismoos/fastr">fastr</a>.</p>
<p>I&#8217;ve always used Rails when I needed to create a web application in Ruby, but despite how great it is to code in, the performance and concurrency is not up to par. </p>
<p>Don&#8217;t get me wrong &#8212; Rails can scale, but it is not inherently very good when it comes to an individual instance&#8217;s performance.  While this is hopefully changing in Rails 3, I wanted to see what kind of concurrency and performance I could get out of a simple <a href="http://rubyeventmachine.com/">EventMachine</a> web application. Thus, fastr was born.</p>
<h2>Fastr&#8217;s Architecture</h2>
<p>Fastr is nothing special. It is an extremely simple MVC style web framework, similar in configuration to Rails.</p>
<p>What makes it different though, is how it handles requests and responses.</p>
<p>The core of fastr runs on an EventMachine reactor, which is basically just a big event loop. EventMachine is very capable of maintaining thousands of connections in one instance. This is great when you want an application that supports Comet and chunked responses. There is very minimal overhead in having thousands of connections that have occasional data flowing through.</p>
<p>EventMachine and Fastr also support the ability to defer a response until a long running task finishes executing. This is nice because it won&#8217;t block the rest of the application. The only catch is you are limited to EventMachine&#8217;s thread pool size, which I believe defaults to 20. You can always up this number though, if you want.</p>
<h2>Routing</h2>
<p>The routing is very similar to Rails, an example routes.rb file looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"> router.<span style="color:#9900CC;">draw</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>route<span style="color:#006600; font-weight:bold;">|</span>
        route.<span style="color:#9966CC; font-weight:bold;">for</span> <span style="color:#996600;">'/:controller/:action'</span>
        <span style="color:#008000; font-style:italic;">#route.for '/home/:action', :action =&gt; '[A-Za-z]+'</span>
        <span style="color:#008000; font-style:italic;">#route.for '/test', :to =&gt; 'home#index'</span>
 <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<h2>Controllers</h2>
<p>Controllers are simple, with just a list of actions that are called based on the route. Actions should return a valid Rack response. There are convenience methods in the controller that help in creating Rack responses.</p>
<p>The nice thing about the controllers in Fastr is that you can defer responses with ease. Here is an example of a deferred response:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">def</span> long_running_task
    defer_response<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">200</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;Content-Type&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;text/plain&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>response<span style="color:#006600; font-weight:bold;">|</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;in our deferred response...now we can do cool stuff!&quot;</span>
      response.<span style="color:#9900CC;">send_data</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;hey<span style="color:#000099;">\n</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
      long_task = <span style="color:#CC0066; font-weight:bold;">proc</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
        log.<span style="color:#9900CC;">debug</span> <span style="color:#996600;">&quot;Sleeping for 5 seconds...but this won't block other requests&quot;</span>
        <span style="color:#CC0066; font-weight:bold;">sleep</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        log.<span style="color:#9900CC;">debug</span> <span style="color:#996600;">&quot;Finished sleeping, returning response to client.&quot;</span>
        <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#996600;">&quot;finished&quot;</span>
      <span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
      callback = <span style="color:#CC0066; font-weight:bold;">proc</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>result<span style="color:#006600; font-weight:bold;">|</span>
        log.<span style="color:#9900CC;">debug</span> <span style="color:#996600;">&quot;Callback result: #{result}&quot;</span>
        response.<span style="color:#9900CC;">send_data</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{result}<span style="color:#000099;">\n</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        response.<span style="color:#9900CC;">succeed</span>
      <span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
      response.<span style="color:#9900CC;">task</span><span style="color:#006600; font-weight:bold;">&#40;</span>long_task, callback<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>The alternative render methods also exist, where you can render a HAML template or just text:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">render<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:text</span>, <span style="color:#996600;">&quot;Hello, world!&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
render<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:haml</span>, <span style="color:#ff3333; font-weight:bold;">:template</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;index&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;"># this searches for index.haml in your app/views/ folder</span></pre></div></div>

<h2>Future</h2>
<p>For now, fastr is just a toy framework for me, that I hope to share with anyone interested in learning about building web frameworks.</p>
<p>I intend to start writing some tests as well as making fastr more robust. I don&#8217;t mean to displace any other Ruby web framework, but as I learn with fastr I hope to contribute what I learn back to projects like Rails and Sinatra.</p>
<p>Also, I&#8217;d like to get em-mysql or equivalent integrated so that you can really enjoy a event-driven web framework &#8212; event with database access.</p>
<p>Check out the GitHub page for more examples on getting fastr up and running.</p>
<p>GitHub: <a href="http://github.com/chrismoos/fastr">http://github.com/chrismoos/fastr</a></p>
]]></content:encoded>
			<wfw:commentRss>http://chrismoos.com/2010/06/08/fastr-ruby-web-framework/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Unlocking the full potential of the&#160;iPhone</title>
		<link>http://chrismoos.com/2010/04/17/unlocking-the-full-potential-of-the-iphone/</link>
		<comments>http://chrismoos.com/2010/04/17/unlocking-the-full-potential-of-the-iphone/#comments</comments>
		<pubDate>Sun, 18 Apr 2010 04:43:48 +0000</pubDate>
		<dc:creator>Chris Moos</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[future]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://chrismoos.com/?p=753</guid>
		<description><![CDATA[Since Apple launched the iPhone in 2007 there has been an unprecedented growth in the mobile phone market. From new advances in hardware, such as touch screens, to operating systems mimicking the full power of a desktop computer. Never has a smartphone been able to penetrate the demographics of 10 year olds, to teenagers, or [...]]]></description>
			<content:encoded><![CDATA[<p>Since Apple launched the iPhone in 2007 there has been an unprecedented growth in the mobile phone market. From new advances in hardware, such as touch screens, to operating systems mimicking the full power of a desktop computer. Never has a smartphone been able to penetrate the demographics of 10 year olds, to teenagers, or mom and dad &#8212; until the iPhone. </p>
<p>There are now hundreds of thousands of applications built for mobile phones, with every use case you can imagine. But even with the growth and advances of the past few years, the industry is still in its youth. </p>
<p>Apple, with its enormous success, is still constantly on the front page because of its questionable practice &#8212; sole control of the iPhone platform. Unlike desktop operating systems, such as Windows or Mac OS X, where the user is in complete control of the operating system, the iPhone is a jail, with Apple deciding what can come in and go out.</p>
<p>The App Store, the only way for a developer to target an iPhone, or a user to install an application on the iPhone, is in constant censorship mode. Certain API&#8217;s are not allowed and questionable content is put to rest. </p>
<p>It is time that Apple realizes that it is not only the hardware in the iPhone, or the software that powers it, that makes it a powerful force in the mobile phone market. The power is in the <em>apps</em>, the platform, and in the imaginations of developers.</p>
<p>Even though there are many applications for the iPhone, there could be so much more. The iPhone is a powerful device that can be used to provide a platform for mobile applications in every industry possible. Medical, industrial, retail &#8212; the list goes on. But as long as Apple is in control of what happens on the iPhone, developers will never be able to harness the full potential of such a beautiful device.</p>
<p>Apple now has the ability to turn the iPhone, and the new iPad, into a commodity device. The PC of the mobile world. My intuition tells me that Apple won&#8217;t let this happen. They prefer to maintain complete control of their platform, and while making it a premium and luxury item, they stop it from attaining the growth that it most definitely can achieve. </p>
<p>The future is in Apple&#8217;s hands &#8212; and they have the ability to make it an awesome place.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrismoos.com/2010/04/17/unlocking-the-full-potential-of-the-iphone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Groovy scripts and JVM&#160;Security</title>
		<link>http://chrismoos.com/2010/03/24/groovy-scripts-and-jvm-security/</link>
		<comments>http://chrismoos.com/2010/03/24/groovy-scripts-and-jvm-security/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 02:26:20 +0000</pubDate>
		<dc:creator>Chris Moos</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://chrismoos.com/?p=729</guid>
		<description><![CDATA[
Groovy is a very cool dynamic language for the JVM. Because it runs on the JVM, it also has the great security features as well.

Let&#8217;s see how we can run trusted code and allow a dynamic (possibly user defined) script to execute with limited permissions. We will also see how the script can call functions [...]]]></description>
			<content:encoded><![CDATA[<p>
Groovy is a very cool dynamic language for the JVM. Because it runs on the JVM, it also has the great security features as well.
</p>
<p>Let&#8217;s see how we can run trusted code and allow a dynamic (possibly user defined) script to execute with limited permissions. We will also see how the script can call functions in our trusted code and how we can elevate privileges to allow the untrusted script to get access to trusted data.</p>
<h3>Setting up a security policy</h3>
<p>We are going to create a java policy file that gives our script and groovy full access, but no permissions for our untrusted scripts</p>
<p><strong>~/.java.policy</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">grant codeBase <span style="color: #0000ff;">&quot;file:/Users/chris/securegroovy/trusted.groovy&quot;</span> <span style="color: #009900;">&#123;</span>
  permission java.<span style="color: #006633;">security</span>.<span style="color: #003399;">AllPermission</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
grant codeBase <span style="color: #0000ff;">&quot;file:${groovy.home}/-&quot;</span> <span style="color: #009900;">&#123;</span>
    permission java.<span style="color: #006633;">security</span>.<span style="color: #003399;">AllPermission</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
grant codeBase <span style="color: #0000ff;">&quot;file:/restrictedScript&quot;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p><span id="more-729"></span></p>
<h3>Trusted Script</h3>
<p>Now we are going to create our Trusted script, which will evaluate our untrusted script in a sandbox.</p>
<p><strong>trusted.groovy</strong></p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #a1a100;">com.cmoos</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #a1a100;">java.security.*</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> TrustedScript <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #993333;">int</span> main<span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">String</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> args<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #993399;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Checking to see if security manager is enabled...&quot;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">System</span>.<span style="color: #006600;">getSecurityManager</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">==</span> <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      <span style="color: #993399;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Security manager not enabled, using default.&quot;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #aaaadd; font-weight: bold;">System</span>.<span style="color: #006600;">setSecurityManager</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">SecurityManager</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
      <span style="color: #993399;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Security manager enabled.&quot;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* Create a shell with a restricted code base */</span>
    <span style="color: #000000; font-weight: bold;">def</span> binding <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">Binding</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>trusted: TrustedScript<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">def</span> shell <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GroovyShell<span style="color: #66cc66;">&#40;</span>binding<span style="color: #66cc66;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">def</span> codeSource <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GroovyCodeSource<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">File</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;untrusted.groovy&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #FFCC33;">getText</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #ff0000;">&quot;UntrustedScript&quot;</span>, <span style="color: #ff0000;">&quot;/restrictedScript&quot;</span><span style="color: #66cc66;">&#41;</span>
    shell.<span style="color: #006600;">evaluate</span><span style="color: #66cc66;">&#40;</span>codeSource<span style="color: #66cc66;">&#41;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #cc66cc;">0</span>
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #aaaadd; font-weight: bold;">String</span> getSystemProperty<span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">String</span> name<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #993399;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Raising privileges to access system property...&quot;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #aaaadd; font-weight: bold;">AccessController</span>.<span style="color: #006600;">doPrivileged</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span> <span style="color: #66cc66;">-&gt;</span> <span style="color: #aaaadd; font-weight: bold;">System</span>.<span style="color: #006600;">getProperty</span><span style="color: #66cc66;">&#40;</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">as</span> <span style="color: #aaaadd; font-weight: bold;">PrivilegedAction</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>We specify the code base to assign to the script, which will inherit the permissions in our security policy.</p>
<p>We also pass in our class into the script&#8217;s binding, allowing it to call our methods. This let&#8217;s us specify an API for the script to use to access trusted data, which we control access to.</p>
<p>By using <strong>AccessController.doPrivileged()</strong>, we can elevate our privileges to that of the calling code base.</p>
<h3>Untrusted Script</h3>
<p><strong>untrusted.groovy</strong></p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #993399;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;I'm in a sandbox...let's see if I can access a system property&quot;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #aaaadd; font-weight: bold;">System</span>.<span style="color: #006600;">getProperty</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;java.home&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">catch</span><span style="color: #66cc66;">&#40;</span>java.<span style="color: #006600;">security</span>.<span style="color: #aaaadd; font-weight: bold;">AccessControlException</span> e<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #993399;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Couldn't get property: ${e.getMessage()}&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Call our trusted code (which is accessible through a binding) and get the property */</span>
<span style="color: #993399;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Calling trusted code to get property...&quot;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993399;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;java.home: ${trusted.getSystemProperty(&quot;</span>java.<span style="color: #006600;">home</span><span style="color: #ff0000;">&quot;)}&quot;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>This code is executed in a sandbox, with permissions defined in our security policy. You can see that if we try to do something we don&#8217;t have permission for, access is denied.</p>
<p>By calling our trusted class, which has all permissions, we can give the script access to certain things, but we control it.</p>
<h3>Running the example</h3>
<pre>
$ groovy trusted.groovy
Checking to see if security manager is enabled...
Security manager not enabled, using default.
I'm in a sandbox...let's see if I can access a system property
Couldn't get property: access denied (java.util.PropertyPermission java.home read)
Calling trusted code to get property...
Raising privileges to access system property...
java.home: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
</pre>
]]></content:encoded>
			<wfw:commentRss>http://chrismoos.com/2010/03/24/groovy-scripts-and-jvm-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting started with Scala using&#160;SBT</title>
		<link>http://chrismoos.com/2010/02/10/getting-started-with-scala-using-sbt/</link>
		<comments>http://chrismoos.com/2010/02/10/getting-started-with-scala-using-sbt/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 02:13:03 +0000</pubDate>
		<dc:creator>Chris Moos</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[sbt]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://chrismoos.com/?p=707</guid>
		<description><![CDATA[One of my biggest gripes with Java (and all the languages that run on the JVM) is getting my project setup and building it. Maven is not my favorite, and ant..well..I don&#8217;t like it either. Fortunately, if you want to start a new project in Scala, there is a great build tool available that takes [...]]]></description>
			<content:encoded><![CDATA[<p>One of my biggest gripes with Java (and all the languages that run on the JVM) is getting my project setup and building it. Maven is not my favorite, and ant..well..I don&#8217;t like it either. Fortunately, if you want to start a new project in Scala, there is a great build tool available that takes a lot of the pain out of project management and building &#8211; SBT, <a href="http://code.google.com/p/simple-build-tool/">simple-build-tool</a>.</p>
<blockquote><p>sbt is a simple build tool for Scala projects that aims to do the basics well. It requires Java 1.5 or later.</p></blockquote>
<h3>Installing SBT</h3>
<p>
I&#8217;m using Mac OS X, but the following instructions should be pretty much the same on any Unix based OS.
</p>
<p>You can find the latest version of SBT <a href="http://code.google.com/p/simple-build-tool/downloads/list">here</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>simple-build-tool.googlecode.com<span style="color: #000000; font-weight: bold;">/</span>files<span style="color: #000000; font-weight: bold;">/</span>sbt-launcher-0.5.6.jar
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> sbt-launcher-0.5.6.jar <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>sbt-launcher.jar
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;java -Xmx512M -jar /usr/local/bin/sbt-launcher.jar <span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\$</span>@<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">tee</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>sbt
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>sbt</pre></div></div>

<p>This will install the SBT jar and create a script called <em>sbt</em> that will allow you to run the sbt jar.</p>
<p>Just type <em>sbt</em> and press enter, and you now have access to sbt.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ sbt
Project does not exist, create new project? <span style="color: #7a0874; font-weight: bold;">&#40;</span>y<span style="color: #000000; font-weight: bold;">/</span>N<span style="color: #000000; font-weight: bold;">/</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span> : n</pre></div></div>

<p><span id="more-707"></span></p>
<h3>Creating a new Scala project</h3>
<p>Now we will create a Hello World Scala project with SBT.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> hello_scala
<span style="color: #7a0874; font-weight: bold;">cd</span> hello_scala</pre></div></div>

<p>Running the <em>sbt</em> command in a directory where there is no project will prompt you to create one.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">sbt</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Project does not exist, create <span style="color: #000000; font-weight: bold;">new</span> project<span style="color: #339933;">?</span> <span style="color: #009900;">&#40;</span>y<span style="color: #339933;">/</span>N<span style="color: #339933;">/</span>s<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> y
<span style="color: #003399;">Name</span><span style="color: #339933;">:</span> Hello, Scala<span style="color: #339933;">!</span>
Organization <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span> 
Version <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1.0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span> 
Scala version <span style="color: #009900;">&#91;</span>2.7.7<span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span> 
sbt version <span style="color: #009900;">&#91;</span>0.5.6<span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span> 
<span style="color: #339933;">::</span> retrieving <span style="color: #339933;">::</span> sbt#boot
	confs<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #000000; font-weight: bold;">default</span><span style="color: #009900;">&#93;</span>
	<span style="color: #cc66cc;">2</span> artifacts copied, <span style="color: #cc66cc;">0</span> already retrieved <span style="color: #009900;">&#40;</span>9911kB<span style="color: #339933;">/</span>72ms<span style="color: #009900;">&#41;</span>
<span style="color: #339933;">::</span> retrieving <span style="color: #339933;">::</span> sbt#boot
	confs<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #000000; font-weight: bold;">default</span><span style="color: #009900;">&#93;</span>
	<span style="color: #cc66cc;">3</span> artifacts copied, <span style="color: #cc66cc;">0</span> already retrieved <span style="color: #009900;">&#40;</span>3409kB<span style="color: #339933;">/</span>15ms<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#91;</span>success<span style="color: #009900;">&#93;</span> Successfully initialized directory structure.
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span> Building project Hello, Scala<span style="color: #339933;">!</span> <span style="color: #cc66cc;">1.0</span> using sbt.<span style="color: #006633;">DefaultProject</span>
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span>    with sbt 0.5.6 and Scala 2.7.7
<span style="color: #009900;">&#91;</span>success<span style="color: #009900;">&#93;</span> Build completed successfully.
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span> 
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span> Total build time<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span> s</pre></div></div>

<p>Awesome. It handles all the Scala dependencies for us! Now let&#8217;s create a file that contains our Hello, Scala example.</p>
<p>Below is the directory structure of an SBT project.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ls</span>
lib	project	src</pre></div></div>

<h3>Creating our HelloScala sources and running</h3>
<p>Now we are going to create our main file, <strong>HelloScala.scala</strong></p>
<p><strong>src/main/scala/HelloScala.scala</strong></p>

<div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">object</span> HelloScala <span style="color: #F78811;">&#123;</span>
  <span style="color: #0000ff; font-weight: bold;">def</span> main<span style="color: #F78811;">&#40;</span>args<span style="color: #000080;">:</span> Array<span style="color: #F78811;">&#91;</span>String<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
    println<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;Hello, Scala!&quot;</span><span style="color: #F78811;">&#41;</span>
  <span style="color: #F78811;">&#125;</span>
<span style="color: #F78811;">&#125;</span></pre></div></div>

<p>And now we can build and run it by just issuing the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">sbt run</pre></div></div>

<p>And the output:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span> Building project Hello, Scala<span style="color: #339933;">!</span> <span style="color: #cc66cc;">1.0</span> using sbt.<span style="color: #006633;">DefaultProject</span>
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span>    with sbt 0.5.6 and Scala 2.7.7
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span> 
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> compile <span style="color: #339933;">==</span>
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span>   Source analysis<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #000000; font-weight: bold;">new</span><span style="color: #339933;">/</span>modified, <span style="color: #cc66cc;">0</span> indirectly invalidated, <span style="color: #cc66cc;">0</span> removed.
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span> Compiling main sources...
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span> Nothing to compile.
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span>   Post<span style="color: #339933;">-</span>analysis<span style="color: #339933;">:</span> <span style="color: #cc66cc;">2</span> classes.
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> compile <span style="color: #339933;">==</span>
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span> 
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> copy<span style="color: #339933;">-</span>resources <span style="color: #339933;">==</span>
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> copy<span style="color: #339933;">-</span>resources <span style="color: #339933;">==</span>
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span> 
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> run <span style="color: #339933;">==</span>
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span> Running HelloScala ...
<span style="color: #006633;">Hello</span>, Scala<span style="color: #339933;">!</span>
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> run <span style="color: #339933;">==</span>
<span style="color: #009900;">&#91;</span>success<span style="color: #009900;">&#93;</span> Successful.
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span> 
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span> Total time<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span> s
<span style="color: #009900;">&#91;</span>success<span style="color: #009900;">&#93;</span> Build completed successfully.
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span> 
<span style="color: #009900;">&#91;</span>info<span style="color: #009900;">&#93;</span> Total build time<span style="color: #339933;">:</span> <span style="color: #cc66cc;">1</span> s</pre></div></div>

<p>And that&#8217;s it. Setting up a new Scala project with SBT is painless. In the next part I will talk about managing dependencies and how SBT makes this also very easy.</p>
<p>You can read a lot more about SBT by checking out <a href="http://code.google.com/p/simple-build-tool/w/list">their wiki</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrismoos.com/2010/02/10/getting-started-with-scala-using-sbt/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>AjaxTask &#8211; a rails plugin for managing background&#160;tasks</title>
		<link>http://chrismoos.com/2010/02/09/ajaxtask-a-rails-plugin-for-managing-background-tasks/</link>
		<comments>http://chrismoos.com/2010/02/09/ajaxtask-a-rails-plugin-for-managing-background-tasks/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 06:14:27 +0000</pubDate>
		<dc:creator>Chris Moos</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[background]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[workling]]></category>

		<guid isPermaLink="false">http://chrismoos.com/?p=684</guid>
		<description><![CDATA[SOAP, Background Tasks, and AJAX
Recently in Rails I&#8217;ve been interacting with various SOAP services and running them in the background with Workling. I needed to relay the SOAP response to the client&#8217;s web browser, so I decided to use AJAX to poll the status of my background tasks.
This is great if you have < 30 [...]]]></description>
			<content:encoded><![CDATA[<h3>SOAP, Background Tasks, and AJAX</h3>
<p>Recently in Rails I&#8217;ve been interacting with various SOAP services and running them in the background with Workling. I needed to relay the SOAP response to the client&#8217;s web browser, so I decided to use AJAX to poll the status of my background tasks.</p>
<p>This is great if you have < 30 second background tasks running, but don't want to block a user (and a request). </p>
<p>The Solution</p>
<p>I created a Rails plugin, called <a href="http://github.com/chrismoos/ajaxtask">AjaxTask</a>, that has two components:</p>
<ul>
<li>Methods to use in your controller to define a task handler and create tasks</li>
<li>Javascript library to manage the AJAX between the browser and the handler.</li>
</ul>
<p>GitHub Link: <a href="http://github.com/chrismoos/ajaxtask">http://github.com/chrismoos/ajaxtask</a></p>
<p>In a nutshell, the client initiates a task, the handler responds with a task ID, and the client polls at a user defined interval until the task has finished, or has an error.</p>
<p>The plugin takes the pain out of implementing the handler, as well as the Javascript. All you have to do is run code for your task, and periodically update the status.</p>
<p>I am using <a href="http://github.com/purzelrakete/workling">Workling</a> to run my background tasks, as well as maintain the status using Workling&#8217;s return store.</p>
<p>Okay, enough with the intro, here is the example.</p>
<p><span id="more-684"></span></p>
<h3>Example</h3>
<h4>Controller/Routes</h4>
<p>The first thing to do is define the handler. This instructs the AjaxTask plugin to create a handler that will respond to ajax requests, as well as dispatch to your actual tasks. The only parameter to <em>ajaxtask_handler</em> is a symbol, which <strong>MUST</strong> be identical to a named route. This is how a URL gets from Rails to the plugin.</p>
<p><em>routes.rb</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">map.<span style="color:#9900CC;">ajaxtask_demo</span> <span style="color:#996600;">'/ajaxtask/handler/:task'</span>, <span style="color:#ff3333; font-weight:bold;">:controller</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:demo</span>, <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:ajaxtask_demo</span></pre></div></div>

<p><em>demo_controller.rb</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">ajaxtask_handler <span style="color:#ff3333; font-weight:bold;">:ajaxtask_demo</span></pre></div></div>

<p>Now we will define a task:</p>
<p><em>demo_controller.rb</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">ajaxtask <span style="color:#ff3333; font-weight:bold;">:mytask</span></pre></div></div>

<p>This tells the plugin to respond to a task named <em>mytask</em>.</p>
<p>By doing this, we must implement two methods in our controller. </p>
<p><em>mytask_start</em> is called when a browser starts a new task. You should probably fire off your background task in this method.</p>
<p><em>mytask_start</em> should return a unique ID for the task. By using Workling and calling .async, a unique ID is returned.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> mytask_start
    <span style="color:#0000FF; font-weight:bold;">return</span> MyWorklingWorker.<span style="color:#9900CC;">async_mytask</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> mytask_status<span style="color:#006600; font-weight:bold;">&#40;</span>uid<span style="color:#006600; font-weight:bold;">&#41;</span>
    Workling.<span style="color:#0000FF; font-weight:bold;">return</span>.<span style="color:#9900CC;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span>uid<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<h4>The Worker</h4>
<p>The worker is the meat of our background task. In this we will do something that might take a while, and also update the status.</p>
<p><em>my_workling_worker.rb</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> MyWorklingWorker <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">Workling::Base</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> mytask<span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#41;</span>
    Workling.<span style="color:#0000FF; font-weight:bold;">return</span>.<span style="color:#9900CC;">set</span><span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:uid</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:pending <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'i am just starting...wait up!'</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">begin</span>
      <span style="color:#008000; font-style:italic;"># your long running task goes here</span>
			<span style="color:#CC0066; font-weight:bold;">sleep</span> <span style="color:#006666;">10</span>
    <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> e
      Workling.<span style="color:#0000FF; font-weight:bold;">return</span>.<span style="color:#9900CC;">set</span><span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:uid</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:error <span style="color:#006600; font-weight:bold;">=&gt;</span> e.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0000FF; font-weight:bold;">return</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    Workling.<span style="color:#0000FF; font-weight:bold;">return</span>.<span style="color:#9900CC;">set</span><span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:uid</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:done <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'i finished!})
  end
end</span></pre></div></div>

<p>The important things to note here are what we set the <em>return</em> to. AjaxTask recognizes the following:</p>
<ul>
<li>:error</li>
<li>:pending</li>
<li>:done</li>
</ul>
<p>They should be pretty self explanatory. Now let&#8217;s see what the client side looks like.</p>
<h3>The Client</h3>
<p>For the client, we will be interacting with the AjaxTask javascript library. Make sure you copy the <em>ajaxtask.js</em> file to your javascripts directory, and include it in your page. The following will copy the javascript for you:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> vendor<span style="color: #000000; font-weight: bold;">/</span>plugins<span style="color: #000000; font-weight: bold;">/</span>ajaxtask
rake ajax_task_js</pre></div></div>

<p>Here is an example of what an HTML page that uses AjaxTask:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;">&lt;%= javascript_include_tag <span style="color: #ff0000;">'ajaxtask.js'</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
function mytaskHandler() {
	$(this).bind('onTaskError', onTaskError);
	$(this).bind('onTaskFinished', onTaskFinished);
	$(this).bind('onTaskPending', onTaskPending);
&nbsp;
	function onTaskError(event, error) {
		alert('error: ' + error);
	}
&nbsp;
	function onTaskPending(event, data) {
		alert(&quot;pending: &quot; + data);
	}
&nbsp;
	function onTaskFinished(event, data) {
		alert(&quot;finished: &quot; + data);
	}
}
&nbsp;
$(document).ready(function() {	
	var myTask = new AjaxTask({
		url: &quot;<span style="color: #009900;">&lt;%= ajaxtask_demo_url :task =<span style="color: #000000; font-weight: bold;">&gt;</span></span> :mytask %&gt;&quot;,
		handler: new mytaskHandler(),
		taskStatusDiv: $(&quot;#taskStatus&quot;),
		taskStatusLoadingMsg: 'Please wait while my task runs...',
		taskStatusLoadingImg: '/images/smallactivity.gif',
		taskStatusErrorMsg: 'Oops...something bad happened.'
	});
	myTask.start();
});
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;taskStatus&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Looking at the above client code, you can see how easy it is to present a background task&#8217;s processing to a user. </p>
<p>That does it for now, I&#8217;ll try to document and post more soon abou AjaxTask.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrismoos.com/2010/02/09/ajaxtask-a-rails-plugin-for-managing-background-tasks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
