<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="en-US">
  <id>tag:jim.revsystems.com,2005:/posts</id>
  <link rel="alternate" type="text/html" href="http://jim.revsystems.com" />
  
  <title>Jim Bancroft's Developing Thoughts</title>
  <updated>2009-02-11T19:14:14Z</updated>
  <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/JimBancroftsDevelopingThoughts" /><feedburner:info uri="jimbancroftsdevelopingthoughts" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
    <id>tag:jim.revsystems.com,2005:Post/6</id>
    <published>2009-02-11T19:14:14Z</published>
    <updated>2009-02-11T19:14:14Z</updated>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JimBancroftsDevelopingThoughts/~3/tSQfClgD9Zc/working-with-flex-remoteobjects" />
    <title>Working with Flex RemoteObjects</title>
    <content type="html">&lt;p&gt;First off I'd like to apologize for the amount of time that's gone by since I last posted.  This blogging thing is still relatively new to me and it's been very hard to get into the habit of posting regularly.  I've set a new goal for myself of posting at least once per week.  Today I decided to post about handling multiple asynchronous requests to the same &lt;a href="http://livedocs.adobe.com/flex/3/langref/mx/rpc/remoting/RemoteObject.html"&gt;RemoteObject&lt;/a&gt; method in Flex.&lt;/p&gt;

&lt;h4&gt;RemoteObject&lt;/h4&gt;

&lt;p&gt;A Flex &lt;strong&gt;RemoteObject&lt;/strong&gt; is basically a way for your client-side ActionScript code to communicate with a server-side object.  There are at least a few ways to configure your RemoteObjects, but that's beyond the scope of this discussion.  For now, I'll assume that you've got one of these setup like the following:&lt;/p&gt;

&lt;pre&gt;
&lt;code class="html"&gt;&amp;lt;mx:RemoteObject id=&amp;quot;myService&amp;quot; destination=&amp;quot;myService&amp;quot;&amp;gt;
  &amp;lt;mx:method name=&amp;quot;myMethod&amp;quot; result=&amp;quot;onMethodResult(event);&amp;quot; fault=&amp;quot;onMethodFault(event);&amp;quot;/&amp;gt;
&amp;lt;/mx:RemoteObject&amp;gt;&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;Now, you're probably used to invoking &lt;strong&gt;myMethod&lt;/strong&gt; something like this:&lt;/p&gt;

&lt;pre&gt;
&lt;code class="java"&gt;myService.myMethod(parameters);&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;...and when the server-side method returns a result, your &lt;strong&gt;onMethodResult&lt;/strong&gt; gets called with the result of the invocation.&lt;/p&gt;

&lt;p&gt;What if you need to call &lt;strong&gt;myMethod&lt;/strong&gt; multiple times, perhaps once for each object in an &lt;strong&gt;ArrayCollection&lt;/strong&gt;?  What if in the result method, you need to know which object that result belongs to?  Unfortunately using the methods outlined above, there's no way to determine this information.  The solution lies in the class &lt;a href="http://livedocs.adobe.com/flex/3/langref/mx/rpc/AsyncToken.html"&gt;AsyncToken&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;AsyncToken&lt;/h4&gt;

&lt;p&gt;Basically the goal is to get a reference to some "metadata" about your method call in the result function.  In our example we want to figure out which element of an &lt;strong&gt;ArrayCollection&lt;/strong&gt; was the parameter used to make the method call.&lt;/p&gt;

&lt;p&gt;First off you need to change the way you invoke your method so that you can store a reference to the &lt;strong&gt;AsyncToken&lt;/strong&gt; that's generated with each call.&lt;/p&gt;

&lt;pre&gt;
&lt;code class="java"&gt;var token:AsyncToken = myService.getOperation(&amp;quot;myMethod&amp;quot;).send(parameters);&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;Calling the &lt;strong&gt;send&lt;/strong&gt; method is essentially the same as using the method itself except it returns an instance of AsyncToken which is associated with this particular request.  The next thing you'll want to do is modify your &lt;strong&gt;RemoteObject&lt;/strong&gt; definition so that it doesn't specify general result or fault methods.&lt;/p&gt;

