<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss 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" version="2.0">

<channel>
	<title>12noobs</title>
	
	<link>http://www.12noobs.com</link>
	<description>    You should love Ruby.</description>
	<pubDate>Sat, 23 Aug 2008 01:17:48 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/12noobs" type="application/rss+xml" /><item>
		<title>Beware of the Proxy design pattern -read method_missing-</title>
		<link>http://www.12noobs.com/2008/08/23/beware-proxy-design-pattern-method_missing/</link>
		<comments>http://www.12noobs.com/2008/08/23/beware-proxy-design-pattern-method_missing/#comments</comments>
		<pubDate>Sat, 23 Aug 2008 01:11:38 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[caller]]></category>

		<category><![CDATA[method_missing]]></category>

		<category><![CDATA[proxy]]></category>

		<guid isPermaLink="false">http://www.12noobs.com/?p=20</guid>
		<description><![CDATA[You probably read about how easy it was to implement the Proxy design pattern in Ruby. 
Thanks to the Ruby method_missing method, you can pass messages to underlying objects. See the previous article Local resource available in the wild, thanks to DRb for a fully described example.
But there&#8217;s one caveat, you have to be very [...]]]></description>
			<content:encoded><![CDATA[<p>You probably <a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&#038;location=http%3A%2F%2Fwww.amazon.com%2FDesign-Patterns-Ruby-Addison-Wesley-Professional%2Fdp%2F0321490452%3Fie%3DUTF8%26s%3Dbooks%26qid%3D1219452626%26sr%3D8-1&#038;tag=12noobs-20&#038;linkCode=ur2&#038;camp=1789&#038;creative=9325" onclick="">read</a><img src="http://www.assoc-amazon.com/e/ir?t=12noobs-20&amp;l=ur2&amp;o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> about how easy it was to implement the Proxy design pattern in Ruby. </p>
<p>Thanks to the Ruby <em>method_missing</em> method, you can pass messages to underlying objects. See the previous article <a href="/2008/05/01/local-resource-available-in-the-wild-thanks-to-drb/">Local resource available in the wild, thanks to DRb</a> for a fully described example.</p>
<p>But there&#8217;s one caveat, you have to be very careful when implementing your <em>method_missing</em> method.</p>
<p>Take this code for example:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">def</span> method_missing<span style="color:#006600; font-weight:bold;">&#40;</span>name, <span style="color:#006600; font-weight:bold;">*</span>args, <span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#008000; font-style:italic;"># Get the first arg, which contain information about which underlying</span>
  <span style="color:#008000; font-style:italic;"># object to call.</span>
  id = arg<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Call the corresponding underlying object with the first argument removed</span>
  my_underlying_objects<span style="color:#006600; font-weight:bold;">&#91;</span>id<span style="color:#006600; font-weight:bold;">&#93;</span>.__send__<span style="color:#006600; font-weight:bold;">&#40;</span>name, <span style="color:#006600; font-weight:bold;">*</span>args<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>..<span style="color:#006666;">-1</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>If you execute this code, you&#8217;ll be stuck in an infinite loop. Why ? There&#8217;s a typo, one typo which will cause a <strong>segmentation fault</strong>. I wrote <em>arg[0]</em> instead of <em>args[0]</em>.</p>
<p>To detect this problem before it happens, we can take advantage of the <a href="http://www.ruby-doc.org/core/classes/Kernel.html#M005955" onclick="">Kernel#caller</a> method. It generates the current execution stask. Here is how we can use it to detect that the current object is calling himself:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">def</span> method_missing<span style="color:#006600; font-weight:bold;">&#40;</span>name, <span style="color:#006600; font-weight:bold;">*</span>args, <span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#008000; font-style:italic;"># Check that we're not calling 'method_missing' recursively</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC0066; font-weight:bold;">caller</span>.<span style="color:#9900CC;">first</span>.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#996600;">&quot;#{self.class} is calling itself -method #{name}-. Verify that you do not call a non existing method !!&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Get the first arg, which contain information about which underlying</span>
  <span style="color:#008000; font-style:italic;"># object to call.</span>
  id = args<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Call the corresponding underlying object with the first argument removed</span>
  my_underlying_objects<span style="color:#006600; font-weight:bold;">&#91;</span>id<span style="color:#006600; font-weight:bold;">&#93;</span>.__send__<span style="color:#006600; font-weight:bold;">&#40;</span>name, <span style="color:#006600; font-weight:bold;">*</span>args<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>..<span style="color:#006666;">-1</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>That&#8217;s all, we just check that the caller method is not in the current <strong>file</strong>. If your <em>method_missing</em> code become more and more complex, especially if it includes some meta-programming tricks, you&#8217;ll feel A LOT safer!</p>
<p>One last thing: <a href="http://www.ruby-doc.org/core/classes/Kernel.html#M005955" onclick="">Kernel#caller</a> is not what we could call a non-expensive method, you should only use it in development.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.12noobs.com/2008/08/23/beware-proxy-design-pattern-method_missing/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Go faster to your Home directory in the Terminal</title>
		<link>http://www.12noobs.com/2008/06/03/go-faster-to-your-home-directory-in-the-terminal/</link>
		<comments>http://www.12noobs.com/2008/06/03/go-faster-to-your-home-directory-in-the-terminal/#comments</comments>
		<pubDate>Tue, 03 Jun 2008 12:11:22 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
		
		<category><![CDATA[Mac]]></category>

		<category><![CDATA[Terminal]]></category>

		<guid isPermaLink="false">http://www.12noobs.com/?p=16</guid>
		<description><![CDATA[In any Unix system, to go to your Home directory, you&#8217;d type this:

cd ~

The ~ character is hidden on Mac keyboards but like all other special characters, it is cleverly placed. You just have to push those keys:  n.
Why cleverly placed ? Think about the spanish ñ character. Try all key combinations with the [...]]]></description>
			<content:encoded><![CDATA[<p>In any Unix system, to go to your Home directory, you&#8217;d type this:</p>

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

<p>The <strong>~</strong> character is hidden on Mac keyboards but like all other <em>special</em> characters, it is cleverly placed. You just have to push those keys: <img src='http://www.danrodney.com/mac/img/menusym-option.gif' alt='Option' class='alignnone' /> <strong>n</strong>.</p>
<p>Why cleverly placed ? Think about the spanish <strong>ñ</strong> character. Try all key combinations with the <img src='http://www.danrodney.com/mac/img/menusym-option.gif' alt='Option' class='alignnone' /> with and without the <img src='http://www.danrodney.com/mac/img/menusym-shift.gif' alt='Shift' class='alignnone' /> key. You&#8217;ll be surprised. After several minutes, you&#8217;ll understand why each <em>special</em> character is placed on one specific character key.</p>
<p>But let&#8217;s get back to the subject of this post: to go to your Home directory, you don&#8217;t have to type the  <strong>~</strong> character, just type:</p>

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

<p>That&#8217;s it.</p>
<p>Now that you know everything about <em>special</em> characters, it&#8217;s time to learn the Mac OS X keyboard shortcuts. Feel free to visit the <a href="http://www.danrodney.com/mac/" onclick="">Mac Central website</a>,  <em>your place for good, concise, Mac related hints</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.12noobs.com/2008/06/03/go-faster-to-your-home-directory-in-the-terminal/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Leopard, where are those Ruby gems?</title>
		<link>http://www.12noobs.com/2008/06/02/leopard-where-are-those-ruby-gems/</link>
		<comments>http://www.12noobs.com/2008/06/02/leopard-where-are-those-ruby-gems/#comments</comments>
		<pubDate>Mon, 02 Jun 2008 12:02:12 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[documentation]]></category>

		<category><![CDATA[gem]]></category>

		<guid isPermaLink="false">http://www.12noobs.com/?p=14</guid>
		<description><![CDATA[It&#8217;s always useful to check the code of those downloaded Ruby gems. You should try for at least two reasons: learning and submitting bugs. It&#8217;s always a good idea to give technical details about bugs you encounter. The community is small and responsive, get involved  
You&#8217;re lucky, Leopard user, Apple made a great work [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s always useful to check the code of those downloaded Ruby gems. You should try for at least two reasons: <strong>learning</strong> and <strong>submitting bugs</strong>. It&#8217;s always a good idea to give technical details about bugs you encounter. The community is <em>small</em> and responsive, get involved <img src='http://www.12noobs.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>You&#8217;re lucky, Leopard user, Apple made a great work embedding Ruby in Mac OS X 10.5. You have the latest version of Ruby, 1.8.6, and RubyGems installed.</p>
<p>Apple guys set a specific directory for all Ruby related things.</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Ruby<span style="color: #000000; font-weight: bold;">/</span>Gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>This directory contains exploded gems and their documentation. For example, you can examine the content of the ActiveRecord gem and its documentation with those two commands (I hope you use <a href="http://macromates.com/" onclick="">TextMate</a>&#8230;).</p>

<div class="wp_syntax"><div class="code"><pre class="bash">mate <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Ruby<span style="color: #000000; font-weight: bold;">/</span>Gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>activerecord<span style="color: #000000;">-2.1</span><span style="color: #000000;">.0</span><span style="color: #000000; font-weight: bold;">/</span>
open <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Ruby<span style="color: #000000; font-weight: bold;">/</span>Gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>doc<span style="color: #000000; font-weight: bold;">/</span>activerecord<span style="color: #000000;">-2.1</span><span style="color: #000000;">.0</span><span style="color: #000000; font-weight: bold;">/</span>rdoc<span style="color: #000000; font-weight: bold;">/</span>index.html</pre></div></div>

<p>No need to google &#8220;activerecord&#8221;, everything&#8217;s on you hard drive.</p>
<p><strong>Note</strong>: Rubygems has evolved since the release of Leopard. But hopefully, it&#8217;s simple to update it. Just download the <a href="http://rubyforge.org/frs/?group_id=126" onclick="">last version</a> and <a href="http://docs.rubygems.org/read/chapter/3" onclick="">one simple command</a> will do the work.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.12noobs.com/2008/06/02/leopard-where-are-those-ruby-gems/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Local resource available in the wild, thanks to DRb</title>
		<link>http://www.12noobs.com/2008/05/01/local-resource-available-in-the-wild-thanks-to-drb/</link>
		<comments>http://www.12noobs.com/2008/05/01/local-resource-available-in-the-wild-thanks-to-drb/#comments</comments>
		<pubDate>Thu, 01 May 2008 18:59:52 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[DRb]]></category>

		<category><![CDATA[metaprogramming]]></category>

		<guid isPermaLink="false">http://www.12noobs.com/?p=12</guid>
		<description><![CDATA[You have a resource that you want to share between multiple processes, and it could be a resource persited on the local hard drive, like an index, a persitent hash (Berkeley DB, InfinitiyDB), or simply a file.
With DRb, aka Distributed Ruby, you can share a resource via TCP. DRb will do the annoying job for [...]]]></description>
			<content:encoded><![CDATA[<p>You have a resource that you want to share between multiple processes, and it could be a resource persited on the local hard drive, like an index, a persitent hash (Berkeley DB, InfinitiyDB), or simply a file.</p>
<p>With DRb, aka <a href="http://chadfowler.com/ruby/drb.html" onclick="">Distributed Ruby</a>, you can share a resource via TCP. DRb will do the annoying job for you: <a href="http://en.wikipedia.org/wiki/Marshalling_%28computer_science%29" onclick="">marshalling</a>. And that is <a href="http://www.ruby-doc.org/core/classes/Marshal.html" onclick="">COO</a><a href="http://www.extinction.fr/aaaaah/" onclick="">L</a>, and RMI is <a href="http://notetodogself.blogspot.com/2006/01/java-rmi-headaches.html" onclick="">NOT COOL</a>.</p>
<p>As usual in Ruby, using a library is as simple as calling the <a href="http://www.ruby-doc.org/core/classes/Kernel.html#M005967" onclick="">require</a> method. To use DRb in your application, write this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'drb'</span></pre></div></div>

<p>In this post, we&#8217;ll implement a Remote Hash. It will be accessible to an unlimited number of processes on an unlimited number of computers. Let&#8217;s code a simple DRb server for your resource.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> Server
  <span style="color:#9966CC; font-weight:bold;">def</span> start
    <span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;starting Ferret servers...&quot;</span>
    DRb.<span style="color:#9900CC;">start_service</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;druby://localhost:7000&quot;</span>, HashProxy.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot; done&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> join
    DRb.<span style="color:#9900CC;">thread</span>.<span style="color:#9900CC;">join</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> shutdown
    <span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;stopping Ferret servers...&quot;</span>
    DRb.<span style="color:#9900CC;">stop_service</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot; done&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
s = Server.<span style="color:#9900CC;">new</span>
s.<span style="color:#9900CC;">start</span>
<span style="color:#CC0066; font-weight:bold;">trap</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;INT&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>s.<span style="color:#9900CC;">shutdown</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#008000; font-style:italic;"># Catch CTRL-C to do a clean shutdown of the DRb server</span>
s.<span style="color:#9900CC;">join</span></pre></div></div>

<p>The instance of <em>HashProxy</em> will be the distributed object between the DRb server and the DRb clients. We call it &#8220;proxy&#8221; because it will exactly have the same behaviour as the real resource hidden behind it. This is where the <a href="http://www.ruby-doc.org/core/classes/Kernel.html#M005951" onclick=""><em>method_missing</em></a> magic happen.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> HashProxy
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize <span style="color:#006600; font-weight:bold;">*</span>args
    <span style="color:#0066ff; font-weight:bold;">@local_resource</span> = <span style="color:#CC00FF; font-weight:bold;">Hash</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">*</span>args
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> method_missing<span style="color:#006600; font-weight:bold;">&#40;</span>name, <span style="color:#006600; font-weight:bold;">*</span>args, <span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@local_resource</span>.__send__<span style="color:#006600; font-weight:bold;">&#40;</span>name, <span style="color:#006600; font-weight:bold;">*</span>args, <span style="color:#006600; font-weight:bold;">&amp;</span>block<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 <em>Object.__send__</em> method is an alias to <a href="http://www.ruby-doc.org/core/classes/Object.html#M000335" onclick=""><em>Object.send</em></a>, to avoid conflics with a possibly existing method named <em>send</em> in the current object or its superclasses or included modules.</p>
<p>There is one problem with this implementation, DRb will, like a web server, handle client requests simultaneously. We have to protect our hash thanks to a mutex. Every clients will have to wait in line to access the remote resource.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'thread'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> HashProxy
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize <span style="color:#006600; font-weight:bold;">*</span>args
    <span style="color:#0066ff; font-weight:bold;">@mutex</span> = <span style="color:#CC00FF; font-weight:bold;">Mutex</span>.<span style="color:#9900CC;">new</span>
    <span style="color:#0066ff; font-weight:bold;">@local_resource</span> = <span style="color:#CC00FF; font-weight:bold;">Hash</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">*</span>args
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> method_missing<span style="color:#006600; font-weight:bold;">&#40;</span>name, <span style="color:#006600; font-weight:bold;">*</span>args, <span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@mutex</span>.<span style="color:#9900CC;">synchronize</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      <span style="color:#0066ff; font-weight:bold;">@local_resource</span>.__send__<span style="color:#006600; font-weight:bold;">&#40;</span>name, <span style="color:#006600; font-weight:bold;">*</span>args, <span style="color:#006600; font-weight:bold;">&amp;</span>block<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>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>As we said earlier, each method of <em>HashProxy</em>, and so each method of <em>Hash</em>, is now available to any remote Ruby code, using the <em>HashProxy</em> class, instead of <em>Hash</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> RemoteHash
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize
    <span style="color:#0066ff; font-weight:bold;">@hash_proxy</span> = DRbObject.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">nil</span>,<span style="color:#996600;">&quot;druby://localhost:7000&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> method_missing<span style="color:#006600; font-weight:bold;">&#40;</span>name, <span style="color:#006600; font-weight:bold;">*</span>args, <span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@hash_proxy</span>.__send__<span style="color:#006600; font-weight:bold;">&#40;</span>name, <span style="color:#006600; font-weight:bold;">*</span>args, <span style="color:#006600; font-weight:bold;">&amp;</span>block<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>In your application, you&#8217;ll use your remote resource like a local resource, without knowing about those network and marshalling things.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby">h = RemoteHash.<span style="color:#9900CC;">new</span>
h<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:roger</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#006666;">1</span>
h<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:moore</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#006666;">-1</span>
<span style="color:#CC0066; font-weight:bold;">p</span> h<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:roger</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#008000; font-style:italic;"># =&gt; 1</span></pre></div></div>

<p>Unfortunately, I couldn&#8217;t call methods with blocks.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby">h.<span style="color:#CC0066; font-weight:bold;">select</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>k,v<span style="color:#006600; font-weight:bold;">|</span> v <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#008000; font-style:italic;"># =&gt;</span>
<span style="color:#008000; font-style:italic;"># ArgumentError: wrong number of arguments (0 for 1)</span>
<span style="color:#008000; font-style:italic;"># </span>
<span style="color:#008000; font-style:italic;"># method select at line 9</span>
<span style="color:#008000; font-style:italic;"># method __send__ at line 9</span>
<span style="color:#008000; font-style:italic;"># method method_missing at line 9</span>
<span style="color:#008000; font-style:italic;"># at top level  at line 17</span>
<span style="color:#008000; font-style:italic;"># Program exited.</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">p</span> h.<span style="color:#9900CC;">sort</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>a,b<span style="color:#006600; font-weight:bold;">|</span> a<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&lt;=&gt;</span>b<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#008000; font-style:italic;"># =&gt;</span>
<span style="color:#008000; font-style:italic;"># DRb::DRbConnError: DRb::DRbServerNotFound</span>
<span style="color:#008000; font-style:italic;"># </span>
<span style="color:#008000; font-style:italic;"># method current_server in drb.rb at line 1650</span>
<span style="color:#008000; font-style:italic;"># method to_id  in drb.rb at line 1712</span>
<span style="color:#008000; font-style:italic;"># method initialize in drb.rb at line 1048</span>
<span style="color:#008000; font-style:italic;"># method new  in drb.rb at line 642</span>
<span style="color:#008000; font-style:italic;"># method make_proxy in drb.rb at line 642</span>
<span style="color:#008000; font-style:italic;"># method dump in drb.rb at line 559</span>
<span style="color:#008000; font-style:italic;"># method send_request in drb.rb at line 605</span>
<span style="color:#008000; font-style:italic;"># method send_request in drb.rb at line 906</span>
<span style="color:#008000; font-style:italic;"># method send_message in drb.rb at line 1194</span>
<span style="color:#008000; font-style:italic;"># method method_missing in drb.rb at line 1086</span>
<span style="color:#008000; font-style:italic;"># method open in drb.rb at line 1170</span>
<span style="color:#008000; font-style:italic;"># method method_missing in drb.rb at line 1085</span>
<span style="color:#008000; font-style:italic;"># method with_friend  in drb.rb at line 1103</span>
<span style="color:#008000; font-style:italic;"># method method_missing in drb.rb at line 1084</span>
<span style="color:#008000; font-style:italic;"># method __send__ at line 9</span>
<span style="color:#008000; font-style:italic;"># method method_missing at line 9</span>
<span style="color:#008000; font-style:italic;"># at top level  at line 18</span>
<span style="color:#008000; font-style:italic;"># Program exited.</span></pre></div></div>

<p>One last word, about <em>method_missing</em>, Jay Field wrote an <a href="http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html" onclick="">excellent article</a> about dynamically defining the methods of an external class, instead of using <em>method_missing</em>. It will surely help you debugging your piece of art.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.12noobs.com/2008/05/01/local-resource-available-in-the-wild-thanks-to-drb/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Install Apache Tomcat 5.5.x on Mac OS X Tiger or Leopard</title>
		<link>http://www.12noobs.com/2008/04/24/install-apache-tomcat-55x-on-mac-os-x-tiger-or-leopard/</link>
		<comments>http://www.12noobs.com/2008/04/24/install-apache-tomcat-55x-on-mac-os-x-tiger-or-leopard/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 20:38:27 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<category><![CDATA[Mac OS X]]></category>

		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://www.12noobs.com/?p=11</guid>
		<description><![CDATA[I was working at La Cantine today, a great co-working place in Paris. In fact, I prefer this place than incubators. It&#8217;s like a big loft with long tables, cozy armchairs, sofas, a bar; anything you need to work in an productive environmnent. You&#8217;ll meet developers, designers, investors, technical book writers, etc. 
And when you [...]]]></description>
			<content:encoded><![CDATA[<p>I was working at <a href="http://lacantine.org/" onclick="">La Cantine</a> today, a great co-working place in Paris. In fact, I prefer this place than incubators. It&#8217;s like a big loft with long tables, cozy armchairs, sofas, a bar; anything you need to work in an productive environmnent. You&#8217;ll meet developers, designers, investors, technical book writers, etc. </p>
<p>And when you work/play/chat/drink in a co-working place, there&#8217;s regularly someone with a problem. Noob questions like &#8220;I can&#8217;t connect to the Wifi network&#8221;! &#8220;I can&#8217;t restore my backup!&#8221;, and also more <em>advanced</em> questions.</p>
<p>So, I was asked today: &#8220;How can I install Tomcat on my MacBook ?&#8221;. I supposed that in 2008, there should be tons of articles about installing Tomcat on a Mac, but I did not find one. Actually, I admit that I only looked at the first result page on Google&#8230; you know that Google is pretty good at crawling blogs. Did you try to search for <a href="http://www.google.com/search?q=flex+ruby+graph" onclick="">flex ruby graph</a> or <a href="http://www.google.com/search?q=flex+ruby+graph" onclick="">ruby sqs graph</a> ?</p>
<p>Before calling for help, the guy -let&#8217;s call him Roger- read some forum posts, began to install Tomcat in <em>/usr/local</em>, set its environment variables, and ran into the famous error message &#8220;The BASEDIR environment variable is not defined correctly&#8221;.</p>
<p>Roger, you need to know one thing: there&#8217;s <em>develoment environment</em> and <em>production environment</em>. So do those three simple things and you&#8217;ll be fine:</p>
<ul>
<li>Untar <a href="http://tomcat.apache.org/download-55.cgi" onclick="">Tomcat</a> to your <em>/Applications</em> directory. <strong>Important</strong>: Take the <em>tar.gz</em> archive, it keeps file modes and authorizations for *nix systems</li>
<p>.</p>
<li>With the Terminal, create a file named <em>.bash_profile</em> in your home directory (aka <em>~</em>) via the command <em>nano ~/.bash_profile</em> and copy-paste this text:
</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">CATALINA_HOME=</span><span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>apache-tomcat<span style="color: #000000;">-5.5</span><span style="color: #000000;">.26</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">JAVA_HOME=</span><span style="color: #000000; font-weight: bold;">/</span>System<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Frameworks<span style="color: #000000; font-weight: bold;">/</span>JavaVM.framework<span style="color: #000000; font-weight: bold;">/</span>Versions<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.5</span><span style="color: #000000; font-weight: bold;">/</span>Home
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">starttomcat=</span><span style="color: #ff0000;">&quot;$CATALINA_HOME/bin/startup.sh&quot;</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">stoptomcat=</span><span style="color: #ff0000;">&quot;$CATALINA_HOME/bin/shutdown.sh&quot;</span></pre></div></div>

<ul>
<li>
Start a new Terminal and type <strong>starttomcat</strong> and <strong>stoptomcat</strong> to&#8230; you guess.
</li>
</ul>
<p>I did put Tomcat in the <em>/Applications</em> folder for on reason: it&#8217;s not hidden in the Finder and it&#8217;s easily accessible. Noobs do not understand the difference between <em>system directories</em> and <em>friendly directories</em> on Mac OS X. And they want to see the Tomcat folder, so they can put their .war files in the <em>webapps</em> directory and check log files with one click on the mouse button.</p>
<p>By the way, I didn&#8217;t ask Roger why the hell he was coding a new project in Java. And I really do not want to know&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.12noobs.com/2008/04/24/install-apache-tomcat-55x-on-mac-os-x-tiger-or-leopard/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Dynamic Graph Visualization in Flex, Ruby and Amazon SQS - Part 2 - Ruby and SQS</title>
		<link>http://www.12noobs.com/2008/04/21/dynamic-graph-visualization-in-flex-ruby-and-amazon-sqs-part-2-ruby/</link>
		<comments>http://www.12noobs.com/2008/04/21/dynamic-graph-visualization-in-flex-ruby-and-amazon-sqs-part-2-ruby/#comments</comments>
		<pubDate>Mon, 21 Apr 2008 21:32:24 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[AWS]]></category>

		<category><![CDATA[Flex]]></category>

		<category><![CDATA[SQS]]></category>

		<guid isPermaLink="false">http://www.12noobs.com/?p=8</guid>
		<description><![CDATA[Update: An Amazon guy sent me a mail because I used the old SQS API. Please use the gems from RightScale instead of the one presented below, it supports the new SQS WSDL, which is cheaper.
Thanks to the first part of this article, you master Flex and ActionScript 3 like nobody. Don&#8217;t you ?
It&#8217;s now [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong> An Amazon guy sent me a mail because I used the old SQS API. Please use the <a href="http://rightaws.rubyforge.org/" onclick="">gems from RightScale</a> instead of the one presented below, it supports the new SQS WSDL, which is cheaper.</p>
<p>Thanks to the <a href="/2008/04/18/dynamic-graph-visualization-in-flex-ruby-and-amazon-sqs-part-1-flex/">first part</a> of this article, you master Flex and ActionScript 3 like nobody. Don&#8217;t you ?</p>
<p>It&#8217;s now time to retrieve some data. You could need a realtime updated graph to monitor a bunch of rackmount servers, your database, your mailbox, or the activity of your friends of Facebook, who knows. After taking a look at the <a href="http://technorati.com/pop/blogs/" onclick="">Technorati top blogs list</a>, I wondered what was the activity of readers on those blogs, ie. check how many comments are posted on their last articles.</p>
<p>This article will focus on the data provider, coded in Ruby. And remember, the retrieved data will be sent to an Amazon SQS queue.</p>
<p>I know, why would we need to use Ruby and Amazon SQS when we can do all those tasks directly in ActionScript 3 ? Like I wrote before, you could use it to monitor something which is not directly accessible by Flash, as the ActionScript code is executed on the client computer. Data providers could also be CPU/Network expensive and/or spreaded in a computing cloud. Hey, finally, don&#8217;t you want to read some Ruby code ?</p>
<p>Let&#8217;s parse those RSS feeds. You&#8217;ll need one <a href="http://www.rubygems.org/" onclick="">gem</a>, the &#8220;Flexible RSS and Atom reader for Ruby&#8221;: <a href="http://simple-rss.rubyforge.org/" onclick="">simple-rss</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'open-uri'</span> <span style="color:#008000; font-style:italic;"># To retrieve data from the word wide web</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span> <span style="color:#008000; font-style:italic;"># Needed to load installed gems</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'simple-rss'</span>
&nbsp;
feeds_url = <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#123;</span>
  http:<span style="color:#006600; font-weight:bold;">//</span>feeds.<span style="color:#9900CC;">feedburner</span>.<span style="color:#9900CC;">com</span><span style="color:#006600; font-weight:bold;">/</span>Techcrunch
  http:<span style="color:#006600; font-weight:bold;">//</span>feeds.<span style="color:#9900CC;">feedburner</span>.<span style="color:#9900CC;">com</span><span style="color:#006600; font-weight:bold;">/</span>Mashable
  ... <span style="color:#9900CC;">a</span> lot more here ...
<span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
feeds_url.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>feed_url<span style="color:#006600; font-weight:bold;">|</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Parse each feed</span>
  rss = SimpleRSS.<span style="color:#9900CC;">parse</span> <span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>feed_url<span style="color:#006600; font-weight:bold;">&#41;</span>
  rss.<span style="color:#9900CC;">entries</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>entry<span style="color:#006600; font-weight:bold;">|</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">begin</span>
      entry.<span style="color:#9900CC;">guid</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;/&quot;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> entry.<span style="color:#9900CC;">guid</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">-1</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#006666;">47</span>
      comments_feed_url = <span style="color:#996600;">&quot;#{entry.guid}feed&quot;</span>
      rss_comments = SimpleRSS.<span style="color:#9900CC;">parse</span> <span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>comments_feed_url<span style="color:#006600; font-weight:bold;">&#41;</span>
      rss_comments.<span style="color:#9900CC;">entries</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>comment<span style="color:#006600; font-weight:bold;">|</span>
        <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Found a new comment #{comment.title} on '#{entry.title}'&quot;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">rescue</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;There was a problem retrieving comments from #{comments_feed_url}&quot;</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></pre></div></div>

<p>As I want to keep the code simple, I only chose Wordpress blogs, as you can retrieve the comments feed for each entry easily: adding &#8220;/feed&#8221; to the end of the entry url.</p>
<p>Whis <a href="assets/dp1.rb" target="_blank">this code</a>, you&#8217;ll get something like:</p>

<div class="wp_syntax"><div class="code"><pre class="xml">Found a new comment By: Tim-TechFruit on 'LoveFilm merges with Amazon’s DVD rentals'
Found a new comment By: Esi on 'Cuill has Irish roots'
Found a new comment By: Sam B on 'Women more likely to give passwords for chocolate? Yeah, but did they offer the men guilt-free sex?'
Found a new comment By: john b on 'Women more likely to give passwords for chocolate? Yeah, but did they offer the men guilt-free sex?'
Found a new comment By: Carl on 'Women more likely to give passwords for chocolate? Yeah, but did they offer the men guilt-free sex?'</pre></div></div>

<p>We said earlier that we wanted to monitor the comments, right ? We will put this code in a infinite loop, and keep the found comments in a hash, just to announce only the new ones.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby">comments = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#008000; font-style:italic;"># hash of found comments</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">loop</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  feeds_url.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>feed_url<span style="color:#006600; font-weight:bold;">|</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># Parse each feed</span>
    rss = SimpleRSS.<span style="color:#9900CC;">parse</span> <span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>feed_url<span style="color:#006600; font-weight:bold;">&#41;</span>
    rss.<span style="color:#9900CC;">entries</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>entry<span style="color:#006600; font-weight:bold;">|</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">begin</span>
        entry.<span style="color:#9900CC;">guid</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;/&quot;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> entry.<span style="color:#9900CC;">guid</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">-1</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#006666;">47</span>
        comments_feed_url = <span style="color:#996600;">&quot;#{entry.guid}feed&quot;</span>
        rss_comments = SimpleRSS.<span style="color:#9900CC;">parse</span> <span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>comments_feed_url<span style="color:#006600; font-weight:bold;">&#41;</span>
        rss_comments.<span style="color:#9900CC;">entries</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>comment<span style="color:#006600; font-weight:bold;">|</span>
          <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#9966CC; font-weight:bold;">not</span> comments<span style="color:#006600; font-weight:bold;">&#91;</span>comment.<span style="color:#9900CC;">guid</span><span style="color:#006600; font-weight:bold;">&#93;</span>
            comments<span style="color:#006600; font-weight:bold;">&#91;</span>comment.<span style="color:#9900CC;">guid</span><span style="color:#006600; font-weight:bold;">&#93;</span> = comment.<span style="color:#9900CC;">guid</span>
            <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Found a new comment #{comment.title} on '#{entry.title}'&quot;</span>
          <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;">rescue</span>
        <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;There was a problem retrieving comments from #{comments_feed_url}&quot;</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>
&nbsp;
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;... waiting 1 minute ...&quot;</span>
  <span style="color:#CC0066; font-weight:bold;">sleep</span> <span style="color:#006666;">60</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Whis <a href="assets/dp2.rb" target="_blank">this code</a>, you&#8217;ll get something like:</p>

<div class="wp_syntax"><div class="code"><pre class="xml">Found a new comment by: Buster Cherry on 'Crazy Gets Evicted!'
Found a new comment by: DONT MAKE FUN OF HOMELESS on 'Crazy Gets Evicted!'
Found a new comment by: joe on 'Crazy Gets Evicted!'
Found a new comment by: Oh, Give Me a Home Where the... on 'Crazy Gets Evicted!'
... waiting 1 minute ...
... waiting 1 minute ...
... waiting 1 minute ...
Found a new comment by: beth on 'Ben Savage Is Still Alive'
Found a new comment by: Dain Starr on 'Ben Savage Is Still Alive'
Found a new comment by: I LOVE BEN SAVAGE!! on 'Ben Savage Is Still Alive'
Found a new comment by: Chuy on 'Ben Savage Is Still Alive'</pre></div></div>

<p>It would be a good idea to check each new feed in a new thread, as 99% of the processing time is devoted to network requests. We&#8217;ll use a new gem for this: <a href="http://rubyforge.org/frs/?group_id=1306" onclick="">fastthread</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'fastthread'</span>
&nbsp;
threads = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
comments = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#008000; font-style:italic;"># hash of found comments</span>
&nbsp;
feeds_url.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>feed_url<span style="color:#006600; font-weight:bold;">|</span>
  t = <span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">new</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#CC0066; font-weight:bold;">loop</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      rss = SimpleRSS.<span style="color:#9900CC;">parse</span> <span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>feed_url<span style="color:#006600; font-weight:bold;">&#41;</span>
      rss.<span style="color:#9900CC;">entries</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>entry<span style="color:#006600; font-weight:bold;">|</span>
&nbsp;
        <span style="color:#008000; font-style:italic;"># ...</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      <span style="color:#CC0066; font-weight:bold;">sleep</span> <span style="color:#006666;">60</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  threads <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> t
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Wait for all threads to exit (never, in this case)</span>
threads.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span> t.<span style="color:#9900CC;">join</span> <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>With <a href="/assets/dp3.rb" target="_blank">this code</a>, you&#8217;ll see the same output as earlier, but, you guess, with every messages mixed.</p>
<p>Finally, we can put our data in an Amazon SQS queue. In the graph, we&#8217;ll show one node per feed, add a child node when a new comment comes in. This way, we only need one message format, only containing the feed URL.</p>
<p>It&#8217;s time to register to <a href="http://www.amazon.com/Simple-Queue-Service-home-page/b?ie=UTF8&#038;node=13584001" onclick="">Amazon SQS</a>. You&#8217;ll get two keys: <em>AWS access key</em> and <em>AWS secret access key</em>. You&#8217;ll also need to install a new gem: <a href="http://sqs.rubyforge.org/" onclick="">SQS</a>.</p>
<p>Just require &#8217;sqs&#8217; as the other gems, set your credentials, and create a queue named &#8220;feeds&#8221;.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'sqs'</span>
&nbsp;
SQS.<span style="color:#9900CC;">access_key_id</span> = <span style="color:#996600;">&quot;my key here&quot;</span>
SQS.<span style="color:#9900CC;">secret_access_key</span> = <span style="color:#996600;">&quot;my secret key here&quot;</span>
queue = SQS.<span style="color:#9900CC;">create_queue</span> <span style="color:#996600;">&quot;feeds&quot;</span></pre></div></div>

<p>Each time a comment is detected, we can put a message in the queue.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby">rss_comments.<span style="color:#9900CC;">entries</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>comment<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#9966CC; font-weight:bold;">not</span> comments<span style="color:#006600; font-weight:bold;">&#91;</span>comment.<span style="color:#9900CC;">guid</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    comments<span style="color:#006600; font-weight:bold;">&#91;</span>comment.<span style="color:#9900CC;">guid</span><span style="color:#006600; font-weight:bold;">&#93;</span> = comment.<span style="color:#9900CC;">guid</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Found a new comment #{comment.title} on '#{entry.title}'&quot;</span>
    queue.<span style="color:#9900CC;">send_message</span> <span style="color:#996600;">&quot;#{feed_url}&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>You can download the full code <a href="/assets/dp4.rb" target="_blank">here</a>.</p>
<p>When you&#8217;ve finished playing, you can delete the queue with the following piece of code.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby">SQS.<span style="color:#9900CC;">get_queue</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;feeds&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">delete</span>!</pre></div></div>

<p>You&#8217;re now ready to animate this with our Flex graph. It will be the subject of the next and last part of this article. (actually, there will be a fourth post to illustrate all of this, think about a racing game&#8230;).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.12noobs.com/2008/04/21/dynamic-graph-visualization-in-flex-ruby-and-amazon-sqs-part-2-ruby/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Dynamic Graph Visualization in Flex, Ruby and Amazon SQS - Part 1 - Flex</title>
		<link>http://www.12noobs.com/2008/04/18/dynamic-graph-visualization-in-flex-ruby-and-amazon-sqs-part-1-flex/</link>
		<comments>http://www.12noobs.com/2008/04/18/dynamic-graph-visualization-in-flex-ruby-and-amazon-sqs-part-1-flex/#comments</comments>
		<pubDate>Fri, 18 Apr 2008 07:02:35 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[AWS]]></category>

		<category><![CDATA[Flex]]></category>

		<category><![CDATA[SQS]]></category>

		<guid isPermaLink="false">http://www.12noobs.com/?p=1</guid>
		<description><![CDATA[In this first post, we&#8217;ll try to create a animated graph in Flex. Data is retrieved periodically from an Amazon SQS queue and the graph is updated in realtime. Why Amazon SQS ? You work in a distributed environment, don&#8217;t you ?
As Ruby is my favourite language these days, the data provider will be implemented [...]]]></description>
			<content:encoded><![CDATA[<p>In this first post, we&#8217;ll <em>try</em> to create a animated graph in Flex. Data is retrieved periodically from an <a href="http://www.amazon.com/Simple-Queue-Service-home-page/b?ie=UTF8&amp;node=13584001" onclick="">Amazon SQS</a> queue and the graph is updated in realtime. Why Amazon SQS ? You work in a distributed environment, don&#8217;t you ?</p>
<p>As Ruby is my favourite language these days, the data provider will be implemented in Ruby. Is there a better language to show concise but featureful snippets of code ?</p>
<p>Part 1 is dedicated to Flex. I&#8217;m not a real fan of Flash for web apps, but sometimes, you can&#8217;t avoid it when you <em>have to impress</em> colleagues&#8230; I&#8217;m sure you could do the same thing with Silverlight, but as far as I know, my Mac Mini does not really like Microsoft IDEs. In the second part, we&#8217;ll retrieve data from a <em>famous</em> API, in Ruby, and put them in an Amazon SQS queue. The last and third part will show you how to interact between Flex and Amazon SQS, the graph will be alive, to make you glad like hell.</p>
<p>You&#8217;ll need the <a href="http://www.adobe.com/cfusion/entitlement/index.cfm?e=flex3email" onclick="">Flex 3.0 SDK</a>. For Flex and Air fans out there, you can obviously use Flex Builder 3 Professional.</p>
<p>If you discover the Flex 3.0 SDK, take a look at the <a href="http://www.adobe.com/support/documentation/en/flex/" onclick="">Adobe Flex resources</a> website, a gold mine. If you fell lazy, for now, simply follow these <a href="http://www.adobe.com/support/documentation/en/flex/3/releasenotes_flex3_sdk.html#installation" onclick="">instructions</a> to install the Flex SDK.</p>
<p>It&#8217;s time to begin coding, simply create a .mxml file. It will contain all our Flex code.</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="font-weight: bold; color: black;">?&gt;</span></span> 
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mx:Application</span>
    <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span>
    <span style="color: #000066;">xmlns:adobe</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/fc&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/mx:Application<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p>You can compile and run it with the commands:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">mxmlc dynamicgraph.mxml
open dynamicgraph.swf</pre></div></div>

<p>See <a href="/assets/dg1.mxml" target="_blank">this code</a> in <small>(Please open the article to see the flash file or player.)</small>.</p>
<p>To generate graphs, I noticed two Flex components, <a href="http://code.google.com/p/flexvizgraphlib/" onclick="">flexvizgraphlib</a> and <a href="http://mark-shepherd.com/blog/springgraph-flex-component/" onclick="">SpringGraph</a>. <em>flexvizgraphlib</em> seems promising but misses one mandatory feature for this project: realtime node updates. <em>SpringGraph</em> is a bit old, but it&#8217;s well designed and answers our need, so let&#8217;s use it. Copy the SpringGraph.swc file to the &#8220;/frameworks/libs&#8221; folder of your Flex SDK installation, simple.</p>
<p>Let&#8217;s create a simple graph:</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="font-weight: bold; color: black;">?&gt;</span></span> 
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mx:Application</span>
      <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span>
      <span style="color: #000066;">xmlns:adobe</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/fc&quot;</span>
      <span style="color: #000066;">initialize</span>=<span style="color: #ff0000;">&quot;onLoad()&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;adobe:SpringGraph</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;springgraph&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> 
  	<span style="color: #000066;">backgroundColor</span>=<span style="color: #ff0000;">&quot;#869ca7&quot;</span> <span style="color: #000066;">repulsionFactor</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;adobe:itemRenderer<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mx:Component<span style="font-weight: bold; color: black;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mx:Label</span> <span style="color: #000066;">fontSize</span>=<span style="color: #ff0000;">&quot;14&quot;</span> <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;{data.id}&quot;</span> <span style="color: #000066;">color</span>=<span style="color: #ff0000;">&quot;#ffffff&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>					
       <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/mx:Component<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/adobe:itemRenderer<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/adobe:SpringGraph<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mx:Script<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #339933;">&lt;![CDATA[</span>
<span style="color: #339933;">      import com.adobe.flex.extras.controls.springgraph.Graph;</span>
<span style="color: #339933;">      import com.adobe.flex.extras.controls.springgraph.Item;</span>
&nbsp;
<span style="color: #339933;">      private var graph: Graph = new Graph();</span>
<span style="color: #339933;">      private var rootItem: Item;</span>
&nbsp;
<span style="color: #339933;">      private function onLoad(): void {</span>
<span style="color: #339933;">        addNode(&quot;R&quot;);</span>
<span style="color: #339933;">        addNode(&quot;1&quot;, &quot;R&quot;);</span>
<span style="color: #339933;">        addNode(&quot;1.1&quot;, &quot;1&quot;);</span>
<span style="color: #339933;">        addNode(&quot;1.2&quot;, &quot;1&quot;);</span>
<span style="color: #339933;">        addNode(&quot;1.3&quot;, &quot;1&quot;);</span>
<span style="color: #339933;">        addNode(&quot;2&quot;, &quot;R&quot;);</span>
<span style="color: #339933;">        addNode(&quot;2.1&quot;, &quot;2&quot;);</span>
<span style="color: #339933;">        addNode(&quot;2.2&quot;, &quot;2&quot;);</span>
<span style="color: #339933;">      }</span>
&nbsp;
<span style="color: #339933;">      private function addNode(id:String, linkedTo:String = null): void {</span>
<span style="color: #339933;">        var item: Item = new Item(id);</span>
<span style="color: #339933;">        graph.add(item);</span>
<span style="color: #339933;">        if(linkedTo)</span>
<span style="color: #339933;">          graph.link(graph.find(linkedTo), item);</span>
<span style="color: #339933;">        springgraph.dataProvider = graph;</span>
<span style="color: #339933;">      }</span>
<span style="color: #339933;">    ]]&gt;</span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/mx:Script<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/mx:Application<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p>See <a href="/assets/dg2.mxml" target="_blank">this code</a> in <small>(Please open the article to see the flash file or player.)</small>.</p>
<p>It seems to be a lot of code, but it&#8217;s dead simple. You&#8217;re smart, just read it and you&#8217;ll understand it.</p>
<p>So, we&#8217;ve just created an animated 8-nodes graph, and we can even drag nodes and pan the whole graph with the mouse. Remember, the objective of this <em>project</em> is to retrieve data from an Amazon SQS queue. We want this to be fluid, so we won&#8217;t update the graph more than x times per second. Let&#8217;s implement a Timer which will periodically add nodes to our graph.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">adobe</span>.<span style="color: #006600;">flex</span>.<span style="color: #006600;">extras</span>.<span style="color: #006600;">controls</span>.<span style="color: #006600;">springgraph</span>.<span style="color: #006600;">Graph</span>;
<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">adobe</span>.<span style="color: #006600;">flex</span>.<span style="color: #006600;">extras</span>.<span style="color: #006600;">controls</span>.<span style="color: #006600;">springgraph</span>.<span style="color: #006600;">Item</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">Timer</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">TimerEvent</span>;
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> graph: Graph = <span style="color: #000000; font-weight: bold;">new</span> Graph<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> rootItem: Item;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> timer: Timer = <span style="color: #000000; font-weight: bold;">new</span> Timer<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">300</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> itemCount: <span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>;
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">onLoad</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>: <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
  addNode<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;R&quot;</span><span style="color: #66cc66;">&#41;</span>
  timer.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;timer&quot;</span>, timerHandler<span style="color: #66cc66;">&#41;</span>;
  timer.<span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> timerHandler<span style="color: #66cc66;">&#40;</span>event:TimerEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
  addNode<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#40;</span>++itemCount<span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #ff0000;">&quot;R&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>itemCount == <span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span>
    timer.<span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> addNode<span style="color: #66cc66;">&#40;</span>id:<span style="color: #0066CC;">String</span>, linkedTo:<span style="color: #0066CC;">String</span> = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>: <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
   <span style="color: #66cc66;">&#40;</span>...<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>See <a href="/assets/dg3.mxml" target="_blank">this code</a> in <small>(Please open the article to see the flash file or player.)</small>.</p>
<p>This code creates 30 nodes, every 300 milliseconds. And to reward your hard work, you can still play with the nodes while the graph is updated. We can now put the finishing touches, special effects. Let&#8217;s blur new nodes and play a <em>funny</em> <a href="/assets/bloop.mp3">sound</a> as they appear.</p>
<p>Add this XML code after the &lt;adobe:SpringGraph/&gt; tag definition:</p>

<div class="wp_syntax"><div class="code"><pre class="xml">  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mx:Parallel</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;newItemEffect&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mx:SoundEffect</span> <span style="color: #000066;">source</span>=<span style="color: #ff0000;">&quot;@Embed(source='assets/bloop.mp3')&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mx:Blur</span> <span style="color: #000066;">duration</span>=<span style="color: #ff0000;">&quot;200&quot;</span> 
      <span style="color: #000066;">blurXFrom</span>=<span style="color: #ff0000;">&quot;10.0&quot;</span> <span style="color: #000066;">blurXTo</span>=<span style="color: #ff0000;">&quot;0.0&quot;</span> 
      <span style="color: #000066;">blurYFrom</span>=<span style="color: #ff0000;">&quot;10.0&quot;</span> <span style="color: #000066;">blurYTo</span>=<span style="color: #ff0000;">&quot;0.0&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/mx:Parallel<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p>You can then simply associate this effect to &#8220;new-node&#8221; events:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">onLoad</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>: <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
  addNode<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;R&quot;</span><span style="color: #66cc66;">&#41;</span>
  timer.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;timer&quot;</span>, timerHandler<span style="color: #66cc66;">&#41;</span>;
  timer.<span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  springgraph.<span style="color: #006600;">addItemEffect</span> = newItemEffect;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>See <a href="/assets/dg4.mxml" target="_blank">this code</a> in <small>(Please open the article to see the flash file or player.)</small>.</p>
<p>Of course, all credits go to <a href="http://mark-shepherd.com/blog/" onclick="">Mark Shepherd</a>, for providing this wonderful library and its source code.</p>
<p>If you want to know more about Flex, especially making a Rails app powered by a Flex UI, go buy <a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&#038;location=http%3A%2F%2Fwww.amazon.com%2FFlexible-Rails-Flex-2%2Fdp%2F1933988509%2F&#038;tag=12noobs-20&#038;linkCode=ur2&#038;camp=1789&#038;creative=9325" onclick="">Flexible Rails: Flex 3 on Rails 2</a><img src="http://www.assoc-amazon.com/e/ir?t=12noobs-20&amp;l=ur2&amp;o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> ! French readers, you can get it <a href="http://www.amazon.fr/gp/redirect.html?ie=UTF8&#038;location=http%3A%2F%2Fwww.amazon.fr%2FFlexible-Rails-Stuart-Eccles%2Fdp%2F1933988509&#038;tag=12noobs-21&#038;linkCode=ur2&#038;camp=1642&#038;creative=6746" onclick="">here</a><img src="http://www.assoc-amazon.fr/e/ir?t=12noobs-21&amp;l=ur2&amp;o=8" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />. I bought this book 2 years ago, when it still was a beta PDF. Peter Armstrong then found a paperback editor, and you&#8217;ll easily understand why if you read it.</p>
<p>Check back soon for the next part.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.12noobs.com/2008/04/18/dynamic-graph-visualization-in-flex-ruby-and-amazon-sqs-part-1-flex/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
