<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Nicholas Hagen</title>
	<atom:link href="http://www.znetdevelopment.com/blogs/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.znetdevelopment.com/blogs</link>
	<description>Tidbits and blogs from Nicholas Hagen related to software, web design, and usability</description>
	<lastBuildDate>Sat, 07 Jan 2012 07:27:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>CSS3 Photo Gallery Example</title>
		<link>http://www.znetdevelopment.com/blogs/2012/01/07/css3-photo-gallery-example/</link>
		<comments>http://www.znetdevelopment.com/blogs/2012/01/07/css3-photo-gallery-example/#comments</comments>
		<pubDate>Sat, 07 Jan 2012 07:20:45 +0000</pubDate>
		<dc:creator>Nicholas Hagen</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[Gallery]]></category>
		<category><![CDATA[Photo]]></category>
		<category><![CDATA[Webkit]]></category>

		<guid isPermaLink="false">http://www.znetdevelopment.com/blogs/?p=509</guid>
		<description><![CDATA[I was looking into the new CSS3 transformations and 3D capabilities for a photo gallery I was creating for my blog and created the following effect that acts like a spinner allowing you to spin through the images as if they were on a turnstile. The best part is that all the animations and perspectives [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking into the new CSS3 transformations and 3D capabilities for a photo gallery I was creating for my blog and created the following effect that acts like a spinner allowing you to spin through the images as if they were on a turnstile.  The best part is that all the animations and perspectives are purely done in CSS.  The only portion of the code in javascript is just advancing the images by updating the rotation of each image.  Because the animations and perspectives are driven by the browser, you get more fluid animations.</p>
<p>Note that this demo only works in Chrome and Safari as required to support the Webkit capabilities.</p>
<p><a href="http://www.znetdevelopment.com/gallery.html" title="Photo Gallery Demo" target="_blank">Photo Gallery Demo</a></p>
<p><span id="more-509"></span></p>
<div>
<script src="https://gist.github.com/1574062.js?file=PhotoGallery"></script>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.znetdevelopment.com/blogs/2012/01/07/css3-photo-gallery-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Server vs Client-Side Rendering</title>
		<link>http://www.znetdevelopment.com/blogs/2012/01/05/server-vs-client-side-rendering/</link>
		<comments>http://www.znetdevelopment.com/blogs/2012/01/05/server-vs-client-side-rendering/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 22:40:52 +0000</pubDate>
		<dc:creator>Nicholas Hagen</dc:creator>
				<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Client]]></category>
		<category><![CDATA[Client-Side]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[Rendering]]></category>
		<category><![CDATA[Scalability]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Server-Side]]></category>
		<category><![CDATA[Templating]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.znetdevelopment.com/blogs/?p=504</guid>
		<description><![CDATA[I&#8217;ve come to a strange realization today. Several industry leaders and even some companies (http://d8p.it/17392,Leaving_JSPs_in_the_dust:_moving_LinkedIn_to_dust.js_client-side_templates_%7C_LinkedIn_Engineering.html) are moving to using Javascript and related libraries to move most code to the client for high scalability solutions. In thought, that is a great idea. However, it&#8217;s a bit of a strange paradigm. Initially, there was only a handful [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve come to a strange realization today.  Several industry leaders and even some companies (<a href="http://d8p.it/17392,Leaving_JSPs_in_the_dust:_moving_LinkedIn_to_dust.js_client-side_templates_%7C_LinkedIn_Engineering.html">http://d8p.it/17392,Leaving_JSPs_in_the_dust:_moving_LinkedIn_to_dust.js_client-side_templates_%7C_LinkedIn_Engineering.html</a>) are moving to using Javascript and related libraries to move most code to the client for high scalability solutions.</p>
<p>In thought, that is a great idea.  However, it&#8217;s a bit of a strange paradigm.  Initially, there was only a handful of languages to program in.  Then, there was only a handful of languages to write server-side web applications in.  Then, tons more came to the scene.  Why? Because no one language fits all cases.  Some are more optimized at specific use cases and make sense.  As a Java guy, I&#8217;ve used several of these, but each has their place.  JSF works great in form-heavy, intranet sites.  Grails works great in dynamic, database-driven systems.  Struts has its place. Library Xyz has its place.</p>
<p>If the world moves to rendering more code on the client via Javascript, in a sense, we go backward (ok, not really, but bear with me).  There is only 1 language on the client side: javascript.  Yes, Google exposed us to Dart, but realistically that will never mean anything because IE, Opera, Safari, etc will never support it, just as Mozilla never supported Visual Basic on the web.  Javascript is the defacto &#8220;scripting&#8221; language on the web and always will be (unless someone manages to convince the entire industry and the entire world otherwise).</p>
<p>Yes, I know there are a ton of Javascript emulators (coffeescript, dart to a degree, objective j, etc), but it&#8217;s still javascript.  There are even a ton of libraries in JS to simplify it so you don&#8217;t feel like you are using JS.  In the end though, it&#8217;s all javascript and you are bound to the browser support, performance, and bottlenecks (even more so in some cases where emulators make things easy but use crazy hacks in javascript to make it work resulting in expensive operations).</p>
<p>Anyways, I&#8217;m not trying to advocate one way or the other (I, myself, have not really made up my mind, yet).  I just found it strange how the progression of web applications was driven server side by the advancement of new languages and methodologies.  To purely go client side, you are almost binding yourself to a single language: Javascript.  Worse yet, there is no real progression possible other than emulators, which always scare me (I prefer having control of what something is doing rather than a cross compiler or emulator doing it for me).  Maybe in a few years, emulators and javascript will advance enough that we can have different languages and libraries that are highly performant making you be able to choose the right language for the right use case and job. Only time will tell.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.znetdevelopment.com/blogs/2012/01/05/server-vs-client-side-rendering/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Alternatives to 3/4G Naming</title>
		<link>http://www.znetdevelopment.com/blogs/2011/12/16/alternatives-to-34g-naming/</link>
		<comments>http://www.znetdevelopment.com/blogs/2011/12/16/alternatives-to-34g-naming/#comments</comments>
		<pubDate>Fri, 16 Dec 2011 14:21:36 +0000</pubDate>
		<dc:creator>Nicholas Hagen</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[3G]]></category>
		<category><![CDATA[4G]]></category>
		<category><![CDATA[Cell]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.znetdevelopment.com/blogs/2011/12/16/alternatives-to-34g-naming/</guid>
		<description><![CDATA[Currently the term 4G is thrown out there by carriers in a complete marketing purpose. Originally, 4G was reserved for LTE Advanced which is not expected in usage for 3-5 years prolly. Since then to one up each carrier they have made HSPA+ 4G. Now we have 3 distinct technologies (HSPA+, LTE, LTE Advanced) that [...]]]></description>
			<content:encoded><![CDATA[<p>Currently the term 4G is thrown out there by carriers in a complete marketing purpose. Originally, 4G was reserved for LTE Advanced which is not expected in usage for 3-5 years prolly. Since then to one up each carrier they have made HSPA+ 4G. Now we have 3 distinct technologies (HSPA+, LTE, LTE Advanced) that are all considered 4G. Consumers end up confused by the marketing gimmick. To further confuse it, there are different speeds for HSPA+: 7, 14.4, 21, etc. Phones do not always support all speeds. In the end consumers are hurt. </p>
<p>As an alternative, why don&#8217;t we go back to the way modems or CD drives worked. For example, modems were once 14.4, followed by 28.8, followed by 56K. You knew exactly the theoretical difference from one modem to the next. It just made sense. We could easily do the same with mobile technologies. </p>
<p>Another approach would be to use a system like CD drives back in the day. They all baselines off a given speed and then became 2x, 4x, 8x, etc. Again this easily makes sense what you are getting from one case to the next. </p>
<p>Mobile carriers should think about this type of approach rather than confusing its end users with 4G that gets tossed around with no merit or meaning. Seriously, how much faster is 4G over 3G?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.znetdevelopment.com/blogs/2011/12/16/alternatives-to-34g-naming/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Why Do People Still Use Texting?</title>
		<link>http://www.znetdevelopment.com/blogs/2011/10/26/why-do-people-still-use-texting/</link>
		<comments>http://www.znetdevelopment.com/blogs/2011/10/26/why-do-people-still-use-texting/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 02:45:59 +0000</pubDate>
		<dc:creator>Nicholas Hagen</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Beejive]]></category>
		<category><![CDATA[Google Talk]]></category>
		<category><![CDATA[Google Voice]]></category>
		<category><![CDATA[iMessage]]></category>
		<category><![CDATA[Meebo]]></category>
		<category><![CDATA[SMS]]></category>
		<category><![CDATA[Texting]]></category>

		<guid isPermaLink="false">http://www.znetdevelopment.com/blogs/?p=495</guid>
		<description><![CDATA[Question: Why do people still text when it is the biggest ripoff in history? 5,000% markup! http://www.nytimes.com/2011/10/10/technology/paying-to-text-is-becoming-passe-companies-fret.html?_r=1&#038;hp http://www.zdnet.com/blog/btl/the-biggest-ripoff-text-message-beats-movie-popcorn/30327 http://gthing.net/the-true-price-of-sms-messages It literally costs carriers next to nothing to send a message. The message piggybacks all the other packets, so those packets would be sent regardless if a text is sent. Plus, the infrastructure is already built [...]]]></description>
			<content:encoded><![CDATA[<p>Question: Why do people still text when it is the biggest ripoff in history?  5,000% markup!</p>
<ul>
<li><a href="http://www.nytimes.com/2011/10/10/technology/paying-to-text-is-becoming-passe-companies-fret.html?_r=1&#038;hp">http://www.nytimes.com/2011/10/10/technology/paying-to-text-is-becoming-passe-companies-fret.html?_r=1&#038;hp</a></li>
<li><a href="http://www.zdnet.com/blog/btl/the-biggest-ripoff-text-message-beats-movie-popcorn/30327">http://www.zdnet.com/blog/btl/the-biggest-ripoff-text-message-beats-movie-popcorn/30327</a></li>
<li><a href="http://gthing.net/the-true-price-of-sms-messages">http://gthing.net/the-true-price-of-sms-messages</a></li>
</ul>
<p>It literally costs carriers next to nothing to send a message. The message piggybacks all the other packets, so those packets would be sent regardless if a text is sent. Plus, the infrastructure is already built in.</p>
<p>So, why in the world do they charge $.25 a text? How is that not illegal?</p>
<p>The &#8220;real&#8221; answer&#8230;too many of us buy into it and the carriers make billions of dollars off of it.  The biggest reason I hear is &#8220;well I already have unlimited texts&#8221;.  Let&#8217;s do the math though.  At $10/month, that is $120/year.  At $20/month, that&#8217;s $240/year.  If you are on a smartphone, cancel your texting plan and you can get a new smartphone every year. That just makes sense to me, which is why I explicitly opt out of texting and save myself the money.  As everyone continues to move towards smartphones, it really does not make sense to pay for texting anymore.  There are too many free options.</p>
<p>1. <a href="http://www.google.com/voice">Google Voice</a><br />
Google Voice gives you a custom phone number to which you can send and receive text messages completely &#8220;free&#8221;.  When you pair that with a smartphone, the messages are delivered to your phone directly rather than as a text message. When you text someone, again it is delivered directly via Google Voice, but it is sent to the other person as a text.  Case in point, you cancel your texting plan, save $20/month, and still get free texting.  Why would you not do this?</p>
<p>2. <a href="http://www.google.com/talk">Google Talk</a><br />
For those on Android-based devices, they come with Google Talk out of the box. Simply sign in with your Google account and you can send messages to anyone else on Google Talk including iPhone users, desktop/laptop users, iPad/iPod Touch users, etc. For example, I use the iPhone application <a href="http://www.beejive.com/">Beejive </a>(highly recommended) to text my android friends.  Again, completely free!</p>
<p>3. <a href="http://www.apple.com/ios/features.html">iMessage</a><br />
Apple now offers the iMessage platform that allows talking to other Apple-device users without incurring texting charges.</p>
<p>4. <a href="http://www.meebo.com">Meebo</a><br />
Meebo is another Instant Messaging client that allows sending messages to other users on any instant messaging platform (Google Talk, MSN, Yahoo, AIM, etc).</p>
<p>5. Facebook<br />
As much as I hate facebook, people still want to use it. That said, they also offer a messaging platform to send direct messages without using text messages.</p>
<p>So, I conclude with the question again? Why would anyone pay for texting? Join the Anti-SMS movement and save yourself $20/month (go enjoy a nice dinner each month instead).  Let&#8217;s all IM, not Text :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.znetdevelopment.com/blogs/2011/10/26/why-do-people-still-use-texting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>3 Ways to Skin a Fibonacci</title>
		<link>http://www.znetdevelopment.com/blogs/2011/09/11/3-ways-to-skin-a-fibonacci/</link>
		<comments>http://www.znetdevelopment.com/blogs/2011/09/11/3-ways-to-skin-a-fibonacci/#comments</comments>
		<pubDate>Sun, 11 Sep 2011 18:48:26 +0000</pubDate>
		<dc:creator>Nicholas Hagen</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[Fibonacci]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.znetdevelopment.com/blogs/?p=490</guid>
		<description><![CDATA[Fibonacci sequences and their calculations are always an interesting computer science question and sometimes even an interview question. There are endless ways to calculate a fibonacci value and mathematicians way smarter than I am have much better ways. This is really just a blog post on three simple Java-based solutions. In no way is this [...]]]></description>
			<content:encoded><![CDATA[<p>Fibonacci sequences and their calculations are always an interesting computer science question and sometimes even an interview question.  There are endless ways to calculate a fibonacci value and mathematicians way smarter than I am have much better ways.  This is really just a blog post on three simple Java-based solutions.  In no way is this meant to convey an optimal solution.  Rather, the intent of this exercise was to demonstrate how simple changes can improve a simple algorithm.  Too many times as developers we quickly implement a solution (usually to save time) when a few extra lines or additional thought could improve the overall throughput.  That being said, as you read this post, don&#8217;t focus on the implementation, but rather the subtle changes that improve the overall effectiveness.<br />
<span id="more-490"></span><br />
So, let&#8217;s get to it.  First off, a quick reminder of what the <a href="http://en.wikipedia.org/wiki/Fibonacci_number">fibonacci sequence</a> is:</p>
<pre>1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...</pre>
<p>Basically, the sequence is defined as <code>F(x) = F(x-1) + F(x-2)</code> where <code>F(0) = 1</code> and <code>F(1) = 1</code>.  That is basically the easiest solution to code against via recursion.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">long</span> fibonacci<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> index<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>index <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">||</span> index <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">return</span> fibonacci<span style="color: #009900;">&#40;</span>index <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> fibonacci<span style="color: #009900;">&#40;</span>index <span style="color: #339933;">-</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>That solution is extremely easy to write, it makes sense, and works.  But how well does it work?  F(20) averaged 0.1ms, F(30) averaged 8ms, and F(40) almost a second.  It is obviously an exponential algorithm.  The reason for this is that <code>F(4) = F(3) + F(2)</code>, but <code>F(3)</code> is just <code>F(2) + F(1)</code>.  Essentially, our recursion is executing the same values over and over again since we execute each index two times.  One way to avoid that duplication is to implement caching.  This would result in only executing each index once at the cost of a local cache.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> Map<span style="color: #339933;">&lt;</span>Integer, Long<span style="color: #339933;">&gt;</span> CACHE <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>Integer, Long<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">long</span> fibonacci<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> index<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>index <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">||</span> index <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #003399;">Integer</span> key <span style="color: #339933;">=</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>index<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">Long</span> value <span style="color: #339933;">=</span> CACHE.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>value <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> value.<span style="color: #006633;">longValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">long</span> result <span style="color: #339933;">=</span> fibonacci<span style="color: #009900;">&#40;</span>index <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> fibonacci<span style="color: #009900;">&#40;</span>index <span style="color: #339933;">-</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    CACHE.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>key, <span style="color: #003399;">Long</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">return</span> result<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Using this cache-based mechanism, we now get 0.1ms at F(40).  That is almost 10,000 times faster and all we did was add a caching layer.  A simple change for a massive improvement.  Caching can be used at any layer of an application and often times can easily improve the application stack with little effort.  Further, libraries like Spring AOP or CDI interceptors can automatically add behind-the-scenes caching to any method only requiring a few lines of code for high improvements.</p>
<p>We can actually further improve this and without using a cache.  If you again look at the sequence:</p>
<p><code>F(4) = F(3) + F(2)</code></p>
<p>We can replace <code>F(3)</code> with its value <code>F(2) + F(1)</code> resulting in:</p>
<p><code>F(4) = F(2) + F(1) + F(2)</code></p>
<p>This can be further simplified to:</p>
<p><code>F(4) = [F(2) * 2] + F(1)</code></p>
<p>Generally speaking, this is equivalent to:</p>
<p><code>F(X) = [F(X-2) * 2] + F(X-3)</code></p>
<p>We could again use recursion for X-2 and X-3, but we are back in the same exponential algorithm.  Instead, we can be smart and rather than return a single value, return 2 values (the value itself and the previous value).  In this way, the recursion can just take the resulting array and now has both X-2 and X-3.  This results in only invoking the sequence for every other value a single time without using a cache.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">long</span> fibonacci<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> index<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> _fibonacci<span style="color: #009900;">&#40;</span>index<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">long</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> _fibonacci<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> index<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>index <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">long</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>index <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">long</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">long</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> result <span style="color: #339933;">=</span> _fibonacci<span style="color: #009900;">&#40;</span>index <span style="color: #339933;">-</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">long</span> value <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> result<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// result is X-2, so X-1 is just X-2 + X-3</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">long</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> value, result<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> result<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Using this new algorithm, F(40) now only takes 0.005ms, another 20x improvement.  Using only a few additional lines of code, we managed to simplify a standard fibonacci calculation by 200,000 times.  That&#8217;s pretty significant in my book at the minimal cost of thought, analysis, and performance testing.</p>
<p>Other ideas to improve the calculation is using the multiple cores in modern day server hardware.  For example, you could invoke F(X-1) in one thread and F(X-2) in a separate thread and then join on the results.  There are also plenty of math-based solutions that may make sense.  </p>
<p>In any sense, no matter what the algorithm or how simple it may seem, there are always multiple ways to skin the cat and those ways often lead to improved performance.  Performance should always be one of the first things to consider, not the last.  Minor improvements can buy you the performance sooner than later.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.znetdevelopment.com/blogs/2011/09/11/3-ways-to-skin-a-fibonacci/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>4 Reasons Samsung Should Buy WebOS</title>
		<link>http://www.znetdevelopment.com/blogs/2011/08/29/4-reasons-samsung-should-buy-webos/</link>
		<comments>http://www.znetdevelopment.com/blogs/2011/08/29/4-reasons-samsung-should-buy-webos/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 16:02:37 +0000</pubDate>
		<dc:creator>Nicholas Hagen</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Home Entertainment]]></category>
		<category><![CDATA[HP]]></category>
		<category><![CDATA[HTC]]></category>
		<category><![CDATA[Palm]]></category>
		<category><![CDATA[Phone]]></category>
		<category><![CDATA[RIM]]></category>
		<category><![CDATA[Samsung]]></category>
		<category><![CDATA[Tablet]]></category>
		<category><![CDATA[WebOS]]></category>

		<guid isPermaLink="false">http://www.znetdevelopment.com/blogs/?p=487</guid>
		<description><![CDATA[Is Samsung thinking about buying WebOS? I really like this idea if it&#8217;s true, although I really doubt it. I have a hard time believing Samsung would ditch everything (Android, Bada, etc) to concentrate on WebOS. However, I do believe that WebOS could benefit Samsung and the community. I think Android is a great concept, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.appleinsider.com/articles/11/08/29/samsung_rumored_to_buy_webos_to_compete_with_apples_ios_mac_os_x.html">Is Samsung thinking about buying WebOS</a>?  I really like this idea if it&#8217;s true, although I really doubt it.  I have a hard time believing Samsung would ditch everything (Android, Bada, etc) to concentrate on WebOS.  However, I do believe that WebOS could benefit Samsung and the community.  I think Android is a great concept, but its execution was only truly successful because it was a free alternative to Apple allowing phone manufacturers to jump in the game quickly for little cost.  Android is still well behind Apple in terms of stability, usability, consistency, etc.  Yes, they have many more features, but those features came at the cost of consistency and design; something Apple never loses focus of.  As a result, you get a great notification system with a poor attempt at a music/video player.  It just feels too quirky at times..so much to the point that Samsung, HTC, etc all create custom themes to better manage it.  That only leads to being behind by 1 or 2 releases while they attempt to bring their software stack up to the fast development pace of Android.<br />
<span id="more-487"></span><br />
On the other hand, WebOS is a great platform that was designed very well as a direct competitor to Apple.  It&#8217;s only issue was execution in terms of marketing, hardware, licensing, etc.  They never got going and only had 1 or 2 phones on the market.  With little market share, no one was going to develop for the platform resulting in a poor app store that is so critical in today&#8217;s smartphone market.  HP was supposed to help, but that was utter failure again due to lack of quality hardware and market.  In all honesty, it may just be too late to compete with Apple and itsfan boys and girls and the free/open-ness of Android and its many devices/platforms/carriers that it supports.</p>
<p>That being said, I think Samsung would be a good fit for four key reasons.</p>
<p>First, they may feel threatened by Google&#8217;s purchase of Motorola and want distancing from Android.  WebOS would offer that distance and uniqueness.  Rather than rely on Android and the unknown future it holds or the unknown venture Google puts Motorola in, it could adopt WebOS and have full control of its stack.  They would no longer rely on Google to implement certain features or deal with custom themes.  They would own the entire stack.</p>
<p>Second, Samsung is in legal-hell with Apple and could use a large patent portfolio that WebOS has.  Apple never sued Palm/HP despite its threats and prolly because of the patent war that would have resulted.  Samsung may feel better off having those patents rather than the open patents from Android.  Samsung could easily ditch Android, drop the lawsuits, adopt WebOS and start fresh.  Apple may still target Samsung, but at least Samsung would have more fighting power back.  Today&#8217;s world seems heavy on the idea of buying up patent portfolios, so Samsung may be interested purely from that perspective while also getting a good OS (win/win).</p>
<p>Third, Samsung already knows how to make great quality hardware.  They just need a great quality OS and WebOS could be that answer.  They would hten have a true portfolio to sell to all of its carriers it already supports (almost all of them) to compete heavily with Apple on a level playing field.  The issue with Palm and then HP is that they dug themselves into a hole with only supporting a single carrier and a single model.  People want choices: keyboards or no keyboards, AT&#038;T or Verizon, Spring or T-Mobile, $100 or $300, dual-core or single-core.  Samsung has the manufacturing expertise to build those models and has the support of its various carriers that it could push a single platform to everyone.  For example, think Galaxy S and now the upcoming Galaxy S2.  Galaxy S3 could be the WebOS feature phone for all carriers.</p>
<p>Fourth and finally, Samsung has a complete hardware portfolio from phones, to tablets, to computers, to TVs, to home entertainment centers.  If they truly want to complete with Apple, they need a consistent environment across platforms.  Android is starting on that venture, but their inconsistencies continue to bite them.  WebOS already works on phones and tablets, and HP/Palm was busy at work making it support computers.  If Samsung added WebOS integration into its set top boxes and TVs, and did it right without sacrificing usability, it could have a full system.  Push content from your phone or tablet directly to your TV, control your entertainment/HTPC from your phone, control your lighting and thermostat, the options are endless.  Apple is heading this direction and its great designs and usability give them the edge.  WebOS has the capability of matching and even exceeding Apple.  It just needs the right partner.  Samsung has the capability and WebOS could be its answers.  </p>
<p>Ultimately, it is highly unlikely unfortunately, but it makes sense if you think about it.  I&#8217;ve always thought HTC may have been a better fit for WebOS, but HTC is set of supporting everyone it seems (Android, Windows, etc).  RIM may also be a fit, but RIM is in the enterprise market and will never make it in the consumer market or even the entertainment market.  It&#8217;s not where they are as a company.  WebOS needs a company that can be everywhere in a consumer&#8217;s life.  Samsung already does that and WebOS can tie it all together.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.znetdevelopment.com/blogs/2011/08/29/4-reasons-samsung-should-buy-webos/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Original Syntax Highlighter</title>
		<link>http://www.znetdevelopment.com/blogs/2011/08/22/original-syntax-highlighter/</link>
		<comments>http://www.znetdevelopment.com/blogs/2011/08/22/original-syntax-highlighter/#comments</comments>
		<pubDate>Mon, 22 Aug 2011 20:54:39 +0000</pubDate>
		<dc:creator>Nicholas Hagen</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Joke]]></category>
		<category><![CDATA[Syntax Highlighter]]></category>

		<guid isPermaLink="false">http://www.znetdevelopment.com/blogs/?p=482</guid>
		<description><![CDATA[All of our IDEs and text editors support syntax highlighting&#8230;however, here is the original highlighter before the invention of computers :) Does anyone remember these things? Next time you are writing pseudo code on your napkin or paper, break out one of these babies and make sure to use the proper color&#8230;you know, blue for [...]]]></description>
			<content:encoded><![CDATA[<p>All of our IDEs and text editors support syntax highlighting&#8230;however, here is the original highlighter before the invention of computers :)  Does anyone remember these things?  Next time you are writing pseudo code on your napkin or paper, break out one of these babies and make sure to use the proper color&#8230;you know, blue for variables, black for operations, red for functions&#8230;or was it yellow for operations, green for operations&#8230;all up to you I guess.  Enjoy your multi-colored, syntax highlighting aware, pseudo-code creating pen!</p>
<p><a href="http://www.znetdevelopment.com/blogs/wp-content/uploads/2011/08/multi-colored-ball-pen.jpg"><img src="http://www.znetdevelopment.com/blogs/wp-content/uploads/2011/08/multi-colored-ball-pen.jpg" alt="" title="multi-colored-ball-pen" class="aligncenter size-full wp-image-483" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.znetdevelopment.com/blogs/2011/08/22/original-syntax-highlighter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google+ vs Facebook and Twitter: My Personal Thoughts</title>
		<link>http://www.znetdevelopment.com/blogs/2011/08/12/google-vs-facebook-and-twitter-my-personal-opinions/</link>
		<comments>http://www.znetdevelopment.com/blogs/2011/08/12/google-vs-facebook-and-twitter-my-personal-opinions/#comments</comments>
		<pubDate>Fri, 12 Aug 2011 21:15:32 +0000</pubDate>
		<dc:creator>Nicholas Hagen</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Circles]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Google Plus]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://www.znetdevelopment.com/blogs/?p=476</guid>
		<description><![CDATA[For anyone who knows me personally, you most likely know that I despise Facebook and for plenty of reasons, most of which I consider valid (although some are just my personal annoyances). I&#8217;m also not an avid Twitter user, although I do use it to post my blog articles and share technology tidbits. However, I [...]]]></description>
			<content:encoded><![CDATA[<p>For anyone who knows me personally, you most likely know that I despise Facebook and for plenty of reasons, most of which I consider valid (although some are just my personal annoyances).  I&#8217;m also not an avid Twitter user, although I do use it to post my blog articles and share technology tidbits.  However, I have completely bought into Google+, though I do know there are several issues there as well&#8230;some contradictory to my own opinions, but I&#8217;ll take the pros over the cons.  Anyways, back to the topic: Why Google+ over Facebook?<br />
<span id="more-476"></span></p>
<p>The main reason why I bought into Google+ so quickly was that it featured Circles.  Circles basically allows you to manage your relationships into groups.  I had actually semi-planned out an implementation in my head as an attempt to do something similar, even though I knew I&#8217;d never finish.  The concept of having &#8216;circles of friends&#8217; or &#8216;trust circles&#8217; just makes sense on so many levels.  Not only did Google implement it, but they implemented it very well.  I now have a choice over my data and where it goes.  Yes, I know Facebook does this, but the fact that the Google+ implementation is built around the concept makes it incredibly easy to use.  Google+ expects you to use it.  </p>
<p>Here are the reasons why I choose Google+ over Facebook.  Hopefully, these give you more insight into making your own decisions.</p>
<p>First of all, as a technology user/evangelist (or at least my goal), I want my information to be somewhat public.  I want my blog articles to be easily accessible and directly searchable.  Further, I want my name out there to credit my knowledge.  However, I also want my personal information about myself, my family, etc to be private but shareable to my direct family.  I also want certain information to be more or less available depending on context.  Google+, via Circles, allows me this opportunity.  I can easily segregate my personal/private life from my techie life.  Doing that on Facebook is just a headache in the making.  Doing it on Twitter is just too open.  Google+ is the best of both worlds.</p>
<p>Second, Google+ allows you to follow others without requiring a direct consensus (ala Twitter).  On Facebook, you more or less have to be joint friends to follow each other.  Google+ went the Twitter style so that I may follow others such as other techies without them first approving me.  This works because of the Circle relationships.  If I choose to follow someone, then I will have access to their public information (techie blog posts), but will not have access to their private info (unless, they of course add me themselves and put me in an associated circle).  The other cool part of Circles is that you do not know if or what circle someone else put you in&#8230;nor do you care really unless you are stalking in which case you prolly have other issues :)  Your circles are your circles and private to you as they should be.</p>
<p>Third, Google+ breaks down the notion of &#8216;friends&#8217;.  Let&#8217;s be honest, the term &#8216;friend&#8217; has been completely broken by Facebook.  Your boss is not your friend.  Your friend&#8217;s friend&#8217;s acquaintance is also not your friend.  A &#8216;friend&#8217; is someone who you trust and confide in.  Facebook used that term way too loosely.  Google+ took circles and defines a set of default circles that make very good sense: Family, Friends, Acquaintance , Following, etc.  You simply add users to one or more groups where they make sense.  You can even add your own groups such as Workplace, Book Club, etc.  Users now have direct understandable relationships to you and it makes it easy when selecting which groups to share content with.</p>
<p>Fourth, streams, news feeds, call it what you want, become much more manageable.  I often times do not want to know that some person I know is eating a burger.  However, I do want to know what the tech community is doing more often.  Circles makes this completely easy.  I can view the entire stream (ala Facebook), or I can view specific streams, or I can view a specific user&#8217;s stream.  This way I can see just my techie stream and occasionally check other streams.  It is entirely up to you on how you manage that data, which is the real point here:  it is up to you, not Google, not someone else.</p>
<p>Fifth, Google+ allows me to control my sharing capabilities.  For public information, I want to directly share it and allow others to re-share it.  For private information, however, I only want those in my circles to see my content without allowing them to re-share it.  On every post, you can edit it via the drop down and select Disable Reshare.  This basically removes the &#8216;Share&#8217; link from other users.  Yes, I know they can simply copy and paste, but it at least makes it semi-harder.</p>
<p>Hopefully you can see how Google+ and in particular Circles makes extreme sense.  Google+ did not just take Facebook and Twitter and mash them together.  They created a real solution that directly correlates to managing relationships in life.  That is what defines usability: software that provides a direct association to life in order for a user to directly apply its natural association.</p>
<p>I know I have discussed all the good things, so how about some bad things to even the playing field.</p>
<p>First, Google+ is still in the market of acquiring user information to create large graphs in order to better their company as is Facebook and Twitter.  Google+ was not created solely to allow you to talk to your relationships&#8230;it was created so that Google would have that social data that companies desperately desire.  So, if you are paranoid about your data being locked up in some big corporation, then you may have issues.  That being said, I do believe that Google is the lesser of the two evils (and I am to an extent semi-paranoid which is why I despise Facebook).  Facebook is willing to abuse their power to make themselves richer, regardless of its impact on users.  Google is held to a higher standard, IMO.  That may not be completely true, but I believe there is some validity to it.  Google has shown this by making privacy more straighforward and easier to access.  They also provide more insight into your data including allowing you to backup your data or transfer it to another service.  Finally, they allow you to delete your entire profile, unlike Facebook which refuses to relinquish control of your information more or less.</p>
<p>Second, Google+ is still in beta and a work in progress.  Because of that it is clumsy and not completely apparent at all times.  For example, there is no good way to message a user directly.  However, Google Chat does allow you to easily do that so there are options.  Google is continually integrating their entire product line, so it will come, just not there quite yet.  That being said, it is very usable and works.  I use it often to include my blog articles, family pictures, etc.  I have had no major issues as of yet.</p>
<p>Third, Google+ is still in limited beta meaning you have to have an invitation (ping me if you want one).  As a result, not all of your friends or family will be on there&#8230;odds are they won&#8217;t.  But hey, don&#8217;t you want to lead the revolution, not sit back and watch it?  Convince your friends and family to join and they will be there :)  I believe that as Google+ begins to stabilize and more feature rich that users will realize the impact of Circles and all the other features and jump ship, so don&#8217;t let the absence of your buddies hold you back.</p>
<p>Fourth, device support is still limited.  Google+ is supposed on iOS and Android, but IMO, its support is not all that well.  They allow you to upload pictures (although limited number) and post updates, but editing, disabling resharing, etc are all missing.  Those features are coming and the mobile apps are very usable.  They are just not as rich as they could be.  Again, though, don&#8217;t let that hold you back.  Time will tell the real story.</p>
<p>Fifth, feature X on Facebook or Twitter does not exist.  Remember, Google+ is still in beta and those features are more or less coming (where they make sense obviously).  Google+ is not going to add a feature just because&#8230;it has to make sense.  The best part though is that Google+ is listening to its users and as users voice their opinions, priorities most likely will change.  If enough users want a feature, Google will prolly investigate the time and effort.  So, if you really want feature X, just drop the Google+ team feedback and let them know.  They are listening.  Google+ wants to be successful and not operate in a complete vacuum.</p>
<p>With all that being said, I definitely encourage you to try it out.  It won&#8217;t be without its issues, but neither is Facebook, Twitter, or [put your favorite other platform here].  As users begin to switch and Google implements features, the platform will become better and better.  Hopefully the pros and cons listed here will help to encourage your adoption.</p>
<p>If you want more information or need an invite, just let me know.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.znetdevelopment.com/blogs/2011/08/12/google-vs-facebook-and-twitter-my-personal-opinions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easy REST: Groovy, Grails, and JAXRS</title>
		<link>http://www.znetdevelopment.com/blogs/2011/08/08/easy-rest-groovy-grails-and-jaxrs/</link>
		<comments>http://www.znetdevelopment.com/blogs/2011/08/08/easy-rest-groovy-grails-and-jaxrs/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 17:33:16 +0000</pubDate>
		<dc:creator>Nicholas Hagen</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[JAXRS]]></category>
		<category><![CDATA[Jersey]]></category>
		<category><![CDATA[JMX]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.znetdevelopment.com/blogs/?p=465</guid>
		<description><![CDATA[I needed an easy way to get an API up and running for a project that exposed JMX as an API (in order to easily interoperate with non-Java clients [ie: iOS…more details coming]). There are a variety of tools, resources, languages, etc to do this, but the one that I found easiest was via Grails [...]]]></description>
			<content:encoded><![CDATA[<p>I needed an easy way to get an API up and running for a project that exposed JMX as an API (in order to easily interoperate with non-Java clients [ie: iOS…more details coming]).  There are a variety of tools, resources, languages, etc to do this, but the one that I found easiest was via <a href="http://www.grails.org/">Grails</a> using a <a href="http://code.google.com/p/grails-jaxrs/">JAXRS</a> plugin which is a <a href="http://en.wikipedia.org/wiki/Java_API_for_RESTful_Web_Services">Java-based standard</a> for RESTful services.<br />
<span id="more-465"></span><br />
Grails is already a superb language for building websites and as part of that has strong built-in support for XML and JSON rendering.  However, you still have to have controllers to interact with the model, which is to some degree cumbersome.  This is where the rich plugin ecosystem that Grails exposes comes in.  Grails has a great plugin called <a href="http://code.google.com/p/grails-jaxrs/">JAXRS</a>.  It is based on the Java-standard and uses <a href="http://jersey.java.net/">Jersey</a> (or alternatively a few other options) at its core to handle the API paths.  Jersey is typically built on Java-based apps, but being Groovy/Grails is JVM-based, it works equally well there.  The JAXRS plugin exposes a <code>create-resource</code> command to quickly create a resource artifact.  That artifact is a Groovy-based class that uses the built-in Jersey annotations.  At that point it is just a matter of interacting with the Grails system (domain classes, services, GORM, etc).  The following is an extremely simple way to get up and running (this is based on Grails 1.3.7):</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">grails create-app test
cd test
grails install-plugin jaxrs
grails create-resource com.znet.test.api.Users
grails create-domain-class com.znet.test.domain.User
grails create-domain-class com.znet.test.domain.Address</pre></div></div>

<p>At this point you can modify the <code>grails-app/domain/com/znet/test/domain/User.groovy</code> file to add a few properties:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> User <span style="color: #66cc66;">&#123;</span>
	<span style="color: #993333;">int</span> id<span style="color: #66cc66;">;</span>
	<span style="color: #aaaadd; font-weight: bold;">String</span> firstName<span style="color: #66cc66;">;</span>
	<span style="color: #aaaadd; font-weight: bold;">String</span> lastName<span style="color: #66cc66;">;</span>
	Address address<span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Also, edit <code>grails-app/domain/com/znet/test/domain/Address.groovy</code> to add its properties:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Address <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">static</span> belongsTo <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#91;</span>user:User<span style="color: #66cc66;">&#93;</span>
&nbsp;
	<span style="color: #993333;">int</span> id<span style="color: #66cc66;">;</span>
	<span style="color: #aaaadd; font-weight: bold;">String</span> city<span style="color: #66cc66;">;</span>
	<span style="color: #aaaadd; font-weight: bold;">String</span> state<span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Now, edit the <code>grails-app/resources/com/znet/test/api/UsersResource.groovy</code></p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #a1a100;">com.znet.test.domain.*</span><span style="color: #66cc66;">;</span>
&nbsp;
@Path<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/api/users'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UsersResource <span style="color: #66cc66;">&#123;</span>
	@GET
	@Produces<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'application/xml'</span>, <span style="color: #ff0000;">'application/json'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
	List<span style="color: #66cc66;">&lt;</span>User<span style="color: #66cc66;">&gt;</span> getUser<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		User.<span style="color: #006600;">list</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This class will basically intercept any URL request going to <code>/api/users</code> and invoke the <code>getUser</code> method.  That method uses standard GORM to return a list of users.</p>
<p>Before we test though, we need to get some initial content in our development database, add the following to the <code>grails-app/conf/BootStrap.groovy</code> file:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #a1a100;">com.znet.test.domain.*</span><span style="color: #66cc66;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Bootstrap <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">def</span> init <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span> servletContext <span style="color: #66cc66;">-&gt;</span>
		Address addr1 <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Address<span style="color: #66cc66;">&#40;</span>id:<span style="color: #cc66cc;">1</span>,city:<span style="color: #ff0000;">'New York'</span>, state:<span style="color: #ff0000;">'NY'</span><span style="color: #66cc66;">&#41;</span>
		addr1.<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
		User user1 <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> User<span style="color: #66cc66;">&#40;</span>id:<span style="color: #cc66cc;">1</span>,firstName:<span style="color: #ff0000;">'John'</span>,lastName:<span style="color: #ff0000;">'Doe'</span>,address:addr1<span style="color: #66cc66;">&#41;</span>
		user1.<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
		Address addr2 <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Address<span style="color: #66cc66;">&#40;</span>id:<span style="color: #cc66cc;">2</span>,city:<span style="color: #ff0000;">'Los Angeles'</span>,state:<span style="color: #ff0000;">'CA'</span><span style="color: #66cc66;">&#41;</span>
		addr2.<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
		User user2 <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> User<span style="color: #66cc66;">&#40;</span>id:<span style="color: #cc66cc;">2</span>,firstName:<span style="color: #ff0000;">'Jane'</span>,lastName:<span style="color: #ff0000;">'Doe'</span>,address:addr2<span style="color: #66cc66;">&#41;</span>
		user2.<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Running <code>grails run-app</code> should launch the server at which point the following URL should bring up an XML list with both users:  http://127.0.0.1:8080/test/api/users</p>
<p>All that work with only a handful of code.  It could not get much more easier than that.  Add another property to the user object and wallah, it shows up.  This model really allows you to quickly build up an API with little effort.  Further, using the power and simplicity of the GORM domain model, you can map a database model into a composite domain model into an API model.  The best part is you only have one set of classes to do so and Grails/JAXRS takes care of the mappings to/from the database and to/from the API.  Further, you get both JSON/XML out of the box.  For example, simply configure your browser to support application/json, it would render the output in JSON rather than XML.  This is one of the downfalls of the JAXRS plugin however in that you have to tweak your browser manually.  I actually created a simple mime-type filter that intercepts requests and sets the <code>Accept</code> header mime-type accordingly.  This allows you to suffix a URL with .json or .xml or set a query param such as <code>format=json</code>.  Drop me a comment if you are interested in learning more about that filter.</p>
<p>The JAXRS <a href="http://code.google.com/p/grails-jaxrs/w/list">documentation</a> has much more information on other cool facets.  One of those is the ability to generate <a href="http://code.google.com/p/grails-jaxrs/wiki/GettingStarted#Scaffolding">scaffolding</a> of domain-based resources including lists, gets, puts, and posts via the <code>generate-resource</code> command.  This truly provides the complete database to API modeling.</p>
<p>That is the simple method.  My case, however, did not use GORM or databases, but instead JMX.  So what does JAXRS offer us here?  The JAXRS actually handles domain classes differently from plain POJOs or POGOs.  In fact, out of the box, you cannot simply create a POGO and expose it automatically.  However, doing so only involves a few lines of code to expose a custom provider.  Create a new directory in grails-app called providers.  Within that directory, create a new Groovy class (creating any associated subdirectories per the package name).</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">@<span style="color: #aaaadd; font-weight: bold;">Provider</span>
@Produces<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'text/xml'</span>, <span style="color: #ff0000;">'application/xml'</span>, <span style="color: #ff0000;">'text/x-json'</span>, <span style="color: #ff0000;">'application/json'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #000000; font-weight: bold;">class</span> DomainObjectWriter <span style="color: #000000; font-weight: bold;">extends</span> DomainObjectWriterSupport <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #993333;">boolean</span> isWriteable<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">Class</span> type, Type genericType,
	                    <span style="color: #aaaadd; font-weight: bold;">Annotation</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> annotations, MediaType mediaType<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">;</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #aaaadd; font-weight: bold;">Object</span> writeToXml<span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">Object</span> obj, <span style="color: #aaaadd; font-weight: bold;">OutputStream</span> entityStream, <span style="color: #aaaadd; font-weight: bold;">String</span> charset<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">def</span> xml <span style="color: #66cc66;">=</span> obj <span style="color: #000000; font-weight: bold;">as</span> XML<span style="color: #66cc66;">;</span>
		xml.<span style="color: #006600;">render</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">OutputStreamWriter</span><span style="color: #66cc66;">&#40;</span>entityStream<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #aaaadd; font-weight: bold;">Object</span> writeToJson<span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">Object</span> obj, <span style="color: #aaaadd; font-weight: bold;">OutputStream</span> entityStream, <span style="color: #aaaadd; font-weight: bold;">String</span> charset<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">def</span> json <span style="color: #66cc66;">=</span> obj <span style="color: #000000; font-weight: bold;">as</span> JSON<span style="color: #66cc66;">;</span>
		json.<span style="color: #006600;">render</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">OutputStreamWriter</span><span style="color: #66cc66;">&#40;</span>entityStream<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This basically tells the Jersey and JAXRS environment to load the provider class and use it for handling marshaling to JSON and/or XML.  The actual implementation only involves delegation to the great built in support exposed by Grails and the XML and JSON converters.  Those converters have built-in support for POJOs, POGOs, as well as any other custom registration schemes.  For example, to register a custom handler, create a new Groovy class (ie: within src/groovy):</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> CustomObjectMarshaller <span style="color: #000000; font-weight: bold;">implements</span> ObjectMarshaller<span style="color: #66cc66;">&lt;</span>JSON<span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">boolean</span> supports<span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">Object</span> object<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// check if this marshaller can handle the specified object</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">;</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> marshalObject<span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">Object</span> object, JSON json<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// render object</span>
		JSONWriter writer <span style="color: #66cc66;">=</span> json.<span style="color: #006600;">getWriter</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
		writer.<span style="color: #006600;">object</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
		writer.<span style="color: #006600;">key</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'hello'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
		json.<span style="color: #006600;">convertAnother</span><span style="color: #66cc66;">&#40;</span>object.<span style="color: #006600;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This is a really simple example, but you essentially register a marshaller per mime type (JSON, XML, etc) and then use the custom writers to write out properties and values.  Ideally, you would invoke convertAnother using a sub-property of object which would find the associated marshaller for that object.</p>
<p>Going back to our example JMX use case, I can now create composite domain models in <code>src/groovy</code> such as:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> JmxNode <span style="color: #66cc66;">&#123;</span>
	<span style="color: #aaaadd; font-weight: bold;">String</span> name<span style="color: #66cc66;">;</span>
	<span style="color: #aaaadd; font-weight: bold;">String</span> description<span style="color: #66cc66;">;</span>
	<span style="color: #aaaadd; font-weight: bold;">String</span> objectName<span style="color: #66cc66;">;</span>
	List<span style="color: #66cc66;">&lt;</span>JmxAttribute<span style="color: #66cc66;">&gt;</span> attributes<span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> JmxAttribute <span style="color: #66cc66;">&#123;</span>
	<span style="color: #aaaadd; font-weight: bold;">String</span> name<span style="color: #66cc66;">;</span>
	<span style="color: #aaaadd; font-weight: bold;">String</span> description<span style="color: #66cc66;">;</span>
	<span style="color: #aaaadd; font-weight: bold;">String</span> dataType<span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>If I were to build that domain model and expose it to a resource, it would render out the complete domain graph.  Note that you will end up with other properties such as <code>class</code> and <code>version</code> which are part of the POJO/POGO.  If you want to remove those, simply create a custom handler/marshaller to not render those properties.</p>
<p>These examples are fairly trivial, but as you begin to add business logic, they will begin to become more complex.  As resources are grails artifacts and as such spring beans, you can inject them as any other controller.  This allows me to keep resources clean and delegate to services.  As such I inject services as such:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">@Path<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'…'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #000000; font-weight: bold;">class</span> JmxNodeResource <span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">// inject the associated service</span>
	<span style="color: #000000; font-weight: bold;">def</span> jmxNodeService<span style="color: #66cc66;">;</span>
	..
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The actual service is responsible for building up each part of the domain part.  A given service may delegate to other services to build up the composite model.  For example;</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> JmxNodeService <span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">// inject the attribute service</span>
	<span style="color: #000000; font-weight: bold;">def</span> jmxAttributeService<span style="color: #66cc66;">;</span>
&nbsp;
	JmxNode getJmxNode<span style="color: #66cc66;">&#40;</span>…<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		JmxNode node <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JmxNode<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
		<span style="color: #808080; font-style: italic;">// build up node</span>
		<span style="color: #808080; font-style: italic;">// get list of JMX attributes</span>
		node.<span style="color: #006600;">attributes</span> <span style="color: #66cc66;">=</span> attrs.<span style="color: #663399;">collect</span> <span style="color: #66cc66;">&#123;</span> attr <span style="color: #66cc66;">-&gt;</span>
			delegate building of JmxAttribute to the attribute service
			jmxAttributeService.<span style="color: #006600;">getJmxAttribute</span><span style="color: #66cc66;">&#40;</span>attr<span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> JmxAttributeService <span style="color: #66cc66;">&#123;</span>
	JmxAttribute getJmxAttribute<span style="color: #66cc66;">&#40;</span>…<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		…
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Now, we have clean separation from marshaling, resources, services, and domain.  In a sense, MVC for RESTful applications.  So far, though, we have only hit the tip of the iceberg, so let&#8217;s take one more example and dig a bit deeper.</p>
<p>My API example allows me to specify the JMX host as part of the URL for which I want information on.  The API basically acts as a JMX router allowing JMX properties over a common XML/JSON format.  We saw earlier on that we use <code>@Path</code> to define the URL.  Does that mean I have to have a resource for every single JMX host?  Of course not…we use substitution params and inject the values into our methods.  For example:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">@Path<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/api/jmx/{service}/mbeans/{node}'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #000000; font-weight: bold;">class</span> JmxMBeanResource <span style="color: #66cc66;">&#123;</span> … <span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This path basically allows me to specify a service as well as an MBean node.  For example, the following URL would invoke this resource class:</p>
<p><code>/api/jmx/serverB:5555/mbeans/java.lang.Management</code></p>
<p>To actually perform the lookup and handling, I delegate the resource to a JmxMBeanService class:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">@Path<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/api/jmx/{service}/mbeans{node}'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #000000; font-weight: bold;">class</span> JMXMBeanResource <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">def</span> jmxMBeanService<span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">// inject service bean</span>
&nbsp;
	@GET
	JmxNode getJmxNode<span style="color: #66cc66;">&#40;</span>…<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> jmxMBeanService.<span style="color: #006600;">getJmxNode</span><span style="color: #66cc66;">&#40;</span>…<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The service is a standard service (i.e.: <code>grails create-service</code>) that uses JMX (check out the <code><a href="http://groovy.codehaus.org/api/groovy/util/GroovyMBean.html">GroovyMBean</a></code> helper class) to lookup the MBean information and returns it as a JmxNode with a list of its JmxAttributes.  It&#8217;s as easy as that and the resource stays very clean.  However, we are still missing one part…the injection of the path parameters.  Here is where Jersey and its annotations come into play.  We inject them into the method signature:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">@GET
JmxNode getJmxNode<span style="color: #66cc66;">&#40;</span>@PathParam<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'service'</span><span style="color: #66cc66;">&#41;</span> JmxService service, @PathParam<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'node'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #aaaadd; font-weight: bold;">String</span> node, 
	           @QueryParam<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'user'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #aaaadd; font-weight: bold;">String</span> user, @QueryParam<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'pass'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #aaaadd; font-weight: bold;">String</span> pass<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">return</span> jmxMBeanService.<span style="color: #006600;">getJmxNode</span><span style="color: #66cc66;">&#40;</span>service, node, user, pass<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The first parameter injects a portion of the path as denoted by the &#8216;service&#8217; substitution variable.  In our test URL above that would be &#8216;<code>serverB:5555</code>&#8216;.  However, notice that we are injecting a value of type JmxService rather than String.  Jersey accepts any primitive type or pre-defined type (String, Date, etc).  If you need a custom type, just make sure that the custom type supports a public constructor taking a single String parameter or supports a <code>static Type valueOf(String)</code> method similar to <code>Integer.valueOf(String)</code>.</p>
<p>The third and fourth parameters allow injection of custom query parameters to allow values to be passed in other than via standard path parameters.  Jersey actually supports quite a few injectable values including cookies, headers, etc.  Jersey will perform type validation and you can even specify formats and regular expressions within the substitution params to add further validation logic.</p>
<p>As you can see we have written only a handful of code, most being the business logic aspect, and have a full defined API.  If you would like a complete sample of the code, just let me know.   I will most likely be open sourcing the API portion to GitHub later this month.</p>
<p>Thanks and as always enjoy.  If you have any questions, drop me a comment below.</p>
<p>Nick</p>
]]></content:encoded>
			<wfw:commentRss>http://www.znetdevelopment.com/blogs/2011/08/08/easy-rest-groovy-grails-and-jaxrs/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>OS X Lion: New Scrolling Behavior</title>
		<link>http://www.znetdevelopment.com/blogs/2011/07/20/os-x-lion-new-scrolling-behavior/</link>
		<comments>http://www.znetdevelopment.com/blogs/2011/07/20/os-x-lion-new-scrolling-behavior/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 03:39:24 +0000</pubDate>
		<dc:creator>Nicholas Hagen</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Multi-Touch]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[OS X Lion]]></category>
		<category><![CDATA[OSX]]></category>

		<guid isPermaLink="false">http://www.znetdevelopment.com/blogs/?p=460</guid>
		<description><![CDATA[It is only day 1, but so far, I&#8217;m already getting quickly annoyed by the new scrolling behavior&#8230;almost to the point I want to switch it back to the previous method. For those who do not know yet, Apple, in the latest version of Mac OS X (Lion), in order to more closely align with [...]]]></description>
			<content:encoded><![CDATA[<p>It is only day 1, but so far, I&#8217;m already getting quickly annoyed by the new scrolling behavior&#8230;almost to the point I want to switch it back to the previous method.  For those who do not know yet, Apple, in the latest version of Mac OS X (Lion), in order to more closely align with iOS, switched the handling of two-finger scrolling behavior.  In iOS, dragging your fingers from bottom to top scrolls down.  In previous versions of OS X, two finger dragging on the track pad from bottom to top would scroll up.  This behavior is now switched, so that bottom to top scrolls down.  The same holds true for right/left.  I&#8217;m going to give it the time to get used to it, but so far not so good.</p>
<p>I&#8217;m not sure the new method makes entire sense though.<span id="more-460"></span>  On iOS and touch-based devices, it completely makes sense as you are literally dragging the screen with your finger.  It&#8217;s a natural interaction as if you are actually pulling a piece of paper up to further read the document.  Before the introduction of multi-touch trackpads, scroll bars were the primary way to perform scrolling.  Scroll bars naturally pull down to scroll down.  As a result, you are actually dragging from top to bottom.  Scroll bars were never meant to interact directly with the viewport, but rather was meant to specify where within the viewport the content should be viewed.  It was like a range widget, for example.  Both of these cases were extremely natural.  Then, multi-touch trackpads came on the scene with two-finger scrolling to be able to ditch the scroll bars.  In this scenario, Apple maintained the top to bottom equals scroll down mentality to make it similar to as if you were literally dragging the scroll bar.  In essence, two finger scrolling was just a quick and easy way to drag the scroll bar.  Now, that logic has been completely flip-flopped and Apple wants you to think in terms of literally dragging the content rather than interacting with a scroll bar.  The problem I have with this is that you are not literally dragging and touching the document.  You are interacting with a physical touchpad.  Further, it is inherent to the brain that you pull down to drag down and pull up to drag up.  For example, a mouse with a scroll wheel would still scroll properly as it just makes sense.  You want to scroll down, scroll the mouse down.  The same should prolly hold true for the touchpad.  Otherwise, it is like trying to trick your natural brain impression.  It&#8217;s like trying to pat your head and rub your stomach&#8230;sure it can be done but you have to trick your brain to do so.</p>
<p>Here is a test to perform for yourself.  Imagine you have a touch screen macbook.  Without thinking try to scroll this article up and down with your finger.  You will prolly notice you tried to literally drag it from top to bottom to scroll down or vice-versa.  It just makes sense which is why it makes sense on iOS.  Now try to do the same experiment from the touchpad and you&#8217;ll almost certainly want to do the opposite because you are now thinking in terms of scroll bars, not windows (after all you are interacting with the scroll, not the window).  The only question I have is whether that rationale is because we have become used to scrolling in that sense from trackpads or whether it truly is natural.  Apple is betting on the former and expecting over time that the natural expectation will change to better align with iOS.  I will play with their little experiment for now, but I&#8217;m guessing I may switch back at some point.</p>
<p>How are others handling the change in Lion?  Switched yet?  Think the new way makes natural sense?</p>
<p><strong>[UPDATE Aug 8, 2011] </strong></p>
<p>It has been a few weeks now using the new scrolling behavior and honestly I have got used to it (most of the time at least).  I still find myself at times reverting to the old system and I&#8217;m still convinced it is due to the inherent expectation of using a scroll pad to do so.  The biggest issue, however, is that my brain is now really confused since at home on my Mac I use one method and then at work on my PC I use the opposite method via the scroll wheel on the mouse.  I keep going back and forth in my brain.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.znetdevelopment.com/blogs/2011/07/20/os-x-lion-new-scrolling-behavior/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