&lt;pre&gt;
&lt;code class="html"&gt;&amp;lt;mx:RemoteObject id=&amp;quot;myService&amp;quot; destination=&amp;quot;myService&amp;quot;&amp;gt;
  &amp;lt;mx:method name=&amp;quot;myMethod&amp;quot;/&amp;gt;
&amp;lt;/mx:RemoteObject&amp;gt;&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;Instead, you'll be specifying your result callback using the &lt;strong&gt;AsyncToken&lt;/strong&gt; and its collection of &lt;a href="http://livedocs.adobe.com/flex/3/langref/mx/rpc/IResponder.html"&gt;IResponder&lt;/a&gt; objects.  An &lt;strong&gt;IResponder&lt;/strong&gt; is basically an object that you specify to respond to the result or fault events for a given &lt;strong&gt;AsyncToken&lt;/strong&gt;.  Flex provides several default implementations of &lt;strong&gt;IResponder&lt;/strong&gt; and we'll be using the &lt;a href="http://livedocs.adobe.com/flex/3/langref/mx/collections/ItemResponder.html"&gt;ItemResponder&lt;/a&gt; variant.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;ItemResponder&lt;/strong&gt; allows us to specify an object to associate with the AsyncToken that will be provided to the result method.  So let's say that the &lt;strong&gt;parameters&lt;/strong&gt; we were using earlier is actually a reference to the object in the collection that we've been iterating through, and we want to make that same reference available in the result.  After calling the &lt;strong&gt;send&lt;/strong&gt; method and obtaining the reference to the &lt;strong&gt;AsyncToken&lt;/strong&gt;, specify the responder and store the reference to &lt;strong&gt;parameters&lt;/strong&gt; like this:&lt;/p&gt;

&lt;pre&gt;
&lt;code class="java"&gt;token.addResponder(new ItemResponder(onMethodResult, onMethodFault, parameters));&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;Also, change the signature of your onMethodResult and onMethodFault functions to look like this:&lt;/p&gt;

&lt;pre&gt;
&lt;code class="java"&gt;public function onMethodResult(result:Object, token:Object = null):void;&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;where &lt;strong&gt;result&lt;/strong&gt; is the &lt;strong&gt;ResultEvent&lt;/strong&gt; and &lt;strong&gt;token&lt;/strong&gt; is that reference to &lt;strong&gt;parameters&lt;/strong&gt; that you stored when you added the responder.  Now you can make several calls to the same remote method and you can associate an arbitrary ActionScript object with each call.  Neat! &lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JimBancroftsDevelopingThoughts/~4/tSQfClgD9Zc" height="1" width="1"/&gt;</content>
    <author>
      <name>Jim Bancroft</name>
    </author>
  <feedburner:origLink>http://jim.revsystems.com/posts/working-with-flex-remoteobjects</feedburner:origLink></entry>
  <entry>
    <id>tag:jim.revsystems.com,2005:Post/5</id>
    <published>2008-10-31T19:59:56Z</published>
    <updated>2008-10-31T19:59:56Z</updated>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JimBancroftsDevelopingThoughts/~3/Pe_fbWr86S4/comments" />
    <title>Comments</title>
    <content type="html">&lt;p&gt;So I've added comments on this blog via &lt;a href="http://disqus.com/"&gt;Disqus&lt;/a&gt;.  I'll test the comments using this post, and I look forward to hearing feedback from anyone that might read this blog in the future.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JimBancroftsDevelopingThoughts/~4/Pe_fbWr86S4" height="1" width="1"/&gt;</content>
    <author>
      <name>Jim Bancroft</name>
    </author>
  <feedburner:origLink>http://jim.revsystems.com/posts/comments</feedburner:origLink></entry>
  <entry>
    <id>tag:jim.revsystems.com,2005:Post/4</id>
    <published>2008-09-30T15:33:04Z</published>
    <updated>2008-09-30T16:34:11Z</updated>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JimBancroftsDevelopingThoughts/~3/B6IM-pmSKIU/feeds-and-icons" />
    <title>Feeds and Icons</title>
    <content type="html">&lt;p&gt;Well it's been another week or two and I've made a few other improvements to my blog.&lt;/p&gt;

