tag:blogger.com,1999:blog-16162069872066905232024-03-05T10:51:45.619-08:00The Coder LoungeDeepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.comBlogger102125tag:blogger.com,1999:blog-1616206987206690523.post-66434738735499567612018-11-28T23:01:00.001-08:002018-11-28T23:06:22.071-08:00Dependency Upgrades: Why Software Engineers Need A Policy And Process <div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background-color: white; box-sizing: border-box; margin-bottom: 1.421em; text-align: justify;">
For most software engineers, dependency management includes upgrades and best practice suggests upgrading dependencies proactively. In order to ensure a smooth process and one that is maintained properly, it is best to have a well-defined policy and process. <span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box;"> </span></div>
<div style="background-color: white; box-sizing: border-box; color: #384554; font-family: Charter-Roman; font-size: 20px; margin-bottom: 1.421em;">
<span style="box-sizing: border-box; font-weight: 700;"><img alt="Ecommerce Software Dependency Policies and Procedures" class="img-responsive alignright wp-image-30248 size-medium" height="200" sizes="(max-width: 300px) 100vw, 300px" src="https://www.getelastic.com/wp-content/uploads/GettyImages-887606138-300x200.jpg" srcset="https://www.getelastic.com/wp-content/uploads/GettyImages-887606138-300x200.jpg 300w, https://www.getelastic.com/wp-content/uploads/GettyImages-887606138-768x512.jpg 768w, https://www.getelastic.com/wp-content/uploads/GettyImages-887606138-1024x683.jpg 1024w, https://www.getelastic.com/wp-content/uploads/GettyImages-887606138-72x48.jpg 72w, https://www.getelastic.com/wp-content/uploads/GettyImages-887606138-338x225.jpg 338w" style="border: 0px; box-sizing: border-box; display: inline; float: right; height: auto; margin: 0.4em 0px 1.6em 1.6em; max-width: 100%; vertical-align: middle;" title="Ecommerce Software Dependency Policies and Procedures" width="300" />Why you need a policy and</span><span style="box-sizing: border-box; font-weight: 700;"> </span><span style="box-sizing: border-box; font-weight: 700;">process</span><span style="box-sizing: border-box; font-weight: 700;"> </span><span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box;"> </span></div>
<div style="background-color: white; box-sizing: border-box; margin-bottom: 1.421em; text-align: justify;">
All software depends on other software to accomplish useful tasks. Even the smallest <i style="box-sizing: border-box;">hello world </i> program depends on the libraries of the language it is written in. Typically, as a piece of software gets more sophisticated it depends on more third-party software or libraries. Leveraging existing third-party libraries is a standard practice for engineers to enable faster development.<span style="font-size: 20px;"> </span><span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box; font-size: 20px;"> </span></div>
<div style="background-color: white; box-sizing: border-box; margin-bottom: 1.421em; text-align: justify;">
However, vulnerabilities and bugs of dependencies become vulnerabilities and bugs of the software the dependencies are included in. As a result, dependencies must be chosen with due consideration, and constantly monitored. Best practice is to not only upgrade dependencies proactively, but to also be on the latest versions of libraries as often as possible.</div>
<div style="background-color: white; box-sizing: border-box; color: #384554; font-family: Charter-Roman; font-size: 20px; margin-bottom: 1.421em;">
<span style="box-sizing: border-box; font-weight: 700;">Why Upgrade Dependencies?</span><span style="box-sizing: border-box; font-weight: 700;"> </span><span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box;"> </span></div>
<div style="background-color: white; box-sizing: border-box; margin-bottom: 1.421em; text-align: justify;">
The single biggest reason for upgrading dependencies is <span style="box-sizing: border-box; font-weight: 700;">security</span>. Most software has vulnerabilities that are gradually fixed over time. Upgrading dependencies, is the<span style="color: #384554;"> </span><a href="https://hackernoon.com/psa-upgrading-out-of-date-dependencies-is-one-of-the-most-important-things-you-can-do-a9e65e28a786" style="background: 0px 0px; box-sizing: border-box; color: #009ddc; transition: all 0.1s ease 0s;">simplest way </a> to avoid security issues. The latest versions can introduce new vulnerabilities that are not yet discovered. However, it is still safer to upgrade in order to fix known vulnerabilities.<span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box;"> </span></div>
<div style="background-color: white; box-sizing: border-box; margin-bottom: 1.421em; text-align: justify;">
Most of the <a href="https://glebbahmutov.com/blog/why-upgrade-dependencies/" style="background: 0px 0px; box-sizing: border-box; color: #009ddc; transition: all 0.1s ease 0s;">changes between versions</a><span style="color: #384554;"> </span>are <span style="box-sizing: border-box; font-weight: 700;">bug fixes </span> and <span style="box-sizing: border-box; font-weight: 700;">performance improvements</span>, that’s another good reason to upgrade. In recent tests, a docker version upgrade gave a significant boost to the performance numbers. <span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box;"> </span></div>
<div style="background-color: white; box-sizing: border-box; margin-bottom: 1.421em; text-align: justify;">
Other reasons to upgrade include being able make use of new features, avoiding giant upgrade steps as it is always easier to update in smaller increments, and it is also easier to upgrade a single dependency if everything else is up to date. <span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box; font-size: 20px;"> </span></div>
<div style="background-color: white; box-sizing: border-box; color: #384554; font-family: Charter-Roman; margin-bottom: 1.421em;">
<span style="box-sizing: border-box; font-size: 20px; font-weight: 700;">Upgrade Experiences</span></div>
<div style="text-align: justify;">
Software developers should be upgrading dependencies on a regular basis. Here are a few examples of good, bad and ugly dependency upgrades that inform the upgrade process. </div>
<br />
<div style="background-color: white; box-sizing: border-box; color: #384554; font-family: Charter-Roman; font-size: 20px; margin-bottom: 1.421em;">
<span style="box-sizing: border-box; font-weight: 700;">The Good</span> <span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box;"> </span></div>
<div style="background-color: white; box-sizing: border-box; margin-bottom: 1.421em; text-align: justify;">
Overall library upgrades should be smooth or have relatively few issues. Good libraries maintain backward compatibility, and provide suitable replacements for any APIs that are deprecated. As a result, upgrading such libraries should involve only minor code changes. Good migration guides, and well-crafted deprecation warnings make this process relatively painless. Recent examples of these include various Apache Commons libraries, Mockito, and RxJava. <span style="font-size: 20px;"> <span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box;"> </span></span></div>
<div style="background-color: white; box-sizing: border-box; color: #384554; font-family: Charter-Roman; font-size: 20px; margin-bottom: 1.421em;">
<span style="box-sizing: border-box; font-weight: 700;">The Bad</span> <span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box;"> </span></div>
<div style="background-color: white; box-sizing: border-box; color: #384554; font-family: Charter-Roman; margin-bottom: 1.421em;">
<span style="box-sizing: border-box; font-size: 20px; font-weight: 700;"><img alt="bad commerce software dependency upgrades" class="img-responsive alignleft wp-image-30255 size-medium" height="195" sizes="(max-width: 300px) 100vw, 300px" src="https://www.getelastic.com/wp-content/uploads/GettyImages-909882638-300x195.jpg" srcset="https://www.getelastic.com/wp-content/uploads/GettyImages-909882638-300x195.jpg 300w, https://www.getelastic.com/wp-content/uploads/GettyImages-909882638-768x500.jpg 768w, https://www.getelastic.com/wp-content/uploads/GettyImages-909882638-1024x666.jpg 1024w, https://www.getelastic.com/wp-content/uploads/GettyImages-909882638-72x47.jpg 72w, https://www.getelastic.com/wp-content/uploads/GettyImages-909882638-346x225.jpg 346w" style="border: 0px; box-sizing: border-box; display: inline; float: left; height: auto; margin: 0.4em 1.6em 1.6em 0px; max-width: 100%; vertical-align: middle;" width="300" /></span></div>
<div style="text-align: justify;">
Every now and then an upgrade does not go according to plan, and unexpected issues arise due to not having the bugs or changes well documented. Recent example of this occurred with an upgrade to Guava version 25. Guava upgrades are typically seamless and jumping to version 25 was expected to be a simple version bump. <span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box;"> </span></div>
<br />
<div style="background-color: white; box-sizing: border-box; margin-bottom: 1.421em; text-align: justify;">
However, intermittent errors occurred in performance tests because of a misbehaving cache. The intermittent nature of the errors meant that they were difficult to track down, resulting in a days long testing to locate the issue. To allow enough time to deal with such surprises, it is best to do upgrades at the beginning of a release cycle.</div>
<div style="background-color: white; box-sizing: border-box; color: #384554; font-family: Charter-Roman; font-size: 20px; margin-bottom: 1.421em;">
<span style="box-sizing: border-box; font-weight: 700;">The Ugly</span> <span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box;"> </span></div>
<div style="background-color: white; box-sizing: border-box; margin-bottom: 1.421em; text-align: justify;">
Sometimes an upgrade can get ugly. This is typically the case when a number of dependencies have to be upgraded in lockstep. This problem will be exacerbated if regular upgrades are not done, and several upgrades of versions need to take place in one go. <span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box;"> </span></div>
<div style="background-color: white; box-sizing: border-box; margin-bottom: 1.421em; text-align: justify;">
As an example, a recent Spring upgrade required upgrading Cucumber. Upgrading Cucumber required upgrading Spring. Also resulting in needing to upgrade Camel, Junit, Servicemix, and Gemini. Attempting to untangle this dependency web was challenging. <span style="font-size: 20px;"> <span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box;"> </span><span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box;"> </span></span></div>
<div style="background-color: white; box-sizing: border-box; color: #384554; font-family: Charter-Roman; font-size: 20px; margin-bottom: 1.421em;">
<span style="box-sizing: border-box; font-weight: 700;"><img alt="ugly dependency upgrades" class="img-responsive alignright wp-image-30256 size-medium" height="196" sizes="(max-width: 300px) 100vw, 300px" src="https://www.getelastic.com/wp-content/uploads/automation-300x196.png" srcset="https://www.getelastic.com/wp-content/uploads/automation-300x196.png 300w, https://www.getelastic.com/wp-content/uploads/automation-768x501.png 768w, https://www.getelastic.com/wp-content/uploads/automation-72x47.png 72w, https://www.getelastic.com/wp-content/uploads/automation-345x225.png 345w, https://www.getelastic.com/wp-content/uploads/automation.png 974w" style="border: 0px; box-sizing: border-box; display: inline; float: right; height: auto; margin: 0.4em 0px 1.6em 1.6em; max-width: 100%; vertical-align: middle;" width="300" />Automation </span><span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box;"> </span></div>
<div style="background-color: white; box-sizing: border-box; margin-bottom: 1.421em; text-align: justify;">
Upgrading dependencies is not the most exciting work for an engineer. To ensure upgrades are quick and happen often, it is strongly recommended to leverage all automated tools available. <span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box;"> </span></div>
<div style="background-color: white; box-sizing: border-box; margin-bottom: 1.421em; text-align: justify;">
For example, Versions Maven Plugin is best to use for maven projects to generate reports listing the libraries that have new versions available. The plugin can also auto-upgrade the versions directly in source code. Most languages and frameworks have similar tooling available. <span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box;"> </span></div>
<div style="background-color: white; box-sizing: border-box; margin-bottom: 1.421em; text-align: justify;">
It is worth noting to only use the auto-upgrade feature to do revision, and minor version upgrades. These upgrades are typically quick and require minimal code changes. Overall, the plugin is a huge time saver. <span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box;"> </span></div>
<div style="background-color: white; box-sizing: border-box; margin-bottom: 1.421em; text-align: justify;">
A major version upgrade is often a more conscious decision to upgrade with the understanding that such an upgrade will require some work. <span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box;"> </span></div>
<div style="background-color: white; box-sizing: border-box; margin-bottom: 1.421em; text-align: justify;">
New vulnerabilities are discovered every day, and it is hard to keep up with without some automation. <span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box;"> </span><span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box;"> </span></div>
<div style="background-color: white; box-sizing: border-box; margin-bottom: 1.421em; text-align: justify;">
Use a security and license compliance tool, e.g. Black Duck, to identify vulnerabilities and license compliance issues in the open source libraries. <span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box;"> </span></div>
<div style="background-color: white; box-sizing: border-box; margin-bottom: 1.421em; text-align: justify;">
Lastly, it is recommended to create a robust suite of functional and performance tests that ensure library upgrades do not have negative consequences. <span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box; font-size: 20px;"> </span></div>
<div style="background-color: white; box-sizing: border-box; font-size: 20px; margin-bottom: 1.421em;">
<span style="box-sizing: border-box; font-weight: 700;">The Upgrade Process</span><span style="box-sizing: border-box; font-weight: 700;"> </span><span style="box-sizing: border-box; font-weight: 700;">– what a strong process looks like </span><span data-ccp-props="{"134233117":true,"134233118":true}" style="box-sizing: border-box;"> </span></div>
<ol style="background-color: white; box-sizing: border-box;">
<li style="box-sizing: border-box; text-align: justify;">Identify the libraries to be upgraded. Leverage an automated tool in this step. Most languages and frameworks have one. E.g. Use <i style="box-sizing: border-box;">Versions Maven Plugin</i><i style="box-sizing: border-box;"> </i>for Maven projects. <span data-ccp-props="{"134233117":true,"134233118":true,"335559685":360,"335559731":0}" style="box-sizing: border-box;"> </span></li>
<li aria-setsize="-1" data-aria-level="1" data-aria-posinset="2" data-font="Avenir Roman,Arial" data-leveltext="%1." data-listid="3" style="box-sizing: border-box; text-align: justify;">Ensure version being upgraded to does not have known security vulnerabilities, and license issues. Before changing a single line of code one can verify candidate versions using a security compliance tool e.g. Black Duck. <span data-ccp-props="{"134233117":true,"134233118":true,"335559685":360,"335559731":0}" style="box-sizing: border-box;"> </span></li>
<li aria-setsize="-1" data-aria-level="1" data-aria-posinset="2" data-font="Avenir Roman,Arial" data-leveltext="%1." data-listid="3" style="box-sizing: border-box; text-align: justify;">Do the bare minimum code change to upgrade the version i.e. fix any compilation errors, and any functional test failures. Don’t try to use any new features at this point. <span data-ccp-props="{"134233117":true,"134233118":true,"335559685":360,"335559731":0}" style="box-sizing: border-box;"> </span></li>
<li aria-setsize="-1" data-aria-level="1" data-aria-posinset="2" data-font="Avenir Roman,Arial" data-leveltext="%1." data-listid="3" style="box-sizing: border-box; text-align: justify;">Verify performance. Run your whole performance test suite. <span data-ccp-props="{"134233117":true,"134233118":true,"335559685":360,"335559731":0}" style="box-sizing: border-box;"> </span></li>
<li aria-setsize="-1" data-aria-level="1" data-aria-posinset="2" data-font="Avenir Roman,Arial" data-leveltext="%1." data-listid="3" style="box-sizing: border-box; text-align: justify;">As much as possible, do the upgrades at the beginning of a release cycle to give you time to live with any surprises that might come up. <span data-ccp-props="{"134233117":true,"134233118":true,"335559685":360,"335559731":0}" style="box-sizing: border-box;"> </span></li>
<li aria-setsize="-1" data-aria-level="1" data-aria-posinset="2" data-font="Avenir Roman,Arial" data-leveltext="%1." data-listid="3" style="box-sizing: border-box; text-align: justify;">As an optional exercise – use the new features. Take a look at release notes of the new versions, check if there is anything that catches the eye and would be helpful. Use your judgement to determine if it might be useful to spend a bit of time on this. <span data-ccp-props="{"134233117":true,"134233118":true,"335559685":360,"335559731":0}" style="box-sizing: border-box;"> </span></li>
</ol>
<div style="background-color: white; box-sizing: border-box; margin-bottom: 1.421em;">
In closing, be sure to continue to learn from experiences and fine tune this process.</div>
<div style="background-color: white; box-sizing: border-box; color: #384554; font-family: Charter-Roman; margin-bottom: 1.421em;">
<span style="font-size: x-small;">Note: This was originally posted on <a href="https://www.getelastic.com/dependency-upgrades-why-commerce-software-engineers-need-a-policy-and-process" target="_blank">GetElastic - Enterprise Commerce Blog</a>.</span></div>
</div>
Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com0tag:blogger.com,1999:blog-1616206987206690523.post-86299832314952476002017-07-04T23:38:00.001-07:002017-07-04T23:38:59.093-07:00Testing for Exceptions in RxJava 2.x<div dir="ltr" style="text-align: left;" trbidi="on">
RxJava 2.x provides useful assertions to test for exception conditions. Assume we have the following class with three methods that result in three different error conditions<br />
<ol style="text-align: left;">
<li>No Error</li>
<li>An exception</li>
<li>An exception with a distinct property, in this case an exception message.</li>
</ol>
<br />
<script src="https://gist.github.com/deepakazad/ba4436b22d4b7a0f515d2dce294e094b.js"></script>
<br />
We can write one test for each of the three error conditions by using the different asserts available in RxJava<br />
<ol style="text-align: left;">
<li><i>assertNoErrors()</i> </li>
<li><i>assertError(Class<? extends Throwable> errorClass)</i></li>
<li><i>assertError(Throwable error)</i></li>
<li><i>assertError(Predicate<Throwable> errorPredicate)</i></li>
</ol>
<div>
The ability to write custom <i>errorPredicate</i> is extremely useful when the same exception type is thrown from several locations but each exception instance can have a different property such as the exception message.</div>
<br />
<script src="https://gist.github.com/deepakazad/1678341a8a06fbf5f25c5760219fe79e.js"></script>
</div>
Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com0tag:blogger.com,1999:blog-1616206987206690523.post-31130986216699585142017-06-27T21:17:00.002-07:002017-06-27T21:20:29.147-07:00Tip for writing RxJava code for beginners<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: left;">
Let's say you are using RxJava (or RxAndroid) and your goal is to write code which looks something like the <i style="font-weight: bold;">foo</i> method shown in the snippet below. Once you are experienced in writing functional code this appears trivial, however for programmers used to imperative programming style this can appear daunting.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpN59hIyInB7HWi5OOHvlx8SNTgtux9EAl89X2MABdbNuUVAHKeepVNIT3s0qtqIfSmq0M3Th9JlolnCLRHCaVUk8EnR1cOM_iwM08Yg_XwIjxbSxWwbs2ZtHc4b_xVlMxywrHAgs2Hgme/s1600/Goal.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="560" data-original-width="702" height="319" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpN59hIyInB7HWi5OOHvlx8SNTgtux9EAl89X2MABdbNuUVAHKeepVNIT3s0qtqIfSmq0M3Th9JlolnCLRHCaVUk8EnR1cOM_iwM08Yg_XwIjxbSxWwbs2ZtHc4b_xVlMxywrHAgs2Hgme/s400/Goal.png" width="400" /></a></div>
<br />
Here is a step by step process which should hopefully make things simpler.<br />
<br />
<b>Step 1</b>: Invoke the first method in the desired chain, and use the IDE to assign it's return value to a local variable. This way you can see the type of this expression.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgJDtptv5hNht7KxziM3JLxcdGG0ha-2ucbo6D6USUa38qEHZ9qjuOltk5Ftxu-hy0c9z8N8nUeRpn_9jhTuUoN1wqSHSjPvTGGI19PaIzL1QisHFVgxo3UARD26Hlg4bWt_Zx7vtoMR9X/s1600/Step1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="164" data-original-width="702" height="93" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgJDtptv5hNht7KxziM3JLxcdGG0ha-2ucbo6D6USUa38qEHZ9qjuOltk5Ftxu-hy0c9z8N8nUeRpn_9jhTuUoN1wqSHSjPvTGGI19PaIzL1QisHFVgxo3UARD26Hlg4bWt_Zx7vtoMR9X/s400/Step1.png" width="400" /></a></div>
<b>Step 2</b>: Use the local variable created in Step 1 to invoke the second method. If you are unsure about <b><i>map</i></b> vs <b><i>flatMap</i></b>, simply use <b><i>map</i></b> by default. Again, using the IDE assign the result to a local variable. In this new variable a <b><i>Maybe</i></b> is nested inside an <b><i>Observable</i></b>.<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjx0A417m0_0_fNG_asvJjUhrMjfdGkGdxus7AxG2Dchl_Pkb1UT6PY3B4lSTySXObSRpoGJmUJjW54bCr-kOmQe-uQJJ4xjdDAYG4xFxMi8XwXgJ1Kz18kje95_vRiEul8C6vnXNHljNn5/s1600/Step2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="154" data-original-width="1106" height="88" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjx0A417m0_0_fNG_asvJjUhrMjfdGkGdxus7AxG2Dchl_Pkb1UT6PY3B4lSTySXObSRpoGJmUJjW54bCr-kOmQe-uQJJ4xjdDAYG4xFxMi8XwXgJ1Kz18kje95_vRiEul8C6vnXNHljNn5/s640/Step2.png" width="640" /></a></div>
<br />
<b>Step 3</b>: This nesting is a hint to change <b><i>map</i></b> to a <b><i>flatMap</i></b> operation.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg24NGSL26uwBfpCP4Q7-wEcdoIjeracqOT5Y3Jc3tZRNMYnWnlcH52yGX1axnRVzvJEbacstF2I-xo_0wTUTrKC2TZk8RZqWnyo_sSbfKy7160dpeQajz97fIt4-m0M6PK8XsY6FVypSRO/s1600/Step3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="138" data-original-width="1280" height="67" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg24NGSL26uwBfpCP4Q7-wEcdoIjeracqOT5Y3Jc3tZRNMYnWnlcH52yGX1axnRVzvJEbacstF2I-xo_0wTUTrKC2TZk8RZqWnyo_sSbfKy7160dpeQajz97fIt4-m0M6PK8XsY6FVypSRO/s640/Step3.png" width="640" /></a></div>
<br />
<b>Step 4:</b> Follow the above steps for the remaining method calls in the goal.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFZDXUAB1HtlJV1HpVwmN4a-PZam4TiWcBjhdWnMpuvC8nBq5tWdbAzl0By7DdPgHHu2B6CO_68vu2T4_ndQfPvNhKgoKAw1TpnZI7B7F0cQv1fTJ4otCTRyzLAcLbF6eawl6qykzGmd_c/s1600/Step4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="236" data-original-width="1332" height="112" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFZDXUAB1HtlJV1HpVwmN4a-PZam4TiWcBjhdWnMpuvC8nBq5tWdbAzl0By7DdPgHHu2B6CO_68vu2T4_ndQfPvNhKgoKAw1TpnZI7B7F0cQv1fTJ4otCTRyzLAcLbF6eawl6qykzGmd_c/s640/Step4.png" width="640" /></a></div>
<b><br /></b>
<b>Step 5:</b> Simply use the IDE to inline all the local variables to reach the goal.<br />
<br />
<br /></div>
Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com0tag:blogger.com,1999:blog-1616206987206690523.post-51591211784459118022017-06-27T20:22:00.000-07:002017-06-28T10:57:23.441-07:00RxJava: Converting to Single type<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
In RxJava <b>Single</b> is a special type. It must emit exactly one value. Other types like <i>Observable</i> and <i>Maybe</i> can emit no values. If one is not careful these properties can lead to runtime errors in the code.<br />
<div>
<br /></div>
<div>
<b>Converting a Maybe to Single</b></div>
<div>
<br /></div>
<div>
As shown by the tests in these <a href="https://gist.github.com/deepakazad/e3c66f4d90078d8df990ec8a3f5c9156">examples</a> this will rightly result in error.</div>
<div>
<br /></div>
<script src="https://gist.github.com/deepakazad/e3c66f4d90078d8df990ec8a3f5c9156.js"></script>
<br />
<div>
<b>Converting an Observable to Single</b></div>
<div>
<b><br /></b></div>
<div>
Oddly enough as converting an empty Observable to Single does not result in an error. Maybe that's a bug in RxJava implementation? A quick read of the code does seem to indicate that.<br />
<br />
However, the javadoc of <i>Observable#flatMapSingle</i> says <i>"Maps each element of the upstream Observable into SingleSources</i>", and the method returns an <i>Observable.</i> So the behaviour is correct, the second snippet with a non-empty Observable shows that. Maybe the methods could have been named better?</div>
<div>
<br /></div>
<div>
Converting an Observable which emits too many values to a Single rightly results in an error.</div>
<div>
<br /></div>
<script src="https://gist.github.com/deepakazad/02314dc72b799069bb3a016a2adf1150.js"></script>
<br />
<div>
<div>
<b><br /></b>
<b>Converting a Flowable to Single</b></div>
</div>
<div>
<b><br /></b></div>
<div>
Flowable exhibits same behaviour as Observable as shown in these <a href="https://gist.github.com/deepakazad/0d1836a30b2885e71e42fb6185c62d78">snippets</a>.</div>
<div>
<br /></div>
<script src="https://gist.github.com/deepakazad/0d1836a30b2885e71e42fb6185c62d78.js"></script>
<br />
<div>
<b><br /></b>
<b>Converting a Completable to Single</b></div>
<div>
<br /></div>
<div>
Just for completeness (no pun intended), <a href="https://gist.github.com/deepakazad/62642152539dfaf5116a51ea34f3ff4b">this</a> works as expected.</div>
</div>
<div>
<br /></div>
<script src="https://gist.github.com/deepakazad/62642152539dfaf5116a51ea34f3ff4b.js"></script></div>
Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com1tag:blogger.com,1999:blog-1616206987206690523.post-5705525381614397112016-05-13T15:48:00.000-07:002016-05-13T15:48:27.915-07:00AngularJS and Amazon S3 & CloudFront - HTML5 mode and Social Sharing<div dir="ltr" style="text-align: left;" trbidi="on">
<b>The Setup</b><br />
You have a single page AngularJS application hosted on Amazon S3 and CloudFront. You have used one of the two possible <a href="http://blog.deepakazad.com/2016/05/deploy-static-web-app-to-aws-cloudfront.html">configurations</a>, i.e. with or without static website hosting enabled on S3.<br />
<br />
<b>Problem</b><br />
Sharing a link from your website on Facebook, Twitter, Linkedin etc does not work well, because none of them run JavaScript to understand a shared link. This is a huge problem because in a Single Page Application (SPA) you set the page titles and descriptions using JavaScript.<br />
<br />
A minor problem is also that your website urls are not pretty and include hashbang symbols i.e. # or #!. Besides not looking nice, URLs with hashbang symbols also do not work well when links are shared on any of the social networks.<br />
<br />
<b>Solution</b><br />
The first part of the solution requires <b>enabling HTML5 mode</b> in the AngularJS application. Once HTML5 mode is enabled your links will change from<br />
<blockquote class="tr_bq">
http://example.com/#/path TO http://example.com/path</blockquote>
<b>Client Side Changes</b><br />
This part is simple as shown in this <a href="https://gist.github.com/deepakazad/954d99cb077523d7df68d680d849e5b9">gist</a><br />
<script src="https://gist.github.com/deepakazad/954d99cb077523d7df68d680d849e5b9.js"></script>
<br />
<br />
Next make sure all the links in your app are correct<br />
1. Change # to / in all hrefs in your app. This should be easily done via find and replace. Find matches for 'href="#' and replace with 'href="/'<br />
2. Make sure any assets included in the apps' index.html have a href starting with /. That is change any href values from "path/to/css/ to "/path/to/css"<br />
<br />
<b>Server Side Changes</b><br />
Now when you open the home page and use the website by clicking around everything should work fine. However, if you copy paste a link directly in the browser you will get a 404. To fix this 404 error we need some server side changes.<br />
<br />
<i><b> - Development (Grunt)</b></i><br />
Quite likely you are using Grunt on your dev machine. First install connect-modrewrite and then add a middleware to the livereload section as shown in this <a href="https://gist.github.com/deepakazad/8ef0b18377c64b964d732ac35673ff2c">gist</a>.<br />
<script src="https://gist.github.com/deepakazad/8ef0b18377c64b964d732ac35673ff2c.js"></script>
<br />
<br />
<b><i> - Production (Amazon S3 and CloudFront)</i></b><br />
Assuming you do NOT have static website hosting enabled on S3. All you have to do is create couple of Custom Error Responses on CloudFront.<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4K3OcQ67Smki76-n0wzJgbqCP_Y-XnhYPYuk60fGe2TRmRQM_zDWUmUWOV0CyWK8qnDyPDpBWRPEmyup_AmjjXeKZ4bk8MKWvN7in2ZG69efR4zgm6Yo8RT2IGngMtQHpYHmGbd1Q2CS9/s1600/cloudfront-error-response.png" imageanchor="1"><img border="0" height="89" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4K3OcQ67Smki76-n0wzJgbqCP_Y-XnhYPYuk60fGe2TRmRQM_zDWUmUWOV0CyWK8qnDyPDpBWRPEmyup_AmjjXeKZ4bk8MKWvN7in2ZG69efR4zgm6Yo8RT2IGngMtQHpYHmGbd1Q2CS9/s640/cloudfront-error-response.png" width="640" /></a><br />
<br />
<br />
<b>Detect JavaScript Support</b><br />
We filter out the social networks by providing them with a static HTML page containing all the relevant meta tags, and also a simple JavaScript snippet that redirects JavaScript-capable browsers to the root URL, with the correct route hashed out, so that CloudFront & S3 take you to the application and Angular interprets the route correctly. An example of such a file is shown in this <a href="https://gist.github.com/deepakazad/9b572e5d10d588ca266b6f844f7336b3">gist</a>.<br />
<script src="https://gist.github.com/deepakazad/9b572e5d10d588ca266b6f844f7336b3.js"></script>
<br />
Now when you share the link "https://example.com/path/index.html" social networks will be able to create nice cards. When a user clicks on this link, they will be redirected to the right place.<br />
<br />
Notice that the shared link includes "index.html", we can get rid of that if we enable Static Website Hosting on S3. More on that later...<br />
<br />
<b>Refrences</b><br />
1. https://medium.com/@gigbloc/deep-linking-rich-social-sharing-seo-with-angularjs-and-amazon-s3-82f99cf83cb5#.fl6miptq1<br />
2. http://www.ericluwj.com/2015/11/17/seo-for-angularjs-on-s3.html<br />
3. http://www.ericluwj.com/2015/11/10/angularjs-with-html5-mode-on-s3.html<br />
4. http://stackoverflow.com/questions/24283653/angularjs-html5mode-using-grunt-connect-grunt-0-4-5</div>
Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com0tag:blogger.com,1999:blog-1616206987206690523.post-44297441662415087082016-05-13T14:32:00.000-07:002016-05-13T14:32:28.669-07:00Deploy a static web app to AWS Cloudfront and S3<div dir="ltr" style="text-align: left;" trbidi="on">
There are two ways to deploy a static web apps to AWS CloudFront and S3.<br />
<br />
1. Enable <a href="http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html">Static Website Hosting</a> on S3. Once this is enabled, you can also setup CloudFront to point to S3 website endpoint. Make sure this is not the standard S3 endpoint. Here, CloudFront is simply caching the static files. All files in S3 will also be accessible without CloudFront.<br />
<br />
2. Use CloudFront to point to the standard S3 endpoint. This way you make S3 bucket contents available only to CloudFront. In this scenario CloudFront both caches the files and is also a gatekeeper to all the files.</div>
Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com0tag:blogger.com,1999:blog-1616206987206690523.post-50758945760771045772015-10-20T23:57:00.000-07:002015-10-20T23:57:14.934-07:00What to use for login - username, email or phone number?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
It seems trivial on surface, pick a strategy and go with it. However, it can be useful to pause a think about your exact use case as each of username, email and phone number have distinct pros and cons.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
If you are developing a mobile app, <b>phone number along with a one time password</b> is a good option to use for login. Whatsapp, Telegram and others use this strategy. The clear advantage is that most users have a phone number (people with tablets may not have a phone number), and a user does not have to remember a password. However, phone numbers can change often, especially if a user moves to a different city or country. As a result, a user can lose access to their account unless the app allows to change phone numbers by some means. Moreover, a user's phone number may have previously belonged to someone else. This may result in a user getting access to someone else's account. Users may need to provide an email or an alternate phone number to help avoid these pitfalls.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<b>Username along with a password</b> is a good option both for mobile apps and web apps. A user can choose a unique username and a password. Now no user can access another user's account by accident as in the case of phone numbers, and the user does not lose access to their account as long as they remember the username and password. However, remembering usernames and passwords for all the different apps is hard. An email address or phone number would be required for username and password recovery. One big advantage of usernames is that users can try your app without providing their personal information i.e. email or phone number. Also, the registration step can be really quick, if users don't have to verify their email or phone number to start using the app or wait for a one time password. Snapchat uses this strategy. At the time of registration it asks for username, password and email, but does not force you to verify the email before using the app. You can verify your email later (you may not have email setup on your phone) so that you can recover your account details in case you forget them.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
For web apps,<b> email along with a password</b> is a good option. Emails should typically change less frequently than phone numbers. (Some people use the email from their ISPs and hence end up changing it frequently, but I suspect they are in a minority). If emails are used, users don't need to remember a username and an email is already unique, so a user does not have to spend time coming up with something unique as in the case of usernames. Recovery of account details with an email is also simple. However, it is a good idea to get a user to verify their email address. Some apps force users to complete this verification before giving them access to the app, which lengthens the registration process. On the other hand, if emails are not verified, you may end up in a situation where another user has created an account with your email address, and hence you cannot use that email address to create an account. Users on popular apps like Facebook often face <a href="https://www.google.com/search?q=facebook+someone+using+my+email">this situation</a>. Email with a password can also be used for mobile apps, however it is useful to remember that a user may not have email setup on their phone hence may not be able to verify their email right away, or access an one time password. </div>
</div>
Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com1tag:blogger.com,1999:blog-1616206987206690523.post-29821219355950100472015-09-10T18:29:00.000-07:002015-09-10T18:29:43.888-07:00Use different email address for different Git repositories<div dir="ltr" style="text-align: left;" trbidi="on">
Navigate to the repository directory, use the following commands to set user config for that repository<br />
<blockquote class="tr_bq">
$ git config user.name "Deepak Azad"<br />
$ git config user.email "deepak@example.com"</blockquote>
Alternatively, modify the config file of the repository directly and add the following lines to it<br />
<blockquote class="tr_bq">
[user]<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>name = Deepak Azad<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>email = deepak@example.com</blockquote>
</div>
Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com0tag:blogger.com,1999:blog-1616206987206690523.post-4793928152104883852015-07-07T23:47:00.000-07:002015-07-07T23:47:49.621-07:00Bringing back conversations<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
We are a generation that relies heavily on technology to stay connected to friends. There are many alternatives that make being connected very convenient. We like sending texts over WhatsApp or Facebook Messenger, or having a fun exchange of doodled-pictures on Snapchat, or liking someone’s photos on Instagram, and so on to "stay in touch". These are convenient to use. You don’t need to give your full attention. They’re not in real-time, which means we get to edit, delete, retouch, to make it just as we want it to be. “<a href="http://www.pewinternet.org/2011/09/19/americans-and-text-messaging/">I would rather text than talk</a>” has become more common, but these lack the basic elements that make it an conversation - body language, eye contact, tone of voice, mood, emotions etc.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
These connections end up <a href="https://www.youtube.com/watch?v=c6Bkr_udado">replacing the conversations</a> in our lives. We connect with more and more people. But in the process, we set ourselves up to be isolated because of lack of conversations. We are <a href="https://www.ted.com/talks/sherry_turkle_alone_together?language=en">connected yet lonely</a>.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Actively engaging in a conversation requires phone/voice calls, video calls using FaceTime, Skype, and likewise. They’re the next best thing to seeing someone in-person. However, they have a lot of resistance associated with them. For example, a lot of effort usually goes in scheduling of video calls, and there is always the uncertainty about how long they will take.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
We decided to take on these problems by building something that brings conversations back in people’s lives, something that allows you to connect as intimately as a face-to-face conversation and as conveniently as a text message. This is our new app <b>Knock</b>.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Knock keeps video calls short to just 5 minutes. In our tests, we found that it's ample time to catch up if you're regularly in touch. It is easy to find 5 minutes for a quick catch-up with someone. You’re more likely to answer if you know the calls are guaranteed to be short. </div>
<div style="text-align: justify;">
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3ouWJR5hIs5KmDb7sQl8ZvJ41p3v4mZEx-JSa8ht3uC89PhCZIexE_O54qSaMnl4GI2hglZd0t8zYpEs9gNaE5OH6oaX1xKrBQubasJr3cutv7MnVQm27jaKLO8AasUti8e7aXBjjgjEK/s1600/Video-Call.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="193" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3ouWJR5hIs5KmDb7sQl8ZvJ41p3v4mZEx-JSa8ht3uC89PhCZIexE_O54qSaMnl4GI2hglZd0t8zYpEs9gNaE5OH6oaX1xKrBQubasJr3cutv7MnVQm27jaKLO8AasUti8e7aXBjjgjEK/s200/Video-Call.gif" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Short and timed video calls</td></tr>
</tbody></table>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
We also allow you to Knock multiple friends at the same time to see who is available at that moment. The app queues up the knocks, and you get on a call with whoever is the first one to respond.</div>
<div style="text-align: justify;">
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0CjzbWtuMRlw3_jlNU7XUubUnrQCVXRQ5xQMoXrCvyLiehDbUyToemZmbc5p_P1rG9TaFJTwq4ex7bMdSIdjAdP3WAfVVKjRHgYMXa7COtZt_gR1zHp_UIbvzwOn1PYrFaHg2kTE3zR3t/s1600/Just-Knock.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="193" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0CjzbWtuMRlw3_jlNU7XUubUnrQCVXRQ5xQMoXrCvyLiehDbUyToemZmbc5p_P1rG9TaFJTwq4ex7bMdSIdjAdP3WAfVVKjRHgYMXa7COtZt_gR1zHp_UIbvzwOn1PYrFaHg2kTE3zR3t/s200/Just-Knock.gif" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Knock multiple friends at the same time</td></tr>
</tbody></table>
<div style="text-align: justify;">
<br />
When you don’t see a Knock, we delete the notification from your phone. As a result there is no notification clutter on your device, and you don't feel pressured to call back right away. But, we do make sure that you know who was "thinking of you" (you missed their Knocks). You can always open the app and check that. However, we don't show when or how many times they Knock’d, or don’t tell them you saw it when you see it. </div>
<div style="text-align: justify;">
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQV7doNk7M3GheeiyxyM_Uit4QmbR6MMfdAyPRFfErs0FUpPP56R_QQnfmRUT7hOAA743x911XCpmf6H_4fcF1TKZOQRMNmVxgiRtgZBYmWoTVMSFUxbAkULpSn0ZnWaFEg3yTVFXz1SOq/s1600/Retraction.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="193" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQV7doNk7M3GheeiyxyM_Uit4QmbR6MMfdAyPRFfErs0FUpPP56R_QQnfmRUT7hOAA743x911XCpmf6H_4fcF1TKZOQRMNmVxgiRtgZBYmWoTVMSFUxbAkULpSn0ZnWaFEg3yTVFXz1SOq/s200/Retraction.gif" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">No notification clutter</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9nijiTRsA-_mo4qOctgoVmJWx52dXysZE4RFcsDu-jDHiEmF_Z06DtfJjNFjP5B6WfmIdlYmeko-JUZgjzAIaf6RAw97uM-L_cP5f8yZy7wckRIpt8yHRe9Y-9MisgTGEKa4NPxdxEFjp/s1600/Thinking-of-You.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="193" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9nijiTRsA-_mo4qOctgoVmJWx52dXysZE4RFcsDu-jDHiEmF_Z06DtfJjNFjP5B6WfmIdlYmeko-JUZgjzAIaf6RAw97uM-L_cP5f8yZy7wckRIpt8yHRe9Y-9MisgTGEKa4NPxdxEFjp/s200/Thinking-of-You.gif" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Find out who was "Thinking of you"</td></tr>
</tbody></table>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
It's like knocking on someone's door for a quick chat, and leaving a little note behind to let them know that you stopped by.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Putting it concisely connections are useful, but we love conversations! Knock is our try to bring back the conversations. Knock is currently in beta and is available on iOS. Download it <a href="http://beta.justknock.co/ios/download/">here</a>. Invite your friends, and <b>Just Knock</b>! :)</div>
<div style="text-align: justify;">
<a href="http://beta.justknock.co/ios/download/" style="background-attachment: scroll; background-color: #f65983; background-image: url('https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjv4F98N3CylC24yz3Rpgn6rKEkvW0-0Rm-DL7eMOJEnQrYQhmKnKENt-IiPiTfWySaoHmaD0d-0XpnKuvME42BPAuFqsXoDMoU2jtlnluZe9572x3UkHUlAOyA9Rft55hz7KJSp-f1f3-Q/h120/apple-os-icon.png'); background-position: 11% 48%; background-repeat: no-repeat; background-size: 17px; border-radius: 10px; box-shadow: #cc2c57 0px 2px 1px 0px, #ff91ae 0px 1px 2px 0px inset; color: white; display: block; font-family: Ubuntu, Helvetica, sans-serif; font-size: 16px; font-weight: 300; height: 34px; margin-left: auto; margin-right: auto; margin-top: 30px; padding-left: 31px; padding-top: 13px; position: static; text-align: center; text-decoration: none; transition: all 300ms ease; width: 240px;"> Download Knock (beta) </a>
</div>
<div style="text-align: justify;">
<br /></div>
</div>
Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com0tag:blogger.com,1999:blog-1616206987206690523.post-87956851659086075082014-01-30T12:06:00.000-08:002014-01-30T12:06:30.734-08:00Invalid techniques of proof<div dir="ltr" style="text-align: left;" trbidi="on">
Recently I took an algorithms course which involved a lot of proofs. I used to work together with my buddies on some of the hard problems, and while trying to come up with a proof for a particularly hard problem I would often joking say to my buddies "I bet a $1000 that this is true, are you willing to take this bet?" "Proof is complete if no one takes the bet."<br />
<br />
While searching for types of proof techniques, I stumbled across this hilarious collection of<a href="http://school.maths.uwa.edu.au/~berwin/humour/invalid.proofs.html"> invalid proof techniques</a>. Obviously, I had to submit <a href="http://school.maths.uwa.edu.au/~berwin/humour/invalid.proofs.html#4.EntrysuggestedbyDeepakAzad">my proof technique</a> as well, which is now part of that amazing collection.</div>
Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com0tag:blogger.com,1999:blog-1616206987206690523.post-37068586725923627392012-11-19T16:57:00.000-08:002012-11-19T16:58:37.208-08:00Contributing Java Editor templates via a plugin<div dir="ltr" style="text-align: left;" trbidi="on">
JDT provides several <a href="http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Fconcepts%2Fconcept-editor-templates.htm">editor templates</a>. You can also add your own via the <b>Templates View</b>. However, if you want to share the templates between your several workspaces or with others you can also create a plugin.<br />
<br />
As a first step, define the following extension for the extension point <b>org.eclipse.ui.editors.templates</b>.
<br />
<blockquote class="tr_bq">
<extension<br />
point="org.eclipse.ui.editors.templates"><br />
<include<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>file="templates/default-templates.xml"<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>translations="$nl$/templates/default-templates.properties"><br />
</include><br />
</extension></blockquote>
The xml file just contains the template descriptors. For example, here is a template for printing the enclosing type and the enclosing method.<br />
<blockquote class="tr_bq">
<template name="debugout" description="%Templates.debugout" id="com.eclipse.jdt.ui.templates.debugout" context="java-statements" enabled="true" autoinsert="true"><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>System.out.println("${enclosing_type}#${enclosing_method}(..)");${cursor}<br />
</template></blockquote>
You can read about the available template variables in <a href="http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Fconcepts%2Fconcept-template-variables.htm">Eclipse help</a>.<br />
<br />
I have also shared a plugin with the above code on <a href="https://github.com/deepakazad/MyTools/tree/master/MyJavaEditorTemplates">GitHub</a>.</div>
Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com2tag:blogger.com,1999:blog-1616206987206690523.post-66962639249098543752012-11-06T16:54:00.002-08:002012-11-06T16:55:42.784-08:00Debugging with sysouts made awesome<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
At times I like to <a href="http://blog.deepakazad.com/2010/06/print-points-debugging-by-writing-to.html">debug by writing to console</a>. However, in a long debugging session I often end up with several sysout statements in several files/methods, which makes it hard to track where a particular line of console output came from.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
In the past I tried to use <a href="http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Fconcepts%2Fconcept-editor-templates.htm&cp=1_2_6">code templates</a> to also print the 'enclosing type' and 'enclosing method', but I often forgot to use the template. In any case, via templates you cannot 'link' back to the source code.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<a href="http://jeeeyul.wordpress.com/2012/10/18/make-system-out-println-rocks/">Jeeeyul</a> presents a neat solution - just replace PrintStream by a DebugStream so that you can also print 'file : line number : method name' information. I took this code, added it to a plugin and then added this plugin to my launch config. Now everytime I launch an Eclipse Application 'DebugStream' gets activated. </div>
<br />
Essentially, the plugin converts console messages from<br />
<blockquote class="tr_bq">
Hello World.</blockquote>
to include a link to the source code<br />
<blockquote class="tr_bq">
(HelloWorld.java:10) main(..) : Hello World.</blockquote>
<div>
I have uploaded the plugin on Github - <a href="https://github.com/deepakazad/MyTools/tree/master/DebugWithSysout">https://github.com/deepakazad/MyTools/tree/master/DebugWithSysout</a></div>
</div>
Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com0tag:blogger.com,1999:blog-1616206987206690523.post-71542409672449287962012-07-28T17:20:00.001-07:002012-07-28T17:20:58.995-07:00Going back to school<div dir="ltr" style="text-align: left;" trbidi="on">
After working at IBM for 5 years, I am going back to school. August 10th is my last day as a 'full-time' JDT committer, after which I head to University of British Columbia for Masters in Computer Science. I am looking forward to spending two fun-filled years in Vancouver. :-)<br />
<br />
It has been fun contributing to Eclipse so far, and in my free time I will likely continue to contribute. So, I will not actually say 'Good bye'.</div>
Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com5tag:blogger.com,1999:blog-1616206987206690523.post-80577083133657859212012-07-01T07:15:00.000-07:002012-07-01T07:15:55.460-07:00Eclipse Tip: Stepping into selection and hyperlink debugging<div dir="ltr" style="text-align: left;" trbidi="on">
The Java debugger allows you to step into a single method within a series of chained or nested method calls. Simply select the method you wish to step into and select <b>Step into Selection</b> from the Java editor context menu. I prefer to use the shortcut <b>Ctrl+F5</b>.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-1eJg4hNAoedZyPp2teF9fLCg6QAynVt7ENAXtILgbFjvSgLyGTAvomeDeIHcEfKyE2eJuVGg5aUh5YKRxYcF2ZbkCK4YzoBERsqHAz_nfUjgggEmqbGjyjX5_Tr3rc6uGQG8aOk_Td12/s1600/step_into_selection.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-1eJg4hNAoedZyPp2teF9fLCg6QAynVt7ENAXtILgbFjvSgLyGTAvomeDeIHcEfKyE2eJuVGg5aUh5YKRxYcF2ZbkCK4YzoBERsqHAz_nfUjgggEmqbGjyjX5_Tr3rc6uGQG8aOk_Td12/s1600/step_into_selection.png" /></a></div>
<br />
<span style="background-color: white;">You can also step into a method by using hyperlink navigation. Simply place the cursor over the method you wish to step into and use </span><b style="background-color: white;">Ctrl+Alt+Click</b><span style="background-color: white;"> to step into the method (rather than </span><b style="background-color: white;">Ctrl+Click</b><span style="background-color: white;"> which will navigate to the source code).</span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdNqv2oZn1yFhrdJR3_urElILlKLXuSpdGu1siRoju9yBwRn1gzKS056KHJIGoscxU3j4aVof0sAtvSjM1hTBFgN6N2K-hzR9G68GxrgynYhCQvpjzjCV0xU3vj0zA1wym2ZMtvoFz350G/s1600/hyperlink_step.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdNqv2oZn1yFhrdJR3_urElILlKLXuSpdGu1siRoju9yBwRn1gzKS056KHJIGoscxU3j4aVof0sAtvSjM1hTBFgN6N2K-hzR9G68GxrgynYhCQvpjzjCV0xU3vj0zA1wym2ZMtvoFz350G/s1600/hyperlink_step.png" /></a></div>
</div>Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com0tag:blogger.com,1999:blog-1616206987206690523.post-31632280834365080192012-06-30T09:43:00.000-07:002012-06-30T09:43:22.744-07:00Improving Java code quality with Eclipse Juno<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white;">The Eclipse Java compiler performs more checks and analyses than are mandated by the Java Language Specification. </span><span style="background-color: white;">See </span><span style="background-color: white;">Java > Compiler > Errors/Warnings preference page for available options.</span><br />
<br />
Now several of these options should be obvious, however a few maybe not :-) In Juno we (I mean Stephan) added <a href="http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-improve_code_quality.htm&cp=1_3_9">a few pages</a> to give<span style="background-color: white;"> some background on certain analyses and hints on how to make the best use of them.</span><br />
<span style="background-color: white;"><br /></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqBP_6l8lJ10nF4jtWztPozRnMUmkrucQ6xBGWwPEXRMLU_DhbV1qK9UNJ5A5gg63CMu4bSUCpc4OzLo_bbGavJVRR0gnO_iHK_rwuV_HIKJ3CvQbYWUFwnNPB4BN4cfQZJrWVgMTBUtpy/s1600/improving-java-code-quality.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqBP_6l8lJ10nF4jtWztPozRnMUmkrucQ6xBGWwPEXRMLU_DhbV1qK9UNJ5A5gg63CMu4bSUCpc4OzLo_bbGavJVRR0gnO_iHK_rwuV_HIKJ3CvQbYWUFwnNPB4BN4cfQZJrWVgMTBUtpy/s1600/improving-java-code-quality.png" /></a></div>
<span style="background-color: white;"><br /></span><br />
<span style="background-color: white;">Please let us know if these pages could be improved, or if you want to know more details on some other compiler options as well.</span></div>Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com1tag:blogger.com,1999:blog-1616206987206690523.post-46072447057831542632012-06-28T03:13:00.000-07:002012-06-28T03:16:03.731-07:00Eclipse Demo Camp 2012 - Bangalore<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white;">The </span><a href="http://wiki.eclipse.org/Eclipse_DemoCamps_Juno_2012/Bangalore" style="background-color: white;">Demo Camp</a><span style="background-color: white;"> happened last Friday, and was great fun! A couple of things stood out for me.</span><br />
<br />
First, I was pleasantly surprised to see people from Bosch already exploring Orion and evaluating how they can use the Orion platform and the Orion editors at their work.<br />
<br />
Second, I came to know about <a href="http://code.google.com/a/eclipselabs.org/p/eclipse-spykit/">Eclipse Spykit</a> which looks an interesting project. Based on <a href="http://www.ibm.com/developerworks/opensource/library/os-ecspy1/">Runtime Spy</a> Eclipse Spykit creates more charts and does a bit more analysis on what happens during Eclipse startup. Annamali started this project and mentioned that he is looking for contributors.<br />
<br />
Oh yeah, the Fajitas were good and the wine was excellent!</div>Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com0tag:blogger.com,1999:blog-1616206987206690523.post-39887745768882427852012-06-19T22:44:00.000-07:002012-06-19T22:44:25.524-07:00Eclipse Demo Camp 2012 - Bangalore<div dir="ltr" style="text-align: left;" trbidi="on">
It's demo camp time again! <span style="background-color: white;">I will be speaking this Friday at the </span><a href="http://wiki.eclipse.org/Eclipse_DemoCamps_Juno_2012/Bangalore" style="background-color: white;">Eclipse Demo Camp Bangalore</a> where I<span style="background-color: white;"> will demo some of the interesting new features in JDT for Juno and also show off a few tips and tricks. </span><br />
<span style="background-color: white;"><br /></span><br />
<span style="background-color: white;">It should be fun discussing Eclipse over some Tapas and wine :-) </span><span style="background-color: white;">Thanks </span><span style="background-color: white;">Annamalai for organizing this!</span></div>Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com0tag:blogger.com,1999:blog-1616206987206690523.post-75544287632075349582012-06-14T09:19:00.001-07:002012-06-14T09:21:10.821-07:00JDT Tip: Toggle between inserting and replacing content assist<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdTtjzCkYk7veb9WPlO98zRrnCP1TdbxdHzwEswtfSGq5OKWry8oXTVHwSISVB6WKi3Zl5njVvUm2pju9w91JVOwzo6A975COdn_yDdJr9iNZ899EGhmDEaklhP8oBOTRVd3G6IpzDtz7L/s1600/content-assist-overwrites.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdTtjzCkYk7veb9WPlO98zRrnCP1TdbxdHzwEswtfSGq5OKWry8oXTVHwSISVB6WKi3Zl5njVvUm2pju9w91JVOwzo6A975COdn_yDdJr9iNZ899EGhmDEaklhP8oBOTRVd3G6IpzDtz7L/s1600/content-assist-overwrites.png" /></a></div>
<br />
When content assist is invoked on an existing identifier, it can either replace the identifier with the chosen completion or do an insert.<br />
<br />
The default behavior is to insert. You can toggle this behavior while inside the content assist selection dialog by <b>pressing and holding the Ctrl key</b> while selecting the completion. The highlighted text is overwritten.<br />
<br />
If you wish the completion to overwrite without pressing the Ctrl key then you can select 'Preferences > Java > Editor > Content Assist > Completion overwrites'.</div>Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com6tag:blogger.com,1999:blog-1616206987206690523.post-24480133619237293232012-05-03T09:42:00.000-07:002012-05-03T09:42:08.262-07:00Subwords completion<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: left;">
Not so long ago I was fairly happy with JDT's content assist, and then I started using Subwords completion from <a href="http://www.eclipse.org/recommenders/">Code Recommenders</a> project and now it is fair to say that I cannot write code without it! :-)</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
The idea is simple enough - you should not have to type a name from the beginning to find a match in the content assist popup. It really helps when I do not know if I have to 'find' an element or 'get' an element.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgh-_AKQpOYqLM4YGbWrDV5NLbdNyugnxIg7mF3aO_UrJz3yh4gwGBgsIScLlduWXw3FqDu0llawHkPl-ag7zrABsLrrnqUQuPI0JK9s2SwarKW7f7hb6_Qbn5AZDktsP1_RcoZDJLqdqp3/s1600/subwords-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgh-_AKQpOYqLM4YGbWrDV5NLbdNyugnxIg7mF3aO_UrJz3yh4gwGBgsIScLlduWXw3FqDu0llawHkPl-ag7zrABsLrrnqUQuPI0JK9s2SwarKW7f7hb6_Qbn5AZDktsP1_RcoZDJLqdqp3/s1600/subwords-1.png" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
The feature is sophisticated enough to understand a rough shorthand e.g. dclr for declaration.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQJ5WkdOMxz3xJqUYW4-DOhZlElGQi0GQaMVaqV5sCcq49kM0YHUx1KbqRf0Rq8EHNK5xkWPqN3SNpv_7LdBpK01Y_etqXr3Gj4TWm4Mee1LV21D1NOZ_L3i5p-SULVporoOr4WlUBwyKw/s1600/subwords-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQJ5WkdOMxz3xJqUYW4-DOhZlElGQi0GQaMVaqV5sCcq49kM0YHUx1KbqRf0Rq8EHNK5xkWPqN3SNpv_7LdBpK01Y_etqXr3Gj4TWm4Mee1LV21D1NOZ_L3i5p-SULVporoOr4WlUBwyKw/s1600/subwords-2.png" /></a></div>
<br />
<br />
It is also sophisticated enough to understand that a method or type name in Java is composed of several words e.g. 'ty + dclr' finds all 'type' + 'declarations'.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJeG9NZFzuKXdQeoNUZtGlKq1I8VrjxXsU_nBsYGBVT2AX_hCK00ppJw_XVTI_ZJN7-uBRA7wwMVrGlukZb5T-dmgDJGU8YgGzDE7NJYx7GdVoXwCz_dejGE6ZIUEH66zI7izKDYvxnwi3/s1600/subwords-3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJeG9NZFzuKXdQeoNUZtGlKq1I8VrjxXsU_nBsYGBVT2AX_hCK00ppJw_XVTI_ZJN7-uBRA7wwMVrGlukZb5T-dmgDJGU8YgGzDE7NJYx7GdVoXwCz_dejGE6ZIUEH66zI7izKDYvxnwi3/s1600/subwords-3.png" /></a></div>
<br /></div>Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com13tag:blogger.com,1999:blog-1616206987206690523.post-19308814698564392762012-05-02T23:02:00.000-07:002012-05-02T23:02:14.447-07:00JDT 3.8/4.2 M7 - New and Noteworthy<div dir="ltr" style="text-align: left;" trbidi="on">
As usual we devoted most of our time in M7 towards polish and performance, nevertheless we managed a few new and noteworthy items.<br />
<br />
<div style="text-align: justify;">
Firstly a word about <b>bracket matching</b>. So far, a matching bracket was found when the caret was placed immediately 'after' a bracket. This caused confusion because a user can also think in terms of placing the caret 'inside' or 'outside' a bracket pair, see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=9503">bug 9503</a>. We tweaked this during M6 so that the start bracket was highlighted when the caret is before (not after) the end bracket, i.e. bracket matching now worked when the caret was 'inside' a bracket pair. We realized that this was still not ideal, and also that the old behavior was broken which some of users were already accustomed to.</div>
<br />
<div style="text-align: justify;">
All this has been improved and now a matching bracket is found both when the caret is placed either immediately before or immediately after a bracket<b> </b>i.e. <b>now bracket matching just works in all cases</b> a user might expect it to work.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-9jd8kOqWNNxAlvLuUPR9d6Fc4SXS73xrRgF-hoIt27deFslpxMiwWjeyH0FDc9kxhRcJ-_vg8vUc6Rnrovu1aXWwsg0inyDIchYPbafXUuBTs-0AGxW90Owiyl6hWwbSkA0O2kog-COL/s1600/matching-bracket.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-9jd8kOqWNNxAlvLuUPR9d6Fc4SXS73xrRgF-hoIt27deFslpxMiwWjeyH0FDc9kxhRcJ-_vg8vUc6Rnrovu1aXWwsg0inyDIchYPbafXUuBTs-0AGxW90Owiyl6hWwbSkA0O2kog-COL/s1600/matching-bracket.png" /></a></div>
<span style="text-align: justify;">You can </span><b style="text-align: justify;">hover over a closing curly brace</b><span style="text-align: justify;"> and see the source near the matching
opening brace in a hover. This is helpful when you want to see the code near the
start of a long code block. The hover also tells the number of lines in the code
block.</span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgagqwaWO3ve2iT6Qa3gta49TR0VojQa8bv719FkHsl451-YKU22l9jXP3efeH749ROG7xQ3qhsTJHeLxOg-NQfMs7-6JuFONZwfk0koWLfll6jT3B5Awh3oVpAjX8p9IrKrq5cbFQb9Dw5/s1600/bracket-hover-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgagqwaWO3ve2iT6Qa3gta49TR0VojQa8bv719FkHsl451-YKU22l9jXP3efeH749ROG7xQ3qhsTJHeLxOg-NQfMs7-6JuFONZwfk0koWLfll6jT3B5Awh3oVpAjX8p9IrKrq5cbFQb9Dw5/s1600/bracket-hover-1.png" /></a></div>
<br />
The hover is also useful to temporarily 'highlight' a code block.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZYIp2GHuQky2cs-E8EqZTPvMIM5HJ_8Goty3gYgCYu3uqLxLZdssJzomzWRQdrMxFh7Wisnk8NbkWWRYMgZvmkXbiv0qIrVGtiVhAp2cDX9L2sNTT5q9QsEGMGr1KeF9ZQ6u2djPGtUtn/s1600/bracket-hover-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZYIp2GHuQky2cs-E8EqZTPvMIM5HJ_8Goty3gYgCYu3uqLxLZdssJzomzWRQdrMxFh7Wisnk8NbkWWRYMgZvmkXbiv0qIrVGtiVhAp2cDX9L2sNTT5q9QsEGMGr1KeF9ZQ6u2djPGtUtn/s1600/bracket-hover-2.png" /></a></div>
<br />
<div style="text-align: justify;">
In M6 we had tweaked the warning on enum based switch statements, unfortunately the tweaks were not ideal and resulted in a bit of activity on <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=374605">bugzilla</a>. This has been improved and new compiler options have been added to take care of all cases.
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ_1OcjuQ4S4fMeTh5ifUgjo6OMYbtXfRNNfXB0ARNj4go6iCzeLCJSRL6eLUxAqM7Y9mz32J-NqOtk18QixilpWd3PQuw9L3Qxw6mVzq0k_gbFv8hJ3hjGtYXRDaTpq3TbUs4KiZYo3-h/s1600/switch-new-warnings.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ_1OcjuQ4S4fMeTh5ifUgjo6OMYbtXfRNNfXB0ARNj4go6iCzeLCJSRL6eLUxAqM7Y9mz32J-NqOtk18QixilpWd3PQuw9L3Qxw6mVzq0k_gbFv8hJ3hjGtYXRDaTpq3TbUs4KiZYo3-h/s1600/switch-new-warnings.png" /></a></div>
<br />
<div style="text-align: justify;">
Those who are using <a href="http://blog.deepakazad.com/2011/12/annotation-based-null-analysis-with-jdt.html"><b>null annotations</b></a> will also discover that there are a few new quick fixes to help you a little bit. One set of quick fixes help to quickly setup a project to use null annotations, i.e. appropriately add the annotations jar to the build path. The second set of quick fixes help you fix problems with respect to incorrect usage of null annotations, missing annotations etc. This second set is not yet perfect, see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=337977">bug 337977</a>. </div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
As always, feedback is greatly appreciated especially in the form of bug reports!</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
In other news, during this milestone I also earned <a href="http://dev.eclipse.org/mhonarc/lists/platform-text-dev/msg00415.html">commit rights on Platform/Text</a> project :-)</div>
</div>Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com0tag:blogger.com,1999:blog-1616206987206690523.post-59483071543141622792012-04-20T10:10:00.000-07:002012-04-20T10:10:54.404-07:00Recovering from a hard disk failure<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIHhg7cUrvGzd6aHFOGumEvBJGdErfVObtuqtqCP-6FYoSaGoQvZH-MQQsYhE-Gb036V95izS6VWp6ECNuIXz74ZoFWf0tDPYJChYlVZlfwsGU1eVsCWtnj-pEF-pRLjFZ8muJSGzrWdIc/s1600/crashed-hard-disk.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="149" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIHhg7cUrvGzd6aHFOGumEvBJGdErfVObtuqtqCP-6FYoSaGoQvZH-MQQsYhE-Gb036V95izS6VWp6ECNuIXz74ZoFWf0tDPYJChYlVZlfwsGU1eVsCWtnj-pEF-pRLjFZ8muJSGzrWdIc/s200/crashed-hard-disk.jpg" width="200" /></a></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
A few weeks back the hard disk of my laptop computer crashed, and as a hard disk had never crashed in my vicinity earlier I was a bit unsure about what to do. I could have used one of those data recovery services, however I decided to tackle the problem on my own because - <b>no one cares for my data more than me </b>and you cannot really trust a stranger with your data. I ended up spending a fair bit of time trying to recover my data. Here is a summary of what I did</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
1. Essentially my computer had stopped booting up. On powering it on, the Loading Windows screen would come and then a <a href="http://en.wikipedia.org/wiki/Blue_Screen_of_Death">blue-screen-of-death</a>. Now this could be because some OS files are corrupted, or there is a problem with master-boot-record, mother board issue or a gazillion other things. Hence, the first step is to <b>verify that it is an hard disk issue</b>. To do so get a bootable CD/DVD or a USB and boot using that, if the system boots then something is probably wrong with the hard disk. If you do not have a bootable CD/DVD/USB ready at hand, ask around, a bootable Linux disc is not too hard to find.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
2. I could boot my system using a bootable USB drive. Once booted I tried to access the hard disk in question, however that did not work. The hard disk would not mount. I even tried using a bootable <a href="http://en.wikipedia.org/wiki/BartPE">BartPE</a> disk, and even that did not help. So something was seriously wrong with my hard disk.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
3. Now I was certain that there is a serious failure and I would need some <b>special tools</b> to recover my data. At this point you have 2 choices in front of you</div>
<div style="text-align: justify;">
a) Boot your system using a bootable disk and use a specialized software installed on that bootable disk to recover your data</div>
<div style="text-align: justify;">
b) Take out your hard disk and connect it to another computer as a secondary drive.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Let me explain both choices and reasons behind why I went with option (b)</div>
<div style="text-align: justify;">
a) For this option, you can use BartPE to boot your computer. BartPE has a <a href="http://www.runtime.org/peb.htm">plugin</a> for <a href="http://www.runtime.org/data-recovery-software.htm">GetDataBack</a>, however I found this option a bit cumbersome to use. There were a few steps to setup everything nicely so as to copy data on to an external drive. Hence, I thought of exploring option (b)</div>
<div style="text-align: justify;">
b) In this option, the major hurdle is to be able to connect your hard disk to another computer because you need some hardware which not everyone may not have lying around. Luckily for me a friend had <a href="http://www.newmodeus.com/shop/index.php?main_page=page&id=7">replaced</a> his CD/DVD drive with a secondary hard disk and he was kind enough to lend me the hard disk bay for a few days :-) I also had another laptop readily available, something that may not be true for everyone. Once I was able to connect my faulty hard drive to another computer as a secondary drive, I could use any number of data recovery tools like <a href="http://www.runtime.org/data-recovery-software.htm">GetDataBack</a>, <a href="http://www.ptdd.com/">Partition Table Doctor</a>, or freeware such as <a href="http://pcinspector.de/default.htm?language=1">PC Inspector File recovery</a>. Some more tools can be found at <a href="http://alternativeto.net/searchresult.aspx?search=data%20recovery">alternativeto.net</a>.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
4. Now reading data from my faulty hard drive was a simple task, it was slow but simple enough. However, some sectors on the disk were clearly bad and there were quite a few I/O errors while recovering the data. Hence, I was a bit unsure about the quality of data I was getting back - maybe some files were forever lost, or maybe some files were corrupted - essentially I did not know if I could trust the data. Now I also had a few months old data backup on an external drive, hence I thought to start with that and compare with the recovered data and sort of <b>merge</b> the two :-) Again there are a few tools which can help with this, <a href="http://www.microsoft.com/download/en/details.aspx?id=15155">Microsoft SyncToy</a> is fairly neat and is also free, <a href="http://www.scootersoftware.com/">Beyond Comapre</a> is a bit better but is not free.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Now I could have avoided all this if I frequently did a data backup. In any case it was kind of interesting to do all this and I did learn a few things along the way. The most important lesson obviously being - <b>take a data backup every week</b>! :-)</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Note: I should also mention that somewhere in between I also tried the <a href="http://howto.wired.com/wiki/Save_Your_Hard_Drive_by_Freezing_It">freezing-the-hard-disk</a> trick. I know it sounds a bit crazy, and it did not work for me, but for <a href="http://www.emergingtechs.com/posts/put-your-hard-drive-in-the-freezer-to-recover-data/">some folks</a> it seems to <a href="http://geeksaresexy.blogspot.in/2006/01/freeze-your-hard-drive-to-recover-data.html">help</a> a bit.</div>
</div>Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com0tag:blogger.com,1999:blog-1616206987206690523.post-56705808246860043112012-04-15T22:53:00.000-07:002012-04-15T22:57:07.519-07:00YourKit profiler APIs<div dir="ltr" style="text-align: left;" trbidi="on">
YourKit provides APIs to start and stop measuring from within your application, e.g.<br />
<blockquote class="tr_bq">
com.yourkit.api.Controller controller = new com.yourkit.api.Controller();<br />
controller.startCPUProfiling (com.yourkit.api.ProfilingModes.CPU_TRACING , null);<br />
controller.stopCPUProfiling();<br />
controller.captureSnapshot (com.yourkit.api.ProfilingModes.SNAPSHOT_WITHOUT_HEAP);</blockquote>
To use these APIs include <i><Profiler Installation Directory>/lib/yjp-controller-api-redist.jar</i> in the classpath. Read more about YourKit APIs <a href="http://www.yourkit.com/docs/90/help/api.jsp">here</a>.</div>Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com0tag:blogger.com,1999:blog-1616206987206690523.post-64430807768404590402012-04-11T10:32:00.000-07:002012-04-11T10:33:42.091-07:00Permanently enable 'Open command window here' in Windows 7<div dir="ltr" style="text-align: left;" trbidi="on">
By default you need to right-click a folder, while pressing the SHIFT key, in order to access 'Open command window here' context menu option. However, it can be enabled permanently with the help of following steps<br />
<ul style="text-align: left;">
<li>Click Start, Run and type Regedit.exe</li>
<li>Navigate to the following location:</li>
<ul>
<li>HKEY_CLASSES_ROOT\Directory\shell\cmd</li>
</ul>
<li>In the right-pane, delete the REG_SZ value named Extended</li>
</ul>
</div>Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com4tag:blogger.com,1999:blog-1616206987206690523.post-46040155265529440502012-03-21T23:36:00.000-07:002012-03-21T23:36:42.439-07:00Contributing a quick fix and a quick assist for Java code<div dir="ltr" style="text-align: left;" trbidi="on">
JDT offers a large number of <a href="http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Fconcepts%2Fconcept-quickfix-assist.htm">quick fixes and quick assists</a> for Java code. However, you may want to implement your own as well, and it is actually quite easy to do so with the help of <a href="http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.isv%2Freference%2Fextension-points%2Forg_eclipse_jdt_ui_quickFixProcessors.html">org.eclipse.jdt.ui.quickFixProcessors</a>
and <a href="http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.isv%2Freference%2Fextension-points%2Forg_eclipse_jdt_ui_quickAssistProcessors.html">org.eclipse.jdt.ui.quickAssistProcessors</a>
extension points.<br />
<br />
<b>Using the extension points</b><br />
To create a new extension for the extension points you need to first provide
the required extensions in the plugin.xml. For example, JDT defines the
following processors<br />
<br />
<pre> <extension
point="org.eclipse.jdt.ui.quickFixProcessors">
<quickFixProcessor
name="%defaultQuickFixProcessor"
class="org.eclipse.jdt.internal.ui.text.correction.QuickFixProcessor"
id="org.eclipse.jdt.ui.text.correction.QuickFixProcessor">
</quickFixProcessor>
</extension>
<extension
point="org.eclipse.jdt.ui.quickAssistProcessors">
<quickAssistProcessor
name="%defaultQuickAssistProcessor"
class="org.eclipse.jdt.internal.ui.text.correction.QuickAssistProcessor"
id="org.eclipse.jdt.ui.text.correction.QuickAssistProcessor">
</quickAssistProcessor>
</extension>
</pre>
<br />
For a description of the individual attributes, please refer to the extension
point documentation.<br />
<br />
<b>Contributing a quick fix and a quick assist</b><br />
To contribute a quick fix, you need to create the class that implements the <code>org.eclipse.jdt.ui.text.java.IQuickFixProcessor</code> interface. This is the same class that you specified in the extension
declaration. Each Java problem has a unique id which is defined in <code>org.eclipse.jdt.core.compiler.IProblem</code> interface. For a particular Java problem you may offer one or more correction
proposals.<br />
<br />
To contribute a quick assist, you need to create the class that implements
the <code>org.eclipse.jdt.ui.text.java.IQuickAssistProcessor</code> interface. Again, this is the same class that you specified in the extension
declaration.<br />
<br />
<b>Supplying the right IJavaCompletionProposal</b><br />
JDT provides the following default implementations for correction proposals
that can be used to contribute quick fixes and quick assists.<br />
<ul>
<li><code>org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal</code></li>
<li><code>org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal</code></li>
<li><code>org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal</code></li>
</ul>
Typically you will use an <code>org.eclipse.jdt.core.dom.rewrite.ASTRewrite</code>,
in that case you should create an <code>ASTRewriteCorrectionProposal</code>. However, if as a
result of a quick assist you want to start an action e.g. open a wizard, you
should create a <code>ChangeCorrectionProposal</code> and override its <code>apply(IDocument)</code>
method.<br />
<br />
Note: These default implementations <a href="http://blog.deepakazad.com/2012/03/jdt-3842-m6-new-and-noteworthy.html">became API</a> only in 3.8/4.2 (Juno) M6.<br />
<br />
<b>Manipulating Java code via ASTRewrite</b><br />
Using ASTRewrite is simple enough, you can read more about AST and ASTRewrite in <a href="http://www.eclipse.org/articles/article.php?file=Article-JavaCodeManipulation_AST/index.html">this Eclipse Corner Article</a> and in <a href="http://www.eclipsecon.org/2010/sessions/?page=sessions&id=1339">this EclipseCon tutorial (slides 44-46)</a>. However, sometimes you may not know which AST nodes need to be modified and to what. <a href="http://www.eclipse.org/jdt/ui/astview/index.php">ASTView plugin</a> helps you visualize the AST of a Java source file, and is really helpful in identifying what modifications need to be done in the AST.</div>Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com1tag:blogger.com,1999:blog-1616206987206690523.post-23714047943231830792012-03-16T23:22:00.001-07:002012-03-16T23:28:10.539-07:00JDT 3.8/4.2 M6 - New and Noteworthy<div dir="ltr" style="text-align: left;" trbidi="on">
M6 was a long milestone - there was one extra week of development - and hence we could do a little bit more. There are quite a few new features and a few API additions as well.<br />
<br />
JDT always provided extension points to<b> contribute Quick Fixes/Assists</b>. However, it was hard for contributors to supply the right IJavaCompletionProposal required by IQuickFixProcessor and IQuickAssistProcessor interfaces. This has been improved as JDT now provides the following<b> default implementations for correction proposals</b><br />
<br />
<ul style="text-align: left;">
<li>org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal</li>
<li>org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal</li>
<li>org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal</li>
</ul>
<br />
This makes it easier to implement quick fixes/assists that operate on .java files and use an ASTRewrite. Of course you could always use the internal implementations, but then your code would be littered with forbidden access warnings and the implementations could change any time :)<br />
<br />
The <b>bracket matching</b> support in Java Editor has been improved, and among other things it now supports highlighting of <b>enclosing brackets</b>.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0LDds2rSLxr8wUSWx2o1t3-a5hKB-3SfPt6duAvVTnXECh7cuk_ALyYGh_XKwoNN6-jxgr3fxFv_gjM6udO-ZNudvsZzLLQGj7C6PK8dhs104JLX8CfEUK7eEHG7UVWugihHVgz-kkIWH/s1600/enclosing-brackets.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0LDds2rSLxr8wUSWx2o1t3-a5hKB-3SfPt6duAvVTnXECh7cuk_ALyYGh_XKwoNN6-jxgr3fxFv_gjM6udO-ZNudvsZzLLQGj7C6PK8dhs104JLX8CfEUK7eEHG7UVWugihHVgz-kkIWH/s1600/enclosing-brackets.png" /></a></div>
This can be configured on the <b>Java > Editor</b> preference page.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEha_wsg9MAHiJWwd8J4Pv4tD5B0H9_O9d2g1JqQc0RZegJZCKWVZxDJTLicfojXqoESYjU_I-_BhuxSgHSPFNCfLsQxMCZnFBPuLyiC8apdCbFEGNi53NY6TMIFWw_Za_4NTvosqfprrsGs/s1600/bracket-highlighting-preferences.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEha_wsg9MAHiJWwd8J4Pv4tD5B0H9_O9d2g1JqQc0RZegJZCKWVZxDJTLicfojXqoESYjU_I-_BhuxSgHSPFNCfLsQxMCZnFBPuLyiC8apdCbFEGNi53NY6TMIFWw_Za_4NTvosqfprrsGs/s1600/bracket-highlighting-preferences.png" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
While the feature is visible in Java editor, the infrastructure is in Platform/Text. Hence, if anyone wishes to add the same functionality to other editors they can make use of the following types</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<ul style="text-align: left;">
<li>org.eclipse.jface.text.source.DefaultCharacterPairMatcher</li>
<li>org.eclipse.jface.text.source.MatchingCharacterPainter</li>
</ul>
<div>
<br /></div>
<div>
<div>
<div>
<div>
Marcel Bruch, of <a href="http://www.eclipse.org/recommenders/">Code Recommenders</a> fame, added the concept of <b>sorting to the content assist framework</b> by adding several new APIs on the content assistant and the processor - see org.eclipse.jface.text.contentassist.ICompletionProposalSorter. Thanks Marcel, and hope to see more contributions from you in future! :-)</div>
</div>
</div>
</div>
<div>
<br /></div>
There are a few more interesting items, like <b>Selectively ignore errors/warnings from source folders </b>and<br />
<b>Null analysis treats org.eclipse.core.runtime.Assert like Java assert</b>. You can read the <a href="http://download.eclipse.org/eclipse/downloads/drops4/S-4.2M6-201203151300/eclipse-news-M6.html">complete list here</a>.<br />
<br />
As always, feedback is greatly appreciated especially in the form of bug reports!</div>Deepakhttp://www.blogger.com/profile/12947774811212314687noreply@blogger.com6