<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Chandra Patni</title>
	<atom:link href="http://rubyorchard.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://rubyorchard.wordpress.com</link>
	<description>A blog about programming, computing</description>
	<lastBuildDate>Tue, 07 May 2013 13:54:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='rubyorchard.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Chandra Patni</title>
		<link>http://rubyorchard.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://rubyorchard.wordpress.com/osd.xml" title="Chandra Patni" />
	<atom:link rel='hub' href='http://rubyorchard.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Merge with elegance</title>
		<link>http://rubyorchard.wordpress.com/2010/09/01/merge-with-elegance/</link>
		<comments>http://rubyorchard.wordpress.com/2010/09/01/merge-with-elegance/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 07:32:34 +0000</pubDate>
		<dc:creator>Chandra Patni</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://rubyorchard.wordpress.com/?p=149</guid>
		<description><![CDATA[It&#8217;s perhaps the last time I asked this interview question last week. Write a function to return a sorted array containing all elements from two given int arrays. The input arrays are sorted but omission is intentional. Bonus points for: &#8230; <a href="http://rubyorchard.wordpress.com/2010/09/01/merge-with-elegance/"><em>Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></em></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyorchard.wordpress.com&#038;blog=11011406&#038;post=149&#038;subd=rubyorchard&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>It&#8217;s perhaps the last time I asked this interview question last week. Write a function to return a sorted array containing all elements from two given int arrays. The input arrays are sorted but omission is intentional. Bonus points for:</p>
<ol>
<li>asking if input array is already sorted?</li>
<li>identifying that it&#8217;s the merge step of merge-sort algorithm</li>
<li>or naming the function merge</li>
</ol>
<p>I have seen correct, clever, dumb, outrageous, uncomfortable and painful responses. For those who provide good answers, I ask them to identify Queue operations and think of an elegant solution instead of the fastest solution. Here is a stunningly elegant implementation of merge operation which treats input and output arrays as Queues.</p>
<pre class="ruby">

#ignore mutability of a, b
#first is peek operation and shift is dequeue operation 
def merge(a, b)
  c = []
  c &lt;&lt; (a.first &lt; b.first ? a.shift : b.shift) until 
      a.empty? || b.empty? 
  c += a
  c += b
end
</pre>
<p>Java solution in 7 lines of code:</p>
<pre class="java">
public static int[] merge(int[] a, int[] b) {
  Q cq = new Q(new int[a.length + b.length]);
  Q aq = new Q(a);
  Q bq = new Q(b);

  while(aq.notEmpty() &amp;&amp; bq.notEmpty()) 
      cq.enqueue(aq.peek() &lt; bq.peek() ? aq.dequeue() : bq.dequeue());
  while(aq.notEmpty()) cq.enqueue(aq.dequeue());
  while(bq.notEmpty()) cq.enqueue(bq.dequeue());
  
  return cq.elms;
}

//You will need a helper Queue class called Q to go with it. 
class Q {
    int current;
    int[] elms;

    Q(int[] elms) {
        this.elms = elms;
    }

    boolean notEmpty() {
        return current = elms.length;
    }

    int peek() {
        return elms[current];
    }

    int dequeue() {
        return elms[current++];
    }

    void enqueue(int elm) {
        elms[current++] = elm;
    }
}
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rubyorchard.wordpress.com/149/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rubyorchard.wordpress.com/149/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyorchard.wordpress.com&#038;blog=11011406&#038;post=149&#038;subd=rubyorchard&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rubyorchard.wordpress.com/2010/09/01/merge-with-elegance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/63b09042812754c8e25faf71e3c3f09c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rubyorchard</media:title>
		</media:content>
	</item>
		<item>
		<title>Object Notations beyond JavaScript</title>
		<link>http://rubyorchard.wordpress.com/2010/08/17/object-notations-beyond-javascript/</link>
		<comments>http://rubyorchard.wordpress.com/2010/08/17/object-notations-beyond-javascript/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 18:41:40 +0000</pubDate>
		<dc:creator>Chandra Patni</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://rubyorchard.wordpress.com/?p=115</guid>
		<description><![CDATA[JavaScript Object Notation is a data interchange format based on a subset of JavaScript. The beauty of JSON is in identifying a subset of language constructs which are safe for data interchange. For instance the following snippet represents a valid &#8230; <a href="http://rubyorchard.wordpress.com/2010/08/17/object-notations-beyond-javascript/"><em>Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></em></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyorchard.wordpress.com&#038;blog=11011406&#038;post=115&#038;subd=rubyorchard&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>JavaScript Object Notation is a data interchange format based on a subset of JavaScript. The beauty of JSON is in identifying a subset of language constructs which are safe for data interchange. For instance the following snippet represents a valid JavaScript but it&#8217;s unsafe for data interchange and is invalid JSON.</p>
<p><code><br />
{"body" : "Chunky " + "Bacon"}<br />
</code>  </p>
<p>On the the other hand, the example below is using String literals is safe for data interchange and is valid JSON.</p>
<p><code><br />
{"body" : "Chunky Bacon"}<br />
</code></p>
<p>This simple idea goes a long way. Instead of defining our own format for data interchange, we are using subset of a language for exchanging objects by computer programs and since it&#8217;s represented in JavaScript, it&#8217;s easy for programmers to understand. Once you think about safety, it&#8217;s intuitive to see the subset of language constructs useful for data interchange. </p>
<p>The idea behind JSON employing JavaScript is analogous to REST employing HTTP. This makes JSON natural format for RESTful services and typically RESTful services provide data in JSON and XML formats. However, often working with Ruby and PHP, I find neither JSON nor XML, particularly enjoyable for hacking services. I would much prefer REST services data in the native format of language I am working with. From service provider point of view, it&#8217;s worthwhile to target other dynamic languages like Ruby, PHP, Python, etc. This leads to the generalization of Object Notations which involves identifying a safe set of language constructs and using them for data interchange. For instance the Ruby and PHP Object Notations for above snippet can be represented as: </p>
<p>Ruby Object Notation:<br />
<code><br />
{:body =&gt; "Chunky Bacon"}<br />
</code></p>
<p>PHP Object Notation:<br />
<code><br />
array("body" =&gt; "Chunky Bacon")<br />
</code></p>
<p>Service provider who provide formats like XML and JSON,</p>
<ul>
<li><a href="http://api.example.com/posts/1.json" rel="nofollow">http://api.example.com/posts/1.json</a></li>
<li><a href="http://api.example.com/posts/1.xml" rel="nofollow">http://api.example.com/posts/1.xml</a></li>
</ul>
<p>should also consider other object notations like:</p>
<ul>
<li><a href="http://api.example.com/posts/1.rbon" rel="nofollow">http://api.example.com/posts/1.rbon</a></li>
<li><a href="http://api.example.com/posts/1.phpon" rel="nofollow">http://api.example.com/posts/1.phpon</a></li>
<li><a href="http://api.example.com/posts/1.pyon" rel="nofollow">http://api.example.com/posts/1.pyon</a></li>
</ul>
<p>Object notation with padding is the generalization of JSONP where the Object Notation is passed as argument to a specified function which allows programming REST easier than just returning them as values. For RESTful services, JSON and other object notations are better fit than XML. For an example in action, check out <a href="http://github.com/rubyorchard/geoip-rest">http://github.com/rubyorchard/geoip-rest</a> for GeoIP City and Country REST APIs which offer object notation in Ruby, PHP, JSON and XML formats.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rubyorchard.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rubyorchard.wordpress.com/115/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyorchard.wordpress.com&#038;blog=11011406&#038;post=115&#038;subd=rubyorchard&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rubyorchard.wordpress.com/2010/08/17/object-notations-beyond-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/63b09042812754c8e25faf71e3c3f09c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rubyorchard</media:title>
		</media:content>
	</item>
		<item>
		<title>Near-Far Cache Architecture</title>
		<link>http://rubyorchard.wordpress.com/2010/04/10/near-far-cache-architecture/</link>
		<comments>http://rubyorchard.wordpress.com/2010/04/10/near-far-cache-architecture/#comments</comments>
		<pubDate>Sun, 11 Apr 2010 04:31:21 +0000</pubDate>
		<dc:creator>Chandra Patni</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Memcached]]></category>

		<guid isPermaLink="false">http://rubyorchard.wordpress.com/?p=54</guid>
		<description><![CDATA[Near-far cache architecture is a robust architecture for deploying cache tier for web applications with following features. Improve Performance Protect data tier and do it reliably Cache consistency Deploying memcached on few nodes and keeping round trip time (RTT) from &#8230; <a href="http://rubyorchard.wordpress.com/2010/04/10/near-far-cache-architecture/"><em>Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></em></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyorchard.wordpress.com&#038;blog=11011406&#038;post=54&#038;subd=rubyorchard&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Near-far cache architecture is a robust architecture for deploying cache tier for web applications with following features.</p>
<ol>
<li>Improve Performance </li>
<li>Protect data tier and do it reliably</li>
<li>Cache consistency </li>
</ol>
<p>Deploying memcached on few nodes and keeping round trip time (RTT) from web/app servers to memcached servers Θ(sub millisecond) can easily improve the performance of web apps. So, without much work, we can easily improve the performance and meet our first goal. These nodes make the Far Cache. </p>
<p>Will far cache reliably protect data tier? Perhaps not. A digged, slashdotted, techcrunched blog post may create hot-spots in certain memcached nodes. Memcached response slowdown may cause requests to backlog and some memcached nodes are likely to fall and network switches may saturate. Hot memcached node failures may expose data tier and there is never one cockroach.  </p>
<p>To solve hot-spot problem, we introduce near caches. A near cache is a memcached node running on the web server or app server itself. We also cache a key in near cache and if we get a near cache miss, we fetch it from far cache and put into near cache. It prevents hot-spots from forming in the far cache. But wait, we just introduced another problem. The moment we start putting data into near cache, we run into cache consistency issues and user may observe the inconsistency. With near cache, inconsistency can&#8217;t be eliminated without sacrificing scale out, but we can provide user observed consistency. This can be done by near caching only for few seconds &#8212; it works just the way alternating current works. If near cache timeout is smaller than user page round trip time plus user thinking time, then a user will not observe inconsistency introduced by near cache. 3 seconds near cache timeout is a sweet spot for us and guarantees that far cache will get 20 hits per minutes per cache key per web or app server and only user visiting next link within 3 seconds may see inconsistent data in some cases when far cache is being refreshed. We may not have impressive cache hit ratio for near cache but it protects far cache and network and provides soft user observed consistency. With some domain specific tweaking of cache keys and dynamic near cache timeout, we get 85% near cache hits.</p>
<p><img src="http://rubyorchard.files.wordpress.com/2010/04/near-cache-stats.png?w=560" alt="" title="near-cache-stats"   class="alignnone size-full wp-image-69" /></p>
<p>What is the timeout for far cache? Obviously, it should be grater than near cache timeout and if the data tier can&#8217;t handle troff traffic, then it must be greater than wavelength of the traffic cycle which is typically 24 hours. If you don&#8217;t want to charge users for far cache miss as much as possible, then far cache data for a long time (a week or so) and have an application level timeout by wrapping cached values. </p>
<p><code><br />
class CacheValue {<br />
    Date last_updated;<br />
    Object value;<br />
}<br />
</code> </p>
<p>If the far cache value expires according to application level timeout, then we still serve the data from far cache but issue a background update. Keep application level timeout Θ(minutes) and Far cache timeout Θ(weeks).</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rubyorchard.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rubyorchard.wordpress.com/54/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyorchard.wordpress.com&#038;blog=11011406&#038;post=54&#038;subd=rubyorchard&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rubyorchard.wordpress.com/2010/04/10/near-far-cache-architecture/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/63b09042812754c8e25faf71e3c3f09c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rubyorchard</media:title>
		</media:content>

		<media:content url="http://rubyorchard.files.wordpress.com/2010/04/near-cache-stats.png" medium="image">
			<media:title type="html">near-cache-stats</media:title>
		</media:content>
	</item>
		<item>
		<title>New Relic RPM to monitor memcached</title>
		<link>http://rubyorchard.wordpress.com/2010/04/03/new-relic-rpm-to-monitor-memcached/</link>
		<comments>http://rubyorchard.wordpress.com/2010/04/03/new-relic-rpm-to-monitor-memcached/#comments</comments>
		<pubDate>Sun, 04 Apr 2010 02:50:23 +0000</pubDate>
		<dc:creator>Chandra Patni</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Memcached]]></category>
		<category><![CDATA[Monitoring]]></category>
		<category><![CDATA[RPM]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://rubyorchard.wordpress.com/?p=37</guid>
		<description><![CDATA[New Relic Infrastructure Agent now can be used to monitor memcached farm. It runs stats on configured memcached nodes periodically and ships data to New Relic RPM. The stats are reported  for each node and also aggregated stats are reported &#8230; <a href="http://rubyorchard.wordpress.com/2010/04/03/new-relic-rpm-to-monitor-memcached/"><em>Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></em></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyorchard.wordpress.com&#038;blog=11011406&#038;post=37&#038;subd=rubyorchard&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://rubyorchard.github.com/memcached_newrelic_ia/">New Relic Infrastructure Agent</a> now can be used to monitor memcached farm. It runs stats on configured memcached nodes periodically and ships data to New Relic RPM. The stats are reported  for each node and also aggregated stats are reported for all nodes. Check out the source at <a href="http://github.com/rubyorchard/memcached_newrelic_ia">github</a>.</p>
<p><a href="http://rubyorchard.files.wordpress.com/2010/04/newrelic-memcached-dashboard-screenshot.png"><img class="alignnone size-full wp-image-38" title="newrelic-memcached-dashboard-screenshot" src="http://rubyorchard.files.wordpress.com/2010/04/newrelic-memcached-dashboard-screenshot.png?w=560" alt=""   /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rubyorchard.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rubyorchard.wordpress.com/37/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyorchard.wordpress.com&#038;blog=11011406&#038;post=37&#038;subd=rubyorchard&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rubyorchard.wordpress.com/2010/04/03/new-relic-rpm-to-monitor-memcached/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/63b09042812754c8e25faf71e3c3f09c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rubyorchard</media:title>
		</media:content>

		<media:content url="http://rubyorchard.files.wordpress.com/2010/04/newrelic-memcached-dashboard-screenshot.png" medium="image">
			<media:title type="html">newrelic-memcached-dashboard-screenshot</media:title>
		</media:content>
	</item>
		<item>
		<title>List Accumulators</title>
		<link>http://rubyorchard.wordpress.com/2009/12/31/list-accumulators/</link>
		<comments>http://rubyorchard.wordpress.com/2009/12/31/list-accumulators/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 22:12:33 +0000</pubDate>
		<dc:creator>Chandra Patni</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Accumulators]]></category>
		<category><![CDATA[Arrays]]></category>
		<category><![CDATA[Erlang]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Lists]]></category>
		<category><![CDATA[Range]]></category>

		<guid isPermaLink="false">http://rubyorchard.wordpress.com/?p=28</guid>
		<description><![CDATA[Suppose we want to separate  a container type object into its component parts. Accumulators provide an elegant solution to this problem. We create a list of accumulators and traverse through the original list and collect each element into the appropriate &#8230; <a href="http://rubyorchard.wordpress.com/2009/12/31/list-accumulators/"><em>Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></em></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyorchard.wordpress.com&#038;blog=11011406&#038;post=28&#038;subd=rubyorchard&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Suppose we want to separate  a container type object into its component parts. Accumulators provide an elegant solution to this problem. We create a list of accumulators and traverse through the original list and collect each element into the appropriate component. In Ruby, we can use inject method to implement accumulators. Suppose we want to split a list of integers into two lists of even  and odd numbers. We create two empty accumulator lists for even and odd numbers.</p>
<p><code><br />
(5..30).inject([[], []]) do |evenOdds, n|<br />
evenOdds[n%2].push(n)<br />
evenOdds<br />
end<br />
</code></p>
<p>=&gt; [[6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30], [5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]]</p>
<p>Accumulators fit naturally into functional programming language. Here is an Erlang code to do the same.</p>
<p><code><br />
module(acc).<br />
-export([even_odds/1]).<br />
-import(lists, [reverse/1]).<br />
even_odds(List) -&gt;<br />
even_odds(List, [], []).<br />
even_odds([H|T], Evens, Odds) -&gt;<br />
case (H rem 2) of<br />
0 -&gt; even_odds(T, [H|Evens], Odds);<br />
1 -&gt; even_odds(T, Evens, [H|Odds])<br />
end;<br />
even_odds([],Evens, Odds) -&gt;<br />
[lists:reverse(Evens), lists:reverse(Odds)].<br />
</code><br />
<code><br />
acc:even_odds(lists:seq(5, 30)).<br />
</code></p>
<p>[[6,8,10,12,14,16,18,20,22,24,26,28,30],<br />
[5,7,9,11,13,15,17,19,21,23,25,27,29]]</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rubyorchard.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rubyorchard.wordpress.com/28/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyorchard.wordpress.com&#038;blog=11011406&#038;post=28&#038;subd=rubyorchard&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rubyorchard.wordpress.com/2009/12/31/list-accumulators/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/63b09042812754c8e25faf71e3c3f09c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rubyorchard</media:title>
		</media:content>
	</item>
		<item>
		<title>Bulletproof debugging method to debug Java remote debugging</title>
		<link>http://rubyorchard.wordpress.com/2009/12/25/bulletproof-debugging-method-to-debug-java-remote-debugging/</link>
		<comments>http://rubyorchard.wordpress.com/2009/12/25/bulletproof-debugging-method-to-debug-java-remote-debugging/#comments</comments>
		<pubDate>Fri, 25 Dec 2009 22:05:36 +0000</pubDate>
		<dc:creator>Chandra Patni</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Debug]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jdb]]></category>
		<category><![CDATA[jdwp]]></category>
		<category><![CDATA[JVM]]></category>
		<category><![CDATA[Remote Deugging]]></category>

		<guid isPermaLink="false">http://rubyorchard.wordpress.com/?p=15</guid>
		<description><![CDATA[JVM remote debugging tips explains how to tame JVM remote debugging <a href="http://rubyorchard.wordpress.com/2009/12/25/bulletproof-debugging-method-to-debug-java-remote-debugging/"><em>Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></em></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyorchard.wordpress.com&#038;blog=11011406&#038;post=15&#038;subd=rubyorchard&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>JVM remote debugging can be sometime tricky and elusive &#8212; especially when the process is running as a service. How can you separate JVM issues from other factors such as process running as service as a different user,  firewall blocking debug  port. One way to separate these is to know a bulletproof configuration for JVM remote debugging. Without further ado, here it is:</p>
<p><code>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005</code></p>
<p>Note that  this only applies to Java 5 and above. If you are still in  stone ages, hopefully you are not reading this blog either. This is great but how can I test it quickly? I still can&#8217;t connect. My server runs headless Linux environment, and I don&#8217;t have access to my pretty IDE. One method to use telnet.</p>
<p><code>telnet silly.example.com 5005</code></p>
<p>It works but there is something better. Command line <code>jdb</code> and its little known use to connect to remote process. You can also use it do debugging if you like.</p>
<p><code>/usr/java/current/bin/jdb -connect com.sun.jdi.SocketAttach:hostname=silly.example.com,port=5005</code><br />
Set uncaught java.lang.Throwable<br />
Set deferred uncaught java.lang.Throwable<br />
Initializing jdb &#8230;<br />
&gt; <kbd>exit</kbd></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rubyorchard.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rubyorchard.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyorchard.wordpress.com&#038;blog=11011406&#038;post=15&#038;subd=rubyorchard&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rubyorchard.wordpress.com/2009/12/25/bulletproof-debugging-method-to-debug-java-remote-debugging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/63b09042812754c8e25faf71e3c3f09c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rubyorchard</media:title>
		</media:content>
	</item>
		<item>
		<title>Oracle Hierarchical Query in Hibernate</title>
		<link>http://rubyorchard.wordpress.com/2008/03/09/oracle-hierarchical-query-in-hibernate/</link>
		<comments>http://rubyorchard.wordpress.com/2008/03/09/oracle-hierarchical-query-in-hibernate/#comments</comments>
		<pubDate>Mon, 10 Mar 2008 01:51:00 +0000</pubDate>
		<dc:creator>Chandra Patni</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://rubyorchard.wordpress.com/2008/03/09/oracle-hierarchical-query-in-hibernate</guid>
		<description><![CDATA[When you need them, there is no replacement of Oracle hierarchical queries. They scale linearly with each level while a join would scale exponentially. At the same time, we would like Hibernate to do the hard work of mapping result &#8230; <a href="http://rubyorchard.wordpress.com/2008/03/09/oracle-hierarchical-query-in-hibernate/"><em>Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></em></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyorchard.wordpress.com&#038;blog=11011406&#038;post=12&#038;subd=rubyorchard&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>When you need them, there is no replacement of Oracle hierarchical queries. They scale linearly with each level while a join would scale exponentially. At the same time, we would like Hibernate to do the hard work of mapping result set to entities. Here is an example of Hibernate Native Query which would fetch the organization chart from famous scott.emp table.<br />
<code><br />
Session  s = (Session) em.getDelegate();<br />
String orgChartQuery = "select {emp.*} from EMP {emp} \n" +<br />
"start with emp.mgr is null \n" +<br />
"connect by prior emp.empno = emp.mgr\n" +<br />
"order siblings by ename";<br />
@SuppressWarnings("unchecked")<br />
List list = s.createSQLQuery(orgChartQuery)<br />
.addEntity("emp", Employee.class)<br />
.list();<br />
</code><br />
Now suppose we want to render this in a tree control with breadcurms. We can use the following query.</p>
<p><code><br />
Session  s = (Session) em.getDelegate();<br />
String orgChartQuery = "select sys_connect_by_path(emp.empno, '/') breadcrum,\n"+<br />
"level, {emp.*} from EMP {emp} \n" +<br />
"start with emp.mgr is null \n" +<br />
"connect by prior emp.empno = emp.mgr\n" +<br />
"order siblings by ename";<br />
@SuppressWarnings("unchecked")<br />
List list = s.createSQLQuery(orgChartQuery)<br />
.addScalar("breadcrum", Hibernate.STRING)<br />
.addScalar("level", Hibernate.INTEGER)<br />
.addEntity("emp", Employee.class)<br />
.list();<br />
for (Object[] objects : list) {<br />
String breadcrum = (String) objects[0];<br />
Integer level = (Integer) objects[1];<br />
Employee emp = (Employee) objects[2];<br />
System.out.println(breadcrum +"  "+ level + "   "+emp.getName()<br />
+ " "+emp.getDepartment().getName());<br />
}<br />
</code><br />
Breadcrums willl give you path to the object from the root and level gives the 1 based level in the tree.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/rubyorchard.wordpress.com/12/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/rubyorchard.wordpress.com/12/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rubyorchard.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rubyorchard.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyorchard.wordpress.com&#038;blog=11011406&#038;post=12&#038;subd=rubyorchard&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rubyorchard.wordpress.com/2008/03/09/oracle-hierarchical-query-in-hibernate/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/63b09042812754c8e25faf71e3c3f09c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rubyorchard</media:title>
		</media:content>
	</item>
		<item>
		<title>Handling Date with Google Gears</title>
		<link>http://rubyorchard.wordpress.com/2008/01/11/handling-date-with-google-gears/</link>
		<comments>http://rubyorchard.wordpress.com/2008/01/11/handling-date-with-google-gears/#comments</comments>
		<pubDate>Fri, 11 Jan 2008 18:53:00 +0000</pubDate>
		<dc:creator>Chandra Patni</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Google-Gears]]></category>
		<category><![CDATA[JS]]></category>

		<guid isPermaLink="false">http://rubyorchard.wordpress.com/2008/01/11/handling-date-with-google-gears</guid>
		<description><![CDATA[Suppose you execute the following DML statement in Google Gears: db.execute( "insert or replace into mytable "+ "(id, modified_on) values (?, ?)", [null, new Date()] ); This seemingly works but you are in for a surprise because Date is stored &#8230; <a href="http://rubyorchard.wordpress.com/2008/01/11/handling-date-with-google-gears/"><em>Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></em></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyorchard.wordpress.com&#038;blog=11011406&#038;post=11&#038;subd=rubyorchard&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Suppose you execute the following DML statement in Google Gears:<br />
<code>db.execute(<br />
"insert or replace into mytable "+<br />
"(id, modified_on) values (?, ?)",<br />
[null, new Date()]<br />
);</code><br />
This seemingly works but you are in for a surprise because Date is stored as Date.toString(). SQLite ducktying brain can&#8217;t infer that it&#8217;s a date datum. If you ran select query you will get string back.<br />
<code>Sat Jan 12 2008 02:34:58 GMT-0800 »<br />
(Pacific Standard Time)</code><br />
The downside of storing date as text that you can&#8217;t use any SQLite date time functions in your queries. Due to manifest typing, SQLite happily stores text in a date column. We would like to do better. We would like to store JavaScript Date as native SQLite Date without any loss of information. SQLite itself stores date in Julian Day representation while JavaScript cannonical date representation is number of milliseconds since 1 January 1970 00:00:00 UTC. So, we need to convert JavaScript Date to either Julian Day or text as understood by SQLite. Considering the ease of implementation, efficiency and lossless representation, YYYY-MM-DDTHH:MM:SS.FFF date format seems to fit the bill. This is ISO8601 format. However after some digging in SQLite code, it turns out that if it SQLite also works even if we don&#8217;t zero pad fields. So this simple JavaScript method with minor departure from ISO8601 format does the job well.<br />
<code>dateToSQLiteFormat = function(date) {<br />
return date.getUTCFullYear()+<br />
"-"+date.getUTCMonth() + 1+<br />
"-"+date.getUTCDate()+<br />
"T"+date.getUTCHours()+<br />
":"+date.getUTCMinutes()+<br />
":"+date.getUTCSeconds()+"."+<br />
date.getUTCMilliseconds();<br />
};</code><br />
So far so good. How about converting SQLite dates to JavaScript Date object. This function does that trick.<br />
<code>dateSqlFragment = function(column, alias) {<br />
return " ((strftime('%s', "+column+") -<br />
strftime('%S', "+column+"))*1000 +<br />
strftime('%f', "+column+")*1000) "+<br />
(alias "");<br />
};</code></p>
<p>var rs = db.execute(<br />
&#8220;select id, &#8220;+dateSqlFragment(&#8220;modified_on&#8221;) +<br />
&#8221; from mytable&#8221;);<br />
&#8230;<br />
Date date = new Date(rs.field(1));</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/rubyorchard.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/rubyorchard.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rubyorchard.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rubyorchard.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyorchard.wordpress.com&#038;blog=11011406&#038;post=11&#038;subd=rubyorchard&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rubyorchard.wordpress.com/2008/01/11/handling-date-with-google-gears/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/63b09042812754c8e25faf71e3c3f09c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rubyorchard</media:title>
		</media:content>
	</item>
		<item>
		<title>Smart Copy Plugin for IntelliJ</title>
		<link>http://rubyorchard.wordpress.com/2007/05/04/smart-copy-plugin-for-intellij/</link>
		<comments>http://rubyorchard.wordpress.com/2007/05/04/smart-copy-plugin-for-intellij/#comments</comments>
		<pubDate>Fri, 04 May 2007 12:13:00 +0000</pubDate>
		<dc:creator>Chandra Patni</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[IntelliJ]]></category>
		<category><![CDATA[SmartCopy]]></category>

		<guid isPermaLink="false">http://rubyorchard.wordpress.com/2007/05/04/smart-copy-plugin-for-intellij</guid>
		<description><![CDATA[IntelliJ always seems to do The Right Thing. It comes with code-aware features such as Smart Line Joins, and Smart Line Split. However, there is not Smart Copy to complement Smart Paste. Besides symmetry, there are good reasons to have &#8230; <a href="http://rubyorchard.wordpress.com/2007/05/04/smart-copy-plugin-for-intellij/"><em>Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></em></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyorchard.wordpress.com&#038;blog=11011406&#038;post=10&#038;subd=rubyorchard&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><span class="blsp-spelling-error" id="SPELLING_ERROR_0"><span class="blsp-spelling-error" id="SPELLING_ERROR_0">IntelliJ</span></span> always seems to do The Right Thing. It comes with code-aware features such as <a href="http://blogs.jetbrains.com/idea/2007/03/using-smart-line-joins/">Smart Line Joins</a>, and <a href="http://www.jetbrains.com/idea/docs/help/editing/otherediting.html#smartSplit">Smart Line Split</a>. However, there is not <strong>Smart Copy</strong> to complement <a href="http://www.jetbrains.com/idea/docs/help/editing/otherediting.html#smartPaste">Smart Paste</a>. Besides <span class="blsp-spelling-corrected" id="SPELLING_ERROR_1">symmetry</span>, there are good reasons to have Smart Copy. <span class="blsp-spelling-error" id="SPELLING_ERROR_1">Supppose</span>, you have a <span class="blsp-spelling-error" id="SPELLING_ERROR_2">SQL</span> query in Java Code and you want to run it in <span class="blsp-spelling-error" id="SPELLING_ERROR_3">SQLPlus</span> to see an execution plan. Another example could be embedded XML as compile time constant. When you copy a query embedded in a Java class, perhaps you are interested in its value without without the quotes and plus characters clinging to the copied text.<br />If you are a surprised user, you are not alone. <a href="http://plugins.intellij.net/plugin/?id=1464">Smart Copy</a> is a <span class="blsp-spelling-error" id="SPELLING_ERROR_5">plugin</span> to copy the literal values. Smart Copy action maps to <em><span class="blsp-spelling-error" id="SPELLING_ERROR_6">Ctrl</span>+Alt+Shift+C</em> by default. It copies the value of compile time constants and String literals to the system clipboard. It also copies the selected literals. Entire expression is copied if noting is selected. If it cannot do smart copy, it will fallback to regular copy action. Certainly a candidate for your <em><span class="blsp-spelling-error" id="SPELLING_ERROR_7">Ctrl</span>+C</em> mapping.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/rubyorchard.wordpress.com/10/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/rubyorchard.wordpress.com/10/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rubyorchard.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rubyorchard.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyorchard.wordpress.com&#038;blog=11011406&#038;post=10&#038;subd=rubyorchard&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rubyorchard.wordpress.com/2007/05/04/smart-copy-plugin-for-intellij/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/63b09042812754c8e25faf71e3c3f09c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rubyorchard</media:title>
		</media:content>
	</item>
		<item>
		<title>Maven debug output</title>
		<link>http://rubyorchard.wordpress.com/2007/04/28/maven-debug-output/</link>
		<comments>http://rubyorchard.wordpress.com/2007/04/28/maven-debug-output/#comments</comments>
		<pubDate>Sat, 28 Apr 2007 18:24:00 +0000</pubDate>
		<dc:creator>Chandra Patni</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Debug]]></category>
		<category><![CDATA[Maven]]></category>

		<guid isPermaLink="false">http://rubyorchard.wordpress.com/2007/04/28/maven-debug-output</guid>
		<description><![CDATA[Imagine you are frustrated by one of the maven plugin and you want to turn the debug output on. Google debugging a maven plugin or maven debug output and you may still be out of luck. Here is the brute &#8230; <a href="http://rubyorchard.wordpress.com/2007/04/28/maven-debug-output/"><em>Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></em></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyorchard.wordpress.com&#038;blog=11011406&#038;post=8&#038;subd=rubyorchard&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Imagine you are frustrated by one of the maven plugin and you want to turn the debug output on. Google debugging a maven plugin or maven debug output and you may still be out of luck. Here is the brute force way of doing it.<br />
Open MAVEN_HOME/core/plexus-container-default-1.0-alpha-9.jar and edit org/codehaus/plexus/plexus-bootstrap.xml to set threshold to debug.</p>
<p><code>&lt;component&gt;<br />
&lt;role&gt;org.codehaus.plexus.logging.LoggerManager&lt;/role&gt;<br />
&lt;implementation&gt;<br />
org.codehaus.plexus.logging.console.ConsoleLoggerManager<br />
&lt;/implementation&gt;<br />
&lt;lifecycle-handler&gt;basic&lt;/LIFECYCLE-HANDLER&gt;<br />
&lt;configuration&gt;<br />
&lt;threshold&gt;debug&lt;/threshold&gt;<br />
&lt;/configuration&gt;<br />
&lt;/component&gt;<br />
</code></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/rubyorchard.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/rubyorchard.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rubyorchard.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rubyorchard.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyorchard.wordpress.com&#038;blog=11011406&#038;post=8&#038;subd=rubyorchard&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rubyorchard.wordpress.com/2007/04/28/maven-debug-output/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/63b09042812754c8e25faf71e3c3f09c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rubyorchard</media:title>
		</media:content>
	</item>
	</channel>
</rss>