&lt;h4&gt;Atom Feed&lt;/h4&gt;

&lt;p&gt;First off, I've made a simple feed available using the &lt;a href="http://feeds.feedburner.com/JimBancroftsDevelopingThoughts"&gt;Subscribe link&lt;/a&gt; in the menu on the right side of the page.  There's not much to say about this.  I simply followed the &lt;a href="http://api.rubyonrails.org/classes/ActionView/Helpers/AtomFeedHelper.html#M001609"&gt;example&lt;/a&gt; in the Rails documentation.&lt;/p&gt;

&lt;h4&gt;Icons&lt;/h4&gt;

&lt;p&gt;I've also added some nifty icons to those right side link.  I'm using the &lt;a href="http://www.wefunction.com/function-free-icon-set"&gt;function free icon set&lt;/a&gt; which is available courtesy of &lt;a href="http://www.wefunction.com/"&gt;www.wefunction.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I did run into one problem with the image_tag helper.  The bug is documented &lt;a href="http://rails.lighthouseapp.com/projects/8994/tickets/693-image_tag-adds-strange-dot-after-file-names-on-windows"&gt;here&lt;/a&gt;.  Basically on Windows, image_tag adds an extra "." character at the end of the filename.  Also, this only causes a problem on JBoss (packaged as a war using Warbler) but not on Mongrel.  Weird.&lt;/p&gt;

&lt;p&gt;Anyway... I put together a simple workaround that should alleviate the issue until it gets officially patched.  Basically instead of using image_tag, I defined the following helper function in app/helpers/posts_helper.rb&lt;/p&gt;

&lt;pre&gt;
&lt;code class="ruby"&gt;def clean_image_tag(image_file)
  temp_tag = image_tag(image_file)
  temp_tag[temp_tag.rindex(&amp;quot;.&amp;quot;)] = &amp;quot;&amp;quot;
  temp_tag
end&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;As you can see, it's a simply wrapper for image_tag that removes the last "." from the result.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JimBancroftsDevelopingThoughts/~4/B6IM-pmSKIU" height="1" width="1"/&gt;</content>
    <author>
      <name>Jim Bancroft</name>
    </author>
  <feedburner:origLink>http://jim.revsystems.com/posts/feeds-and-icons</feedburner:origLink></entry>
  <entry>
    <id>tag:jim.revsystems.com,2005:Post/3</id>
    <published>2008-09-15T20:27:56Z</published>
    <updated>2008-09-19T20:56:34Z</updated>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JimBancroftsDevelopingThoughts/~3/ZepUzQ-4M7c/updates-to-my-blog-application" />
    <title>Updates to My Blog Application</title>
    <content type="html">&lt;p&gt;Well it's been another few days since I last posted, and I've made a few more changes to my blog application here.  I think I'm starting to get into the habit of posting on a more regular basis.  The basics of the changes I've made boil down to 2 things: testing and a bunch of minor polishing touches.&lt;/p&gt;

&lt;h3&gt;Testing Using Shoulda&lt;/h3&gt;

&lt;p&gt;The first change to my blog is that I have belatedly setup unit tests for most of the application.  Continuing with the pattern of copying my big brother, I decided to use the wicked awesome &lt;a href="http://www.thoughtbot.com/projects/shoulda"&gt;shoulda&lt;/a&gt; and &lt;a href="http://github.com/thoughtbot/factory_girl/tree/master"&gt;factory_girl&lt;/a&gt; libraries.  I'm a bit ashamed to say that this is really the first time I've setup more than just a trivial test for any project I was doing, but it feels good and I'm hoping to embrace testing more as I develop myself as a programmer.&lt;/p&gt;

