<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Flex, HTML5, and more]]></title>
  <link href="http://n-so.com/blog/atom.xml" rel="self"/>
  <link href="http://n-so.com/blog/"/>
  <updated>2012-02-08T20:42:44-07:00</updated>
  <id>http://n-so.com/blog/</id>
  <author>
    <name><![CDATA[Daniel Wanja]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Blogging...me? Cloud, mobile, and much more]]></title>
    <link href="http://n-so.com/blog/blog/2012/02/08/blogging-dot-dot-dot-me-cloud/"/>
    <updated>2012-02-08T20:18:00-07:00</updated>
    <id>http://n-so.com/blog/blog/2012/02/08/blogging-dot-dot-dot-me-cloud</id>
    <content type="html"><![CDATA[<p>Actually I did setup this whole website using Octopress because I want to blog more. The reality is that I&#8217;m currently working on many pretty awesome projects, a Rails project, an iPad project, a Flex project, and some consulting projects that when the evening comes&#8230;I code some more instead of blogging. But I&#8217;m learning so much cool stuff that I want to share. So here a few of the things I want to talk about:</p>

<p> <!--more--></p>

<p>1) <strong>iOS Apps with Flex Mobile</strong> -  I&#8217;m working on a presentation for a customer for which I will spend 50% time on my own and 50% on my customer time, but will be able to deliver it publicly. Flex mobile is pretty awesome. I&#8217;ll try to record a screencast of the presentation. iPhone, iPad&#8230;here I come. In fact on the 17th of April I&#8217;ll be giving a talk on <a href="http://ria5280.org/calendar/event/2012/4/19/299755">Building iPad apps with Flex 4.6</a>.</p>

<p>2) <strong>Rails 3.x&#8230;just rocks</strong>. I had a small project to create with Rails, and wow..It just flies. I bought a cool HTML template that works just great for a cool admin style Rails application. Note it&#8217;s not a public facing project.</p>

<p>3) <strong><a href="http://iAppDesigner.com">iAppDesigner.com</a></strong> (not up yet) - During the last <a href="http://5280ria.org">Denver RIA Developers Group</a> I had an epiphany of so many technological aspects coming to a cross road, that I had a vision on of great product. This is not the first time that this happens to me, but it&#8217;s the first time that I thought&#8230;wow, this might be actually be needed by many. It happened the same day Apple announced iBook Builder&#8230;the tool to build textbooks for the rested of us. Well, my vision was for a tool to build mobile, phone and tablet apps, for the rest of us. And I had the vision of the technical aspect to build that tool. In fact I even build a proof of concept that works. That&#8217;s the worse part, where in a couple of hour I can prove that I could build a tool in few hundreds of hours or more which would be great&#8230;Just I&#8217;m not sure where to take these few hundreds of hours from&#8230;.as usual&#8230;I keep too busy with day to day consulting activities. However this project will be the main driver for many of the forthcoming blog post as I like to think out loud in the form of blog entries while I code… wanna see what to expect? Then check out <a href="http://awsusageanalyzr.tumblr.com">AwsUsageAnalyzr</a>, it&#8217;s my notes for yet another project I didn&#8217;t release.</p>

<p>4) <strong>Education</strong> - I spoke on Monday with my good friend Solomon White, and he wants to focus more on education. This is definitively one aspect where I try to improve in. But education is not only the next great opportunity, but since I have kids, is really an area where I would love to be able to contribute. Learning is the essence of our society. I feel that there is a big disparity between where software craftsmanship is at it&#8217;s top today and whats teached at schools.</p>

<p>5) <strong>Reality!</strong> This blog entry may actually replace my beginning of year blog post about what I did and where I will go. I am a software coder, loving it, and will continue to do that professionally as long customer want me too and as long as I feel energized by it. There are so many different directions I could focus on: teaching, writing, managing, doing business but I still love coding. I can get up and code until I drop at night. That&#8217;s a gift I enjoy until I won&#8217;t :-)</p>

<p>6) <strong>Community</strong>. I love meeting people that have common interested. I attend several Denver user group, regional and national conferences. They are all awesome. I used to fly from Switzerland to the US to get training, now I can just drive 20 minutes to see awesome presenters and talks with awesome members of the community. All in all, if you are a geek, times are great. I have a few conference planned for the next few month and hope to meet many of you. So see you soon at <a href="http://mtnwestrubyconf.org/">MountainWest RubyConf 2012</a>, at the <a href="http://milehighagile2012.agiledenver.org/">Mile High Agile Conference</a>, at <a href="http://www.360flex.com/">360Flex</a> or at <a href="http://railsconf2012.com/">RailsConf 2012</a>.</p>

<p>7) <strong>Small</strong> also know as mobile. It&#8217;s amazing of much creative applications and services are build around mobile concept. These phones and tablets are getting more powerful, the tools to create apps more sophisticated. So expect some noise from me on that front.</p>

<p>8) <strong>Big</strong> also know as the cloud. Not the iCloud crap…but the Amazon cloud stuff that works. The DropBox cloud you can easily integrate in your apps. The dropbox api can use from you mobile and desktop app. The Heroku server you can start with one command line. The EC instance you ca boot up on a dime when you need. Pusher, DynamoDb…I tell you…Your solution is in fact getting smaller thanks to these cloud services.</p>

<p>So welcome to my new blog I hope you will find enough good content that you will come back from time to time.</p>

