<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1395877744790071528</id><updated>2026-06-22T12:18:12.483+05:30</updated><category term="JavaScript"/><category term="Java"/><category term="Ext Js"/><category term="Google"/><category term="Guava"/><category term="Design Patterns"/><category term="CSS"/><category term="HTML"/><category term="Optimization"/><category term="Performance"/><category term="AngularJs"/><category term="CSS Specificity"/><category term="Chromium"/><category term="Guice"/><category term="HTML5"/><category term="JMeter"/><category term="Load Testing"/><category term="Singleton"/><category term="WCF"/><category term="chrome"/><category term="iframe"/><category term="jsfiddle"/><category term="localStorage"/><category term="password"/><category term="security"/><category term="underscorejs"/><title type='text'>Coding</title><subtitle type='html'>We can&#39;t solve problems by using the same kind of thinking we used when we created them - Albert Einstein</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>46</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-3719953695456870466</id><published>2020-10-18T20:07:00.020+05:30</published><updated>2021-04-27T06:07:42.233+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Design Patterns"/><title type='text'>Application Design Notes</title><content type='html'>&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Don’t be afraid to write your own code, but be absolutely sure you need to&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Don&#39;t reinvent the wheel&lt;/li&gt;&lt;li&gt;Learn more about your libraries and take full advantage&amp;nbsp;&lt;/li&gt;&lt;li&gt;Date time calculation is hard (&lt;a href=&quot;https://en.wikipedia.org/wiki/Leap_second&quot; target=&quot;_blank&quot;&gt;leap second&lt;/a&gt;,&amp;nbsp;&lt;a href=&quot;https://en.wikipedia.org/wiki/Leap_year&quot; target=&quot;_blank&quot;&gt;leap year&lt;/a&gt;), use trusted library&amp;nbsp;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;https://github.com/js-joda/js-joda&quot;&gt;js-joda&lt;/a&gt;,&amp;nbsp;&lt;a href=&quot;https://momentjs.com/&quot; target=&quot;_blank&quot;&gt;momentJs&lt;/a&gt;,&amp;nbsp;&lt;a href=&quot;https://www.joda.org/joda-time/index.html&quot; target=&quot;_blank&quot;&gt;joda (java)&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;li&gt;Simple is better than perfect (nearly) every time&lt;/li&gt;&lt;ul&gt;&lt;li&gt;If you can deliver a sub-optimal solution (that solves the problem but has known limitation) in a week instead of a full featured one in a month DO, IT&lt;/li&gt;&lt;li&gt;Simple system are&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Easy to reason about&amp;nbsp;&lt;/li&gt;&lt;li&gt;Easy to debug&lt;/li&gt;&lt;li&gt;Easy to refactor&lt;/li&gt;&lt;li&gt;Easy to learn&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Simple doesn&#39;t mean you skip good engineering, but you can use duct tape.&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Build things the right way from the start, refactoring is hard and expensive&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Security&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;/2016/03/how-to-store-user-password-at-server.html&quot; target=&quot;_blank&quot;&gt;Manage and store passwords&amp;nbsp;securely&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;a href=&quot;https://opentelemetry.io/&quot; target=&quot;_blank&quot;&gt;Telemetry&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Common retrofitting &quot;grunt work&quot;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Internationalization + localization&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://www.w3.org/WAI/standards-guidelines/wcag/&quot; target=&quot;_blank&quot;&gt;Web Content Accessibility&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Factoring and styling HTML UI&lt;/li&gt;&lt;li&gt;Adding unit test to an existing codebase&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;li&gt;LOG LOG LOG Log, but do it right&lt;/li&gt;&lt;ul&gt;&lt;li&gt;We spend lot of time reading and processing log&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Use&amp;nbsp;&lt;a href=&quot;https://martinfowler.com/articles/patterns-of-distributed-systems/log-segmentation.html&quot; target=&quot;_blank&quot;&gt;log-segmentation&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;When error occur log as much context as possible&lt;/li&gt;&lt;li&gt;Make changing logging verbosity cheap and easy to update at same time&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Build Profiling into your product code&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Performance problem usually occur first time in production&lt;/li&gt;&lt;li&gt;Many large-scale production enviroment are hard to replicate&amp;nbsp;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Have a way to access critical profiling info for production process&lt;/li&gt;&lt;li&gt;Custom HTTMP/Tenet interface&lt;/li&gt;&lt;li&gt;Shared memory window&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;li&gt;Monitor your product end to end not just sub system (&lt;a href=&quot;https://opentelemetry.io/&quot; target=&quot;_blank&quot;&gt;Telemetry&lt;/a&gt;)&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Monitor the entire system end to end the same way as user see it&amp;nbsp;&lt;/li&gt;&lt;li&gt;Monitor the health of individual component&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Avoid platform specific feature wherever you can&amp;nbsp;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Migration can be very-very expensive same time impossible&lt;/li&gt;&lt;li&gt;Running testing on multiple platforms will expose bugs faster&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Write your code like you trust no one&amp;nbsp;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Always test precondition before function execute&amp;nbsp;&lt;/li&gt;&lt;li&gt;If something should be in give state, test for it&lt;/li&gt;&lt;li&gt;Sanitize input and output&lt;/li&gt;&lt;li&gt;Leave these tests in production code&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Choose your dependencies carefully&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Every dependency is a liability. You have to fix (or get fix) any error in them&lt;/li&gt;&lt;li&gt;Prefer open source to close source&amp;nbsp;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;At least you have the option of fixing a problem&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Dependency often increase complexity&amp;nbsp;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Build&lt;/li&gt;&lt;li&gt;Packaging&amp;nbsp;&lt;/li&gt;&lt;li&gt;Licensing&lt;/li&gt;&lt;li&gt;Security, verification (XSS, SQL injection, buffer overflow..)&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;li&gt;If you can pre-generate something, do it&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Lookup table are an underutilized secret weapon&amp;nbsp;&lt;/li&gt;&lt;li&gt;Memory is cheap&lt;/li&gt;&lt;li&gt;Pre calculate result if&lt;/li&gt;&lt;ul&gt;&lt;li&gt;The input to a computation is known to be in given range&lt;/li&gt;&lt;ul&gt;&lt;li&gt;The number of different results is relatively small (&amp;lt;1 Billion)&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Calculation is sufficiently complex&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Example - Pre-compute the time zone conversion from UTC to all time zone for all hours from 01/01/1991 to 12/31/2020&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Why this is complex to calculate?&amp;nbsp;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;23,24,25 hours days DST change must be accurate for historic dates. &lt;a href=&quot;https://www.laphamsquarterly.org/roundtable/time-lords&quot; target=&quot;_blank&quot;&gt;blog&lt;/a&gt;, &lt;a href=&quot;https://www.iana.org/time-zones&quot; target=&quot;_blank&quot;&gt;Time Zone Database&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;li&gt;Applications do crash often&amp;nbsp;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Avoid DDOS attack&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Use &lt;a href=&quot;https://en.wikipedia.org/wiki/Rate_limiting&quot; target=&quot;_blank&quot;&gt;Rate limit&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Every feature will be misused or abused&lt;/li&gt;&lt;li&gt;Isolate to avoid cascade failure&amp;nbsp;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Use &lt;a href=&quot;https://martinfowler.com/bliki/CircuitBreaker.html&quot; target=&quot;_blank&quot;&gt;Circuit breaker&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;No such thing as a long-lived process&lt;/li&gt;&lt;ul&gt;&lt;li&gt;If hardware fails or power removed your process will crash&lt;/li&gt;&lt;li&gt;Design system to be fault tolerant to process re-start&lt;/li&gt;&lt;ul&gt;&lt;li&gt;All state must be external to process&lt;/li&gt;&lt;li&gt;Try to keep services and process stateless&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;li&gt;Keep sever stateless&amp;nbsp;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;One app server should not affect any other server&lt;/li&gt;&lt;li&gt;Server will be easy to scale&amp;nbsp;&lt;/li&gt;&lt;li&gt;Separate cache service from other server to avoid resource contention&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;li&gt;Cache appropriately&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Data, metadata, configuration, static data&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Store redundant&lt;/li&gt;&lt;li&gt;Partition by functions&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Allow people to work independently on features&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Split horizontally&lt;/li&gt;&lt;ul&gt;&lt;li&gt;If you can’t split, you can’t scale&amp;nbsp;&lt;/li&gt;&lt;li&gt;Use standard load balance to route incoming traffic&amp;nbsp;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Because application service created equal and not retain any transaction state&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;li&gt;Decouple functions asynchronously&amp;nbsp;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;If A call B synchronously, A &amp;amp; B are tightly couple. So, if B is down then A is down.&amp;nbsp;&lt;/li&gt;&lt;li&gt;A should be integrated B with asynchronously (with queue, multicast message, path processing, event driven architecture)&lt;/li&gt;&lt;li&gt;&amp;nbsp;Avoid synchronous coupling as much as possible&lt;/li&gt;&lt;li&gt;Move processing to asynchronously flow&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Asynchronously flow example can be&amp;nbsp;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Activity tracking, billing, settlement, reporting, email&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;li&gt;Use &lt;a href=&quot;https://martinfowler.com/articles/feature-toggles.html&quot; target=&quot;_blank&quot;&gt;Feature Toggling&lt;/a&gt; to deliver new functionality to users rapidly but safely.&lt;/li&gt;&lt;li&gt;Virtualize at all level&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Virtual IP for DBs&lt;/li&gt;&lt;li&gt;Virtual IP for load balancer&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/3719953695456870466/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2020/10/application-design-notes.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/3719953695456870466'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/3719953695456870466'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2020/10/application-design-notes.html' title='Application Design Notes'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-8580042162023833834</id><published>2016-03-28T18:48:00.000+05:30</published><updated>2016-04-08T01:44:45.811+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CSS"/><category scheme="http://www.blogger.com/atom/ns#" term="CSS Specificity"/><category scheme="http://www.blogger.com/atom/ns#" term="HTML"/><title type='text'>CSS Specificity</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h5&gt;
&lt;strong&gt;&lt;u&gt;&lt;/u&gt;&lt;/strong&gt;&amp;nbsp;&lt;/h5&gt;
&lt;h5&gt;
&amp;nbsp;&lt;/h5&gt;
&lt;br /&gt;
&lt;h4&gt;
Many time different CSS rules overlap on one or more element. And some people always get confuse about, which rule will take higher priority then other and why? CSS Specificity is the answer of all these kind of questions. &lt;/h4&gt;
&lt;br /&gt;
As the name suggest, the CSS rule which is more specific to the element will take higher priority then other. Means something like “#some_id{}” will always take higher priority then “*{}” universal selector.&amp;nbsp; And if duplicate rules are define then the last rule will be applied to the element. &lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;u&gt;&lt;b&gt;The following list of selectors is by increasing specificity:&lt;/b&gt;&lt;/u&gt; &lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Type selector (e.g., div) and pseudo-elements in selector (e.g., :after) 
&lt;/li&gt;
&lt;li&gt;Class selectors (e.g., .some_class), attributes selectors (e.g., [type=”radio”]) and pseudo-class selector (e.g., :hover) 
&lt;/li&gt;
&lt;li&gt;Id selectors (e.g., #some_id)&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
ID takes higher priority then Class, Type and Universal selector (Note: Universal selector has no effect on specificity, see below special conditions).&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXxbYpEyL2ajaMwpb60tRZ8S0pct7dcOcMiXYMwVNOlWL0IU3M8UeLQqSASBzhlGShYuzYHbfjzukIssUJ_4QE4b2wgMPYK8R5oXuRv7heKSwdEnWQwGIwlYqkEWa3bA-XcpAFUHOJjPw/s1600/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXxbYpEyL2ajaMwpb60tRZ8S0pct7dcOcMiXYMwVNOlWL0IU3M8UeLQqSASBzhlGShYuzYHbfjzukIssUJ_4QE4b2wgMPYK8R5oXuRv7heKSwdEnWQwGIwlYqkEWa3bA-XcpAFUHOJjPw/s1600/1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If duplicate rules are given, then last rule will override the earlier one.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3M0zOxvFcI0OPRvJaTy6XDOyRAzNL2owtu5ntUTHmehr9jR6lc2KlWz_-zj0ASLBRI5HNcSr2J74QlpewUowvLK5Vj8yjSBg3OM21-xwLsTyo284rXdV-BTFdjs8HUN_06dy0w41Th3w/s1600/2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3M0zOxvFcI0OPRvJaTy6XDOyRAzNL2owtu5ntUTHmehr9jR6lc2KlWz_-zj0ASLBRI5HNcSr2J74QlpewUowvLK5Vj8yjSBg3OM21-xwLsTyo284rXdV-BTFdjs8HUN_06dy0w41Th3w/s1600/2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Some special conditions while deciding the selector specificity&lt;/b&gt;:&lt;/u&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;No effect on specificity: Universal selector (*), combinators (+, &amp;gt;, ~, ‘&amp;nbsp; ‘) and negation pseudo-class (:not()) 
&lt;/li&gt;
&lt;li&gt;Inline style always overwrite any styles in external stylesheets and it has highest specificity. 
&lt;/li&gt;
&lt;li&gt;“!important” declaration overrides any other declarations. Although has nothing to do with specificity, but it is a exception.&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
But some time use case become more complex then this, and we have to calculate the selector’s specificity accurately. &lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;strong&gt;Calculating specificity &lt;/strong&gt;&lt;/u&gt;&lt;br /&gt;
&lt;u&gt;&lt;strong&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/u&gt;
As per the &lt;a href=&quot;https://www.w3.org/TR/selectors/#negation&quot;&gt;W3C Recommendation, selector’s specificity&lt;/a&gt; is calculated as follows&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Count the number of ID selectors in the selector (= a) 
&lt;/li&gt;
&lt;li&gt;Count the number of class selectors, attributes selectors, and pseudo-classes in the selector (= b) 
&lt;/li&gt;
&lt;li&gt;Count the number of type selectors and pseudo-elements in the selector (= c) 
&lt;/li&gt;
&lt;li&gt;Ignore the universal selector&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
Selectors inside the negation pseudo-class (i.e&amp;nbsp; :not(x)) are counted like any other, but the negation itself does not count as a pseudo-class.&lt;br /&gt;
Concatenating the three numbers a-b-c (in a number system with a large base) gives the specificity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;Example&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinKI5Tv_EeFLMgw6ba5B3OSCpJ4rqb_Ztu52S1dfUlN0xUzWLoIPMyrA-0GwOsGrfaW0seRUyA319Kz2Lm5ucBtLw44oWOhQn-ezA4e-vsoKGSMyFF1eFi-h_quDoegXAed5xCP54IkZE/s1600/3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinKI5Tv_EeFLMgw6ba5B3OSCpJ4rqb_Ztu52S1dfUlN0xUzWLoIPMyrA-0GwOsGrfaW0seRUyA319Kz2Lm5ucBtLw44oWOhQn-ezA4e-vsoKGSMyFF1eFi-h_quDoegXAed5xCP54IkZE/s1600/3.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
After calculating the specificity &quot;div#div&quot; has highest specificity then others, so this rule will be applied,&lt;br /&gt;
1. div &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; - specificity: 1&lt;br /&gt;
2. div#div &amp;nbsp;- specificity: 101&lt;br /&gt;
3. #div &amp;nbsp; &amp;nbsp; &amp;nbsp; - specificity: 100&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;Some Examples for specificity calculation:&lt;/u&gt; &lt;br /&gt;
&lt;blockquote&gt;
&lt;br /&gt;
&lt;pre&gt;* { }                       /* a=0 b=0 c=0 -&amp;gt; specificity =   0 */
li { }                      /* a=0 b=0 c=1 -&amp;gt; specificity =   1 */
li:first-line { }           /* a=0 b=0 c=2 -&amp;gt; specificity =   2 */
ul li { }                   /* a=0 b=0 c=2 -&amp;gt; specificity =   2 */
ul ol+li { }                /* a=0 b=0 c=3 -&amp;gt; specificity =   3 */
h1 + *[rel=up] { }          /* a=0 b=1 c=1 -&amp;gt; specificity =  11 */
ul ol li.red { }            /* a=0 b=1 c=3 -&amp;gt; specificity =  13 */
li.red.level { }            /* a=0 b=2 c=1 -&amp;gt; specificity =  21 */
style=””                    /* highest specificity        =1000 */
p { }                       /* a=0 b=0 c=1 -&amp;gt; specificity =   1 */
div p { }                   /* a=0 b=0 c=2 -&amp;gt; specificity =   2 */
.sith                       /* a=0 b=1 c=1 -&amp;gt; specificity =  10 */
div p.sith { }              /* a=0 b=1 c=2 -&amp;gt; specificity =  12 */
#sith { }                   /* a=1 b=0 c=0 -&amp;gt; specificity = 100 */
#sith:not(div) { }          /* a=1 b=0 c=1 -&amp;gt; specificity = 101 */
body #darkside .sith p { }  /* a=1 b=1 c=2 -&amp;gt; specificity = 112 */
&lt;/pre&gt;
&amp;nbsp; &lt;/blockquote&gt;
PS: 
&lt;br /&gt;
&lt;a href=&quot;https://www.w3.org/TR/selectors/#specificity&quot; title=&quot;https://www.w3.org/TR/selectors/#specificity&quot;&gt;https://www.w3.org/TR/selectors/#specificity&lt;/a&gt; 
&lt;br /&gt;
&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity&quot; title=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity&quot;&gt;https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity&lt;/a&gt; 
&lt;br /&gt;
&lt;a href=&quot;https://stuffandnonsense.co.uk/archives/css_specificity_wars.html&quot; title=&quot;https://stuffandnonsense.co.uk/archives/css_specificity_wars.html&quot;&gt;https://stuffandnonsense.co.uk/archives/css_specificity_wars.html&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/8580042162023833834/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2016/03/css-specificity.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/8580042162023833834'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/8580042162023833834'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2016/03/css-specificity.html' title='CSS Specificity'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXxbYpEyL2ajaMwpb60tRZ8S0pct7dcOcMiXYMwVNOlWL0IU3M8UeLQqSASBzhlGShYuzYHbfjzukIssUJ_4QE4b2wgMPYK8R5oXuRv7heKSwdEnWQwGIwlYqkEWa3bA-XcpAFUHOJjPw/s72-c/1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-5981821548619970382</id><published>2016-03-24T23:40:00.004+05:30</published><updated>2016-03-24T23:44:02.429+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="password"/><category scheme="http://www.blogger.com/atom/ns#" term="security"/><title type='text'>How to store user password at server!!!</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Trick is, you should never store user password… never ever. &lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the real question is, then how to authenticate and authorize the user with password. And answer is when user enter the password, we should encrypt the password and store the hints.&lt;br /&gt;
&lt;br /&gt;
So next time when user enter the password we follow the same process and compare hints, if both hints are same then password is matched, else it is wrong password. &lt;br /&gt;
&lt;br /&gt;
Next question will be, what kind of hints, and how to generate these hints. &lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;In simple term hints are the obfuscated and fragmented form of user password. 
&lt;/li&gt;
&lt;li&gt;And very important part is hints generation process, which have to be &lt;a href=&quot;https://en.wikipedia.org/wiki/Collision_resistance&quot;&gt;collision resistant&lt;/a&gt;, means there will be very less possibility to find the data which generate same hints (like &lt;a href=&quot;https://en.wikipedia.org/wiki/Cryptographic_hash_function&quot;&gt;Cryptographic hashing functions&lt;/a&gt;&lt;strong&gt;).&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is the simple checklist of password hashing and storing, which you should always keep in mind. 
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1Xrsg4Zqjy1O51dLJJCcDxUpEE5ALo9rxct6TgdDYML7ellagt5sRLapavX3AWzFL53Q6YrpznDnIKn2J2CnGD_CuRKxlsECvTB_wXhQhKgAzK5J3vC30zgfuLKkdaOFNGn1GTawOGG8/s1600/password_hashing.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1Xrsg4Zqjy1O51dLJJCcDxUpEE5ALo9rxct6TgdDYML7ellagt5sRLapavX3AWzFL53Q6YrpznDnIKn2J2CnGD_CuRKxlsECvTB_wXhQhKgAzK5J3vC30zgfuLKkdaOFNGn1GTawOGG8/s1600/password_hashing.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;PS&lt;/strong&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;h3&gt;
&lt;a href=&quot;http://blog.codinghorror.com/youre-probably-storing-passwords-incorrectly/&quot;&gt;You&#39;re Probably Storing Passwords Incorrectly&lt;/a&gt;&lt;/h3&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
&lt;a href=&quot;http://www.aspheute.com/english/20040105.asp&quot;&gt;Storing Passwords - done right!&quot;&lt;/a&gt;&lt;/h3&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
&lt;a href=&quot;https://nakedsecurity.sophos.com/2013/11/20/serious-security-how-to-store-your-users-passwords-safely/&quot;&gt;Serious Security: How to store your users’ passwords safely&lt;/a&gt;&lt;/h3&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/5981821548619970382/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2016/03/how-to-store-user-password-at-server.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/5981821548619970382'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/5981821548619970382'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2016/03/how-to-store-user-password-at-server.html' title='How to store user password at server!!!'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1Xrsg4Zqjy1O51dLJJCcDxUpEE5ALo9rxct6TgdDYML7ellagt5sRLapavX3AWzFL53Q6YrpznDnIKn2J2CnGD_CuRKxlsECvTB_wXhQhKgAzK5J3vC30zgfuLKkdaOFNGn1GTawOGG8/s72-c/password_hashing.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-3781308494885426354</id><published>2015-10-15T12:50:00.000+05:30</published><updated>2015-10-15T12:51:37.973+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="chrome"/><category scheme="http://www.blogger.com/atom/ns#" term="Chromium"/><category scheme="http://www.blogger.com/atom/ns#" term="iframe"/><category scheme="http://www.blogger.com/atom/ns#" term="jsfiddle"/><title type='text'>ERROR: Ignored call to &#39;alert()&#39;. The document is sandboxed, and the &#39;allow-modals&#39; keyword is not set.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Recently I found this issue while writing code snippet in &quot;JSFiddle&quot;. And after searching, found this was happening because of new feature added in &quot;Chrome 46+&quot;. But at the same time Chrome doesn&#39;t have support for &quot;allow-modals&quot; property in &quot;sandbox&quot; attribute.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Chromium issue for above behavior:&lt;/b&gt;&lt;br /&gt;
&lt;a href=&quot;https://codereview.chromium.org/1126253007&quot;&gt;https://codereview.chromium.org/1126253007&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
To make it work you have to add &quot;allow-scripts allow-modals&quot; in &quot;sandbox&quot; attribute, and use &quot;window.alert&quot; instead of &quot;alert&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: xml;&quot;&gt;&amp;lt;!-- Sandbox frame will execute javascript and show modal dialogs --&amp;gt;

&amp;lt;iframe sandbox=&quot;allow-scripts allow-modals&quot; src=&quot;iframe.html&quot;&amp;gt;

&amp;lt;/iframe&amp;gt;

&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Feature added:&lt;/b&gt; Block modal dialog inside a sandboxed iframe.&lt;br /&gt;
Link: &lt;a href=&quot;https://www.chromestatus.com/feature/4747009953103872&quot;&gt;https://www.chromestatus.com/feature/4747009953103872&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Feature working Demo page:&lt;/b&gt;&lt;br /&gt;
&lt;a href=&quot;https://googlechrome.github.io/samples/block-modal-dialogs-sandboxed-iframe/index.html&quot;&gt;https://googlechrome.github.io/samples/block-modal-dialogs-sandboxed-iframe/index.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/3781308494885426354/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2015/10/error-ignored-call-to-alert-document-is.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/3781308494885426354'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/3781308494885426354'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2015/10/error-ignored-call-to-alert-document-is.html' title='ERROR: Ignored call to &#39;alert()&#39;. The document is sandboxed, and the &#39;allow-modals&#39; keyword is not set.'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-4836391857735798113</id><published>2014-12-14T20:55:00.003+05:30</published><updated>2014-12-15T10:24:01.078+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="AngularJs"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>JavaScript: Next Unique ID Function</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Unique ID generation is used in JavaScript application in many places. For 
example giving the unique id to DOM element or may be using it to some data 
structure for storing in memory, where it can be use latter. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Most of the implementation I see is just defining the integer and increasing 
it on every call. But it is potentially candidate to integer overflow issue, 
which can cause errors in many edge case scenario.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: xml;&quot;&gt;var nextUid = (function(){
  var idCounter = 0; //integer counter
  return function (prefix) {
     //counter increment on every call, and it can run into integer overflow issue
     var id = ++idCounter; 
     return String(prefix == null ? &#39;&#39; : prefix) + id;
   }
})();

&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When I was reading through &lt;a href=&quot;https://angularjs.org/&quot; target=&quot;_blank&quot;&gt;AngularJS&lt;/a&gt; source code, found this really good 
implementation of unique ID generation. Below is the extracted and updated version of the same, so you can use it independently.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: xml;&quot;&gt;/**
 A consistent way of creating unique IDs in angular. The ID is a sequence of alpha numeric
 characters such as &#39;012ABC&#39;. The reason why we are not using simply a number counter is that
 the number string gets longer over time, and it can also overflow, where as the nextId
 will grow much slower, it is a string, and it will never overflow.
 
 @returns an unique alpha-numeric string
 */
var nextUid = (function(){
  var uid = [&#39;0&#39;,&#39;0&#39;,&#39;0&#39;];
  return function() {
    var index = uid.length,
        digit;

    while(index) {
      index--;
      digit = uid[index].charCodeAt(0);
      if (digit == 57 /*&#39;9&#39;*/) {
        uid[index] = &#39;A&#39;;
        return uid.join(&#39;&#39;);
      }
      if (digit == 90  /*&#39;Z&#39;*/) {
        uid[index] = &#39;a&#39;;
        return uid.join(&#39;&#39;);
      } 

      if (digit == 122 /*&#39;z&#39;*/) { 
        uid[index] = &#39;0&#39;;
      } else {
        uid[index] = String.fromCharCode(digit + 1);
        return uid.join(&#39;&#39;);
      }
    }
    uid.unshift(&#39;0&#39;);
    return uid.join(&#39;&#39;);
  }
})();

//output: &quot;001&quot;, &quot;002&quot;, &quot;003&quot;, &quot;008&quot;, &quot;009&quot;, &quot;00A&quot;, &quot;00B&quot;, .., &quot;01s&quot;, &quot;01t&quot;, &quot;01u&quot;, &quot;01v&quot; ..etc

&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Benefited of using this function is slow rate of increment, and you will 
never have to worry about the overflow issue.&amp;nbsp;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/4836391857735798113/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2014/12/javascript-next-unique-id-function.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/4836391857735798113'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/4836391857735798113'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2014/12/javascript-next-unique-id-function.html' title='JavaScript: Next Unique ID Function'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-7767515764736309208</id><published>2014-07-27T19:04:00.003+05:30</published><updated>2014-12-12T10:51:54.214+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>JavaScript: Utility function to default function in parameters</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
Recently I came across a interesting discussion on&amp;nbsp;&lt;a href=&quot;http://on%20www.reddit.com/&quot;&gt;reddit&lt;/a&gt;. And that was about a utility function which will give you flexibility to define default function in parameters.&lt;br /&gt;
&lt;br /&gt;
I found it very interesting, so wrote one for me.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: xml;&quot;&gt;/*
in param: defaultArg1, defaultArg2, .... function
return : function 
*/
var defaultParams = function(){
  var args = arguments,
   len = args.length,
   fn = args[--len],
   defaultArg = [];
  
  if(typeof fn !== &#39;function&#39;){
   throw new Error(&#39;invalid arguments&#39;);
  }
  while(len--){
   defaultArg[len] = args[len];
  }
  return function(){  
   var args = arguments,
    fnlen = fn.length,
    params = [];
   while(fnlen--){
     params[fnlen] = args[fnlen] == null ?  defaultArg[fnlen] : args[fnlen];
   }
   return fn.apply(this, params);
  }
}
 
 
 
//how to use 
var alert_my_age = defaultParams(21, function(age) {
  console.log(age);
})
 
alert_my_age()   //#=&amp;gt; Alerts 21
alert_my_age(45) //#=&amp;gt; Alerts 45
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/7767515764736309208/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2014/07/javascript-utility-function-to-default.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/7767515764736309208'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/7767515764736309208'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2014/07/javascript-utility-function-to-default.html' title='JavaScript: Utility function to default function in parameters'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-2314906863015858262</id><published>2014-07-26T18:46:00.000+05:30</published><updated>2015-03-20T17:47:06.099+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="HTML5"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="localStorage"/><title type='text'>JavaScript: Light weight wrapper class for window.localStorage</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;box-sizing: border-box; color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif; font-size: 16px; line-height: 25.6000003814697px; margin-bottom: 16px;&quot;&gt;
Recently I wrote a small &lt;a href=&quot;https://github.com/neerajnandwana/LS&quot; target=&quot;_blank&quot;&gt;wrapper class&lt;/a&gt; around the window.localStorage with useful functionality apart from normal get/set value.&lt;br /&gt;
&lt;br /&gt;
&lt;strong style=&quot;box-sizing: border-box; line-height: 25.6000003814697px;&quot;&gt;For example&lt;/strong&gt;&lt;/div&gt;
&lt;ul class=&quot;task-list&quot; style=&quot;box-sizing: border-box; color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif; font-size: 16px; line-height: 25.6000003814697px; margin-bottom: 16px; margin-top: 0px; padding: 0px 0px 0px 2em;&quot;&gt;
&lt;li style=&quot;box-sizing: border-box;&quot;&gt;Accessors for JSON/Boolean/Number,&lt;/li&gt;
&lt;li style=&quot;box-sizing: border-box;&quot;&gt;Event registering for type create/update/remove/clear events&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;box-sizing: border-box; color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif; font-size: 1.5em; line-height: 1.43; margin-bottom: 16px; margin-top: 1em; position: relative;&quot;&gt;
&lt;a aria-hidden=&quot;true&quot; class=&quot;anchor&quot; href=&quot;https://github.com/neerajnandwana/LS#api-functions&quot; id=&quot;user-content-api-functions&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; bottom: 0px; box-sizing: border-box; color: #4183c4; cursor: pointer; display: block; left: 0px; margin-left: -30px; padding-left: 30px; padding-right: 6px; position: absolute; text-decoration: none; top: 0px;&quot;&gt;&lt;/a&gt;API functions&lt;/h3&gt;
&lt;div class=&quot;highlight highlight-javascript&quot; style=&quot;box-sizing: border-box; color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif; font-size: 16px; line-height: 25.6000003814697px; margin-bottom: 16px;&quot;&gt;
&lt;pre style=&quot;background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Consolas, &#39;Liberation Mono&#39;, Menlo, Courier, monospace; font-size: 14px; font-stretch: normal; line-height: 1.45; overflow: auto; padding: 16px; word-break: normal; word-wrap: normal;&quot;&gt;LS.set(key, value)
LS.setJson(key, jsonObject)
LS.&lt;span class=&quot;pl-s3&quot; style=&quot;box-sizing: border-box; color: #0086b3;&quot;&gt;remove&lt;/span&gt;(key)
LS.&lt;span class=&quot;pl-s3&quot; style=&quot;box-sizing: border-box; color: #0086b3;&quot;&gt;clear&lt;/span&gt;()

LS.get(key)&lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: #a71d5d;&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;pl-s3&quot; style=&quot;box-sizing: border-box; color: #0086b3;&quot;&gt;String&lt;/span&gt;
LS.getJson(key)&lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: #a71d5d;&quot;&gt;:&lt;/span&gt; JsonObject
LS.getNumber(key)&lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: #a71d5d;&quot;&gt;:&lt;/span&gt; Int
LS.getBoolean(key)&lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: #a71d5d;&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;pl-s3&quot; style=&quot;box-sizing: border-box; color: #0086b3;&quot;&gt;Boolean&lt;/span&gt;


&lt;span class=&quot;pl-c&quot; style=&quot;box-sizing: border-box; color: #969896;&quot;&gt;//Event API&lt;/span&gt;
LS.on(&lt;span class=&quot;pl-s3&quot; style=&quot;box-sizing: border-box; color: #0086b3;&quot;&gt;event&lt;/span&gt;, listenerFunction, scope)&lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: #a71d5d;&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;pl-st&quot; style=&quot;box-sizing: border-box; color: #a71d5d;&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;pl-c&quot; style=&quot;box-sizing: border-box; color: #969896;&quot;&gt;//this return function can be used for unregistering from event&lt;/span&gt;

&lt;span class=&quot;pl-c&quot; style=&quot;box-sizing: border-box; color: #969896;&quot;&gt;//different type and listeners callback param&lt;/span&gt;
events type&lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: #a71d5d;&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;pl-s1&quot; style=&quot;box-sizing: border-box; color: #df5000;&quot;&gt;&lt;span class=&quot;pl-pds&quot; style=&quot;box-sizing: border-box;&quot;&gt;&#39;&lt;/span&gt;create&lt;span class=&quot;pl-pds&quot; style=&quot;box-sizing: border-box;&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;   listenerFunction callback param&lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: #a71d5d;&quot;&gt;:&lt;/span&gt; key, value
events type&lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: #a71d5d;&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;pl-s1&quot; style=&quot;box-sizing: border-box; color: #df5000;&quot;&gt;&lt;span class=&quot;pl-pds&quot; style=&quot;box-sizing: border-box;&quot;&gt;&#39;&lt;/span&gt;update&lt;span class=&quot;pl-pds&quot; style=&quot;box-sizing: border-box;&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;   listenerFunction callback param&lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: #a71d5d;&quot;&gt;:&lt;/span&gt; key, newValue, oldValue
events type&lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: #a71d5d;&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;pl-s1&quot; style=&quot;box-sizing: border-box; color: #df5000;&quot;&gt;&lt;span class=&quot;pl-pds&quot; style=&quot;box-sizing: border-box;&quot;&gt;&#39;&lt;/span&gt;remove&lt;span class=&quot;pl-pds&quot; style=&quot;box-sizing: border-box;&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;   listenerFunction callback param&lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: #a71d5d;&quot;&gt;:&lt;/span&gt; key
events type&lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: #a71d5d;&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;pl-s1&quot; style=&quot;box-sizing: border-box; color: #df5000;&quot;&gt;&lt;span class=&quot;pl-pds&quot; style=&quot;box-sizing: border-box;&quot;&gt;&#39;&lt;/span&gt;clear&lt;span class=&quot;pl-pds&quot; style=&quot;box-sizing: border-box;&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;    listenerFunction callback param&lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: #a71d5d;&quot;&gt;:&lt;/span&gt;

&lt;span class=&quot;pl-c&quot; style=&quot;box-sizing: border-box; color: #969896;&quot;&gt;//remove all the registered event for given event type&lt;/span&gt;
LS.removeAllEventListeners(eventType) &lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;box-sizing: border-box; color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif; font-size: 16px; line-height: 25.6000003814697px; margin-bottom: 16px;&quot;&gt;
&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Event registering/unregistering example&lt;/strong&gt;&lt;/div&gt;
&lt;div class=&quot;highlight highlight-javascript&quot; style=&quot;box-sizing: border-box; color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif; font-size: 16px; line-height: 25.6000003814697px; margin-bottom: 16px;&quot;&gt;
&lt;pre style=&quot;background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Consolas, &#39;Liberation Mono&#39;, Menlo, Courier, monospace; font-size: 14px; font-stretch: normal; line-height: 1.45; overflow: auto; padding: 16px; word-break: normal; word-wrap: normal;&quot;&gt;&lt;span class=&quot;pl-c&quot; style=&quot;box-sizing: border-box; color: #969896;&quot;&gt;//registering listener&lt;/span&gt;
&lt;span class=&quot;pl-s&quot; style=&quot;box-sizing: border-box; color: #a71d5d;&quot;&gt;var&lt;/span&gt; updateListenerFn &lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: #a71d5d;&quot;&gt;=&lt;/span&gt; LS.on(&lt;span class=&quot;pl-s1&quot; style=&quot;box-sizing: border-box; color: #df5000;&quot;&gt;&lt;span class=&quot;pl-pds&quot; style=&quot;box-sizing: border-box;&quot;&gt;&#39;&lt;/span&gt;update&lt;span class=&quot;pl-pds&quot; style=&quot;box-sizing: border-box;&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;pl-st&quot; style=&quot;box-sizing: border-box; color: #a71d5d;&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;pl-vpf&quot; style=&quot;box-sizing: border-box;&quot;&gt;key&lt;/span&gt;, &lt;span class=&quot;pl-vpf&quot; style=&quot;box-sizing: border-box;&quot;&gt;newValue&lt;/span&gt;, &lt;span class=&quot;pl-vpf&quot; style=&quot;box-sizing: border-box;&quot;&gt;oldValue&lt;/span&gt;){
    &lt;span class=&quot;pl-c&quot; style=&quot;box-sizing: border-box; color: #969896;&quot;&gt;//code  &lt;/span&gt;
});

&lt;span class=&quot;pl-c&quot; style=&quot;box-sizing: border-box; color: #969896;&quot;&gt;//unregistering listener&lt;/span&gt;
LS.un(&lt;span class=&quot;pl-s1&quot; style=&quot;box-sizing: border-box; color: #df5000;&quot;&gt;&lt;span class=&quot;pl-pds&quot; style=&quot;box-sizing: border-box;&quot;&gt;&#39;&lt;/span&gt;update&lt;span class=&quot;pl-pds&quot; style=&quot;box-sizing: border-box;&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;, updateListenerFn);&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif; font-size: 16px; line-height: 25.6000003814697px;&quot;&gt;
Hope it will be useful for others.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif; font-size: 16px; line-height: 25.6000003814697px;&quot;&gt;
Project links:&amp;nbsp;&lt;a href=&quot;https://github.com/neerajnandwana/LS&quot;&gt;https://github.com/neerajnandwana/LS&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/2314906863015858262/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2014/07/javascript-light-weight-wrapper-class.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/2314906863015858262'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/2314906863015858262'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2014/07/javascript-light-weight-wrapper-class.html' title='JavaScript: Light weight wrapper class for window.localStorage'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-8098572016791096198</id><published>2013-11-20T20:11:00.002+05:30</published><updated>2013-11-20T20:13:01.310+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>New Features and Enhancements from JDK-5 to JDK-7</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
As Oracle is preparing for JDK-8 release with most awaited language features &quot; &lt;a href=&quot;http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html&quot;&gt;lambda expressions&lt;/a&gt;&quot;, I was thinking about the java language evolution since I started my IT career. &lt;br /&gt;
&lt;br /&gt;
New features released in JDK-5 were really impressive, and it created lots of interest in language again.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;JDK-5 (September 30, 2004)&lt;/strong&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.oracle.com/javase/1.5.0/docs/guide/language/generics.html&quot;&gt;Generics&lt;/a&gt; 
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.oracle.com/javase/1.5.0/docs/guide/language/foreach.html&quot;&gt;Enhanced for Loop&lt;/a&gt; 
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.oracle.com/javase/1.5.0/docs/guide/language/autoboxing.html&quot;&gt;Autoboxing/Unboxing&lt;/a&gt; 
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.oracle.com/javase/1.5.0/docs/guide/language/enums.html&quot;&gt;Typesafe Enums&lt;/a&gt; 
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.oracle.com/javase/1.5.0/docs/guide/language/varargs.html&quot;&gt;Varargs&lt;/a&gt; 
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.oracle.com/javase/1.5.0/docs/guide/language/static-import.html&quot;&gt;Static Import&lt;/a&gt; 
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.oracle.com/javase/1.5.0/docs/guide/language/annotations.html&quot;&gt;Metadata&lt;/a&gt; (Annotations) 
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.oracle.com/javase/1.5.0/docs/guide/collections/changes5.html&quot;&gt;Collections Framework&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;strong&gt;JDK-6 (December 11, 2006)&lt;/strong&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.oracle.com/javase/6/docs/technotes/guides/collections/changes6.html&quot;&gt;Collections Framework&lt;/a&gt; 
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://download.oracle.com/javase/6/docs/technotes/guides/scripting/index.html&quot;&gt;Scripting&lt;/a&gt; 
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://download.oracle.com/javase/6/docs/technotes/guides/io/enhancements.html#6&quot;&gt;I/O Support&lt;/a&gt; 
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://download.oracle.com/javase/6/docs/technotes/guides/management/enhancements.html&quot;&gt;Monitoring and Management for the Java Platform&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;strong&gt;JDK-7 (July 28, 2011)&lt;/strong&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.oracle.com/javase/7/docs/technotes/guides/language/binary-literals.html&quot;&gt;Binary Literals&lt;/a&gt; 
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.oracle.com/javase/7/docs/technotes/guides/language/strings-switch.html&quot;&gt;Strings in switch Statements&lt;/a&gt; 
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.oracle.com/javase/7/docs/technotes/guides/language/try-with-resources.html&quot;&gt;The try-with-resources Statement&lt;/a&gt; 
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.oracle.com/javase/7/docs/technotes/guides/language/catch-multiple.html&quot;&gt;Catching Multiple Exception Types and Rethrowing Exceptions with Improved Type Checking&lt;/a&gt; 
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-literals.html&quot;&gt;Underscores in Numeric Literals&lt;/a&gt; 
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.oracle.com/javase/7/docs/technotes/guides/language/type-inference-generic-instance-creation.html&quot;&gt;Type Inference for Generic Instance Creation&lt;/a&gt; 
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.oracle.com/javase/7/docs/technotes/guides/io/enhancements.html#7&quot;&gt;IO and New IO&lt;/a&gt; 
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.oracle.com/javase/7/docs/technotes/guides/concurrency/changes7.html&quot;&gt;Concurrency Utilities&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
Over the past few years, java has become more relevant. It has quietly become the primary foundation for really big companies like Google, LinkedIn, Tumbler, Square and Twitter. &lt;br /&gt;
&lt;br /&gt;
“Java is really the only choice when it comes to the requirements for a company like ours — extreme performance requirements and extreme scalability requirements. There is no viable alternative”— Bob Lee 
&lt;br /&gt;
&lt;br /&gt;
“On August 3, Twitter hit a one-second peak of 143,199 tweets. That’s a massive spike over the norm — about 5,700-tweets-per-second — and the site stayed up”— &lt;a href=&quot;https://blog.twitter.com/2013/new-tweets-per-second-record-and-how&quot;&gt;New Tweets per second record, and how!&lt;/a&gt;&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&lt;strong&gt;PS:&lt;/strong&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.infoq.com/articles/twitter-java-use&quot;&gt;Twitter Shifting More Code to JVM, Citing Performance and Encapsulation As Primary Drivers&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.infoq.com/news/2011/11/yammer-scala&quot;&gt;Yammer Moving from Scala to Java&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://www.youtube.com/watch?v=k-PyVYY7QFI&quot;&gt;On The Cusp Of A Java Renaissance: Where We&#39;ve Been And Where We&#39;re Going&lt;/a&gt; - Bob Lee is the CTO of Square Inc&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/8098572016791096198/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2013/11/new-features-and-enhancements-from-jdk.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/8098572016791096198'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/8098572016791096198'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2013/11/new-features-and-enhancements-from-jdk.html' title='New Features and Enhancements from JDK-5 to JDK-7'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-7181482953682550555</id><published>2013-07-11T17:26:00.000+05:30</published><updated>2013-07-11T17:41:45.039+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ext Js"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>JavaScript [ExtJs3]: Avoid default filtering in ComboBox</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;p&gt;We had a requirement where we wanted to avoid default filtering provided by the ExtJs ComboBox. Instead we wanted to control it based on our business rules. To avoid default filtering we added “editable:false”, but it didn’t help much. As after selecting any value user cannot clear the value from field. We tried few more permutation-combination to achieve all the behaviour we wanted, but nothing worked. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Use-Cases we wanted to achieve in combo box&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Force user to select value from drop down list 
&lt;li&gt;User can clear the value 
&lt;li&gt;Disable the default filtering as filtering is applied based on some business rule and default filtering was clearing it&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here is the final outcome, which satisfied all the use-cases. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:6e22778f-f1bf-4a81-bc46-c4451854784b&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;var combo = new Ext.form.ComboBox({
            store        : store,
            displayField : displayField,
            mode         : &#39;local&#39;,
            triggerAction: &#39;all&#39;,
            forceSelection: true,
            autoSelect: false,
            // don&#39;t allow user to enter the value
            // But at the same time he should be able to delete the value
            // overriding the function to avoid default filter clearing
            initQuery:  function(){
                this.doQuery(&#39;&#39;);
                this.setValue(&#39;&#39;);
            }
});&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;PS: Extjs version – 3.4&lt;/p&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;script src=&quot;http://crux-framework-tools.googlecode.com/svn/trunk/misc/highlight/highlightLoader.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/7181482953682550555/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2013/07/javascript-extjs3-combobox-avoid.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/7181482953682550555'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/7181482953682550555'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2013/07/javascript-extjs3-combobox-avoid.html' title='JavaScript [ExtJs3]: Avoid default filtering in ComboBox'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-7691643011053154802</id><published>2013-05-09T11:44:00.004+05:30</published><updated>2013-05-09T11:46:25.607+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Design Patterns"/><title type='text'>Think “SOLID”</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br/&gt;

&lt;p&gt;&lt;strong&gt;&lt;font size=&quot;4&quot;&gt;S&amp;nbsp; → &lt;/font&gt;&lt;font size=&quot;2&quot;&gt;Single responsibility principle :&lt;/font&gt;&lt;/strong&gt; One class one responsibility&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;font size=&quot;4&quot;&gt;O → &lt;/font&gt;&lt;font size=&quot;2&quot;&gt;Open/closed principle :&lt;/font&gt;&lt;/strong&gt; Open for extension, but closed for modification&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font size=&quot;4&quot;&gt;L&amp;nbsp; → &lt;/font&gt;&lt;font size=&quot;2&quot;&gt;Liskov substitution principle :&lt;/font&gt;&lt;/strong&gt; Design by contract [Link: &lt;a href=&quot;http://en.wikipedia.org/wiki/Liskov_substitution_principle&quot;&gt;Liskov substitution principle&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font size=&quot;4&quot;&gt;I&amp;nbsp;&amp;nbsp; → &lt;/font&gt;&lt;font size=&quot;2&quot;&gt;Interface segregation principle :&lt;/font&gt;&lt;/strong&gt; Many client-specific interfaces are better than one general-purpose interface&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font size=&quot;4&quot;&gt;D → &lt;/font&gt;&lt;font size=&quot;2&quot;&gt;Dependency inversion principle :&lt;/font&gt;&lt;/strong&gt; Abstraction on object and their dependency creation&lt;/p&gt;
&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/7691643011053154802/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2013/05/reminding-myself-think-solid.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/7691643011053154802'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/7691643011053154802'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2013/05/reminding-myself-think-solid.html' title='Think “SOLID”'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-5601199497705979202</id><published>2013-05-06T16:33:00.003+05:30</published><updated>2013-05-06T16:44:04.902+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ext Js"/><title type='text'>Debugging common errors in ExtJs</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;p&gt;If you check ExtJs form, you will find some issues commonly faced by developers. I have seen people spending hours to solve these issues without any clue. &lt;br/&gt;
Here is the list of few errors and expected root cause. Hope it will help someone.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;this.addEvents is not a function&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Check instantiation of the class. Most probably you forgot to write “&lt;strong&gt;new” &lt;/strong&gt;keyword&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;while creating a class object. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;namespace.MyClass is not a constructor&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Check for typo in class definition or class instantiation.&lt;/p&gt;
&lt;p&gt;Did you forget to include the js file in html page or in jsb configuration?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;this.el is undefined / this.el is null&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In ExtJs “el” variable hold the reference of DOM element. And DOM element only initialize, when UI render correctly on web browser. If you are getting this error,&amp;nbsp; then their is major chances of accessing “el” variable before UI component layout or render properly. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;Component is appearing as gray out or it is hanging somewhere else&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;It can happen because of many other issue, but major reason is same id of two component. To resolve this issue, just use diff id for each component. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Some quick FAQ links&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.sencha.com/learn/grid-faq/&quot;&gt;Grid FAQ&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.sencha.com/learn/form-faq/&quot;&gt;Form FAQ&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.sencha.com/learn/tabpanel-faq/&quot;&gt;TabPanel FAQ&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.sencha.com/learn/layout-faq/&quot;&gt;Layout FAQ&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.sencha.com/learn/template-faq/&quot;&gt;Template FAQ&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For more learning resources, you must go through highly recommended “&lt;a href=&quot;http://www.sencha.com/learn/extjs&quot;&gt;Learn ExtJs&lt;/a&gt;” page.&amp;nbsp; &lt;/p&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/5601199497705979202/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2013/05/debugging-common-errors-in-extjs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/5601199497705979202'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/5601199497705979202'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2013/05/debugging-common-errors-in-extjs.html' title='Debugging common errors in ExtJs'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-3872149015026293816</id><published>2013-04-15T23:01:00.000+05:30</published><updated>2013-04-18T10:30:05.675+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Optimization"/><category scheme="http://www.blogger.com/atom/ns#" term="Performance"/><title type='text'>“Bloom Filter” to optimize expensive data lookups</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
Bloom Filter is very useful when you want to optimize the functionality with following constraints&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Data lookup is very expensive  &lt;/li&gt;
&lt;li&gt;False positive is acceptable and  &lt;/li&gt;
&lt;li&gt;False negative is un-acceptable &lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;em&gt;A Bloom filter, conceived by Burton Howard Bloom in 1970, is a space-efficient probabilistic data structure that is used to test whether an element is a member of a set. False positive retrieval results are possible, but false negatives are not; i.e. a query returns either &quot;inside set (may be wrong)&quot; or &quot;definitely not in set&quot;.&lt;/em&gt; – &lt;a href=&quot;http://en.wikipedia.org/wiki/Bloom_filter&quot;&gt;&lt;strong&gt;wikipedia.org&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;
&amp;nbsp;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpb4rFFeOQY7tfAkwhYWUcEvusE79caerf_Y7egLXQ8RhcVmtz9-PpAPuwEdD0FnLH0UBgtNwDyUXPlmvR_XrUdFlZIqW-2GqJBZxRrKuCRubIxf3ffjA0LywBl6C33jPkHxHTfDzUL2c/s1600-h/360px-Bloom_filter_speed.svg%25255B28%25255D.png&quot;&gt;&lt;img alt=&quot;360px-Bloom_filter_speed.svg&quot; border=&quot;0&quot; height=&quot;448&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2GSX9HmdtQhkhqfxBUY8cw4YaTLbbZOfL6_CwTD51rTVCaGZRKx8bkP4SjxtXg7j2AgR1DqqhvdhHZ5335LrZwY3pRmwwM_gHu69ZMVj2yD5KpyzbY-cRmLz0YfITUJA3vUtXosIxEKg/?imgmax=800&quot; style=&quot;border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: block; float: none; margin-left: auto; margin-right: auto;&quot; title=&quot;360px-Bloom_filter_speed.svg&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
It stores only value hash in it’s data structure, so it take very less memory against the very huge data. &lt;br /&gt;
For example if you have set of raw data with &lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;10&lt;sup&gt;7&lt;/sup&gt; elements &lt;/li&gt;
&lt;li&gt;10&lt;sup&gt;5&lt;/sup&gt; distinct value &lt;/li&gt;
&lt;li&gt;and size ~40MB&lt;/li&gt;
&lt;/ul&gt;
Bloom filter will store same data as hash in just ~0.6MB. (&lt;a href=&quot;https://highlyscalable.wordpress.com/2012/05/01/probabilistic-structures-web-analytics-data-mining/&quot;&gt;ref.&lt;/a&gt;)&lt;br /&gt;
And because of the same reason it is quite fast.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;u&gt;Bloom Filter implementation&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;
Guava library has &lt;a href=&quot;https://code.google.com/p/guava-libraries/source/browse/guava/src/com/google/common/hash/BloomFilter.java&quot;&gt;bloom filter implementation&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://github.com/joeyrobert/bloomfilter&quot;&gt;.Net implementation&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;u&gt;Bloom Filter In Use&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Chrome uses Bloom filters to make a preliminary decision whether a particular web site is malicious or safe.  &lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/BigTable&quot;&gt;Google Big table&lt;/a&gt; uses it to reduce disk lookups  &lt;/li&gt;
&lt;li&gt;Squid Web Proxy Cache uses Bloom filters for &lt;a href=&quot;http://wiki.squid-cache.org/SquidFaq/CacheDigests&quot;&gt;cache digests&lt;/a&gt;  &lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://wiki.apache.org/cassandra/ArchitectureOverview&quot;&gt;Cassandra&lt;/a&gt; uses to save IO when performing a key lookup&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;u&gt;&lt;strong&gt;Useful links&lt;/strong&gt;&lt;/u&gt;&lt;br /&gt;
&lt;a href=&quot;http://billmill.org/bloomfilter-tutorial/&quot;&gt;Bloom filter by example&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://algo2.iti.kit.edu/singler/publications/cacheefficientbloomfilters-wea2007.pdf&quot;&gt;Space-Eﬃcient Bloom Filters&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.youtube.com/watch?v=947gWqwkhu0&quot;&gt;&quot;More Optimal Bloom Filters,&quot; Ely Porat (Nov/2007) Google TechTalk video on YouTube&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/3872149015026293816/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2013/04/bloom-filter-to-optimize-expensive-data.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/3872149015026293816'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/3872149015026293816'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2013/04/bloom-filter-to-optimize-expensive-data.html' title='“Bloom Filter” to optimize expensive data lookups'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2GSX9HmdtQhkhqfxBUY8cw4YaTLbbZOfL6_CwTD51rTVCaGZRKx8bkP4SjxtXg7j2AgR1DqqhvdhHZ5335LrZwY3pRmwwM_gHu69ZMVj2yD5KpyzbY-cRmLz0YfITUJA3vUtXosIxEKg/s72-c?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-9222374829754759118</id><published>2013-04-15T18:36:00.001+05:30</published><updated>2015-01-28T18:30:48.171+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Optimization"/><category scheme="http://www.blogger.com/atom/ns#" term="Performance"/><title type='text'>&quot;Stop Words&quot; in full text search</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;a href=&quot;http://en.wikipedia.org/wiki/Stop_words&quot;&gt;&lt;img align=&quot;right&quot; alt=&quot;Stop words&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrdAql8o1hkDtMQaDwLyYAUeKxw-H1MEXR2yv5noiiSx1EGyJIdalS1Zv3235fvMIHoGFisVAoRKkgHFB-TLT9LXJhNx5oPbWH7f2Ym14RJe8KxRWtwqzyYtVM8hZq89mPz4KtygX17GE/?imgmax=800&quot; height=&quot;284&quot; style=&quot;border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline; margin: 5px 10px;&quot; title=&quot;Stop words&quot; width=&quot;284&quot; /&gt; Stop words&lt;/a&gt; are the words without significant information. You can consider these words as a filler words. If these words are used in search statement, then result could potentially contain all the record from data store.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is always a good idea to filter out these words before constructing the search query. It will make the search query smaller, faster and result will be more relevant.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
“&lt;i&gt;One of our major performance optimizations for the “related questions” query is removing the top 10,000 most common English dictionary words (as determined by Google search) before submitting the query to the SQL Server 2008 full text engine. It’s shocking how little is left of most posts once you remove the top 10k English dictionary words. This helps limit and narrow the returned results, which makes the query dramatically faster.&lt;/i&gt;” - &lt;a href=&quot;http://blog.stackoverflow.com/2008/12/podcast-32/&quot;&gt;&lt;strong&gt;stackoverflow.com&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;English stop word list&lt;/b&gt; : &lt;br /&gt;
&lt;a href=&quot;http://jmlr.csail.mit.edu/papers/volume5/lewis04a/a11-smart-stop-list/english.stop&quot;&gt;http://jmlr.csail.mit.edu/papers/volume5/lewis04a/a11-smart-stop-list/english.stop&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Some interesting articles &lt;/strong&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.codinghorror.com/blog/2008/11/stop-me-if-you-think-youve-seen-this-word-before.html&quot;&gt;http://www.codinghorror.com/blog/2008/11/stop-me-if-you-think-youve-seen-this-word-before.html&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.seobythesea.com/2008/08/google-stopword-patent/&quot;&gt;http://www.seobythesea.com/2008/08/google-stopword-patent/&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.googleguide.com/interpreting_queries.html&quot;&gt;http://www.googleguide.com/interpreting_queries.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/9222374829754759118/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2013/04/stop-words-in-full-text-search.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/9222374829754759118'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/9222374829754759118'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2013/04/stop-words-in-full-text-search.html' title='&quot;Stop Words&quot; in full text search'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrdAql8o1hkDtMQaDwLyYAUeKxw-H1MEXR2yv5noiiSx1EGyJIdalS1Zv3235fvMIHoGFisVAoRKkgHFB-TLT9LXJhNx5oPbWH7f2Ym14RJe8KxRWtwqzyYtVM8hZq89mPz4KtygX17GE/s72-c?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-2731739077885666649</id><published>2013-03-04T11:33:00.000+05:30</published><updated>2014-12-26T11:48:14.694+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>[JavaScript] Updating the existing function behaviour</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Ever find a situation when you want to change the function behaviour without duplicating the existing function code. Then you must be looking for this example. &lt;br /&gt;
&lt;br /&gt;
Our test data object&lt;br /&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:5208c88d-624e-46ad-95b0-76b6b68745d5&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre class=&quot;brush: java;&quot;&gt;var user = {
    name: &#39;testWorker&#39;,
    isOnLeave: true
};&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
Original function behaviour &lt;br /&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:6117f989-11d5-4e05-a920-9b73568263a3&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre class=&quot;brush: java;&quot;&gt;var startWork = function(user){
    console.log(&#39;working...&#39;);    
}

[run]   -&amp;gt;startWork(user);
[output]-&amp;gt;working...&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
Now if we want to change the function behaviour based on our data object. &lt;br /&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:f5e4f544-5fcc-41e9-a56d-bae2d047a15a&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre class=&quot;brush: java;&quot;&gt;startWork = (function(){
    //backup original function in private scope
    var _originalFn = startWork;
    //assign new behaviour
    return function(user){
        if(user.isOnLeave){
            console.log(&#39;on leave...&#39;);
        } else {
            _originalFn(user);
        }
    }
})();


[run]   -&amp;gt;startWork(user);
[output]-&amp;gt;on leave...

//change data object
user.isOnLeave = false;
[run]   -&amp;gt;startWork(user);
[output]-&amp;gt;working...&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;Note:&lt;/b&gt; It is not suggested to update the existing function behaviour. Because it can introduce defect which are very hard to debug and resolve. &lt;br /&gt;
&lt;script src=&quot;http://crux-framework-tools.googlecode.com/svn/trunk/misc/highlight/highlightLoader.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;

&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/2731739077885666649/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2013/03/javascript-updating-existing-function.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/2731739077885666649'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/2731739077885666649'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2013/03/javascript-updating-existing-function.html' title='[JavaScript] Updating the existing function behaviour'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-8396183283800207986</id><published>2013-02-11T17:58:00.001+05:30</published><updated>2013-02-18T21:58:29.557+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>JavaScript [Q.JS] Are you stuck in nested callback functions?</title><content type='html'>&lt;p&gt;If you have seen situation when one asynchronous call result used in another asynchronous call. And you tried to make that code look less scary and more readable then you must go through this library and understand it’s nice tricks and syntax. &lt;/p&gt;
&lt;p&gt;Just want to give the same example from its site which clearly shows the problem it is trying to solve. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:6756dfb2-f46f-49ee-8200-57bc6fdafb55&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;step1(function (value1) {
    step2(value1, function(value2) {
        step3(value2, function(value3) {
            step4(value3, function(value4) {
                // Do something with value4
            });
        });
    });
});&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;With &lt;a href=&quot;https://github.com/kriskowal/q&quot;&gt;QJS library&lt;/a&gt;&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:56ad481e-a690-42f1-a70d-71907fc49df1&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;Q.fcall(step1)
.then(step2)
.then(step3)
.then(step4)
.then(function (value4) {
    // Do something with value4
}, function (error) {
    // Handle any error from step1 through step4
})
.done();&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you want to see its potential uses then you should see one of the &lt;strong&gt;WCF data API&amp;nbsp; &lt;/strong&gt;&lt;a href=&quot;http://www.breezejs.com/&quot;&gt;&lt;strong&gt;breezejs&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;.&lt;/strong&gt; &lt;/p&gt;
&lt;p&gt;To test this library i have created a dummy Ajax function which simulate the Ajax asynchronous behaviour. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:bed6a280-c2ff-4f9d-8ceb-aab5e7012f1d&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;var Ajax = function(config){
    var emptyFn = function(){},
        xhr = { 
            success : config.success || emptyFn,
            failure: config.failure || emptyFn,
            call: function(id){
                //random response delay
                var randomNum = Math.floor((Math.random()*3000)+1);
                setTimeout(function(){
                    xhr.success(&#39;[&#39;+config.url+&#39; call]&#39;);
                }, randomNum);
            }
        };
    xhr.call();
    return xhr;
}&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Next step is to wrap Ajax function in &lt;a href=&quot;https://github.com/kriskowal/q&quot;&gt;QJS&lt;/a&gt; promise object. And we are ready to play with &lt;a href=&quot;https://github.com/kriskowal/q&quot;&gt;QJS&lt;/a&gt; features.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:8e789447-1e99-496a-a7db-2e0dcaa358e7&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;var ajaxPromise = function(url){
     var deferred = Q.defer(),
        projectMgr = Ajax({
            url: url,
            success: function(res){
                console.log(&#39;&amp;gt;&amp;gt;&amp;gt;[success]&amp;gt;&amp;gt;&amp;gt;&#39;+res);
                deferred.resolve(res);
            },
            failure: function(res){
                console.log(&#39;&amp;gt;&amp;gt;&amp;gt;[failure]&amp;gt;&amp;gt;&amp;gt;&#39;+res);
                deferred.reject(res);
            } 
        });  
    return deferred.promise;
}&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Feed all Ajax call response to one function&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:ba9b7323-6479-4243-b873-705e2b080d8a&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;Q.all([
 ajaxPromise(&#39;A&#39;),
 ajaxPromise(&#39;B&#39;),
 ajaxPromise(&#39;C&#39;),
 ajaxPromise(&#39;D&#39;)])
.spread(function(responseA, responseB, responseC, responseD){
 //handle data
});&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Waterfall Ajax call where response data passes to the next Ajax call.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:2ecb0a51-b96a-49cf-a6a2-e3405fd178a8&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;Q.fcall(ajaxPromise(&#39;A&#39;))
.then(ajaxPromise(&#39;B&#39;))
.then(ajaxPromise(&#39;C&#39;))
.then(ajaxPromise(&#39;D&#39;))
.then(function (responseD) {
 // Do something with value4
}, function (error) {
 // Handle any error from step1 through step4
}).done();&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;There are couple more useful functions &lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;fail&lt;/strong&gt;:&amp;nbsp;&amp;nbsp; Shorthand function of ‘then’ where you just want to handle the error&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;fin&lt;/strong&gt;:&amp;nbsp;&amp;nbsp; It is a ‘finally’ function which get call without parameter. &lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Example handler &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:d9c2165c-a752-40a0-968b-f1a0e0589431&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;var handlers = {
    mainTask: function(){
            console.debug(&#39;main task - &#39;, arguments);
            return &#39;maintask&#39;;
    },
    task1: function(){
            console.debug(&#39;then task1 - &#39;, arguments);
            return &#39;task1&#39;;
    },
    task2: function(){
            console.debug(&#39;then task2 - &#39;, arguments);
            return &#39;task2&#39;;
    },
    throwError: function(){
            throw new Error(&#39;some error&#39;);
    },
    handleError: function(){
            console.log(&#39;handle error - &#39;, arguments); 
    },
    finallyTask: function(){
            console.debug(&#39;then finallyTask - &#39;, arguments);
            return &#39;finallyTaskDone&#39;;    
    }
};&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Handling the error through ‘then’ function and ‘finally’ &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:25327332-2716-4633-b81f-b928c4cb4095&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;Q.fcall(handlers.mainTask)
.then(handlers.task1)
.then(handlers.throwError)
.then(handlers.task2, handlers.handleError)
.fin(handlers.finallyTask).done(); &lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Same behaviour with ‘fail’ shorthand function&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:5050b901-0b7a-4af5-9ce5-9bed55a45bc8&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;Q.fcall(handlers.mainTask)
.then(handlers.task1)
.then(handlers.throwError)
.then(handlers.task2)
.fail(handlers.handleError)
.fin(handlers.finallyTask).done(); &lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;There are &lt;a href=&quot;https://github.com/kriskowal/q#over-the-wire&quot;&gt;more stuff&lt;/a&gt; you can explore.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;If you are a big fan of one liner code then you can write your code something like below with new array functions&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:a778bc11-8d49-4c33-bf3c-571300e2f0bf&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;var find = function(){ console.log(&#39;find&#39;); },
 validate = function() { console.log(&#39;validate&#39;); },
 update = function() { console.log(&#39;update&#39;); },
 show = function() { console.log(&#39;show&#39;); },
 funcs = [find, validate, update, show];&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;With function chaining&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:d56cfadf-ef3d-4662-a65c-6b5a4f60ff25&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;Q.fcall(find).then(validate).then(update).then(show)&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Or with new ‘forEach’ function&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:992e0d5b-29d2-4f41-9bbb-3720ba5b8d99&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;var result = Q.resolve();
funcs.forEach(function(func){
    result = result.then(func);
});&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Or with ‘reduce’ &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:24a578fd-18f3-40b4-ad25-3b822b9febb1&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;funcs.reduce(function(funca, funcb){
    return funca.then(funcb);
}, Q.resolve())&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Ok above two were not really one liner but these are pretty compact and expressive. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Ajax call retry with some delay&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;There was a scenario in our project where we wanted to show error message after 5 recursive fail to get the data. And i found much easier to do with this library. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:beebd50f-397a-4fdb-b8e1-aee3a78d247c&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;function readRetry(url, retryDelay, times){
    return projectMgrPromise(url)
        .then(function(data){
            console.log(&#39;got the data.&#39;);
        }, function(error){
            if(times == 0){
                throw new Error(&#39;Error while reading the data.&#39;);
            }
            return Q.delay(retryDelay)
                .then(function(){
                    return readRetry(url, retryDelay, times-1);
                });
        })
        .fail(function(error){
            console.log(error);
        });
}

//function call with 5 retry and 200 delay
readRetry(&#39;testUrl&#39;, 200, 5);&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Asynchronous call handing are really hard specially if you are creating single page web application. So it is always better to give some thought on design before writing the code. I still remember battling with async callback issues in our one of the project and we created event system to overcome from it. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;PS: JQuery and DOJO also support these kind of functions. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Some useful links&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a title=&quot;http://wiki.commonjs.org/wiki/Promises/A&quot; href=&quot;http://wiki.commonjs.org/wiki/Promises/A&quot;&gt;http://wiki.commonjs.org/wiki/Promises/A&lt;/a&gt; 
&lt;li&gt;&lt;a title=&quot;http://www.html5rocks.com/en/tutorials/async/deferred/&quot; href=&quot;http://www.html5rocks.com/en/tutorials/async/deferred/&quot;&gt;http://www.html5rocks.com/en/tutorials/async/deferred/&lt;/a&gt; 
&lt;li&gt;&lt;a title=&quot;http://msdn.microsoft.com/en-us/magazine/gg723713.aspx&quot; href=&quot;http://msdn.microsoft.com/en-us/magazine/gg723713.aspx&quot;&gt;http://msdn.microsoft.com/en-us/magazine/gg723713.aspx&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;script src=&quot;http://crux-framework-tools.googlecode.com/svn/trunk/misc/highlight/highlightLoader.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;
&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/8396183283800207986/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2013/02/qjs-are-stuck-in-nested-callback.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/8396183283800207986'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/8396183283800207986'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2013/02/qjs-are-stuck-in-nested-callback.html' title='JavaScript [Q.JS] Are you stuck in nested callback functions?'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-5655360447082076798</id><published>2012-10-30T19:47:00.001+05:30</published><updated>2012-10-30T23:55:48.980+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Google"/><category scheme="http://www.blogger.com/atom/ns#" term="Guice"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>Google Guice: Dependency Injection with Guice 3.0</title><content type='html'>&lt;div style=&quot;text-align: left&quot; dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot; dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot; dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;&lt;a href=&quot;http://code.google.com/p/google-guice/&quot;&gt;Guice&lt;/a&gt; (pronounced &#39;juice&#39;) is a lightweight dependency injection framework for Java 5 and above, from Google.&lt;br&gt;&lt;br&gt;&lt;strong&gt;&lt;u&gt;&lt;/u&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot; dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;&lt;strong&gt;&lt;u&gt;Why &lt;/u&gt;&lt;/strong&gt;&lt;a href=&quot;http://code.google.com/p/google-guice/&quot;&gt;&lt;strong&gt;Google Guice&lt;/strong&gt;&lt;/a&gt;?&lt;br&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot; dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Mature Framework&lt;/strong&gt; – Used in many open source projects like &lt;a href=&quot;http://struts.apache.org/2.2.1/docs/dependency-injection.html&quot;&gt;apache struts&lt;/a&gt;, &lt;a href=&quot;http://shindig.apache.org/&quot;&gt;apache shindig&lt;/a&gt; &lt;a href=&quot;http://code.google.com/p/google-guice/wiki/AppsThatUseGuice&quot;&gt;etc&lt;/a&gt;. Google is using it in many mission critical applications. 
&lt;li&gt;&lt;strong&gt;Simple and easy to use&lt;/strong&gt; – It help in design better application. 
&lt;li&gt;&lt;strong&gt;JSR 330 support&lt;/strong&gt; 
&lt;li&gt;&lt;strong&gt;AOP &lt;strong&gt;support &lt;/strong&gt;&lt;/strong&gt;
&lt;li&gt;&lt;strong&gt;Very light weight&lt;/strong&gt; – less then 1 MB in size 
&lt;li&gt;&lt;strong&gt;Won the 18th &lt;/strong&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Jolt_Awards&quot;&gt;&lt;strong&gt;Jolt Award&lt;/strong&gt;&lt;/a&gt;&amp;nbsp; - for best Library, Framework, or Component. &lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;
&lt;p&gt;&lt;br&gt;&lt;strong&gt;&lt;u&gt;Google Guice with example&lt;/u&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br&gt;Lets consider very high level application design where need services, persistence layer and authentication mechanism. Each of the functionality is very different but very dependent on each other. If we start writing the code without giving much thought on design, then we will be ending with the code, which is &lt;u&gt;very tightly couple, hard to change and even harder to test. &lt;/u&gt;&lt;br&gt;&lt;br&gt;&lt;/p&gt;&lt;u&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioAm_Ymh-SItbwETiNuU_GlJapYIicAEHSyCJn7OoFXdRcnqDV1bog3TZrTc5TlW4OdE2kEyEUH5WoUM29mw5cjUbKJYPDJpZ8sAMo0JEvCIGefnTnwrccSChqe3yG2kQ0IKn6wJSSPvw/s1600-h/ApplicationArchitect%25255B7%25255D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto&quot; title=&quot;ApplicationArchitect&quot; border=&quot;0&quot; alt=&quot;ApplicationArchitect&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzPGBG0odB43zokfdOFFBSNnxAKCPxsIdmFsCa2Ds5h4smjf_Jyf3R3s0FcvyD5nDf_7Alc8ZL3TBmpGKYAQ1quuKpKynJeVppGMHewcSfzoohFgQvfjWNqUJvpASenwEpM42M2MoNqdY/?imgmax=800&quot; width=&quot;443&quot; height=&quot;315&quot;&gt;&lt;/a&gt; &lt;/u&gt;&lt;br&gt;
&lt;div align=&quot;center&quot;&gt;Application design&lt;/div&gt;
&lt;p&gt;&lt;br&gt;&lt;u&gt;Application main class&lt;/u&gt;&lt;br&gt;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:6e8f66de-1ce0-48be-ae60-0aa2aa2bc003&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;public class Application {
 private final AppService service;
 private final AppPersist persist;
 private final AppAuthentication authenticator;

 @Inject
 public Application(AppService service, 
   AppPersist persist, 
   AppAuthentication authenticator) {
  this.service = service;
  this.persist = persist;
  this.authenticator = authenticator;
 }
 
 //Other application related code
}&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;&lt;u&gt;Custom annotation class for user id binding&lt;/u&gt;&lt;br&gt;&lt;br&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:1891af05-f721-4a2b-9bc9-f7e9b964ea01&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;@BindingAnnotation
@Retention(RUNTIME)
@Target({ METHOD, FIELD, PARAMETER})
public @interface User {}&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;u&gt;Service classes&lt;/u&gt; 
&lt;p&gt;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:3a194131-1f70-4f76-add6-ab2b80cc4115&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;public interface AppService {
 void doSomthing();
}&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;br&gt;&lt;br&gt;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:a28444e8-d2d0-4620-a9c3-ab27ed64c1a4&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;public class AppServiceImpl implements AppService{
 private final ServiceConfig config;
 private final AppPersist persist;
 private final AppAuthentication authenticator;
 private final String user;

 @Inject
 public AppServiceImpl(ServiceConfig config, 
   AppPersist persist, 
   AppAuthentication authenticator, 
   @User String user) {
  this.config = config;
  this.persist = persist;
  this.authenticator = authenticator;
  this.user = user;
 }

 @Override
 public void doSomthing() {
  //code
 }
}&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;u&gt;Guice module – wiring the dependencies &lt;/u&gt;&lt;br&gt;&lt;br&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:d3cfc73f-e0da-496f-93e4-84b15b0ff0dd&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;public class AppModule extends AbstractModule{

 @Override
 protected void configure() {
  bind(Application.class);
  bind(AppService.class).to(AppServiceImpl.class);
  bind(AppPersist.class).to(AppPersistImpl.class);
  bind(AppAuthentication.class).to(AppAuthenticationImpl.class);
  bind(String.class).annotatedWith(User.class).toInstance(&quot;UserID&quot;);
 }

 @Provides
 public ServiceConfig getService1Configuration(){
  return new ServiceConfig();
 }

}&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;&lt;u&gt;Application entry point - time to Bootstrap the Guice&lt;/u&gt;&lt;br&gt;&lt;br&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:ceb0f4df-b595-40f3-bc2d-f39df9c1f567&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;public static void main(String... arg) { 
 Injector inject = Guice.createInjector(new Test1Module());
 Application app = inject.getInstance(Application.class);
 app.service.doSomthing();
}&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;strong&gt;&lt;u&gt;How Guice find and inject the dependency? &lt;/u&gt;&lt;/strong&gt;&lt;br&gt;&lt;br&gt;Generally all the bindings are definition under Module classes (Module classes are subclass of &lt;a href=&quot;http://code.google.com/p/google-guice/source/browse/core/src/com/google/inject/AbstractModule.java&quot;&gt;AbstractModule class&lt;/a&gt;)&lt;strong&gt;.&lt;/strong&gt; &lt;br&gt;&lt;br&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:5eb21c21-9ece-483d-a249-4f84de58a063&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;public class AppModule extends AbstractModule{

 @Override
 protected void configure() {
  bind(Application.class);
  bind(AppService.class).to(AppServiceImpl.class);
  ....
 }

 @Provides
 public ServiceConfig getService1Configuration(){
  return new ServiceConfig();
 }

}&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;After getting the binding configuration, Guice inject the dependency based on &lt;strong&gt;@Inject&lt;/strong&gt; annotation. Here are few ways of defining the injection point.&lt;br&gt;&lt;br&gt;&lt;strong&gt;1. Constructor binding&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:e600b7de-bdb5-4283-a26b-b659c1698b10&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;bind(Application.class);&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;Binding point&lt;br&gt;&lt;br&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:0acefa60-9555-47ad-903e-e4a845568a73&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;public class Application {
 ...
 @Inject
 public Application(AppService service,
   AppPersist persist,
   AppAuthentication authenticator) {
  this.service = service;
  this.persist = persist;
  this.authenticator = authenticator;
 }

}&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;strong&gt;2. Linked binding&lt;/strong&gt;&lt;br&gt;&lt;br&gt;It used for binding the interface to target implantation class.&lt;br&gt;&lt;br&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:2427ab2d-7650-4ee1-b585-9ca6b51419cd&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;bind(AppService.class).to(AppServiceImpl.class);
bind(AppPersist.class).to(AppPersistImpl.class);
bind(AppAuthentication.class).to(AppAuthenticationImpl.class);&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;&lt;strong&gt;3. Annotation binding&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:b8c12d2a-b09f-4e93-bb37-a8d320201ce6&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt; bind(String.class).annotatedWith(User.class).toInstance(&quot;UserID&quot;);&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;And the binding point will be annotated with &lt;a href=&quot;mailto:@User&quot;&gt;“@User&lt;/a&gt;” .&lt;br&gt;&lt;br&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:15f15109-a349-4cd5-a5ca-7bd7e143e99f&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;public class AppServiceImpl implements AppService{
 
 ...

 @Inject
 public AppServiceImpl(ServiceConfig config, 
   AppPersist persist, 
   AppAuthentication authenticator, 
   @User String user) {
  this.config = config;
  this.persist = persist;
  this.authenticator = authenticator;
  this.user = user;
 }
 
 ...
}&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;strong&gt;4. Providers methods&lt;/strong&gt;&lt;br&gt;&lt;br&gt;When Guice doesn&#39;t find the binding for injection point then it search for &lt;a href=&quot;mailto:@Provides&quot;&gt;“@Provides&lt;/a&gt;” annotated method under module classes to resolve the type. These provider methods must be define under module classes.&lt;br&gt;&lt;br&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:35a5a2c6-5056-47f3-a075-e6fddfc1e112&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt; public class AppModule extends AbstractModule{
 ...

 @Provides
 public ServiceConfig getService1Configuration(){
  return new ServiceConfig();
 }

}&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;In below code we are using “ServiceConfig” class. Which doesn&#39;t have any defined binding, so Guice will resolve the dependency through Provider function.&lt;br&gt;&lt;br&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:4b9bca7f-d8fb-49bb-b86f-4cbf4b14a573&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;public class AppServiceImpl implements AppService{
 ...

 @Inject
 public AppServiceImpl(ServiceConfig config, 
   AppPersist persist, 
   AppAuthentication authenticator, 
   @User String user) {
  this.config = config;
  this.persist = persist;
  this.authenticator = authenticator;
  this.user = user;
 }

 ...
}&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;&lt;strong&gt;&lt;u&gt;Where we can use @Inject?&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;&lt;br&gt;We can apply @Inject to &lt;br&gt;&lt;br&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Constructor&lt;/strong&gt; – It is a preferred way, because it encourage the immutable behaviour 
&lt;li&gt;&lt;strong&gt;Field&lt;/strong&gt; – This kind of injection are hard to debug
&lt;li&gt;&lt;strong&gt;Method&lt;/strong&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;strong&gt;&lt;u&gt;Unit Testing – Time to test the Application&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;&lt;br&gt;We cannot consider application done-done, till it has sufficient amount of test coverage. The best part of DI framework is, it makes application loosely couple, so unit testing becomes more easer. &lt;br&gt;&lt;br&gt;To test our sample application we need to change the &lt;u&gt;user id, persistence implementation and service configuration,&lt;/u&gt; to align test execution with our testing environment. So we have to re-wire the bindings.&lt;/p&gt;
&lt;p&gt;Here is the Test module for unit testing &lt;/p&gt;
&lt;p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:2a1ed310-9125-492a-8973-5cc9f89df04e&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;public class AppTestModule extends AbstractModule{
 @Override
 protected void configure() {
  bind(AppPersist.class).to(AppTestPersistImpl.class);
  bind(String.class).annotatedWith(User.class).toInstance(&quot;TestUserID&quot;);
 }

 @Provides
 public ServiceConfig getService1Configuration(){
  return new ServiceTestConfig();
 }
} &lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;&lt;br&gt;And below is the unit-test class for our application. In setup function we are overriding the “AppModule” with “AppTestModule”. So now we have “AppPersist” bind with “AppTestPersistImpl” and “UserID” with “TestUserID”. Apart from these changes, other bindings will be untouched. &lt;br&gt;&lt;/p&gt;
&lt;p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:afc169b3-053a-481d-93a8-86add1258cef&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;public class AppTest {
 Injector injector;

 @Before
 public void setup(){
  injector = Guice.createInjector(Modules
     .override(new AppModule())
     .with(new AppTestModule()));
 }
 
 @Test
 public void testMyApp(){
  //TEST CODE
 }
}&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;Isn’t it simple? Here we have all dependences needed for unit testing without doing too much code change :)&lt;script src=&quot;http://crux-framework-tools.googlecode.com/svn/trunk/misc/highlight/highlightLoader.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;&lt;/p&gt;&lt;br&gt;&lt;br&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/5655360447082076798/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2012/10/google-guice-dependency-injection-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/5655360447082076798'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/5655360447082076798'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2012/10/google-guice-dependency-injection-with.html' title='Google Guice: Dependency Injection with Guice 3.0'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzPGBG0odB43zokfdOFFBSNnxAKCPxsIdmFsCa2Ds5h4smjf_Jyf3R3s0FcvyD5nDf_7Alc8ZL3TBmpGKYAQ1quuKpKynJeVppGMHewcSfzoohFgQvfjWNqUJvpASenwEpM42M2MoNqdY/s72-c?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-2371194159558872576</id><published>2012-09-27T12:02:00.000+05:30</published><updated>2012-10-18T17:19:01.043+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="underscorejs"/><title type='text'>JavaScript: underscorejs with examples</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
In &lt;a href=&quot;http://techneerajnandwana.blogspot.in/2012/09/dont-reinvent-wheel-some-useful-js.html&quot;&gt;previous post&lt;/a&gt; I have mention about underscorejs library. And here is the another post to explain bit more about this library. &lt;br /&gt;
&lt;br /&gt;
Some functions used in below example to improve readability&amp;nbsp; &lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:6555402b-eeb3-4bc7-8f47-3edb7ccb6165&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre class=&quot;brush: java;&quot;&gt;function prop(name){
 return function(obj){
  return obj[name];
 }
}

function compareProp(prop, contextProp){
 return function(obj){
  return obj[prop] === this[contextProp];
 }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;strong&gt;Find visible user and show it’s default view&lt;/strong&gt; &lt;br /&gt;
Below is the list of JSON array with user object data. Now we want to show all visible user with it’s default view. &lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:f1067065-5f78-4480-9b38-34c161b9a5cb&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre class=&quot;brush: java;&quot;&gt;var ar = [{
 name: &#39;moe&#39;,
 age: 40,
 display: true,
 defaultView: 1,
 views: [ 
  { name: &#39;Admin&#39;, id: 1 }, 
    { name: &#39;Role1&#39;, id: 2 }, 
    { name: &#39;Role2&#39;, id: 3 } 
]},{
 name: &#39;larry&#39;,
 age: 50,
 display: false,
 defaultView: 1,
 views: [ 
  { name: &#39;Admin&#39;, id: 1 }, 
    { name: &#39;Role1&#39;, id: 2 }, 
    { name: &#39;Role2&#39;, id: 3 } 
]},{
 name: &#39;curly&#39;,
 age: 60,
 display: true,
 defaultView: 2,
 views: [ 
  { name: &#39;Admin&#39;, id: 1 }, 
    { name: &#39;Role1&#39;, id: 2 }, 
    { name: &#39;Role2&#39;, id: 3 } 
]}];&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
Output must be &lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:f10fd7ec-b809-4956-8fce-4ce166124d38&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre class=&quot;brush: java;&quot;&gt;[&quot;moe has default view of Admin&quot;, 
&quot;curly has default view of Role1&quot;]&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
Solution without underscorejs library&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:9567763c-05a0-4247-b0fa-3cd9bed7317e&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre class=&quot;brush: java;&quot;&gt;var data = [];
for(var i=0, il=ar.length; i&amp;lt;il; i++){
    var item = ar[i];
    if(item.display){
        var str = item.name + &quot; has default view of &quot;;
        for(var j=0, jl=item.views.length; j&amp;lt;jl; j++){
            var view = item.views[j];
            if(view.id === item.defaultView){
                str += view.name;
                data.push(str);
                break;
            }
        }
    }
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
And after using underscorejs library&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:40c0a1e9-1a0c-4298-84f0-463925d8b008&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre class=&quot;brush: java;&quot;&gt;var userDefaultView = function(user){ 
 return user.name + &#39; has default view of &#39;+ _.find(user.views,compareProp(&#39;id&#39;,&#39;defaultView&#39;),user).name;
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
by using filter and map&lt;/div&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:a248e42f-02b2-47dd-a035-d226706bcb5f&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre class=&quot;brush: java;&quot;&gt;_.chain(ar)
    .filter(prop(&#39;display&#39;))
    .map(userDefaultView).value();&lt;/pre&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Above method will iterate twice on the list, first for filtering and then for transforming, so performance will not be so good. Here is the better way of achieving the same thing by using reduce method. &lt;/div&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:d986cffc-e155-413e-adfd-9e93b42cda50&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre class=&quot;brush: java;&quot;&gt;_.reduce(ar, function(memo, user){
    if(user.display){ 
        memo.push(userDefaultView(user)); 
    }
    return memo;
}, []);&lt;/pre&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;strong&gt;Parse array data based on it’s type&lt;/strong&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:25a2f3fb-ed1c-45db-b91a-eda11d3d2bed&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre class=&quot;brush: java;&quot;&gt;var data = [
 { value:&quot;test string&quot;,  type:&quot;string&quot; },
 { value:&quot;221132&quot;,   type:&quot;int&quot; },
 { value:&quot;21112.21212&quot;,  type:&quot;float&quot; },
 { value:&quot;2012-09-22T17:01Z&quot;, type:&quot;date&quot; },
 { value:&quot;2012-09-22T17:01Z&quot;, type:&quot;datetime&quot; },
 { value:&quot;test2 string&quot;,  type:&quot;string&quot; },
 { value:&quot;True&quot;,   type:&quot;boolean&quot; },
 { value:&quot;234.1214&quot;,  type:&quot;int&quot; },
 { value:&quot;2000-09-22T04:20Z&quot;, type:&quot;date&quot; },
 { value:&quot;False&quot;,   type:&quot;boolean&quot; }
];&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
and output must be&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:c9e3e66f-fd4d-4601-99b6-34ed6baa606d&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre class=&quot;brush: java;&quot;&gt;[&quot;test string&quot;,
221132,
21112.21212,
&quot;9/22/2012&quot;,
&quot;9/22/2012 17:01&quot;,
&quot;test2 string&quot;,
true,
234,
&quot;9/22/2000&quot;,
false]&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
some formatter functions&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:ca4de90f-97c4-46b6-a366-451e7c44916f&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre class=&quot;brush: java;&quot;&gt;var formattor = function(){
 function stringFormattor(value)  { return value; }
 function intFormattor(value)  { return parseInt(value, 10); }
 function floatFormattor(value)  { return parseFloat(value, 10); }
 function dateFormattor(value)  { return Date.parse(value).toString(&quot;M/d/yyyy&quot;); }
 function datetimeFormattor(value) { return Date.parse(value).toString(&quot;M/d/yyyy HH:mm&quot;); }
 function booleanFormattor(value) { return value === &quot;True&quot;; }

 return {
  &quot;string&quot; : stringFormattor,
  &quot;int&quot;  : intFormattor,
  &quot;float&quot;  : floatFormattor,
  &quot;date&quot;  : dateFormattor,
  &quot;datetime&quot; : datetimeFormattor,
  &quot;boolean&quot; : booleanFormattor
 };
}();&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
And now our underscorejs solution &lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:0e79dc8e-dffb-4d84-b9cc-31a50a2e49d9&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre class=&quot;brush: java;&quot;&gt;_.map(data, function(obj){ return formattor[obj.type](obj.value);});&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
It is really short and expressive code.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Normalize the data&lt;/strong&gt;&lt;br /&gt;
In one of the scenario, we were dealing with large amount of data. And some time data list used to have nested array and it was causing the search too slow.&amp;nbsp; Our first implementation of search function had complexity of O(n) and it’s become O(n&lt;sup&gt;2&lt;/sup&gt;) for another nested array and so on. It was so bad that, some time browser use to become unresponsive. &lt;br /&gt;
To overcome from this issue we decided to normalize the data array to single object and make elements unique property as key. And by doing this the search function complexity is reduce to perfect O(1).&amp;nbsp; Because after normalization we were simply accessing the property instead of find it. &lt;br /&gt;
&lt;br /&gt;
For example if you want to get child “c2” in “p1” element then code will be: “data[‘p1’][‘c2’]”&lt;br /&gt;
&lt;br /&gt;
Here is the raw data &lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:59df9367-d11d-40c4-a83c-c5fedac7d0eb&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre class=&quot;brush: java;&quot;&gt;var data = [{
 key: &#39;p1&#39;,
 name: &#39;parent-1&#39;,
 childs: [{key: &#39;c1&#39;,name: &#39;child-1&#39;},{key: &#39;c2&#39;,name: &#39;child-2&#39;},{key: &#39;c3&#39;,name: &#39;child-3&#39;}]
},{
 key: &#39;p2&#39;,
 name: &#39;parent-2&#39;,
 childs: [{key: &#39;c3&#39;,name: &#39;child-3&#39;},{key: &#39;c4&#39;,name: &#39;child-4&#39;},{key: &#39;c5&#39;,name: &#39;child-5&#39;}]
},{
 key: &#39;p3&#39;,
 name: &#39;parent-3&#39;,
 childs: [{key: &#39;c11&#39;,name: &#39;child-11&#39;},{key: &#39;c12&#39;,name: &#39;child-12&#39;},{key: &#39;c13&#39;,name: &#39;child-13&#39;}]
},{
 key: &#39;p4&#39;,
 name: &#39;parent-4&#39;,
 childs: [{key: &#39;c12&#39;,name: &#39;child-12&#39;},{key: &#39;c14&#39;,name: &#39;child-14&#39;},{key: &#39;c11&#39;,name: &#39;child-11&#39;}]
},{
 key: &#39;p5&#39;,
 name: &#39;parent-5&#39;,
 childs: [{key: &#39;c8&#39;,name: &#39;child-8&#39;},{key: &#39;c1&#39;,name: &#39;child-1&#39;},{key: &#39;c3&#39;,name: &#39;child-3&#39;}]
},{
 key: &#39;p6&#39;,
 name: &#39;parent-6&#39;
}];&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
And expected output after data normalization&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:cbbb191a-0dff-4c64-9ad7-a468164e3a37&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre class=&quot;brush: java;&quot;&gt;{
 p1: {
  key: &#39;p1&#39;,
  name: &#39;parent-1&#39;,
  childs: {
   c1: {key: &#39;c1&#39;,name: &#39;child-1&#39;},
   c2: {key: &#39;c2&#39;,name: &#39;child-2&#39;},
   c3: {key: &#39;c3&#39;,name: &#39;child-3&#39;}
  }
 }, 
...
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Solution&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:d3b4a0e1-02d5-474e-af96-0dd3ce43201d&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre class=&quot;brush: java;&quot;&gt;var normalize = function(p1, p2){
    p1[p2.key] = p2;
    if(p2.childs){ p2.childs = _.reduce(p2.childs,normalize,{}); }
    return p1;
}

_.reduce(data, normalize, {});&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
Again it’s simple, small and readable code. &lt;br /&gt;
&lt;br /&gt;
This is really elegant library with tons of utility functions as you start exploring it, you will find your project codebase much smaller and clean. &lt;br /&gt;
&lt;br /&gt;
PS: &lt;a href=&quot;http://lodash.com/#features&quot;&gt;Lo-Dash&lt;/a&gt;&amp;nbsp;is a drop and replace library for underscorejs with extra features + performance + bug fixes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;http://crux-framework-tools.googlecode.com/svn/trunk/misc/highlight/highlightLoader.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/2371194159558872576/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2012/09/javascript-underscorejs-with-examples.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/2371194159558872576'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/2371194159558872576'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2012/09/javascript-underscorejs-with-examples.html' title='JavaScript: underscorejs with examples'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-5739225200929562184</id><published>2012-09-15T00:01:00.000+05:30</published><updated>2012-09-27T11:51:31.561+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>Don’t reinvent the wheel: Some useful JS libraries</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It is very common to see “Utility” file in many project, which have all commonly used functions. In other word you can say it is kitchen sink file, where people dump all common functions. Before you realize it grows more than 1000 lines and become a maintenance hell. 
&lt;p&gt;So keep in mind, each time when you write a new class or function you are increasing the project maintenance coast. 
&lt;p&gt;&amp;nbsp; &lt;p&gt;There are few things you should consider before writing the code 
&lt;ul&gt;
&lt;li&gt;Know Your Library – Most of the library has some utility functions so keep exploring it. 
&lt;li&gt;Use Utility Library – If existing library doesn&#39;t have needed functionality then always consider using 3rd party Utility Library with good test converge.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Some of my favourite libraries 
&lt;p&gt;&amp;nbsp; &lt;p&gt;&lt;a href=&quot;http://underscorejs.org&quot;&gt;&lt;strong&gt;Underscore JS&lt;/strong&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It is one of the best utility library, which has collection of most commonly used functions. Here are few function with example code. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;u&gt;Each&lt;/u&gt;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:99328da4-8edf-429b-ab8f-aa2f42a23fcf&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;_.each([1, 2, 3], function(num){ alert(num); });
=&amp;gt; alerts each number in turn...
_.each({one : 1, two : 2, three : 3}, function(num, key){ alert(num); });
=&amp;gt; alerts each number in turn...&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;u&gt;Map&lt;/u&gt;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:45dbe282-8d5d-41b7-9041-5e3fda2e8a46&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;_.map([1, 2, 3], function(num){ return num * 3; });
=&amp;gt; [3, 6, 9]
_.map({one : 1, two : 2, three : 3}, function(num, key){ return num * 3; });
=&amp;gt; [3, 6, 9]&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;u&gt;Filter&lt;/u&gt;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:f6131ade-f5dc-476f-9023-71926448ecca&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;var evens = _.filter([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
=&amp;gt; [2, 4, 6]&lt;/pre&gt;&lt;/div&gt;&lt;u&gt;&lt;/u&gt;
&lt;p&gt;&lt;u&gt;Pluck&lt;/u&gt;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:a3839d9b-a9d7-4a05-9491-6dc8fa2fcfc9&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;var stooges = [{name : &#39;moe&#39;, age : 40}, {name : &#39;larry&#39;, age : 50}, {name : &#39;curly&#39;, age : 60}];
_.pluck(stooges, &#39;name&#39;);
=&amp;gt; [&quot;moe&quot;, &quot;larry&quot;, &quot;curly&quot;]&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;u&gt;Union&lt;/u&gt;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:463d5110-78dd-4262-85cc-23ba33acaf9e&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;_.union([1, 2, 3], [101, 2, 1, 10], [2, 1]);
=&amp;gt; [1, 2, 3, 101, 10]&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;u&gt;Intersection&lt;/u&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:78cfe66a-954f-4224-a584-7a698e489906&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;_.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]);
=&amp;gt; [1, 2]&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;u&gt;Keys&lt;/u&gt;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:e8a1b6af-5acb-43a0-875f-b266d58c9528&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;_.keys({one : 1, two : 2, three : 3});
=&amp;gt; [&quot;one&quot;, &quot;two&quot;, &quot;three&quot;]&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;u&gt;Values&lt;/u&gt;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:540dc40a-4cdc-43c6-9dd6-0a15d146d4e2&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;_.values({one : 1, two : 2, three : 3});
=&amp;gt; [1, 2, 3]&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;u&gt;Escape&lt;/u&gt;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:fa9800f1-8ad8-466c-b66d-e91ba653828c&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;_.escape(&#39;Curly, Larry &amp;amp; Moe&#39;);
=&amp;gt; &quot;Curly, Larry &amp;amp;amp; Moe&quot;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;u&gt;Chain&lt;/u&gt;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:357abb0a-0a5f-45ed-98d2-2ba7b953d4b3&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;var stooges = [{name : &#39;curly&#39;, age : 25}, {name : &#39;moe&#39;, age : 21}, {name : &#39;larry&#39;, age : 23}];
var youngest = _.chain(stooges)
  .sortBy(function(stooge){ return stooge.age; })
  .map(function(stooge){ return stooge.name + &#39; is &#39; + stooge.age; })
  .first()
  .value();
=&amp;gt; &quot;moe is 21&quot;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;and more &lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:3aaae126-a86a-4037-a71a-45ebe51fa804&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;var lyrics = [
  {line : 1, words : &quot;I&#39;m a lumberjack and I&#39;m okay&quot;},
  {line : 2, words : &quot;I sleep all night and I work all day&quot;},
  {line : 3, words : &quot;He&#39;s a lumberjack and he&#39;s okay&quot;},
  {line : 4, words : &quot;He sleeps all night and he works all day&quot;}
];

_.chain(lyrics)
  .map(function(line) { return line.words.split(&#39; &#39;); })
  .flatten()
  .reduce(function(counts, word) {
    counts[word] = (counts[word] || 0) + 1;
    return counts;
}, {}).value();

=&amp;gt; {lumberjack : 2, all : 4, night : 2 ... }&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Below is the complete list of functions provided by this library.&amp;nbsp;&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;table style=&quot;border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid&quot; border=&quot;0&quot; cellspacing=&quot;1&quot; cellpadding=&quot;0&quot; width=&quot;100%&quot; align=&quot;center&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;
&lt;p align=&quot;center&quot;&gt;&lt;strong&gt;Collections &lt;/strong&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;
&lt;p align=&quot;center&quot;&gt;&lt;strong&gt;Arrays &lt;/strong&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;
&lt;p align=&quot;center&quot;&gt;&lt;strong&gt;Functions&lt;/strong&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;
&lt;p align=&quot;center&quot;&gt;&lt;strong&gt;Objects&lt;/strong&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;
&lt;p align=&quot;center&quot;&gt;&lt;strong&gt;Utility&lt;/strong&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;
&lt;p align=&quot;center&quot;&gt;&lt;strong&gt;Chaining&lt;/strong&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;each&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;first&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;bind&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;keys&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;noConflict&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;chain&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;map&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;initial&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;bindAll&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;values&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;identity&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;value&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;reduce&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;last&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;memoize&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;functions&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;times&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;reduceRight&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;rest&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;delay&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;extend&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;mixin&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;find&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;compact&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;defer&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;pick&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;uniqueId&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;filter&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;flatten&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;throttle&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;defaults&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;escape&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;reject&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;without&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;debounce&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;clone&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;result&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;all&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;union&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;once&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;tap&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;template&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;any&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;intersection&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;after&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;has&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;include&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;difference&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;wrap&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;isEqual&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;invoke&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;uniq&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;compose&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;isEmpty&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;pluck&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;zip&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;isElement&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;max&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;indexOf&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;isArray&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;min&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;lastIndexOf&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;isObject&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;sortBy&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;range&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;isArguments&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;groupBy&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;isFunction&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;sortedIndex&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;isString&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;shuffle&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;isNumber&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;toArray&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;isFinite&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;size&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;isBoolean&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;isDate&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;isRegExp&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;isNaN&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;isNull&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;80&quot;&gt;isUndefined&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;88&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;76&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p align=&quot;left&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.datejs.com/&quot;&gt;&lt;strong&gt;Date JS&lt;/strong&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This is very fluent JS library for date and really easy to use. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;date comparison &lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:5f85aaf7-50ab-4583-bb6c-2e6a76fd3132&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;var temp = new Date();
temp.setHours(0);
temp.setMinutes(0);
temp.setSeconds(0);
temp.setMilliseconds(0);
 
var today = new Date(someDate.getTime()); 
var today.setHours(0);
var today.setMinutes(0);
var today.setSeconds(0);
var today.setMilliseconds(0);
 
(today == temp); // true|false&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;date comparison with date JS&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:12bb9282-9e6e-438d-960e-6798bfd14811&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;/ with Datejs, but without .same
someDate.clone().clearTime().equals(Date.today());
 
// New
someDate.same().day();
 
// Or,
someDate.is().today();&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;more example &lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:71f12ff6-9e83-49d1-a018-c17745312d75&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;var today = Date.today();
var past = Date.today().add(-6).days();
var future = Date.today().add(6).days();


Date.compare(today, future);                    // -1
Date.compare(today, new Date().clearTime());    // 0
Date.compare(today, past)                       // 1&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Date formatting [&lt;a href=&quot;http://code.google.com/p/datejs/wiki/FormatSpecifiers&quot;&gt;formatting options&lt;/a&gt;] &lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:86f05721-14e6-4c00-a8b0-aebac2a1a55f&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;new Date().toISOString();  // &quot;&quot;2008-04-13T10:07:15Z&quot;&quot;

new Date().toString(&quot;yyyy-MM-ddTHH:mm:ssZ&quot;);  // &quot;2008-04-13T04:11:05Z&quot;

Date.today().toString();           // native .toString() functionality

Date.today().toString(&quot;M/d/yyyy&quot;); // 11/19/2007

Date.today().toString(&quot;d-MMM-yyyy&quot;); // 19-Nov-2007

new Date().toString(&quot;HH:mm&quot;);      // 18:45&lt;/pre&gt;&lt;/div&gt;&lt;script src=&quot;http://crux-framework-tools.googlecode.com/svn/trunk/misc/highlight/highlightLoader.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please check this &lt;a href=&quot;http://code.google.com/p/datejs/wiki/APIDocumentation&quot;&gt;wiki&lt;/a&gt; page for more information about this library. &lt;/p&gt;&lt;script src=&quot;http://crux-framework-tools.googlecode.com/svn/trunk/misc/highlight/highlightLoader.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/5739225200929562184/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2012/09/dont-reinvent-wheel-some-useful-js.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/5739225200929562184'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/5739225200929562184'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2012/09/dont-reinvent-wheel-some-useful-js.html' title='Don’t reinvent the wheel: Some useful JS libraries'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-1169859448621303630</id><published>2012-09-08T23:49:00.004+05:30</published><updated>2012-09-09T16:05:19.487+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>BOM Character: Unknown guest in your file</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Many times I have seen special character like “ &lt;strong&gt;ï»¿ &lt;/strong&gt;” in starting of file and most of the time I ignored it. But recently it started causing more trouble, when my JS validation utility started failing. And log file shows same special character again. After more investigation, I find out it was introduce when I creates a new file in Eclipse. &lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;u&gt;So, what is this symbol?&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
It is a &lt;a href=&quot;http://en.wikipedia.org/wiki/Byte_order_mark&quot;&gt;BOM (byte order mark)&lt;/a&gt; character used to signal the endianness (byte order) of a text file or stream[wiki]. This character differ based on encoding type like&lt;br /&gt;
&lt;br /&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;2&quot; cellspacing=&quot;0&quot; style=&quot;width: 400px;&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;200&quot;&gt;&lt;div align=&quot;center&quot;&gt;
&lt;strong&gt;Encoding&lt;/strong&gt;&lt;/div&gt;
&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;200&quot;&gt;&lt;div align=&quot;center&quot;&gt;
&lt;strong&gt;Symbol&lt;/strong&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;200&quot;&gt;UTF-8&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;200&quot;&gt;ï»¿&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;200&quot;&gt;UTF-16 (BE)&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;200&quot;&gt;þÿ&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;200&quot;&gt;UTF-16 (LE)&lt;/td&gt;
&lt;td valign=&quot;top&quot; width=&quot;200&quot;&gt;ÿþ&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
Next question is, how to remove this character from my file. And if you are using Notepad++ editor it will be much easier. You have to select the “Encoding” option from menu bar and choose “Convert to UTF-8 without BOM”.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhr5cUhx5qV3m4FGqf5TZEne4JuveMFQ3-NrEX4EKn35MTMFiOXXQ9r6Ox6Cz2FADOdR72ZpJtt6UOVHEarn-uQTB9ylLW2pVzgwNVSfzqfaT4a9o0hZJ6UZvdjHaQsJO2fS-Fo3QpP-nA/s1600/notepad+remove+bom.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhr5cUhx5qV3m4FGqf5TZEne4JuveMFQ3-NrEX4EKn35MTMFiOXXQ9r6Ox6Cz2FADOdR72ZpJtt6UOVHEarn-uQTB9ylLW2pVzgwNVSfzqfaT4a9o0hZJ6UZvdjHaQsJO2fS-Fo3QpP-nA/s1600/notepad+remove+bom.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;u&gt;How to handle BOM character in your code?&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/strong&gt;
I will suggest to use some sophisticated library instead of rolling out your own solution. And “&lt;a href=&quot;http://commons.apache.org/io/&quot;&gt;Apache Commons IO&lt;/a&gt;” library has dedicated class “&lt;a href=&quot;http://commons.apache.org/io/api-release/org/apache/commons/io/input/BOMInputStream.html&quot;&gt;BOMInputStream&lt;/a&gt;” for this problem.&lt;br /&gt;
&lt;br /&gt;
Some code snippet from API doc&lt;br /&gt;
&lt;br /&gt;
1. Detect and exclude a UTF-8 BOM&lt;br /&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:8a6afd53-bfc5-426f-8e67-eba9088e4f80&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre class=&quot;brush: java;&quot;&gt; BOMInputStream bomIn = new BOMInputStream(in);
 if (bomIn.hasBOM()) {
     // has a UTF-8 BOM
 }&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
2. Detect a UTF-8 BOM (but don&#39;t exclude it)&lt;br /&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:35bd3d69-8ec3-47f3-b90c-54900cc70cb0&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre class=&quot;brush: java;&quot;&gt; boolean include = true;
 BOMInputStream bomIn = new BOMInputStream(in, include);
 if (bomIn.hasBOM()) {
     // has a UTF-8 BOM
 }&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
3. Detect Multiple BOMs&lt;br /&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:11436134-74c1-40f0-adc3-dbf9998b23db&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre class=&quot;brush: java;&quot;&gt; BOMInputStream bomIn = new BOMInputStream(in, 
   ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE,
   ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE
   );
 if (bomIn.hasBOM() == false) {
     // No BOM found
 } else if (bomIn.hasBOM(ByteOrderMark.UTF_16LE)) {
     // has a UTF-16LE BOM
 } else if (bomIn.hasBOM(ByteOrderMark.UTF_16BE)) {
     // has a UTF-16BE BOM
 } else if (bomIn.hasBOM(ByteOrderMark.UTF_32LE)) {
     // has a UTF-32LE BOM
 } else if (bomIn.hasBOM(ByteOrderMark.UTF_32BE)) {
     // has a UTF-32BE BOM
 }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;script src=&quot;http://crux-framework-tools.googlecode.com/svn/trunk/misc/highlight/highlightLoader.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/1169859448621303630/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2012/09/bom-character-un-unknown-guest-in-your.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/1169859448621303630'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/1169859448621303630'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2012/09/bom-character-un-unknown-guest-in-your.html' title='BOM Character: Unknown guest in your file'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhr5cUhx5qV3m4FGqf5TZEne4JuveMFQ3-NrEX4EKn35MTMFiOXXQ9r6Ox6Cz2FADOdR72ZpJtt6UOVHEarn-uQTB9ylLW2pVzgwNVSfzqfaT4a9o0hZJ6UZvdjHaQsJO2fS-Fo3QpP-nA/s72-c/notepad+remove+bom.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-8462618249734299380</id><published>2012-08-31T15:01:00.001+05:30</published><updated>2012-08-31T15:18:02.682+05:30</updated><title type='text'>“80–20 rule” in Software - Some Interesting facts</title><content type='html'>&lt;p&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Pareto_principle&quot;&gt;80-20 rule&lt;/a&gt; states that, for many events, roughly 80% of the effects come from 20% of the causes. 
&lt;p&gt;&amp;nbsp; &lt;p&gt;&lt;strong&gt;&lt;u&gt;In Software Development&lt;/u&gt;&lt;/strong&gt; 
&lt;ul&gt;
&lt;li&gt;80% of users only require 20% of the features 
&lt;li&gt;80% features are done in 20% of project time (requirement added to the project very late) 
&lt;li&gt;80% of requirement conceptualized by everyone within 20% time of first meeting &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp; &lt;p&gt;I really like the iterative development which help to overcome from these facts because it break big cycle of project development to small feature development cycle, where we can prioritise the feature based on 80% users and start development. It is only successful when features are done within the iteration, and &lt;strong&gt;&lt;a href=&quot;http://agile101.net/2009/09/04/what-does-done-mean-in-agile-software-development/&quot;&gt;I really mean done&lt;/a&gt;&lt;/strong&gt; (*agile methodology has done-done concept and that is very useful) 
&lt;p&gt;And just want to remind another agile practice known as Jamboree meetings for project planning to overcome from last point. 
&lt;p&gt;Actually I am quite fond of agile practices =) 
&lt;p&gt;&amp;nbsp; &lt;p&gt;&lt;strong&gt;&lt;u&gt;In software Quality&lt;/u&gt;&lt;/strong&gt; 
&lt;ul&gt;
&lt;li&gt;20% top most reported bugs fixes, will eliminate 80% of the application error and crashes 
&lt;li&gt;80% of software quality is maintained by 20% of programmers 
&lt;li&gt;80% of bugs in an application are written by 20% of developers 
&lt;li&gt;80% of bugs are fixed in 20% of time 
&lt;li&gt;20% of a business application accounts for 80% of bugs&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp; &lt;p&gt;These facts are really interesting and helpful. Especially it helps, when you are making decision or doing planning. &lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/8462618249734299380/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2012/08/8020-rule-in-software-some-interesting.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/8462618249734299380'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/8462618249734299380'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2012/08/8020-rule-in-software-some-interesting.html' title='“80–20 rule” in Software - Some Interesting facts'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-3195681644840848298</id><published>2012-07-08T15:27:00.000+05:30</published><updated>2013-05-13T23:08:50.796+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Singleton"/><title type='text'>Java: Singleton class - double-checked locking</title><content type='html'>&lt;div style=&quot;text-align: left&quot; dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;Most of the singleton class implementation i have seen are inefficient or buggy specially in multithreaded environment. So, here is my two cents on singleton classes.&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot; dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;&lt;br&gt;We can implement singleton class based on&amp;nbsp; &lt;br&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot; dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;ul&gt;
&lt;li&gt;Eager instantiation and 
&lt;li&gt;Lazy instantiation &lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;br&gt;&lt;strong&gt;Singleton class based on eager instantiation &lt;/strong&gt;&lt;br&gt;In “Effective Java” Josh Bloch preferred using &lt;u&gt;single element enum type&lt;/u&gt; to implement singleton class. &lt;br&gt;&lt;br&gt;&lt;pre class=&quot;brush: java; toolbar: false&quot;&gt;public enum Singleton {
 ISTANCE;
 
 //other methods
}&lt;/pre&gt;&lt;br&gt;&lt;strong&gt;Singleton class based on lazy instantiation&lt;/strong&gt;&lt;br&gt;Some developer use synchronized method to make method thread safe but it make your function very slow. Other way to make function thread safe is synchronized block. But incorrect use of it, will result in same performance bottleneck. &lt;br&gt;Here is the preferred way to make singleton class thread safe. (&lt;u&gt;“double-checked locking” algorithm&lt;/u&gt;).&lt;br&gt;&lt;br&gt;&lt;pre class=&quot;brush: java; toolbar: false&quot;&gt;public class Singleton {
 private static volatile Singleton INSTANCE = null;
 
 private Singleton(){}
 
 public static Singleton getInstance(){
  Singleton inst = INSTANCE;
  if(inst == null){    //first check 
   synchronized (Singleton.class) {
    inst = INSTANCE;
    if(inst == null){  //second check
     INSTANCE = inst = new Singleton();
    }
   }
  }
  return INSTANCE;
 }
 
 //other methods
}&lt;/pre&gt;&lt;br&gt;In above implementation we have two check before creating a new instance of singleton class, and because of this it is known as &lt;u&gt;double lock checking&lt;/u&gt;.&lt;br&gt;&lt;br&gt;Read more about singleton class and &quot;Double-checked locking&quot; on &lt;a href=&quot;http://en.wikipedia.org/wiki/Double-checked_locking&quot;&gt;http://en.wikipedia.org/wiki/Double-checked_locking&lt;/a&gt; and &lt;a href=&quot;http://www.ibm.com/developerworks/java/library/j-dcl/index.html&quot;&gt;http://www.ibm.com/developerworks/java/library/j-dcl/index.html&lt;/a&gt;&lt;br&gt;&lt;script src=&quot;http://crux-framework-tools.googlecode.com/svn/trunk/misc/highlight/highlightLoader.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/3195681644840848298/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2012/07/java-singleton-class.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/3195681644840848298'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/3195681644840848298'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2012/07/java-singleton-class.html' title='Java: Singleton class - double-checked locking'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-7536107530328980905</id><published>2012-06-04T10:41:00.001+05:30</published><updated>2012-06-04T10:51:23.611+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>Java: Strong References, Soft References and Weak References</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
There are many use-cases where we want to control, when our objects are collected by GC(Garbage Collector). Package &quot;java.lang.ref&quot; provides reference-object classes, which support a limited degree of interaction with the garbage collector. And GC reclaim the object memory based on it&#39;s &lt;a href=&quot;http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/ref/package-summary.html#reachability&quot;&gt;reachability&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;

&lt;strong&gt;Strong Reference&lt;/strong&gt;&lt;/h4&gt;
Newly created objects are strongly reachable by the thread that created it. So object will be remain in heap till thread is running or some variable hold this object reference.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: java; toolbar: false&quot;&gt;//leaking array
private static List&amp;lt;String&amp;gt; leakingArrayWithStrongRef = 
                                new LinkedList&amp;lt;String&amp;gt;();

    public void StrongReferenceTest(){
        try {
            for (int i = 0; i &amp;lt; 500000; i++) {
                String data = LEAKING_DATA + i;
                // Add data to our leaking array...
                leakingArrayWithStrongRef.add(data);
            }
        } catch (OutOfMemoryError ofm) {
            System.out.println(&quot;OutOfMemoryError&quot;);
        } catch (Throwable e) {
            System.out.println(&quot;UnexpectedError&quot;);
        }        
    }&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div align=&quot;center&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVZ35NCuUTFOKAdcikIXM2eDY-1jr6CgviAwyBQ4vMBv6ZSwDzaztRJkYASbdHM8D5jD2YmFvKfI0_bDo2rfXgbRcPIol-ucIHP0Sb_Zt0xbSJ7V1XWCWCoQDs4Jm7FOF1CjZuRZ-HOp0/s1600-h/image6.png&quot;&gt;&lt;img alt=&quot;image&quot; border=&quot;0&quot; height=&quot;293&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmL4D_4TacuWp6bcK23Xb_zOuaNyjudclx3zenDTx6xQqPm0wWRNjbv6NMDXikxKhRQb5l887VKVxc5EiH_GagzW5H9cDga-5zH2WEBl2N0Fn1J5lTLc0c8dCW_ZdrJolxpCb925wFVYE/?imgmax=800&quot; style=&quot;border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: block; float: none; margin-left: auto; margin-right: auto;&quot; title=&quot;image&quot; width=&quot;415&quot; /&gt;&lt;/a&gt;Heap Memory trend chart when unwanted objects added in Array &lt;/div&gt;
&lt;br /&gt;
&lt;div align=&quot;left&quot;&gt;
In this example array hold the strong reference of string. As we start adding string object in array then heap memory increase to it&#39;s max limit and throws &quot;OutOfMemoryEerror&quot; exception.&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Soft Reference&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Soft Reference are the &lt;a href=&quot;http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/ref/package-summary.html#reachability&quot;&gt;softly reachable&lt;/a&gt; object. These kind of object will remain in the heap memory till GC clean them out in need of memory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: java; toolbar: false&quot;&gt;//leaking array
private static List&amp;lt;SoftReference&amp;lt;String&amp;gt;&amp;gt; leakingArrayWithSoftRef = 
                                new LinkedList&amp;lt;SoftReference&amp;lt;String&amp;gt;&amp;gt;();

    public void SoftReferenceTest(){
        try {
            for (int i = 0; i &amp;lt; 500000; i++) {
                SoftReference&amp;lt;String&amp;gt; data = new SoftReference&amp;lt;String&amp;gt;(LEAKING_DATA + i);
                // Add data to our leaking array...
                leakingArrayWithSoftRef.add(data);
            }
        } catch (OutOfMemoryError ofm) {
            System.out.println(&quot;OutOfMemoryError&quot;);
        } catch (Throwable e) {
            System.out.println(&quot;UnexpectedError&quot;);
        }     
    }&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div align=&quot;center&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzGzrHNXfZsm4GX3OycL1pyORScLx50XIGCqfjqLKCEd_g35jib77PdutP7xMgHhjgZg2RW-i1vo1M2A7VKy3AB74sFlZjUMGheQOjVd-kGDj1LdutrZLO1qKbHmI15x8xfvMOMc2b4hY/s1600-h/image26.png&quot;&gt;&lt;img alt=&quot;image&quot; border=&quot;0&quot; height=&quot;281&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGqaFoKLv0KYka-YGLE1uQ87RBaTLlba0W1WwS8MeJDGfhL5CfnlEL8A7Y6XDKGFi0El9dLs0PfGWgGCgNMjEnaj4stYgXS40_x_RpxYiOPDw2TD0ouNK4V0fppghcU1HPtLnawsF4CP0/?imgmax=800&quot; style=&quot;border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: block; float: none; margin-left: auto; margin-right: auto;&quot; title=&quot;image&quot; width=&quot;407&quot; /&gt;&lt;/a&gt;Heap Memory trend chart when unwanted objects added in Array &lt;/div&gt;
&lt;br /&gt;
&lt;div align=&quot;left&quot;&gt;
In this example array hold the soft reference of string object. As we start adding string object in array then heap memory increase to it&#39;s max limit and GC reclaim the soft reference object from heap. And in this code you will not get &quot;OutOfMemoryEerror&quot;.&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Weak Reference&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Weak Reference are &lt;a href=&quot;http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/ref/package-summary.html#reachability&quot;&gt;weakly reachable&lt;/a&gt; objects. And these kind of object will reclaim by the GC at any point of time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: java; toolbar: false&quot;&gt;//leaking array
private static List&amp;lt;WeakReference&amp;lt;String&amp;gt;&amp;gt; leakingArrayWithWeakRef = 
                                new LinkedList&amp;lt;WeakReference&amp;lt;String&amp;gt;&amp;gt;();

    public void WeakReferenceTest(){
        try {
            for (int i = 0; i &amp;lt; 500000; i++) {
                WeakReference&amp;lt;String&amp;gt; data = new WeakReference&amp;lt;String&amp;gt;(LEAKING_DATA + i);
                // Add data to our leaking array...
                leakingArrayWithWeakRef.add(data);
            }
        } catch (OutOfMemoryError ofm) {
            System.out.println(&quot;OutOfMemoryError&quot;);
        } catch (Throwable e) {
            System.out.println(&quot;UnexpectedError&quot;);
        }       
    }&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div align=&quot;center&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOVDEAi8lzv3NUruSavCUoJRi7VwslV3Wf17IFu6ot0sdOODaZ4hW9v2OSYuXWw50j7PND80M1TPocnpIV4ZOBrW__uKtL7NFdJNNpbrjncmZ36GEDIrN1wUabS7UfAOPA6Pz6PvYsJjM/s1600-h/image21.png&quot;&gt;&lt;img alt=&quot;image&quot; border=&quot;0&quot; height=&quot;284&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipyWYzvwkkKYAeVidEXjL3KJ5mvT1D6f7qXhsQQDvhecAj_4rv9C2JWBpfppwu4imXistDE8Z2-EQUJY6DyTU9UErN9ZCvM8feo4-JwpT3YipNWttffhUKT2oejmd-MQB3zonEZztxUTY/?imgmax=800&quot; style=&quot;border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: block; float: none; margin-left: auto; margin-right: auto;&quot; title=&quot;image&quot; width=&quot;407&quot; /&gt;&lt;/a&gt; Heap Memory trend chart when unwanted objects added in Array &lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In this example array hold the weak reference of string object. As we start adding string object in array then heap memory start increasing slightly and decrease after few seconds. It&#39;s happen because GC clean these object from the array more frequently. And in this code you will not get &quot;OutOfMemoryEerror&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PS: I have used &quot;jconsole.exe&quot; to generate above graphs, which comes as a part of &quot;JDK&quot; toolkit. &lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/7536107530328980905/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2012/06/java-strong-references-soft-references.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/7536107530328980905'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/7536107530328980905'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2012/06/java-strong-references-soft-references.html' title='Java: Strong References, Soft References and Weak References'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmL4D_4TacuWp6bcK23Xb_zOuaNyjudclx3zenDTx6xQqPm0wWRNjbv6NMDXikxKhRQb5l887VKVxc5EiH_GagzW5H9cDga-5zH2WEBl2N0Fn1J5lTLc0c8dCW_ZdrJolxpCb925wFVYE/s72-c?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-5464167608645959566</id><published>2012-05-20T11:51:00.001+05:30</published><updated>2012-07-19T19:35:17.206+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="JMeter"/><category scheme="http://www.blogger.com/atom/ns#" term="Load Testing"/><title type='text'>JMeter: Creating First Load Test</title><content type='html'>&lt;div style=&quot;text-align: left&quot; dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;&lt;strong&gt;What we want to do&lt;/strong&gt; &lt;/div&gt;
&lt;div style=&quot;text-align: left&quot; dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;ol style=&quot;text-align: left&quot;&gt;
&lt;li&gt;Simulate concurrent users 
&lt;li&gt;Simulate requests 
&lt;li&gt;Generate reports 
&lt;li&gt;Troubleshooting &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&lt;br&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&lt;strong&gt;JMeter GUI&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&lt;u&gt;Test Pan&lt;/u&gt; Plan is a root element where all test related settings are define.&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot;&gt;In &lt;u&gt;Thread Group&lt;/u&gt; we can define pool of user to simulate load on the test&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&lt;u&gt;Work Bench&lt;/u&gt; is for non test helpers&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&amp;nbsp;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdPurYWTLGNvEfupse10M6EdmOIKzRvT-vMo7AfkNsXuzSoMl6eQAtiZosbYJulEvCc7UlQWtoMz6uXHMdkGInqrWXeQHo57fJ9zt1muZFhgSpD63ofjW7fMAUHPONTcDo-o5AiUReiE0/s1600-h/image%25255B112%25255D.png&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYKWNKmtHim0n4V2GCXk-7cOP_w1ddR-J-vXTxYdnOxOng9SMGJd0SS6XddAW2lq0vU6dZix1rRPlnV_gLrWSmZcpEFdz5z4pbAhvfkDE1i4QMcsiClJF12NrIuIw57qOa89SyChwB6P8/?imgmax=800&quot; width=&quot;422&quot; height=&quot;231&quot;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&lt;br&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Common terms in JMeter&lt;/strong&gt;&lt;/div&gt;
&lt;ul style=&quot;text-align: left&quot;&gt;
&lt;li&gt;User&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ⇒ Thread 
&lt;li&gt;Request&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ⇒ Sampler 
&lt;li&gt;Report&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ⇒ Listeners &lt;/li&gt;&lt;/ul&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&lt;br&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Setting up the load test&lt;/strong&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;1. &lt;/strong&gt;&lt;u&gt;Simulate concurrent users &lt;/u&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Add thread &amp;gt; Thread Group 
&lt;ul&gt;
&lt;li&gt;Number of Threads - concurrent users =10 
&lt;li&gt;Ramp-Up Period - seconds until all users are active =1 (eg. if user define 10 Threads and 100 Ramp-Up Period then, it means each thread will start in 100/10=10 seconds time difference) 
&lt;li&gt;Loop Count - how many repetitions =1 
&lt;li&gt;&lt;span style=&quot;background-color: white&quot;&gt;Calculating think time &lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style=&quot;background-color: white&quot;&gt;&lt;/span&gt;&lt;br&gt;
&lt;div style=&quot;text-align: justify&quot;&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&lt;span style=&quot;background-color: white&quot;&gt;&lt;span style=&quot;background-color: white&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Ramp-up time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 120 seconds&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify&quot;&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&lt;span style=&quot;background-color: white&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Number of users&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp; 30 &lt;/span&gt;&lt;br&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify&quot;&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&lt;span style=&quot;background-color: white&quot;&gt;&lt;span style=&quot;background-color: white&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Then think time will be&amp;nbsp; =&amp;nbsp; ramp up time/number of users&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&lt;span style=&quot;background-color: white&quot;&gt;&lt;span style=&quot;background-color: white&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white&quot;&gt;120/30 = &lt;/span&gt;&lt;span style=&quot;background-color: white&quot;&gt;4 seconds&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;span style=&quot;background-color: white&quot;&gt;&lt;/span&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&lt;br&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify&quot;&gt;&lt;span style=&quot;background-color: white&quot;&gt;&lt;span style=&quot;background-color: white&quot;&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;background-color: white&quot;&gt;&lt;/span&gt;&lt;img style=&quot;border-right-width: 0px; background-color: white; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgElqX9_4SODXo1c9qXtcZ2GpWwB2eS93MdzMwUEno_mw4QY-xhLcw0pOk_rH2y2pEjg2n6M6oncspUF74T-gPyTUygKTc9W-EMdsjCMSKkQEr9ICeNITgDz0EPXdYSOSTUDnXQwi8bKtU/?imgmax=800&quot; width=&quot;200&quot; height=&quot;141&quot;&gt;&lt;br&gt;
&lt;ol style=&quot;text-align: left&quot;&gt;&lt;/ol&gt;&lt;br&gt;
&lt;p&gt;&lt;strong&gt;2. &lt;/strong&gt;&lt;u&gt;Simulate requests&lt;/u&gt; &lt;/p&gt;
&lt;ul style=&quot;text-align: left; background-color: white&quot;&gt;
&lt;ul&gt;
&lt;li&gt;Add Sampler &amp;gt; HTTP Request 
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white&quot;&gt;Server Name or IP = &lt;/span&gt;&lt;a style=&quot;background-color: white&quot; href=&quot;http://www.google.com/&quot;&gt;www.google.com&lt;/a&gt; 
&lt;li&gt;&lt;span style=&quot;background-color: white&quot;&gt;Path = /&lt;/span&gt; &lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;
&lt;ul style=&quot;text-align: left; background-color: white&quot;&gt;
&lt;li&gt;
&lt;ul&gt;
&lt;li&gt;&lt;img style=&quot;border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiihC-r8NM-GUlnaCe7zH7akRZnYa57LNmeGpIQELW8j8ImGvrugVDyKByuvYxnqK61pdU0Xto0ZJzjckfNAeexkbWYZVmL-VTCIqZ1-scWRX5UYYet6Q7Qfc9XGf_54q6XpS_hbpyDEa4/?imgmax=800&quot; width=&quot;231&quot; height=&quot;146&quot;&gt; &lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;3. &lt;/strong&gt;&lt;u&gt;Generate reports&lt;/u&gt; &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Add &amp;gt; Listener &amp;gt; Aggregate Graph 
&lt;li&gt;Add &amp;gt; Listener &amp;gt; View Results Tree &lt;/li&gt;&lt;/ul&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&lt;br&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Running the load test &lt;/strong&gt;&lt;/div&gt;
&lt;ul style=&quot;text-align: left&quot;&gt;
&lt;li&gt;Click on Run &amp;gt; Start or &quot;ctr+r&quot; 
&lt;li&gt;Click on &quot;Aggregate Graph&quot; 
&lt;ul&gt;
&lt;li&gt;Click &quot;Display Graph&quot; for chart &lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img style=&quot;border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCDjG7FS2U60dhT74BkTnCtWnPVWh3crcGctnsdt4jTqVWRjfjfRrsR6y-c10DD2gAn4Z-MkFcyszBRq7utiWYYLHZY_zcS5PcqlszlQKXX4K_xBVlq-lFC-WyidRuYOBtn96ybH2JYfs/?imgmax=800&quot; width=&quot;606&quot; height=&quot;313&quot;&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul style=&quot;text-align: left&quot;&gt;
&lt;li&gt;Click on &quot;View Results Tree&quot; &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img style=&quot;border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2p1X5QcjGaC2NyBm3XGE1sZKNOPr6oZkscGq7Nq_MGmS3QPqvGh_OnNHIMUOmwWzKGOQF9SsJdOLAzUAlz6iIOb_ZYYuU-ChruFS8lnjABV20SwYdfAYzj0U_N16fuW8HLzbdI6dZTCM/?imgmax=800&quot; width=&quot;608&quot; height=&quot;283&quot;&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul style=&quot;text-align: left&quot;&gt;
&lt;li&gt;To Re-run the test 
&lt;ul&gt;
&lt;li&gt;Click on Run &amp;gt; Clear All or &quot;ctr+e&quot; 
&lt;li&gt;Click on Run &amp;gt; Start or &quot;ctr+r&quot; &lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&lt;br&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Troubleshooting&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&lt;u&gt;View Results Tree&lt;/u&gt; hold the &quot;Request&quot; and &quot;Response&quot; data for each request so it&#39;s a really good place to verify, if test is running correctly or not.&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&quot;Request&quot; Tab shows data sent to web server&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&quot;Response Data&quot; Tab shows server response body&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&amp;nbsp;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/5464167608645959566/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2012/05/jmeter-creating-first-load-test.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/5464167608645959566'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/5464167608645959566'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2012/05/jmeter-creating-first-load-test.html' title='JMeter: Creating First Load Test'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYKWNKmtHim0n4V2GCXk-7cOP_w1ddR-J-vXTxYdnOxOng9SMGJd0SS6XddAW2lq0vU6dZix1rRPlnV_gLrWSmZcpEFdz5z4pbAhvfkDE1i4QMcsiClJF12NrIuIw57qOa89SyChwB6P8/s72-c?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-5523606908295478840</id><published>2012-05-18T01:16:00.001+05:30</published><updated>2012-05-18T01:27:20.384+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Google"/><category scheme="http://www.blogger.com/atom/ns#" term="Guava"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>Guava: Some useful IO utilities</title><content type='html'>&lt;p&gt;Guava IO package provides very useful utility classes for input/ouput stream, byte stream, file handling and many more. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;&lt;/u&gt;&lt;/strong&gt;Here are few example which show case how these utilities can make your code much cleaner, modular and more readable.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;Copy “&lt;/strong&gt;&lt;a href=&quot;http://docs.oracle.com/javase/1.4.2/docs/api/java/io/InputStream.html&quot;&gt;&lt;em&gt;&lt;strong&gt;InputStream&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt;&lt;strong&gt;” to “&lt;/strong&gt;&lt;a href=&quot;http://www.google.co.in/url?sa=t&amp;amp;rct=j&amp;amp;q=&amp;amp;esrc=s&amp;amp;source=web&amp;amp;cd=1&amp;amp;ved=0CGYQFjAA&amp;amp;url=http%3A%2F%2Fdocs.oracle.com%2Fjavase%2F1.4.2%2Fdocs%2Fapi%2Fjava%2Fio%2FOutputStream.html&amp;amp;ei=5k61T4-DEMKrrAeN_8X6Cw&amp;amp;usg=AFQjCNFo_Pjw5MUdfLmABe4ABrQXeWUREg&amp;amp;sig2=CLWqPya8Uiyn2Tfl73bPzQ&quot;&gt;&lt;em&gt;&lt;strong&gt;OutputStream&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt;&lt;strong&gt;”&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class=&quot;brush: java; toolbar: false&quot;&gt;        InputStream is = CopyStreams.class.getResourceAsStream(&quot;test.txt&quot;);
        OutputStream os = System.out;
        ByteStreams.copy(is, os);&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;Changing &lt;strong&gt;&lt;u&gt;“&lt;/u&gt;&lt;/strong&gt;&lt;a href=&quot;http://docs.oracle.com/javase/1.4.2/docs/api/java/io/InputStream.html&quot;&gt;&lt;em&gt;&lt;strong&gt;InputStream&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt;&lt;strong&gt;&lt;u&gt;”&lt;/u&gt;&lt;/strong&gt; to “byte[]”&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class=&quot;brush: java; toolbar: false&quot;&gt;        InputStream is = CopyStreams.class.getResourceAsStream(&quot;test.txt&quot;);

        byte[] isBytes = ByteStreams.toByteArray(is);      

 // Now if you want to get base64 encoded string then it will be like this  
        String isBase64Str = new sun.misc.BASE64Encoder().encode(isBytes);&lt;/pre&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;Combining two files in one&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class=&quot;brush: java; toolbar: false&quot;&gt;        File input1 = new File(&quot;c:\\testio\\AWords.txt&quot;);
        File input2 = new File(&quot;c:\\testio\\BWords.txt&quot;);
        File output = new File(&quot;c:\\testio\\ABWords.txt&quot;);
        
        InputSupplier&amp;lt;InputStreamReader&amp;gt; rs1 = Files.newReaderSupplier(input1, Charsets.UTF_8);
        InputSupplier&amp;lt;InputStreamReader&amp;gt; rs2 = Files.newReaderSupplier(input2, Charsets.UTF_8);        
        InputSupplier&amp;lt;Reader&amp;gt; combined = CharStreams.join(rs1, rs2);
        
        OutputSupplier&amp;lt;OutputStreamWriter&amp;gt; ws = Files.newWriterSupplier(output, Charsets.UTF_8, false);
        CharStreams.copy(combined, ws);&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;Processing the file&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;brush: java; toolbar: false&quot;&gt;public class IOTest {
    public static LineProcessor&amp;lt;List&amp;lt;String&amp;gt;&amp;gt; collectWordsStartWithZ = 
        new LineProcessor&amp;lt;List&amp;lt;String&amp;gt;&amp;gt;() {
            List&amp;lt;String&amp;gt; collector = Lists.newArrayList();
            final static String PREFIX = &quot;z&quot;;
    
            @Override
            public boolean processLine(String line) {
                String line_ = Strings.nullToEmpty(line).trim().toLowerCase();
                if (!line_.isEmpty() &amp;amp;&amp;amp; line_.startsWith(PREFIX)) {
                    collector.add(line);
                }
                return true;
            }
    
            @Override
            public List&amp;lt;String&amp;gt; getResult() {
                return collector;
            }
        };

    public static void main(String[] args) throws IOException {
        URL resource = IOTest.class.getResource(&quot;test.txt&quot;);
        List&amp;lt;String&amp;gt; lines = Resources.readLines(resource, Charsets.UTF_8, collectWordsStartWithZ);

        for (String line : lines) {
            System.out.println(line);
        }
    }
}&lt;/pre&gt;

&lt;script src=&quot;http://crux-framework-tools.googlecode.com/svn/trunk/misc/highlight/highlightLoader.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/5523606908295478840/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2012/05/guava-some-useful-io-utilities.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/5523606908295478840'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/5523606908295478840'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2012/05/guava-some-useful-io-utilities.html' title='Guava: Some useful IO utilities'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1395877744790071528.post-1317867037914891282</id><published>2012-03-26T16:30:00.001+05:30</published><updated>2012-03-26T16:34:25.480+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ext Js"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>JavaScript [ExtJs3]: Total “Record” count in filtered store</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
There is two way to get record count from the Store&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;u&gt;&lt;strong&gt;store.getTotalCount()&lt;/strong&gt;&lt;/u&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
This function depend on server response value. For accuracy of the value, property shell if return by the server. &lt;br /&gt;
&lt;br /&gt;
Property name for the diff. reader:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;tt&gt;totalProperty&lt;/tt&gt; for &lt;a href=&quot;http://docs.sencha.com/ext-js/3-4/#!/api/Ext.data.JsonReader&quot;&gt;JsonReader&lt;/a&gt;, 
&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;totalRecords&lt;/tt&gt; for &lt;a href=&quot;http://docs.sencha.com/ext-js/3-4/#!/api/Ext.data.XmlReader&quot;&gt;XmlReader&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;&lt;u&gt;&lt;strong&gt;store.getCount()&lt;/strong&gt;&lt;/u&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
Will return you the number of record from the store. &lt;br /&gt;
Or if you have filter on the store, it will give you the number of filtered record.&lt;/blockquote&gt;
&lt;br /&gt;
But if you want to get the total number of record regardless filtering, Then it will be like this&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: java; toolbar: false&quot;&gt;var totalRecords = store.snapshot ? store.snapshot.length : store.getCount();&lt;/pre&gt;
&lt;br /&gt;
“snapshot” is the variable in “Store” which hold the actual data in case if you have applied a filter. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;http://crux-framework-tools.googlecode.com/svn/trunk/misc/highlight/highlightLoader.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.neerajnandwana.com/feeds/1317867037914891282/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.neerajnandwana.com/2012/03/javascript-extjs3-total-record-count-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/1317867037914891282'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1395877744790071528/posts/default/1317867037914891282'/><link rel='alternate' type='text/html' href='http://www.neerajnandwana.com/2012/03/javascript-extjs3-total-record-count-in.html' title='JavaScript [ExtJs3]: Total “Record” count in filtered store'/><author><name>Neeraj</name><uri>http://www.blogger.com/profile/16842037137521332915</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>