&lt;p&gt;If you're interested in a pretty useful guide to getting your rails app setup this way, check out this &lt;a href="http://technicalpickles.com/posts/a-walk-through-of-test-driven-development-with-shoulda"&gt;step-by-step guide&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Other Stuff&lt;/h3&gt;

&lt;h4&gt;Google Analytics&lt;/h4&gt;

&lt;p&gt;Yep, I've enabled Google Analytics on this blog via &lt;a href="http://github.com/rubaidh/google_analytics/tree/master"&gt;this plugin&lt;/a&gt;.  Interestingly enough, I didn't seem to be able to install this plugin using the gem from the master copy on GitHub... might be a &lt;a href="http://logicalawesome.lighthouseapp.com/projects/8570/tickets/956-gem-ownership-issues"&gt;github bug&lt;/a&gt;?&lt;/p&gt;

&lt;h4&gt;Layout/View Changes&lt;/h4&gt;

&lt;p&gt;I fixed a bunch of minor things in my views that should clear up some of the clutter.  Namely, unless you're logged in, you're not going to see links for new posts, editing posts, or deleting posts anymore.&lt;/p&gt;

&lt;p&gt;Anyway... there's still a ton of changes and improvements to be made, and I'll be sure to post about them once I get around to making them all.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JimBancroftsDevelopingThoughts/~4/ZepUzQ-4M7c" height="1" width="1"/&gt;</content>
    <author>
      <name>Jim Bancroft</name>
    </author>
  <feedburner:origLink>http://jim.revsystems.com/posts/updates-to-my-blog-application</feedburner:origLink></entry>
  <entry>
    <id>tag:jim.revsystems.com,2005:Post/2</id>
    <published>2008-09-10T20:53:18Z</published>
    <updated>2008-09-19T20:56:33Z</updated>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JimBancroftsDevelopingThoughts/~3/BCkQgZ-lDsA/changes-to-my-blog" />
    <title>Changes to My Blog</title>
    <content type="html">&lt;p&gt;Well it's been a few days so I figured I'd post an update about the state of things around here.  I've made several improvements and changes to the way posts are handled.&lt;/p&gt;

&lt;h3&gt;jQuery Chili for Syntax Highlighting&lt;/h3&gt;

&lt;p&gt;I guess the first change that I made is that I switched from using the &lt;a href="http://syntax.rubyforge.org/"&gt;syntax&lt;/a&gt; gem for my syntax highlighting to using the &lt;a href="http://noteslog.com/chili/"&gt;Chili&lt;/a&gt; plugin for &lt;a href="http://jquery.com"&gt;jQuery&lt;/a&gt;.  The main reasons for this change are that the Chili seems to be under more active development and it support more styles of syntax.&lt;/p&gt;

&lt;p&gt;Chili itself pretty much works out of the box.  All you really have to do is include jQuery and the plugin on your pages, and then point it at the recipes on your server that tell it how to recognize different languages.  I ran into 2 little snafus while implementing this change.  First, the contents of my &amp;lt;code&amp;gt; blocks needed to have HTML characters escaped, and second, leading and trailing whitespace (including linebreaks) in the code was causing problems with my formatter (see below).  Both issues were resolved using the following piece of code in my &lt;strong&gt;Posts&lt;/strong&gt; model.&lt;/p&gt;

&lt;pre&gt;
&lt;code class="ruby"&gt;class Post &amp;lt; ActiveRecord::Base
  include ActionView::Helpers::TagHelper

  #...

  def escaped_body
    html_body = self.body.gsub(/&amp;lt;code.+?&amp;lt;\/code&amp;gt;/mi) do |code_block|
      code_content = /([^&amp;gt;]*&amp;gt;)(.+?)(&amp;lt;\/code&amp;gt;)/mi.match(code_block)
      code_content[1] + escape_once(code_content[2].strip) + code_content[3]
    end
  end

  #...

end&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;You may notice that I included the &lt;strong&gt;ActionView::Helpers::TagHelper&lt;/strong&gt; in my model to give me access to the &lt;strong&gt;escape_once&lt;/strong&gt; method which does the actual grunt work of escaping.&lt;/p&gt;