<p>Enjoy!
Daniel</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[67 Performance tips from Adobe]]></title>
    <link href="http://n-so.com/blog/blog/2011/12/15/67-performance-tips-from-adobe/"/>
    <updated>2011-12-15T18:51:00-07:00</updated>
    <id>http://n-so.com/blog/blog/2011/12/15/67-performance-tips-from-adobe</id>
    <content type="html"><![CDATA[<p>I just read  <a href="http://help.adobe.com/en_US/as3/mobile/flashplatform_optimizing_content.pdf">Optimizing Performance for the ADOBE FLASH PLATFORM</a> from Adobe.</p>

<p>This is a good read and contains many useful tips and descriptions of optimization you can apply to your application. This become really relevant when developing Flex mobile applications.</p>

<p>Here are the 67 tips highlighted in the document&#8230;</p>

<!-- more -->




<ol>
<li>1. Choose an appropriate display object.</li>
<li>2. Primitive types: Use the getSize() method to benchmark code and determine the most efficient object for the task.</li>
<li>3. Reuse objects, when possible, instead of recreating them.</li>
<li>4. Use object pooling, when possible.</li>
<li>5. Delete all references to objects to make sure that garbage collection is triggered.</li>
<li>6. Avoid filters, including filters processed through Pixel Bender.</li>
<li>7. Use mipmapping to scale large images, if needed consider creating 3D effects manually.</li>
<li>8. Use the Adobe® Flash® Text Engine for read-only text; use TextField objects for input text.</li>
<li>9. Consider using simple callbacks, instead of the event model.</li>
<li>10. Use the hasPriority HTML parameter to delay loading of offscreen SWF files.</li>
<li>11. Freeze and unfreeze objects properly by using the REMOVED_FROM_STAGE and ADDED_TO_STAGE events.</li>
<li>12. Use Event.ACTIVATE and Event.DEACTIVATE events to detect background inactivity and optimize your application appropriately.</li>
<li>13. Consider disabling mouse interactions, when possible.</li>
<li>14. Choose either timers or ENTER_FRAME events, depending on whether content is animated.</li>
<li>15. Minimize the number of Timer objects and registered enterFrame handlers in your application.</li>
<li>16. Stop Timer objects when not in use.</li>
<li>17. In enterFrame event or Timer handlers, minimize the number of changes to the appearance of display objects that cause the screen to be redrawn.</li>
<li>18. To save CPU power, limit the use of tweening, which saves CPU processing, memory, and battery life.</li>
<li>19. Use the Vector class instead of the Array class, when possible.</li>
<li>20. Use the drawing API for faster code execution.</li>
<li>21. Use event capture and bubbling to minimize event handlers.</li>
<li>22. Paint pixels using the setVector() method.</li>
<li>23. Use String class methods such as indexOf(), substr(), or substring() instead of regular expressions for basic string finding and extraction.</li>
<li>24. Use a non-capturing group (“(?:xxxx)”) instead of a group (“(xxxx)”) in a regular expression to group elements without isolating the contents of the group in the result.</li>
<li>25. Consider using an alternative regular expression pattern if a regular expression performs poorly.</li>
<li>26. For a TextField object, use the appendText() method instead of the += operator.</li>
<li>27. Update text fields outside loops, when possible.</li>
<li>28. Avoid using the square bracket operator, when possible.</li>
<li>29. Inline code, when possible, to reduce the number of function calls in your code.</li>
<li>30. Avoid evaluating statements in loops.</li>
<li>31. Use reverse order for while loops.</li>
<li>32. Always use the redraw regions option when building your project.</li>
<li>33. Avoid placing content off-stage. Instead, just place objects on the display list when needed.</li>
<li>34. Use the appropriate Stage quality setting to improve rendering.</li>
<li>35. Avoid using the alpha property, when possible.</li>
<li>36. In general, use the lowest possible frame rate for better performance.</li>
<li>37. Use a low frame rate when video is the only dynamic content in your application.</li>
<li>38. Dynamically change the frame rate of your application.</li>
<li>39. Use the bitmap caching feature for complex vector content, when appropriate.</li>
<li>40. Set the cacheAsBitmapMatrix property when using cached bitmaps in mobile AIR apps.</li>
<li>41. Use the BitmapData class to create custom bitmap caching behavior.</li>
<li>42. Isolate events such as the Event.ENTER_FRAME event in a single handler, when possible.</li>
<li>43. Use the bitmap caching feature and the opaqueBackground property to improve text rendering performance.</li>
<li>44. Favor using asynchronous versions of operations rather than synchronous ones, where available.</li>
<li>45. In AIR desktop applications, consider using an opaque rectangular application window instead of a transparent window.</li>
<li>46. Smooth shapes to improve rendering performance.</li>
<li>47. Divide your application into multiple SWF files.</li>
<li>48. Provide event handlers and error messages for IO errors.</li>
<li>49. Use Flash Remoting and AMF for optimized client-server data communication.</li>
<li>50. Cache assets locally after loading them, instead of loading them from the network each time they’re needed.</li>
<li>51. Don’t change a SQLStatement object’s text property after executing it. Instead, use one SQLStatement instance for each SQL statement and use statement parameters to provide different values.</li>
<li>52. Use database indexes to improve execution speed for data comparing and sorting.</li>
<li>53. Consider pre-compiling SQL statements during application idle times.</li>
<li>54. Group multiple SQL data change operations in a transaction.</li>
<li>55. Process large SELECT query results in parts using the SQLStatement class’s execute() method (with prefetch parameter) and next() method.</li>
<li>56. Consider using multiple asynchronous SQLConnection objects with a single database to execute multiple statements simultaneously.</li>
<li>57. Avoid database schema changes.</li>
<li>58. Use the SQLConnection.compact() method to optimize a database after schema changes.</li>
<li>59. Use a fully qualified table name (including database name) in your SQL statement.</li>
<li>60. Use explicit column names in SQL INSERT and SELECT statements.</li>
<li>61. Avoid joining the same table multiple times in a statement, unless you are comparing the table to itself.</li>
<li>62. Use JOIN (in the FROM clause) to include a table in a query instead of a subquery in the WHERE clause. This tip applies even if you only need a table’s data for filtering, not for the result set.</li>
<li>63. Avoid SQL statements that can’t take advantage of indexes. These statements include the use of aggregate functions in a subquery, a UNION statement in a subquery, or an ORDER BY clause with a UNION statement.</li>
<li>64. Consider avoiding the LIKE operator, especially with a leading wildcard character as in LIKE(&#8216;%XXXX%&#8217;).</li>
<li>65. Consider avoiding the IN operator. If the possible values are known beforehand, the IN operation can be written using AND or OR for faster execution.</li>
<li>66. Consider alternative forms of a SQL statement to improve performance.</li>
<li>67. Directly compare alternate SQL statements to determine which is faster.</li>
</ol>




<br/>


<p>
Enjoy!<br/>
Daniel
</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Adobe's Announcement on Flash: visually!]]></title>
    <link href="http://n-so.com/blog/blog/2011/11/21/adobes-announcement-on-flash-visually/"/>
    <updated>2011-11-21T15:52:00-07:00</updated>
    <id>http://n-so.com/blog/blog/2011/11/21/adobes-announcement-on-flash-visually</id>
    <content type="html"><![CDATA[<p>I&#8217;ve received so much feedback from many of my friends on Flex projects being cancelled or scheduled to be rewritten in another technology than Flex. Great Job Adobe, you did it!</p>


<p>So what was really announced last week is the following:<br /> 

 <!--more-->

<img src="http://www.onrails.org/files/FlasAnnouncement.png" alt="" /></p>


<p>Yes, Adobe will stop development on  the Flash Player in the Browser.<br /> Flash Player on the mobile will continue.<br /> Adobe AIR will continue, on the desktop and mobile.<br /> Captive runtime of AIR allows to create &#8220;native&#8221; apps on mobile and tablets (Android, iOS and more) and desktop WIndows and OSX apps that don&#8217;t need AIR to be distributed. Yep, that continues too.</p>


<p>Of course Adobe tried to clarify their statements after the fact saying the transition to HTML5 will take 3 to 5 years.&nbsp;The following is from Adobe&#8217;s website from Andrew Shorten &amp; Deepa Subramaniam, see: <a href="http://blogs.adobe.com/flex/2011/11/your-questions-about-flex.html">http://blogs.adobe.com/flex/2011/11/your-questions-about-flex.html</a></p>


<p><strong>You said that you believe HTML is the &ldquo;long-term solution for enterprise applications&rdquo; &ndash; can you clarify this statement?</strong></p>


<p>HTML5 related technologies (comprising HTML, JavaScript and CSS) are becoming increasingly capable, such that we have every reason to believe that advances in expressiveness (e.g. Canvas), performance (e.g. VM and GPU acceleration in many browsers) and application-related capabilities (e.g. offline storage, web workers) will continue at a rapid pace. In time (and depending upon your application,<strong><span style="color: #ff0000;"> it could be 3-5 years from now</span></strong>), we believe HTML5 could support the majority of use cases where Flex is used today.</p>


<p>However, Flex has now, and for many years will continue to have, advantages over HTML5 for enterprise application development &ndash; in particular:</p>


<ul><li>Flex offers complete feature-level consistency across multiple platforms</li><li>The Flex component set and programming model makes it extremely productive when building complex application user interfaces</li><li>ActionScript is a mature language, suitable for large application development</li><li>Supporting tools (both Adobe&rsquo;s and third-party) offer a productive environment with respect to code editing, debugging and profiling</li></ul>


<p>&nbsp;</p>


<p>I guess Adobe&#8217;s communication just accelerated that 3 to 5 year timeframe by quite a bit.</p>


<p>Enjoy!</p>


<p>Daniel</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[The Future of Flex.]]></title>
    <link href="http://n-so.com/blog/blog/2011/11/15/the-future-of-flex/"/>
    <updated>2011-11-15T16:06:00-07:00</updated>
    <id>http://n-so.com/blog/blog/2011/11/15/the-future-of-flex</id>
    <content type="html"><![CDATA[<p>At first I thought &#8220;Wow, Adobe really  messed up their communication&#8221;. They could have focused on what they are adding, strong support for HTML5 and CSS4, Adobe AIR for Mobile, and not on what they are removing, the Flash Player in the Browser. But then they also announced that they opened sourced Flex via the Apache Foundation. And the main stream media, the blogosphere, and many developers I know went crazy and said Flex is dead, it&#8217;s over, time to convert all your projects to HTML5.</p>

<p> <!--more--></p>

<p>At a second thought I think it&#8217;s pretty smart what Adobe did. The saying goes &#8220;If you can&#8217;t beat them, join them&#8221;. In fact the Flex against HTML fight wasn&#8217;t one where Adobe had anything to win from. So they just made it loud and clear and now they are saying &#8220;We are HTML5&#8221;. In fact detaching themselves from Flex in appearance allows them to ride the new HTML5 technowave and get in the news when they upgrade their tool, bring out new HTML5 component framework or acquire hot companies like PhoneGap and TypeKit. We are HTML5!!</p>

<p>Adobe has already two great tools for HTML5, Muse and Edge and needs to push them way further and also needs to create or acquire a great HTML component framework such as Sencha so they call build and sell new development tools as well as design tools for the new growing crowd of HTML5 developers.</p>

<p>So where does that leave Flash and Flex. I use a lot Flex in the enterprise, and that&#8217;s where Adobe just did the most damage in my eyes. Go now try to convince any CTO that Flex is a good idea. Flex is a mature framework and Adobe has a great enterprise offering, but it will be hard to convince anyone that Adobe is still behind that technology after the way they managed their communication. This said I think the move of Flex to the Apache open source foundation is a great one and if managed right will give Flex a good run for years to come. Flex is still a great choice for many enterprise projects and will remain so until a solid and widely adopted HTML component framework emerges. If Adobe is smart they could provide that offering.</p>

<p>Flex is also a great environment to develop &#8220;native&#8221; mobile applications that can run on iOS and Android. The forthcoming Flex SDK 4.6 will show that potential and it&#8217;s a great way to create cross platform mobile and tablet applications. Adobe will not kill Adobe AIR for the mobile as it&#8217;s a too appealing growth market. But that message didn&#8217;t get through to the main stream media.</p>

<p>As Adobe said Flash for the desktop for games and Adobe AIR for  mobile will be here for a while. But Adobe has the most to gain if they become the major player in the HTML5 field by providing tools, framework and making the web standards evolve. And they are in a good position to get there. To achieve this goal it also means that they will refocus many of their development teams and this will impact Flash and Flex. Moving the Flex SDK and some of the key developers to the Apache Foundation will allow to continue to evolve the SDK regardless of Adobe&#8217;s new focus. The move a few years ago to the Flex Sparks components and the recent addition of the new mobile components provide a great and mature framework basis for a real open source effort which I believe will have a long life even if it will become a niche environment over the long run. Note I consider Ruby on Rails a niche market, a really great one to be in. Adobe has something great with Adobe AIR for mobile and this is the one area where they could even grow their developers basis if they get their message right. For me AIR for mobile/tablets and the Flex SDK 4.6 is one solution where I can build mobile apps faster than in any other environment and this will be a great business to be in, especially for the enterprise market.</p>

<p>The smart enterprises will realize that Flex is stable and here to stay for the long run, even if it&#8217;s not in the spotlight. They will start HTML projects in parallel to gradually improve their developer workforce and experience in this area. They will also realize that the HTML5 frameworks and coding technics are evolving so rapidly that it will be time consuming just to keep up. Also these frameworks are not as mature and complete as in the Flex ecosystem. Finding Flex developers is difficult, but finding great HTML/Javascript developers is even harder. This said, there is no denying that pretty quickly the HTML5 tools and frameworks will catchup with what Flex offers today in ease of development for enterprise applications.</p>

<p>Personally I&#8217;m looking forward to see how these HTML5/Javascript tools/libraries will evolve and will play with many of them.</p>

<p>So where does all this leaves you, the developer. Well, it&#8217;s for sure time to jump on the new HTML/Javascript bandwagon if you haven&#8217;t yet. I cannot see many companies starting new enterprise projects with Flex. If you are into mobile or tablet development give the new Flex SDK 4.6 a try, I believe there is a great potential for Flex to become a major player in the mobile development arena&#8230;targeting &#8220;native&#8221; applications and not the browser.  Yep, your heard it here first ;-)</p>

<p>Enjoy,
Daniel</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Writing tests is not fun. Anyone who tells you otherwise is a liar....]]></title>
    <link href="http://n-so.com/blog/blog/2011/08/30/writing-tests-is-not-fun-anyone-who-tells-you-otherwise-is-a-liar/"/>
    <updated>2011-08-30T20:03:00-06:00</updated>
    <id>http://n-so.com/blog/blog/2011/08/30/writing-tests-is-not-fun-anyone-who-tells-you-otherwise-is-a-liar</id>
    <content type="html"><![CDATA[<p>At least so says my good friend Sean Voisen in his latest blog entry <a href="http://sean.voisen.org/blog/2011/08/thoughts-on-test-driven-development">Thoughts on test-driven development</a>.</p>

<p>What, you are calling me a liar? :-) I must respectfully disagree with Sean. Not on the fact that he may think it&#8217;s not fun, that&#8217;s his opinion like many other Flex developers that don&#8217;t do testing. I disagree because I see many developers, in other communities, that actually really enjoy testing. If you look at the Ruby community you will see many developpers enjoying doing test driven development, enjoying writing tests, and even expanding the way you can write tests. Check out rspec, Cucumber, and the many of books and screencast on the subject. Checkout all the ruby libraries, they are all pretty well tested. There are many training classes on people that really want to improve doing testing. Many Rails projects are extremly well tested. Many Ruby developers cannot even code without writing tests first.</p>

<p> <!--more--></p>

<p>This said as they are many examples on how to test Ruby and Rails code it&#8217;s easier to get going on with testing in that environment. On the other hand, there are not many example of tested Flex applications and libraries. Not many toturoials on how to test your Flex application.
I happend to do a lot of unit testing for my Flex apps, but I do not test everything, I use tests for more difficult aspects, when I&#8217;m not sure how to design something, when it&#8217;s slow to access a part of the application just to verify that my new code works. Then I write tests and it&#8217;s fun. How many times do you manually repeat a sequence on the UI like start the application, perform a search, click on the grid, open a record, click the calculate button&#8230;Oh no, that not right&#8230;go change some code and do it again. Well that&#8217;s not fun. Every developer I know does that thousands a time a day. Well, write a test and your workflow becomes more fun.</p>

<p>So why are Flex developers not testing? As I mentioned above, there is not much peer pressure to do so as not many Flex developers do testing. Also they are not many examples. In addition it&#8217;s not obvious how to test applications in many case. Often they are not written in a testable manner. Flex/ActionScript is asynchronous and event driven, that&#8217;s harder too.</p>

<p>They are solutions for that and Flex applications are very well suited to testing&#8230;but the sweet spot must be found. And you should start by testing the simple things that have lots of added value. Anywhere you have logic in your code that does filtering, calculation, transform data, write a test&#8230;You gonna like it. FlexUnit 4 as great support for asynchronous or event driven programming, but I agree, at first it&#8217;s not obvious how to best us that support. So again, start with the simple thing, refactor your code so that you can test it in a non-asynchronous way, that will already be helpfull.</p>

<p>So I came to the conclusion that I won&#8217;t be able to convince Flex developers that testing is needed and even fun. I can only hope that as a Flex developer you will start using FlexUnit 4 and try to add tests to your application and persevere and find the sweet spot on where testing is fun and makes you more productive. If you persevere you will like many Ruby developers become a better developer, write better code and faster.</p>

<p>I finally like Sean&#8217;s balanced view on test driven development: &#8220;But would I use TDD for every project I work on? Probably not. For personal â€œone-offâ€ projects or projects I know will not see much future maintenance, the slower development time is simply not worth it. For serious, long-term projects however, TDD is now a must.&#8221;</p>

<p>Testing remains hard, but it&#8217;s just essential if you want to become a great, agile, developer.</p>

<p>Persevere and testing will become your friend!</p>

<p>Enjoy!
Daniel</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Redis-Flex: An ActionScript Library to integrate with Redis]]></title>
    <link href="http://n-so.com/blog/blog/2011/06/13/redis-flex-an-actionscript-library-to-integrate-with-redis/"/>
    <updated>2011-06-13T20:40:00-06:00</updated>
    <id>http://n-so.com/blog/blog/2011/06/13/redis-flex-an-actionscript-library-to-integrate-with-redis</id>
    <content type="html"><![CDATA[<p>Announcing <a href="https://github.com/danielwanja/redis_flex">redis flex</a>  An ActionScript Library to integrate with Redis.</p>

<p>A while back I looked into accessing Redis directly from Flex and I found an existing library, <a href="https://github.com/claus/as3redis">as3redis</a> that however didn&#8217;t support the new unified request protocol.  So I wrote a minimalist wrapper that now allows to send commands to a redis server.</p>

<p>To access the Redis server from Flex just instantiate a Redis instance:</p>

<p> <!--more--></p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='xml'><span class='line'><span class="nt">&lt;redis:Redis</span> <span class="na">id=</span><span class="s">&quot;server&quot;</span>
</span><span class='line'>             <span class="na">connected=</span><span class="s">&quot;server_connectedHandler(event)&quot;</span>
</span><span class='line'>             <span class="na">result=</span><span class="s">&quot;server_resultHandler(event)&quot;</span> <span class="nt">/&gt;</span>
</span></code></pre></td></tr></table></div></figure>


<p>Then you can send commands:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="nx">server</span><span class="p">.</span><span class="nx">send</span><span class="p">(</span><span class="s2">&quot;SET A 123&quot;</span><span class="p">);</span>
</span><span class='line'><span class="nx">server</span><span class="p">.</span><span class="nx">send</span><span class="p">(</span><span class="s2">&quot;GET A&quot;</span><span class="p">);</span>
</span><span class='line'><span class="nx">server</span><span class="p">.</span><span class="nx">send</span><span class="p">([</span><span class="s2">&quot;rpush&quot;</span><span class="p">,</span> <span class="s2">&quot;messages&quot;</span><span class="p">,</span> <span class="s2">&quot;message one&quot;</span><span class="p">]);</span>
</span></code></pre></td></tr></table></div></figure>


<p>Note it&#8217;s not a good idea to connect a Flex application directly to Redis. Redis is usually used in the context of an application server that protects it&#8217;s access in the same way that Flex doesn&#8217;t connect directly to a database. However they may be cases that this could be useful.</p>

<p>Enjoy!</p>

<p>Daniel</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Building Rails Apps for Rich Client - Using the bulk_api from Flex.]]></title>
    <link href="http://n-so.com/blog/blog/2011/05/27/building-rails-apps-for-rich-client-using-the-bulk-api-from-flex/"/>
    <updated>2011-05-27T04:04:00-06:00</updated>
    <id>http://n-so.com/blog/blog/2011/05/27/building-rails-apps-for-rich-client-using-the-bulk-api-from-flex</id>
    <content type="html"><![CDATA[<p>In this screencast we are going to show how to build a Rails app in a couple of minutes that is optimized for Rich Client. The application is a todo application build in Flex connecting using the <a href="https://github.com/drogus/bulk_api">bulk_api</a> to the Rails server using my new <a href="https://github.com/danielwanja/bulk_data_source_flex">bulk data source Flex framework</a>.</p>

<p> <!--more--></p>

<iframe src="http://player.vimeo.com/video/24299809" width="400" height="300" frameborder="0"></iframe>


<p>Enjoy!</p>

<p>Daniel</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[HTML5 Tutorial - RailsConf 2011, Day 1]]></title>
    <link href="http://n-so.com/blog/blog/2011/05/16/html5-tutorial-railsconf-2011-day-1/"/>
    <updated>2011-05-16T19:37:00-06:00</updated>
    <id>http://n-so.com/blog/blog/2011/05/16/html5-tutorial-railsconf-2011-day-1</id>
    <content type="html"><![CDATA[<p>I started RailsConf with the &#8220;Building Web Apps with HTML5: Beyond the Buzzword&#8221; by Mike Subelsky (<a href="https://twitter.com/#!/subelsky">@subelsky</a>).<br/></p>

<p>He prepared twelve html5 exercises that walked the about 250 attendees through various features of html5 over a 2.5 hour session. It&#8217;s fun to have time to work on these features. The high point was having about 200 computers using Websockets to send data back and forth with his server. He created a small ruby program that used EventMachine::WebSocket and it was holding up quite well all these connections.<br/></p>

<p>Here are the notes I took during this tutorial</p>

<p> <!--more--></p>

<p>You can download his tutorial and all files from https://github.com/subelsky/html5tutorial. Look at the tutorial.html file for instructions.<br/></p>

<p>Here are a few highlights of his talk:<br/></p>

<h4>1 - Feature Detection</h4>


<p>By using the <a href="http://www.modernizr.com/">Modernizr</a>  library, we used modernizr-1.7.js, you can detect difference html5 of your browser. <br/></p>

<p>For example:<br/></p>

<ul>
<li>Modernizr.canvas</li>
<li>Modernizr.websockets</li>
</ul>




<h4>2 - Basic Canvas Drawing</h4>


<p>You can get a 2d context and draw on the canvas via that context. You can use <i>fillRect</i> and other primitives like <i>moveTo</i> and <i>lineTo</i> to draw.<br/></p>

<pre>
    var canvas = document.getElementById("main");
    var context = canvas.getContext("2d");
    context.fillRect(0,0,20,20);
</pre>


<br/>


<p><canvas id="canvas_ex2_1" width="450" height="40"></canvas></p>

<script>
var canvas = document.getElementById("canvas_ex2_1");
var context = canvas.getContext("2d");
context.fillStyle = "red";
context.fillRect(0,0,20,20);
</script>




<p>Here I just created a loop to generate 180 rectangles. Note they are clipped due to the width of the canvas.</p>




<p/>

<canvas id="canvas_ex2_2" width="450" height="40"></canvas>

<script>
     var canvas = document.getElementById("canvas_ex2_2");
     var context = canvas.getContext("2d");
     for (var i=0;i<180;i++) {
        context.fillStyle = i % 2 == 0 ? "red" : "blue";
        var w = 5
        context.fillRect(i*w+1,0,w-1,19);
     }
</script>

<h4>3 - Canvas Image Manipulation</h4>

<pre>
    var img = new Image();
    img.src = "http://www.flickr.com/photos/50183640@N05/5616041841/";
    img.onload = function() {
    context.drawImage(img,0,110);
    };
</pre>
<br/>

<canvas id="canvas_ex3" width="200" height="150"></canvas>

<script>
    var canvas = document.getElementById("canvas_ex3");
    var context = canvas.getContext("2d");
    var img = new Image();
    img.src = "http://onrails.org/files/20110516_water.jpg";
    img.onload = function() {
        context.drawImage(img,0,0);
    };  
</script>
<br/>

<h4>4 - Basic Animation</h4>

In this exercise we first load a new image then trap the keystroke and call the up method. Note we use jquery:<br/>

<pre>
    var characters = new Image();
    characters.src = "http://onrails.org/files/20110516_characters.gif";

    characters.onload = function() {
      $(window).keyup(move);
    };
</pre>

In the move the x+y coordinates are updated accordingly and is cleared and redrawn.<br/>

<pre>
      context.clearRect(0,0,width,height);
      context.drawImage(characters,33,0,32,32,x,y,32,32);   
</pre>

Use the left and right arrow keys<br/>
<p>
<canvas id="canvas_ex4" width="450" height="150"></canvas>
<script src="http://onrails.org/files/jquery-1.5.2.js" ></script>
<script>
function Exercise4() {}

Exercise4.prototype.run = function() {
    var canvas = document.getElementById("canvas_ex4");
    var context = canvas.getContext("2d");
    var characters = new Image();
    characters.src = "http://onrails.org/files/20110516_characters.gif";

    characters.onload = function() {
      $(window).keyup(move);
    };

    var x, y;
    x = y = 0;
    
    var height = $(canvas).height();
    var width = $(canvas).width();

    function move(event) {
      switch (event.which) {
        case 38:
          if (y > 0) { y -= 10; }
          break;
        case 40:
          if (y < height) { y += 10; }
          break;
        case 37:
          if (x > 0) { x -= 10; }
          break;
        case 39:
          if (x < width) { x += 10; }
          break;
        default:
          break;
      }

      context.clearRect(0,0,width,height);
      context.drawImage(characters,33,0,32,32,x,y,32,32);
    }
}
var ex4 = new Exercise4();
ex4.run();
</script>


<h4>5 - Fun With Forms</h4>

In this exercise we look at few attributes of the <i>input</i> tag like the <i>placeholder</i> and <i>autofocus</i> attributes.
<pre>
    &lt;input id=&quot;username&quot; placeholder=&quot;Your name&quot; autofocus&gt;
    &lt;input id=&quot;fn&quot; placeholder=&quot;First name&quot;&gt;
</pre>

Use the slider below to scale the image:<br/>
<table border="0">
    <tr>
        <td>
            <input id="username" placeholder="Your name"><br/>
            <input id="fn" placeholder="First name"><br/>
            <input id="ls" placeholder="Last name"><br/>
            <input id="ad" placeholder="Address" ><br/>
            <input id="size" type="range" min="4" max="320" step="8" value="60">
        </td>
        <td>
            <canvas id="canvas_ex5" width="250" height="250"></canvas>
        </td>
    </tr>   
</table>
<br/>

We listen to the change event of the size input and call the draw() function. Note the last two of the drawImage below is the new width and height which will give us the scaling effect.<br/>

<pre>
    &lt;input id=&quot;size&quot; type=&quot;range&quot; min=&quot;4&quot; max=&quot;320&quot; step=&quot;8&quot; value=&quot;60&quot;&gt;
</pre>

<pre>
    function draw() {
      context.clearRect(0,0,width,height);
      context.drawImage(characters,33,0,32,32,0,0,sizeAmt,sizeAmt);
    }   
</pre>  
<script>
function Exercise5() {}

Exercise5.prototype.run = function() {
    var canvas = document.getElementById("canvas_ex5");
    var context = canvas.getContext("2d");

    var characters = new Image();
    characters.src = "http://onrails.org/files/20110516_characters.gif";

    var x, y;
    x = y = 0;
    var sizeAmt = 60;

    var height = $(canvas).height();
    var width = $(canvas).width();

    var sizeEl = $('#size');
    sizeEl.change(function() { 
      sizeAmt = Number(sizeEl.val());
      $('#ad').val(sizeEl.val())
      draw5();
    });

    function draw5() {
      context.clearRect(0,0,width,height);
      context.drawImage(characters,33,0,32,32,0,0,sizeAmt,sizeAmt);
    }
    draw5();
}

var ex5 = new Exercise5();
ex5.run();
</script>

<h4>6 - Local Storage</h4>

If you are in Google Chrome press option-command-j to bring up the javascript console. The you can enter key-values pair associated with the page. It&#8217;s like a client side cookie.<br/>

<pre>
    localStorage.setItem('shaz','bot')
    localStorage.getItem('shaz')
    localStorage.length // return 1
    localStorage.clear()
</pre>

<h4>7 - Canvas Cleanup</h4>

The canvas itself can be styled like any element. Here we set a black background:
<p>
<canvas id="canvas_ex4" class="dark-canvas" width="450" height="50"></canvas>
<pre>
  canvas { 
    background-color: black;
  }

  input { display: block; } 
</pre>  

<style>
  .dark-canvas { 
    background-color: black;
  }

  canvas { 
    background-color: #ccc;
  }

  input { display: block; }
</style>

<h4>8 - Web Sockets</h4>

That was the fun part of the presentation, mike created the a small <a href="https://github.com/subelsky/html5tutorial/blob/master/server/server.rb">ruby application</a> and had over 200 clients connecting to it. <br/>

Here is an extract of the ruby program:<br/>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="k">class</span> <span class="nc">TutorialServer</span>
</span><span class='line'>  <span class="k">def</span> <span class="nf">run</span>
</span><span class='line'>    <span class="no">EventMachine</span><span class="o">.</span><span class="n">run</span> <span class="k">do</span>
</span><span class='line'>      <span class="no">EventMachine</span><span class="o">::</span><span class="no">WebSocket</span><span class="o">.</span><span class="n">start</span><span class="p">(</span><span class="ss">:host</span> <span class="o">=&gt;</span> <span class="vi">@host</span><span class="p">,</span> <span class="ss">:port</span> <span class="o">=&gt;</span> <span class="vi">@port</span><span class="p">)</span> <span class="k">do</span> <span class="o">|</span><span class="n">socket</span><span class="o">|</span>
</span><span class='line'>        <span class="n">socket</span><span class="o">.</span><span class="n">onmessage</span> <span class="k">do</span> <span class="o">|</span><span class="n">msg</span><span class="o">|</span>
</span><span class='line'>          <span class="vi">@logger</span><span class="o">.</span><span class="n">info</span> <span class="s2">&quot;received: </span><span class="si">#{</span><span class="n">msg</span><span class="si">}</span><span class="s2">&quot;</span>
</span><span class='line'>          <span class="n">broadcast</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
</span><span class='line'>        <span class="k">end</span>
</span><span class='line'>      <span class="k">end</span>
</span><span class='line'>      <span class="no">EventMachine</span><span class="o">::</span><span class="n">add_periodic_timer</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span> <span class="p">{</span> <span class="n">broadcast</span><span class="p">(</span><span class="no">JSON</span><span class="o">.</span><span class="n">generate</span><span class="p">({</span> <span class="ss">:type</span> <span class="o">=&gt;</span> <span class="s2">&quot;ping&quot;</span> <span class="p">}))</span> <span class="p">}</span>
</span><span class='line'>    <span class="k">end</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'>
</span><span class='line'>  <span class="k">def</span> <span class="nf">broadcast</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
</span><span class='line'>    <span class="vi">@sockets</span><span class="o">.</span><span class="n">keys</span><span class="o">.</span><span class="n">each</span> <span class="p">{</span> <span class="o">|</span><span class="n">socket</span><span class="o">|</span> <span class="n">socket</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span> <span class="p">}</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'><span class="no">TutorialServer</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="s1">&#39;0.0.0.0&#39;</span><span class="p">,</span><span class="mi">8011</span><span class="p">)</span><span class="o">.</span><span class="n">run</span>
</span></code></pre></td></tr></table></div></figure>

Then when the users moved the character image using the keyboard each keystroke was sent to his server.<br/>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="c1">// create the socket  </span>
</span><span class='line'><span class="kd">var</span> <span class="nx">ws</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">WebSocket</span><span class="p">(</span><span class="s2">&quot;ws://exp.subelsky.com:8011&quot;</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// sent to position+name to server</span>
</span><span class='line'><span class="nx">ws</span><span class="p">.</span><span class="nx">send</span><span class="p">(</span><span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">({</span> <span class="nx">name</span><span class="o">:</span> <span class="nx">name</span><span class="p">,</span> <span class="nx">x</span><span class="o">:</span> <span class="nx">x</span><span class="p">,</span> <span class="nx">y</span><span class="o">:</span> <span class="nx">y</span><span class="p">,</span> <span class="nx">type</span><span class="o">:</span> <span class="s2">&quot;move&quot;</span> <span class="p">}));</span>
</span></code></pre></td></tr></table></div></figure>

Ultimately he wanted to drive multiple clients from his server&#8230;but we ran out of time to dive into this. <br/>

<h4>And much more..</h4>
Mike covered additionally these topics: Embedded Media, Geolocation, Web Workers,  Offline App<br/><br/>

Well that was a couple of hours well spent! Go check out his material on github.<br/>

Enjoy!<br/>

Daniel Wanja

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[T3 Metadata Editor - A cool Flex App]]></title>
    <link href="http://n-so.com/blog/blog/2011/04/09/t3-metadata-editor-a-cool-flex-app/"/>
    <updated>2011-04-09T18:33:00-06:00</updated>
    <id>http://n-so.com/blog/blog/2011/04/09/t3-metadata-editor-a-cool-flex-app</id>
    <content type="html"><![CDATA[<div style="text-align: center;"><img src="http://www.onrails.org/files/T3ME_ss.png" alt="" width="386" height="458" /></div>


<p>A lot of my work is for enterprises for software that is hidden behind closed doors but since I started helping out Thought Equity I have a few visible apps under my belt. Just in time for March madness they released a new version of the http://vault.ncca.com, see my last year&#8217;s entry on <a href="http://n-so.com/blog/blog/2010/03/05/vault-dot-ncaa-dot-com-under-the-hood-of-a-cool-flex-project">&#8220;under the hood of a cool flex project.&#8221;</a></p>


<p>And to capture all that meta data regarding games and movies they created a whole server side infrastructure but they also needed a pretty face for all that power and I got lucky to be one of the main coder on the T3 Metadata Editor.</p>


<p>It&#8217;s fun to work on software that ends up in the press, here are a few extracts found on the web:</p>




<!-- more -->




<p><a href="http://www.msnbc.msn.com/id/42355987">http://www.msnbc.msn.com/id/42355987</a></p>


<p>Sony Pictures is utilizing the T3 Metadata Editor to:<br /> &bull; Search by actor, line of dialogue, location, and a range of other parameters so that they can create interactive features that enable fans to search for words within the script and share their favorite moments<br /> &bull;  Manage restrictions around product placements, talent clearances, and music in order to dynamically create trailers, clips, and other edits for online promotion, social linking, and targeted ads</p>


<p>From <a href="http://videonuze.com/blogs/?2011-04-08/Sony-Pictures-Taps-Value-of-Archive-With-Thought-Equity-s-Metadata-Editor/&amp;id=3025">http://videonuze.com/blogs/?2011-04-08/Sony-Pictures-Taps-Value-of-Archive-With-Thought-Equity-s-Metadata-Editor/&amp;id=3025</a></p>


<p>As Dan Weiner, VP of Marketing and Products at Thought Equity explained, Sony will turn what has been a non-scalable, highly manual process for understanding a film&#8217;s music clearances, product placements and talent clearances, among other things, into a technology-driven process. Ellen Goodridge, VP, Global Digital Strategy and Operations at Sony Pictures said frame-level metadata will let it create innovative digital movie extras like search and music playlists that add to the value and relevance of our digital offerings and make digital movie purchases more collectable for consumers. The deal again shows that in the digital age metadata is the coin of the realm.</p>


<p>You can find out more on the <a href="http://platform.thoughtequity.com/video/home/metadata_services.do">products home&#8217;s page</a> :</p>


<p>A Flex App? Yea, Flex is really cool and allowed us to create a nice visualization of the meta data. For this end I created a custom component that allows to show thousands of entries and annotations visually.  The new version in the works support hierarchies and drag and drop editing. As a framework when <a href="http://theaboutbox.com">Cameron</a>&nbsp;started the project he used the Parsley framework as one of the component was developed in pure Actionscript and we thought that Parsley could simplify integration. I still prefer Swiz, but Parsley is working out for this project.</p>


<p>Thanks again to the awesome team at Thought Equity, this is a fun project!</p>


<p>Enjoy!</p>


<p>Daniel Wanja.</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[iPhone App: Mi-Fi 1.2 now with iOS 4.x support. A must have if you have an Mifi card.]]></title>
    <link href="http://n-so.com/blog/blog/2010/10/13/iphone-app-mi-fi-1-dot-2-now-with-ios-4-dot-x-support-a-must-have-if-you-have-an-mifi-card/"/>
    <updated>2010-10-13T00:28:00-06:00</updated>
    <id>http://n-so.com/blog/blog/2010/10/13/iphone-app-mi-fi-1-dot-2-now-with-ios-4-dot-x-support-a-must-have-if-you-have-an-mifi-card</id>
    <content type="html"><![CDATA[<div style="float:left; padding: 15px;">
<img src="http://www.onrails.org/files/mifi12.jpg" alt="mifi12.jpg" border="0" height="250" align="left" />
<a href="http://itunes.apple.com/app/mi-fi/id333601535?mt=8">
<img src="http://www.onrails.org/files/marketing_badge.png" alt="marketing_badge.png" border="0" width="121" height="61" align="left" />
</a>
</div>


<p>I created the MiFi app during the 360iDev conference on September 29th 2009 and submitted the app the same day. I released a fix a month later and didn&#8217;t touch the application since. I wasn&#8217;t using my Mifi card much until recently when I realized that the app wasn&#8217;t working on iOS 4.1. Then I checked the comments for the Mi-Fi app on the AppStore and realized that there where hundreds of comments of people that have the same issue. Sorry for being so late to realize that. Once I found that out I had to decide wether to remove the application from the store or fix it. So I reopened the project and realized that the way it was written wouldn&#8217;t work in the new Titanium SDK. Despite of the work I decided to rewrite/reorganized the code and voilaâ€¦Mi-Fi 1.2 for iOS 4.1 should now work better than ever. I did not restyle the application, it could look better but it&#8217;s still functional. I also  didn&#8217;t add any feature but at least you should get the battery and reception levels that are the most important features. Another feature I should add soon is to be able to set the ip address of your Mi-Fi card in case you changed from the default address.</p>

<!-- more -->


<p>What is stranger to me is how many people downloaded the application, knowing that it didn&#8217;t work on iOS4. About 400 downloads a weekâ€¦man.. many people must be wondering what this application does and in fact did, as the reviews show. Well, that should be fixed. Sorry for the delay!  Here is the weekly sales trend:</p>

<br/>


<div style="text-align:center;"><img src="http://www.onrails.org/files/20101012MiFiWeeklySales.png" alt="20101012MiFiWeeklySales.png" border="0" width="450" /></div>


<p>I also saw someone created  a $2.99 version of the same app called MyMiFi it does the same thing but it has a nicer design I would say. Maybe I should give &#8220;paid&#8221; a try and will release this one for $.99 centsâ€¦.or should I? The fact is that I really don&#8217;t care about selling 10 apps or even 100 apps at $.99â€¦I maybe wouldn&#8217;t say the say if I sold 1000â€¦So free it stays.</p>

<p>Now internally I had to rewrite the application as somehow the Titanium SDK changed enough that I couldn&#8217;t get it to work. So the new code is also a lot cleaner, so maybe I could add a few features soon:</p>

<p>In short this is the app.js</p>

<figure class='code'><figcaption><span>app.js</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="nx">Titanium</span><span class="p">.</span><span class="nx">include</span><span class="p">(</span><span class="s1">&#39;resource.js&#39;</span><span class="p">);</span>
</span><span class='line'><span class="nx">Titanium</span><span class="p">.</span><span class="nx">include</span><span class="p">(</span><span class="s1">&#39;parser.js&#39;</span><span class="p">);</span>
</span><span class='line'><span class="nx">Titanium</span><span class="p">.</span><span class="nx">include</span><span class="p">(</span><span class="s1">&#39;controller.js&#39;</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'><span class="kd">var</span> <span class="nx">controller</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Controller</span><span class="p">();</span>
</span><span class='line'><span class="nx">controller</span><span class="p">.</span><span class="nx">start</span><span class="p">();</span>
</span><span class='line'>
</span><span class='line'><span class="kd">var</span> <span class="nx">webview</span> <span class="o">=</span> <span class="nx">Titanium</span><span class="p">.</span><span class="nx">UI</span><span class="p">.</span><span class="nx">createWebView</span><span class="p">({</span><span class="nx">url</span><span class="o">:</span><span class="s1">&#39;index.html&#39;</span><span class="p">,</span> <span class="nx">controller</span><span class="o">:</span><span class="nx">controller</span><span class="p">});</span>
</span><span class='line'><span class="kd">var</span> <span class="nb">window</span> <span class="o">=</span> <span class="nx">Titanium</span><span class="p">.</span><span class="nx">UI</span><span class="p">.</span><span class="nx">createWindow</span><span class="p">({</span><span class="nx">fullscreen</span><span class="o">:</span> <span class="kc">true</span> <span class="p">});</span>
</span><span class='line'><span class="nb">window</span><span class="p">.</span><span class="nx">add</span><span class="p">(</span><span class="nx">webview</span><span class="p">);</span>
</span><span class='line'><span class="nb">window</span><span class="p">.</span><span class="nx">open</span><span class="p">();</span>
</span></code></pre></td></tr></table></div></figure>


<p>As you see it loads the index.html which renders the main view. Index.html loads index.js which declares a listener to the update_view event.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="nx">Ti</span><span class="p">.</span><span class="nx">App</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">(</span><span class="s1">&#39;update_view&#39;</span><span class="p">,</span><span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="c1">//..update the view using jquery based on e.state and e.info</span>
</span><span class='line'><span class="p">})</span>
</span></code></pre></td></tr></table></div></figure>


<p>The controller class checks every two seconds the state of the mifi card by getting the mifi status on the following url: &#8220;http://192.168.1.1/getStatus.cgi?dataType=TEXT&#8221;. It then parse the data (different for each version of the card) and creates a unified javascript structure and fire the update_view event:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'> <span class="nx">Titanium</span><span class="p">.</span><span class="nx">App</span><span class="p">.</span><span class="nx">fireEvent</span><span class="p">(</span><span class="s1">&#39;update_view&#39;</span><span class="p">,</span> <span class="p">{</span><span class="nx">state</span><span class="o">:</span><span class="k">this</span><span class="p">.</span><span class="nx">currentState</span><span class="p">,</span> <span class="nx">info</span><span class="o">:</span><span class="nx">info</span><span class="p">});</span>
</span></code></pre></td></tr></table></div></figure>


<p>To make the calls to the mifi card I wrote a Resource class that abstracts the xhr request</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'> <span class="k">this</span><span class="p">.</span><span class="nx">mifi</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Resource</span><span class="p">(</span><span class="s2">&quot;http://192.168.1.1/getStatus.cgi?dataType=TEXT&quot;</span><span class="p">);</span>
</span><span class='line'> <span class="k">this</span><span class="p">.</span><span class="nx">mifi</span><span class="p">.</span><span class="nx">index</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">mifiResult</span><span class="p">.</span><span class="nx">bind</span><span class="p">(</span><span class="k">this</span><span class="p">));</span>
</span></code></pre></td></tr></table></div></figure>


<p>Internally the resource uses the createHTTPClient and makes a standard ajax get call. I haven&#8217;t tried to use jquery&#8217;s .get function directly but assume it may not work with Titanium without some hacking&#8230;</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'>      <span class="kd">var</span> <span class="nx">xhr</span> <span class="o">=</span> <span class="nx">Titanium</span><span class="p">.</span><span class="nx">Network</span><span class="p">.</span><span class="nx">createHTTPClient</span><span class="p">();</span>
</span><span class='line'>      <span class="nx">xhr</span><span class="p">.</span><span class="nx">open</span><span class="p">(</span><span class="s2">&quot;GET&quot;</span><span class="p">,</span> <span class="nx">url</span><span class="p">);</span>
</span><span class='line'>      <span class="nx">xhr</span><span class="p">.</span><span class="nx">send</span><span class="p">();</span>
</span></code></pre></td></tr></table></div></figure>


<p>So Titanium rocks and works pretty well, at least for many iPhone apps. Now let&#8217;s see how long it takes for the approval of another app that I submitted yesterday&#8230;.</p>

<p>Enjoy!
Daniel Wanja</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[360 Flex - Day 1 (Sunday) - Live Blogging]]></title>
    <link href="http://n-so.com/blog/blog/2010/03/07/360-flex-day-1-sunday-live-blogging/"/>
    <updated>2010-03-07T23:17:00-07:00</updated>
    <id>http://n-so.com/blog/blog/2010/03/07/360-flex-day-1-sunday-live-blogging</id>
    <content type="html"><![CDATA[<p>We just had a great breakfast at Peggy Sue&#8217;s Dinner&#8230;and moved over to the Ebay Headquarters where the conferences is about to start.</p>

<p>I&#8217;ll be taking notes during the day and updating this page as we go one.</p>

<p>UPDATE: Now that I typed all that I realized that Justin put up the slides and code on his blog: <a href="http://blog.classsoftware.com/">http://blog.classsoftware.com/</a>.</p>

<!-- more -->




<h1>Connecting Arduino Hardware to Flex: Justin Mclean</h1>


<p>twitter: justinmclean
Justin is from Sydney, Australia.</p>

<p>Content:
* Arduino platform, how to program and how to connect to Flex
* 2/3 Arduino 1/3 Flex
* Hands on</p>

<h3>So we&#8217;ll go through the followings:</h3>


<ul>
<li>Digital Inputs</li>
<li>Digital Outputs</li>
<li>Analogue Inputs</li>
<li>Pulse Width Modulation</li>
<li>Serial Communication</li>
<li>Connecting to Flex</li>
<li>Review and wrap up</li>
</ul>


<p>So Justin gave each attendee one board and a set of components. The board is open source hardware. I think that&#8217;s pretty cool. Feels like the hardware kit I bought for my 6 years son. The board is $25 and with all the components it&#8217;s about $40.</p>

<div style="text-align:center;"><img src="http://onrails.org/files/arduino.png" alt="arduino.png" border="0" width="400" height="300" /></div>


<p>The hardware is provided to all participants by <a href="http://sparkfun.com"><strong>sparkfun.com</strong></a></p>

<h3>Software</h3>


<p>http://arduino.cc/en/Main/Software</p>

<div style="text-align:center;"><img src="http://onrails.org/files/arduino_software.png" alt="arduino_software.png" border="0" width="350" height="247" /></div>


<p>Also install the serial driver: FTDIUSBSerialDriver_10_4_10_5_10_6</p>

<h3>Other Hardwares</h3>


<ul>
<li>ATmega micro-controller from Atmel. It mostly runs in cars.</li>
<li>Arduino Duemilanove</li>
<li>Arduino Pro and Pro mini</li>
<li>Lyllypad (warable)</li>
<li>Funnell IO</li>
<li>Mega</li>
<li>Many others</li>
</ul>


<h3>ATMega328</h3>


<ul>
<li>Hight performance low power RISC</li>
<li>16 Mzh up to 16 mips (faster as your first pc you owned - if you are a bit older)</li>
<li>32K of Memory</li>
<li>SPI and 2 wire serial interfaces</li>
<li>External interrupts, timers, pulse width modulation</li>
</ul>


<h3>IDE</h3>


<ul>
<li>IDE open sourcee and cross platform.</li>
<li>Based on the Processing language</li>
<li>Many open source sketches (projects) and libraries availables. Ethernet library, servers, &#8230;</li>
</ul>


<h3>First Program</h3>




<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="kr">int</span> <span class="nx">ledPin</span> <span class="o">=</span>  <span class="mi">13</span><span class="p">;</span>    <span class="c1">// LED connected to digital pin 13</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// The setup() method runs once, when the sketch starts</span>
</span><span class='line'><span class="k">void</span> <span class="nx">setup</span><span class="p">()</span>   <span class="p">{</span>
</span><span class='line'>  <span class="c1">// initialize the digital pin as an output:</span>
</span><span class='line'>  <span class="nx">pinMode</span><span class="p">(</span><span class="nx">ledPin</span><span class="p">,</span> <span class="nx">OUTPUT</span><span class="p">);</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// the loop() method runs over and over again,</span>
</span><span class='line'><span class="c1">// as long as the Arduino has power</span>
</span><span class='line'>
</span><span class='line'><span class="k">void</span> <span class="nx">loop</span><span class="p">()</span>
</span><span class='line'><span class="p">{</span>
</span><span class='line'>  <span class="nx">digitalWrite</span><span class="p">(</span><span class="nx">ledPin</span><span class="p">,</span> <span class="nx">HIGH</span><span class="p">);</span>   <span class="c1">// set the LED on</span>
</span><span class='line'>  <span class="nx">delay</span><span class="p">(</span><span class="mi">1000</span><span class="p">);</span>                  <span class="c1">// wait for a second</span>
</span><span class='line'>  <span class="nx">digitalWrite</span><span class="p">(</span><span class="nx">ledPin</span><span class="p">,</span> <span class="nx">LOW</span><span class="p">);</span>    <span class="c1">// set the LED off</span>
</span><span class='line'>  <span class="nx">delay</span><span class="p">(</span><span class="mi">1000</span><span class="p">);</span>                  <span class="c1">// wait for a second</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>Now this will make the led blink:</p>

<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/PS5UcEYQdBA&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/PS5UcEYQdBA&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>




<h3>Programming</h3>


<ul>
<li>C like language based o wiring</li>
<li>Write code and compile in IDE</li>
<li>Upload compiled code using USB</li>
<li>Hard to debug</li>
</ul>


<h3>Circuit Basics</h3>


<ul>
<li>Ground and power</li>
<li>Potential difference required for current ot flow</li>
<li>Conductors and resistors</li>
</ul>


<h3>Digital Inputs/Outputs</h3>


<ul>
<li>Digital pins on Arduino are dual purpose</li>
<li>Digital logic and voltage on = 5V off = 0V</li>
<li>Can be set to be input or output via pinMode</li>
</ul>


<h3>Variables</h3>


<ul>
<li>boolean, char, byte, int, long, float, double, string and array</li>
<li>int 16 bits, long 32 bits, float 32 bits</li>
<li>Strings are nul terminated &#8216;\0&#8217;</li>
<li>Declare by <datatype> <variable name>; eg int i;</li>
</ul>


<p>It&#8217;s actually C++&#8230;What?! At a Flex conferences :-)</p>

<h3>Setup Function</h3>


<p></p>

<ul>
<li>Used for initialization</li>
<li>Run when program loaded or board reset</li>
<li>Best place to place calls to pinMode</li>
</ul>


<h3>LEDs</h3>


<ul>
<li>Current will only flow in one direction</li>
<li>Longest pin connect to positive side, shortest to ground</li>
<li>Dont&#8217; connect directly to power source use in series with resistors</li>
</ul>


<div style="text-align:center;"><img src="http://onrails.org/files/leds.png" alt="leds.png" border="0" width="300" height="225" /></div>




<h3>Resistors</h3>


<ul>
<li>Resistors limit current flowing through them</li>
<li>Value and tolerance indicated by cooler bands</li>
<li>Resistor values for LEDs</li>
<li>For RGB or LEG digits you need multiple resitors</li>
<li>REG/GREEN/BLUE 180 oms, WHITE/ULTRAVIOLET 100 oms</li>
</ul>


<div style="text-align:center;"><img src="http://onrails.org/files/resistors.png" alt="resistors.png" border="0" width="300" height="225" /></div>




<h3>Debugging ia Serial Port</h3>


<ul>
<li>Use Serial.begin to set speed</li>
<li>Serial.print, Serial.println to output</li>
<li>Use serial monitor in IDE to view</li>
</ul>


<h3>Blinking LED</h3>


<p>Same program that the first program but this time we just set the led to the pin 3 which is connected to the board.</p>

<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/H_nD-bWSNuI&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/H_nD-bWSNuI&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>




<h3>Digital Inputs</h3>


<ul>
<li>Some logic as inputs; hight 95V0 or low (0V)</li>
<li>Simplest digital input switch</li>
<li>Call pinMode to set as digital input as input</li>
</ul>


<h3>Connect Switch</h3>


<ul>
<li>Wire up push button on breadboard</li>
<li>Change code to turn light on/off</li>
</ul>


<p>Now switches have three states (on, off, and in between) to the board needs to be wired to take that into account so you can program it accordingly. We added a very high resistence (10k) next to switch to ensure that the switch reports 0V when not clicked.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="kr">int</span> <span class="nx">led</span> <span class="o">=</span> <span class="mi">3</span><span class="p">;</span>
</span><span class='line'><span class="kr">int</span> <span class="nx">button</span> <span class="o">=</span> <span class="mi">4</span><span class="p">;</span>
</span><span class='line'>
</span><span class='line'><span class="k">void</span> <span class="nx">setup</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>  <span class="nx">Serial</span><span class="p">.</span><span class="nx">begin</span><span class="p">(</span><span class="mi">9600</span><span class="p">);</span>
</span><span class='line'>  <span class="nx">pinMode</span><span class="p">(</span><span class="nx">led</span><span class="p">,</span> <span class="nx">OUTPUT</span><span class="p">);</span>
</span><span class='line'>  <span class="nx">pinMode</span><span class="p">(</span><span class="nx">button</span><span class="p">,</span> <span class="nx">INPUT</span><span class="p">);</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="k">void</span> <span class="nx">loop</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>  <span class="k">if</span> <span class="p">(</span><span class="nx">digitalRead</span><span class="p">(</span><span class="nx">button</span><span class="p">)</span> <span class="o">==</span> <span class="nx">HIGH</span><span class="p">)</span>  <span class="p">{</span>
</span><span class='line'>    <span class="nx">Serial</span><span class="p">.</span><span class="nx">println</span><span class="p">(</span><span class="s2">&quot;on&quot;</span><span class="p">);</span>
</span><span class='line'>    <span class="nx">digitalWrite</span><span class="p">(</span><span class="nx">led</span><span class="p">,</span> <span class="nx">HIGH</span><span class="p">);</span>
</span><span class='line'>  <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
</span><span class='line'>    <span class="nx">Serial</span><span class="p">.</span><span class="nx">println</span><span class="p">(</span><span class="s2">&quot;off&quot;</span><span class="p">);</span>
</span><span class='line'>    <span class="nx">digitalWrite</span><span class="p">(</span><span class="nx">led</span><span class="p">,</span> <span class="nx">LOW</span><span class="p">);</span>
</span><span class='line'>  <span class="p">}</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>So let&#8217;s look at the wiring and how the switch operates:</p>

<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/45Haml5UCIc&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/45Haml5UCIc&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>




<h3>Internal Pullup Resistors</h3>


<ul>
<li>Set mode to input</li>
<li>digitalWrite to HIGHT to turn on</li>
<li>digitalWrite to LOW to turn off</li>
</ul>


<p>So there is something like the 10K resistor built-in the board to avoid using an extra resistor on the board to make sure the switch values are on or off.</p>

<h3>Switch Issues</h3>


<ul>
<li>Switches can bounce and give and off values while switching</li>
<li>Noise can give false results</li>
<li>More a problem when switching needs to be counted</li>
<li>Use timer to solve issue (time = millis())</li>
</ul>


<h3>Analog Inputs & Potentiometer </h3>


<ul>
<li>Can read values via analogRead</li>
<li>Result is in range 0 to 1023 (10 bits)</li>
<li>Potentiometer is Variable resistor</li>
<li>Eg Read potentiometer values with Analog Inputs</li>
</ul>


<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="kr">int</span> <span class="nx">led</span> <span class="o">=</span> <span class="mi">3</span><span class="p">;</span>
</span><span class='line'><span class="kr">int</span> <span class="nx">pot</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
</span><span class='line'>
</span><span class='line'><span class="k">void</span> <span class="nx">setup</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>  <span class="nx">Serial</span><span class="p">.</span><span class="nx">begin</span><span class="p">(</span><span class="mi">9600</span><span class="p">);</span>
</span><span class='line'>  <span class="nx">pinMode</span><span class="p">(</span><span class="nx">led</span><span class="p">,</span> <span class="nx">OUTPUT</span><span class="p">);</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="k">void</span> <span class="nx">loop</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>    <span class="kr">int</span> <span class="nx">value</span> <span class="o">=</span> <span class="nx">analogRead</span><span class="p">(</span><span class="nx">pot</span><span class="p">);</span>
</span><span class='line'>    <span class="nx">digitalWrite</span><span class="p">(</span><span class="nx">led</span><span class="p">,</span> <span class="nx">HIGH</span><span class="p">);</span>
</span><span class='line'>    <span class="c1">// Set delay based on analog input</span>
</span><span class='line'>    <span class="nx">delay</span><span class="p">(</span><span class="nx">value</span><span class="p">);</span>
</span><span class='line'>    <span class="nx">digitalWrite</span><span class="p">(</span><span class="nx">led</span><span class="p">,</span> <span class="nx">LOW</span><span class="p">);</span>
</span><span class='line'>    <span class="nx">delay</span><span class="p">(</span><span class="nx">value</span><span class="p">);</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>So now when the potentiometer is turned to the right a value of 1023 is returned and the lights blinks on and off for about 1 seconds. Turning to the left makes the delay shorted (down to 0) and you can get it to run blink really fast.</p>

<div style="text-align:center;"><img src="http://onrails.org/files/potentiometer.png" alt="potentiometer.png" border="0" width="400" height="300" /></div>




<h3>LDR</h3>


<ul>
<li>Light dependent resistor (high resistance)</li>
<li>Set flash rate based on value of LDR</li>
</ul>


<p>This is a great full day tutorial and everyone seems to have fun. It&#8217;s pretty basic, but it&#8217;s the first time I program hardware.</p>

<p>Now we are writing fadeIn and fadeOut functions and get the light to pulse on and off</p>

<pre>
void fadeIn(int led) {
  for (int i=0; i<256; i++) {
    analogWrite(led, i);
    delayMicroseconds(5000);
  }
}

void fadeOut(int led) {
  for (int i=255; i >= 0; i--) {
    analogWrite(led, i);
    delayMicroseconds(5000);
  }
}

void loop() {
    fadeIn(led);    
    fadeOut(led);  
}  
</pre>


<p>Now we replace the light sensor by a temperature sensor. There are also air quality sensors, breathalyzers.</p>

<h3>Flex</h3>


<p>Communication between Flex and Arduinos.</p>

<ul>
<li>Software on Arduino (Firmata)</li>
<li>USB serial to socket proxy</li>
<li>Flex event based library to talk to socket (as3Glue)</li>
</ul>


<p>Firmata is an Arduino library that support a binary protocol over serial interface. It&#8217;s Bi-directiona. Use version 2.</p>

<p>In the Arduino IDE let&#8217;s load the StandardFirmata program (File|Examples|Firmata|StandardFirmata). It&#8217;s a 286 lines program similar to the code we wrote so far, but more complex.</p>

<p>Server Proxy</p>

<p>From http://arduino.cc/en/Main/Software the server proxy (end of page)</p>

<p>To configure proxy first find what your serial device is.
In terminal do: ls /dev/cu*</p>

<p>/dev/cu.Bluetooth-Modem       <br/>
/dev/cu.Bluetooth-PDA-Sync    <br/>
/dev/cu.usbserial-A600ailA</p>

<p>Then add this line to your serproxy.cfg:
serial_device=/dev/cu.usbserial-A600ailA</p>

<p>Then we just start the server proxy:
$ ./serproxy
Serproxy - (C)1999 Stefano Busti, (C)2005 David A. Mellis - Waiting for clients</p>

<p>Now in Flex you need to add the as3glue code (http://code.google.com/p/as3glue/) then you can drive arduino as follows:</p>

<pre>
private var arduino:Arduino = new Arduino();

private function init():void {
    arduino.addEventListener(ArduinoEvent.FIRMWARE_VERSION, turnLedOn);         
}

private function turnLedOn(event:ArduinoEvent):void {
    arduino.setPinMode(13, Arduino.OUTPUT);
    arduino.writeDigitalPin(13, Arduino.HIGH);
}
</pre>


<p>A qik look at the class room in the middle of coding their Flex app to drive their Arduino device:</p>

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0" width="425" height="319" id="qikPlayer" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="true" /><param name="movie" value="http://qik.com/swfs/qikPlayer5.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#333333" /><param name="FlashVars" value="streamID=515f621ccf514b6b8ad9dfb0c62ad851&amp;autoplay=false" /><embed src="http://qik.com/swfs/qikPlayer5.swf" quality="high" bgcolor="#333333" width="425" height="319" name="qikPlayer" align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" FlashVars="streamID=515f621ccf514b6b8ad9dfb0c62ad851&amp;autoplay=false"></embed></object>


<p>Now we are going to write some Flex code to have some buttons that turn on/off some functions of the board.</p>

<pre>
private var arduino:Arduino = new Arduino();
private const pin:int = 3;
private const button:int = 4;


private function arduinoInit(event:Event):void {
    arduino.enableDigitalPinReporting();
    arduino.setPinMode(pin, Arduino.OUTPUT);
    arduino.setPinMode(button, Arduino.INPUT);
    
    arduino.addEventListener(ArduinoEvent.DIGITAL_DATA, buttonChanged);
}

private function buttonChanged(event:ArduinoEvent):void {
    if (event.pin==button) {
        event.value == Arduino.HIGH ? turnOn() : turnOff();
    }
}

private function turnOn():void {
    arduino.writeDigitalPin(pin, Arduino.HIGH);
}

private function turnOff():void {
    arduino.writeDigitalPin(pin, Arduino.LOW);
}
</pre>


<p>Thanks Justin, great talk!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[vault.ncaa.com : under the hood of a cool Flex project.]]></title>
    <link href="http://n-so.com/blog/blog/2010/03/05/vault-dot-ncaa-dot-com-under-the-hood-of-a-cool-flex-project/"/>
    <updated>2010-03-05T19:10:00-07:00</updated>
    <id>http://n-so.com/blog/blog/2010/03/05/vault-dot-ncaa-dot-com-under-the-hood-of-a-cool-flex-project</id>
    <content type="html"><![CDATA[<div style="text-align:center;"><img src="http://onrails.org/files/vault.png" alt="vault.png" border="0" width="350" height="378" /></div>


<p><a href="http://www.thoughtequity.com">Thought Equity Motion</a> and <a href="http://www.ncaa.com/">NCAA</a> two days ago officially released the <a href="http://vault.ncaa.com/">Ncaa Vault</a>. A cool Flex app backed by an incredible video database with awesome metedata about each game&#8230;and released just in time for March Madness.</p>

<p>Here are a few of the announcements and online articles describing the services:</p>

<!-- more -->


<ul>
<li><a href="http://www.thoughtequity.com/video/shell/txp/ncaa-and-thought-equity-motion-unveil-first-ever-video-powered-vault-for-ncaa-march-madness.do?title=NCAAÂ®%20and%20Thought%20Equity%20Motion%20Unveil%20First%20Ever%20Video-Powered%20Vault%20for%20NCAA%20March%20MadnessÂ®?title=NCAAÂ®%20and%20Thought%20Equity%20Motion%20Unveil%20First%20Ever%20Video-Powered%20Vault%20for%20NCAA%20March%20MadnessÂ®&mkid=tw_3-3-10">NCAAÂ® and Thought Equity Motion Unveil First Ever Video-Powered Vault for NCAA March MadnessÂ®</a> - by Thought Equity</li>
<li><a href="http://www.nytimes.com/2010/03/03/sports/ncaabasketball/03ncaa.html">N.C.A.A. Tournament Goes Online, Clip by Clip</a> - by the New York Times</li>
<li><a href="http://www.wired.com/playbook/2010/03/say-hello-to-the-ncaa-vault-adieu-to-productivity/#ixzz0hGq1bpTzhttp://www.wired.com/playbook/2010/03/say-hello-to-the-ncaa-vault-adieu-to-productivity/">Say Hello to NCAA Vault, Adieu to Productivity</a> - by Wired</li>
</ul>


<p>In fact with the Vault you can have a URL right into a specific moment of any game and Wired picked out a great <a href="http://bit.ly/c9eQSU">last second tying shot</a>.</p>

<p>The twittersphere feedback is also <a href="http://search.twitter.com/search?q=vault+ncaa">pretty impressive</a>.</p>

<p>This is the most visible Flex app I worked on :-) Late January <a href="http://twitter.com/theaboutbox">Cameron Pope</a> contacted me to ask if I could help on a Flex project for NCAA and Thought Equity. The funny part is that I didn&#8217;t know that Cameron was such a great Flex developer, I met him via the Denver Ruby on Rails User Group (derailed) and I also didn&#8217;t know what NCAA was (don&#8217;t shoot, I didn&#8217;t grow up in the US and we don&#8217;t have TV). So when I asked my father in law about NCAA and realized it was about Basketball I was intrigued by what type of application we needed to build. Cameron showed me the mockups built by Donny Wells which is just an awesome graphical designer. These mockups where just incredible and then I was presented the video service technology the Thought Equity Motion team put together, and I was just blown away and though that this would be a cool project to work on.</p>

<p>Cameron was the main Flex developer and I just worked part time on Monday&#8217;s on this project. If you need and incredible Flex developer just contact Cameron.</p>

<p>Now let&#8217;s dive more into the Flex nitty-gritty details:</p>

<p>For the mvc architecture  we used the <a href="http://swizframework.org/">Swiz Framework</a> and this turned out to  work exceptionally well. Swiz sports some dependency injection features that can be enabled via the [Autowire] tag and I was surprised when I realized I could also just use that feature in an item render. Let&#8217;s look at a little detail&#8230;For the play by play timeline if a play is in the future it is displayed in bold:</p>

<div style="text-align:center;"><img src="http://onrails.org/files/timeline.png" alt="timeline.png" border="0" width="350" height="129" /></div>


<p>So each line of the timelime is rendered by the TimeLineItemRender and you can just autowire the model which contains the playhead position.</p>

<pre>
      [Autowire]
      [Bindable]
      public var vaultModel:Vault;
</pre>


<p>The we can set the style name accordingly based on the play&#8217;s start time and the current playhead position:</p>

<pre>
   styleName="{data.startTime < vaultModel.playheadPosition ? 'past' : 'future'}" 
</pre>


<p>The style of the application was created by the designer and Cameron did a great job reproducing it using <a href="http://www.degrafa.org/">Degrapha</a> for skinning () using an approach similar to this <a href="http://www.degrafa.org/source/ButtonLoader/ButtonLoader.html">example</a> (example <a href="http://www.degrafa.org/source/ButtonLoader/srcview/index.html">source</a>)</p>

<p>Most of my work was around the searching, bug fixing and general architecture overview. We took a similar approach to the one I described <a href="http://onrails.org/articles/2007/11/27/flash-utils-bytearray-compressing-4-1mb-to-20k">here</a> in order to avoid most of the server round trips during searching.</p>

<p>The Flex app is just a pretty face,  behind the scene Thought Equity provides an incredible services that they will expose in many ways, the start can be seen <a href="http://www.thoughtequity.com/video/home/article/ncaa_vault_publishing.do">here</a> and all that data will be able to be accessed via API and other means.</p>

<p>This was a short but incredible project for me, the guys at Though Equity have such an incredible vision on how to turn these sport videos into something so much bigger! Thank you guys for getting me on board.</p>

<div style="text-align:center;"><img src="http://onrails.org/files/thoughtequity.png" alt="thoughtequity.png" border="0" width="245" height="30" /></div>


<p>Enjoy!
Daniel Wanja</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Amazon RDS: Amazon Relational Database Service or MySQL in the Cloud for Ruby On Rails.]]></title>
    <link href="http://n-so.com/blog/blog/2009/10/29/amazon-rds-amazon-relational-database-service-or-mysql-in-the-cloud-for-ruby-on-rails/"/>
    <updated>2009-10-29T03:02:00-06:00</updated>
    <id>http://n-so.com/blog/blog/2009/10/29/amazon-rds-amazon-relational-database-service-or-mysql-in-the-cloud-for-ruby-on-rails</id>
    <content type="html"><![CDATA[<p>For watchthatsite.com (not public yet) I have an instance on EC2 with Rails and MySQL but was looking for a more solid hosting solution for MySQL. And how fortunate, Amazon came out with the solution I need this week. Basically with two command line instructions you can start a new server with mysql configured, tuned, and secured. In this blog entry I will go through the steps that perform to move my sql database to Amazon RDS.</p>

<!-- more -->


<p>You can find more information on Amazon Relational Database Service (API Version 2009-10-16) <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=2927&categoryID=290">here</a>.</p>

<p>Prerequisite: you need to <a href="http://aws.amazon.com/">signup</a> for an account on aws.amazon.com, it can be used for EC2, S3, SimpleDb and all the other services AWS provides.</p>

<h2>1) Install the Command Line Toolkit</h2>


<p>First thing, go download the command line toolkit and read the README.TXT on how to install it. In short you unzip the files, I did put mine at /Developer/aws/RDSCli-1.0.001. Then you create a credential file which contains your AWS access key id and secret key. Then I configured my ~/.bash_profile as follows:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>export AWS_RDS_HOME=/Developer/aws/RDSCli-1.0.001
</span><span class='line'>export AWS_CREDENTIAL_FILE=$AWS_RDS_HOME/credential-file-path.conf
</span><span class='line'>export JAVA_HOME=/Library/Java/Home
</span><span class='line'>export PATH=$AWS_RDS_HOME/bin:$PATH</span></code></pre></td></tr></table></div></figure>


<p>to see that the command line toolkit is setup correctly type $rds &#8211;help</p>

<p>You will need the command line tool to execute several commands described here after.</p>

<h2>2) Create an Instance</h2>


<p>Let&#8217;s create a MySQL Server instance. RDS offers the following 5 server instance classes:</p>

<ul>
<li>db.m1.small (1.7 GB of RAM, $0.11 per hour)</li>
<li>db.m1.large (7.5 GB of RAM, $0.44 per hour)</li>
<li>db.m1.xlarge (15 GB of RAM, $0.88 per hour)</li>
<li>db.m2.2xlarge (34 GB of RAM, $1.55 per hour)</li>
<li>db.m2.4xlarge (68 GB of RAM, $3.10 per hour)</li>
</ul>


<p>I will choose a small instance which I will call dbserver1 with a database name db1 and allocate 5g of database space. I also set the master username as admin and password as secret.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ rds-create-db-instance --db-instance-identifier db1 --allocated-storage 5 --db-instance-class db.m1.small --engine MySQL5.1 --master-username admin --master-user-password secret --db-name db1 --headers</span></code></pre></td></tr></table></div></figure>


<p>The output is the following:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>DBINSTANCE  DBInstanceId  Class        Engine    Storage  Master Username  Status    Backup Retention
</span><span class='line'>DBINSTANCE  db1           db.m1.small  mysql5.1  5        admin            creating  1               
</span><span class='line'>      SECGROUP  Name     Status
</span><span class='line'>      SECGROUP  default  active
</span><span class='line'>      PARAMGRP  Group Name        Apply Status
</span><span class='line'>      PARAMGRP  default.mysql5.1  in-sync</span></code></pre></td></tr></table></div></figure>


<p>Now you have a server running and you are being billed $0.11 per hour, that&#8217;s like $80 a month without bandwidth but with backup&#8230;and it took only 2 minutes to get going. Can&#8217;t beat that.</p>

<p>To see all the instances you have you can issue the</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>rds-describe-db-instances --headers</span></code></pre></td></tr></table></div></figure>




<h2>3) Grant Network Access</h2>


<p>So I will grant access from my notebook, assuming the ip address is 24.19.0.48 (you can also specify ranges i.e. 24.19.0.0/50). (Note that access was revoked by AWS, not sure why??)</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>rds-authorize-db-security-group-ingress default --cidr-ip 24.19.0.48 --headers</span></code></pre></td></tr></table></div></figure>


<p>I also have an ec2 instance which I want to grant access to</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>rds-authorize-db-security-group-ingress default --ec2-security-group-name watchthatsite --ec2-security-group-owner-id 526541544691</span></code></pre></td></tr></table></div></figure>


<p>Note the ec2-security-group-owner-id is your Amazon AWS account number, you can find it for example on you account activity page. To see your security configuration issue the following command: rds-describe-db-security-groups default &#8211;headers</p>

<h2>4) Using the Database</h2>


<p>To use your database you first need to find out the endpoint address of your new server. So describe you instances:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>rds-describe-db-instances --headers command</span></code></pre></td></tr></table></div></figure>




<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>DBINSTANCE  DBInstanceId  Created                   Class        Engine    Storage  Master Username  Status     Endpoint Address                              Port  AZ          Backup Retention
</span><span class='line'>DBINSTANCE  db1           2009-10-28T22:53:31.666Z  db.m1.small  mysql5.1  5        admin            available  db1.cyhik6zpub5c.us-east-1.rds.amazonaws.com  3306  us-east-1b  1               
</span><span class='line'>      SECGROUP  Name     Status
</span><span class='line'>      SECGROUP  default  active
</span><span class='line'>      PARAMGRP  Group Name        Apply Status
</span><span class='line'>      PARAMGRP  default.mysql5.1  in-sync</span></code></pre></td></tr></table></div></figure>


<p>You find out your endpoint address, for me db1.cyhik6zpub5c.us-east-1.rds.amazonaws.com</p>

<p>So now you can connect to your database:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>mysql -h db1.cyhik6zpub5c.us-east-1.rds.amazonaws.com -P 3306 -u admin -p db1</span></code></pre></td></tr></table></div></figure>


<p>Let&#8217;s configure my Rails application to point to that database and run a migration:</p>

<p>So I change my config/database.yml to point to the above database</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>development:
</span><span class='line'>    adapter: mysql
</span><span class='line'>    host: db1.cyhik6zpub5c.us-east-1.rds.amazonaws.com
</span><span class='line'>    reconnect: false
</span><span class='line'>    database: db1
</span><span class='line'>    username: admin
</span><span class='line'>    password: secret</span></code></pre></td></tr></table></div></figure>




<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'> rake db:migrate</span></code></pre></td></tr></table></div></figure>


<p>Wow, seem to work.</p>

<p>Let connect to the mysql console and do a show tables;</p>

<pre>
+-------------------+
| Tables_in_db1     |
+-------------------+
| schema_migrations | 
| users             | 
| watches           | 
+-------------------+
</pre>


<p>Yep, all there.</p>

<p>Now I still have to move my old production database to the new one, so let&#8217;s dump the data from my old database:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>mysqldump watchthatsite_development -u admin &gt; wts.sql</span></code></pre></td></tr></table></div></figure>


<p>and reload that data in the new database:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>mysql -h db1.cyhik6zpub5c.us-east-1.rds.amazonaws.com -P 3306 -u admin -p db1 &lt; wts.sql</span></code></pre></td></tr></table></div></figure>


<p>Restarting my Rails serverâ€¦That&#8217;s all!</p>

<p>Enjoy,
Daniel.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Behind the scene: Quiltivate.com a beautiful Flex on Rails website.]]></title>
    <link href="http://n-so.com/blog/blog/2009/07/16/behind-the-scene-quiltivate-dot-com-a-beautiful-flex-on-rails-website/"/>
    <updated>2009-07-16T04:20:00-06:00</updated>
    <id>http://n-so.com/blog/blog/2009/07/16/behind-the-scene-quiltivate-dot-com-a-beautiful-flex-on-rails-website</id>
    <content type="html"><![CDATA[<p>I met Phil several years ago at Derailed, the (Denver Ruby on Rails user group, and for a long time he was curious about how Flex can be integrated with Rails, about the graphical possibilities that Flex offers, the advantages over plain HTML/CSS/Javascript. Then he told me Kacie, his wife, had an idea about a website. She is passionate about quilts and has an eye for details and excellence. Phil is a geek that loves Rails, Kacie loves quilts,  it&#8217;s like Quilting meets Web 2.0 and <a href="http://quiltivate.com/">quiltivate.com</a> was born. In fact Phil and Kacie hired me to create a Quilt Builder that integrates with <a href="http://quiltivate.com/">Quiltivate.com</a>.</p>

<!-- more -->


<p>Kacie had the vision for the whole concept, a simple to use quilt builder that removes lots of the hassle of calculating how much fabric of what color is needed and allows to play with blocks, shapes and colors. She drew a paper prototype that really highlights the tag line of their site&#8221; Innovating Traditional Quilting&#8221;. <a href="http://quiltivate.com/">Quiltivate.com</a> offer much more than a Quilt Builder, it&#8217;s a blog and a community centered around the art and craft of quilting. Over the last year I spent a couple of hours here and there, well a little more than that, to transform the  paper prototype into a real Flex application.  Rather than writing about what the tool does and how it does it, let&#8217;s have a little look at behind the scene of the Quilt Builder with this video:</p>

<object width="400" height="300"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=5619106&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=5619106&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object>


<p><a href="http://vimeo.com/5619106">Behind the scene: Quiltivate.com a beautiful Flex on Rails website.</a> from <a href="http://vimeo.com/user507500">daniel wanja</a>.</p>


<p>Check out <a href="http://quiltivate.com/">quiltivate.com</a> for a video on how to really use the Quilt Builder and go try it out. As it&#8217;s fresh out of the gates their may be a little quirks here and there, so please let me know what you find. So thank you Kacie and Phil for getting me on this project, it was really fun!</p>

<p>Enjoy,
Daniel.</p>
]]></content>
  </entry>
  
</feed>