&lt;p&gt;Oh... one more thing: Chili doesn't support Ruby syntax out of the box, but since I got the idea to use it from my &lt;a href="http://www.technicalpickles.com"&gt;big brother&lt;/a&gt;, thankfully he already had a Ruby recipe and let me use it :-)&lt;/p&gt;

&lt;h3&gt;Markdown Using BlueCloth&lt;/h3&gt;

&lt;p&gt;Another improvement that I made is that my blog now supports &lt;a href="http://daringfireball.net/projects/markdown/"&gt;Markdown&lt;/a&gt; using the &lt;a href="http://www.deveiate.org/projects/BlueCloth"&gt;BlueCloth&lt;/a&gt; gem.  Again, this is another idea that I basically stole from my big brother, but it's working out quite nicely so far.&lt;/p&gt;

&lt;p&gt;If you're interested in the specifics, I pretty much copied exactly what he said to do in his &lt;a href="http://technicalpickles.com/posts/switched-templating-engine-to-bluecloth"&gt;post&lt;/a&gt; about the same subject.  The only thing that I really changed is that instead of using &lt;strong&gt;self.body&lt;/strong&gt; as the parameter to BlueCloth, I use the output of my &lt;strong&gt;escaped_body&lt;/strong&gt; method.&lt;/p&gt;

&lt;p&gt;Also, be aware that the way to install the BlueCloth gem using JRuby 1.1.4 on Windows is using something like the following line:&lt;/p&gt;

&lt;pre&gt;
&lt;code&gt;jruby -S gem install BlueCloth -y&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;I'm pretty sure that a gem called bluecloth also exists, but JRuby will complain about native extensions if you try to use that.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JimBancroftsDevelopingThoughts/~4/BCkQgZ-lDsA" height="1" width="1"/&gt;</content>
    <author>
      <name>Jim Bancroft</name>
    </author>
  <feedburner:origLink>http://jim.revsystems.com/posts/changes-to-my-blog</feedburner:origLink></entry>
  <entry>
    <id>tag:jim.revsystems.com,2005:Post/1</id>
    <published>2008-09-04T14:22:34Z</published>
    <updated>2008-09-19T20:56:33Z</updated>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JimBancroftsDevelopingThoughts/~3/i7Vaxe0HN_U/first-post" />
    <title>First Post!</title>
    <content type="html">&lt;p&gt;Check it out!  This is my first post in my new blog, written by me (my &lt;a href="http://www.technicalpickles.com"&gt;big brother&lt;/a&gt; says it's a right of passage).&lt;/p&gt;

&lt;p&gt;There's still a TON of work to be done but I think this is probably a decent start.&lt;/p&gt;

&lt;p&gt;In the coming days I'll be moving my existing posts from &lt;a href="http://jbscdev.blogspot.com"&gt;my old blog&lt;/a&gt; over to here.  Already, one improvement I'm enjoying in moving to my own blog is syntax highlighting on my code, as illustrated in the following code snippet.&lt;/p&gt;

&lt;pre&gt;
&lt;code class="ruby"&gt;def to_html
  html_body = self.body.gsub(/&amp;lt;code.+?&amp;lt;\/code&amp;gt;/mi) do |code_block|
    syntax = /class[^=]*=[^&amp;quot;]*&amp;quot;([^&amp;quot;]+)&amp;quot;[^&amp;gt;]*&amp;gt;(.+?)&amp;lt;\/code&amp;gt;/mi.match(code_block)
    convertor = Syntax::Convertors::HTML.for_syntax syntax[1].strip
    convertor.convert syntax[2]
  end
  BlueCloth.new(html_body).to_html
end&lt;/code&gt;
&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/JimBancroftsDevelopingThoughts/~4/i7Vaxe0HN_U" height="1" width="1"/&gt;</content>
    <author>
      <name>Jim Bancroft</name>
    </author>
  <feedburner:origLink>http://jim.revsystems.com/posts/first-post</feedburner:origLink></entry>
</feed>

