tag:blogger.com,1999:blog-62946638759295910182024-03-05T06:22:21.508-08:00Ramblings of a techieBragBoyhttp://www.blogger.com/profile/01173019524783723568noreply@blogger.comBlogger149125tag:blogger.com,1999:blog-6294663875929591018.post-20775578037729634352017-02-05T09:37:00.001-08:002017-02-05T23:52:18.813-08:0015-Game in Android<div dir="ltr" style="text-align: left;" trbidi="on">
Having developed this game earlier (for fun) in <a href="http://tech.bragboy.com/2010/09/free-game-in-java.html">Java Swing</a> and <a href="http://tech.bragboy.com/2010/12/15-game-in-flash-actionscript3.html">Actionscript</a> years before, I thought I would port this to Android as well. Spent a good 6 hours from New Project to put it live on the Play store! Click <a href="https://play.google.com/store/apps/details?id=tech.francium.fifteenpuzzle&hl=en_GB">here</a> for downloading it.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://play.google.com/store/apps/details?id=tech.francium.fifteenpuzzle" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="539" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlhV1d_cFq57Nl-NymYu-8TEPwbm0EVOPf09EaBWdwLtIwsYhkXLYeDo-i5U5Q0ZtOA409qPzus69YkUir6jnNxX4VXx_sm7KMQ3vtBSzrMSL2x0rxNzRsT62-rVG1r9qYb2D_sE-r2HM/s640/Fifteen+puzzle+Android.png" width="640" /></a></div>
<br />
<br />
Cheers,<br />
Braga</div>
bragadeeshhttp://www.blogger.com/profile/05516264230057880613noreply@blogger.com0tag:blogger.com,1999:blog-6294663875929591018.post-48391452300973691172017-01-23T10:27:00.002-08:002017-01-23T10:27:42.113-08:00A simple formula to rapidly succeed<div dir="ltr" style="text-align: left;" trbidi="on">
This is a well-known formula. Wanted to see how it looks in code. Only 5 lines, not bad!<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMlfjOwakEYsNnClWK8l3JuQhsEf_YACGIOQBhveI9E2OSwxYwHisMXF6k_Bmj22gX9G5LGEum8bLpZfBOcDaZCjqPPOKQmABWOPl0uR4noP6_8LEIBILC6iZOOdsyP24gKVNvbZli7cU/s1600/secret+of+success+.png" style="width: 100%;" /></div>
<br />
<br />
Of course, you can force kill this infinite loop :), how far you go is up to you, though!<br />
<br />
Cheers!<br />
Braga</div>
bragadeeshhttp://www.blogger.com/profile/05516264230057880613noreply@blogger.com0tag:blogger.com,1999:blog-6294663875929591018.post-8126285779103672532017-01-21T23:24:00.002-08:002017-01-22T05:47:12.723-08:00Gotchas while Appifying your website in Android with Webview<div dir="ltr" style="text-align: left;" trbidi="on">
<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/AVvXsEiVhJjM1EWSFcMNP0maq17RAkqqjiJb84PVBZUtN-qUVeFbhzMklOQLiGM4GB5dsLQB5xPBbH7VXlYHTh4C4wjID6NavnWsoBffZvtLIyUAaaKXWD8TMwKvBCE11zyk6Fg79LbYjlx8hm8/s1600/Android+Webview.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="261" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVhJjM1EWSFcMNP0maq17RAkqqjiJb84PVBZUtN-qUVeFbhzMklOQLiGM4GB5dsLQB5xPBbH7VXlYHTh4C4wjID6NavnWsoBffZvtLIyUAaaKXWD8TMwKvBCE11zyk6Fg79LbYjlx8hm8/s400/Android+Webview.png" width="400" /></a></div>
<br />
<br />
Android's Webview class is an excellent way to convert your website instantly into an app provided it is responsive. There are a lot of tutorials out there to convert your website into a webview instantly. I too wanted to convert one of my websites into an app.<br />
<br />
However, there are certain things you need to keep in mind before you go ahead and submit in the app store for publication.<br />
<br />
Since this is a relatively newer experience for me, I did not anticipate certain obvious gotchas. My application went through two sets of rejection before I could make it live, perhaps these could be useful for someone in similar waters.<br />
<br />
Ensure that you are aware of all the policies that are set forth by Google Play; may it be copyrighted content, Privacy policy, Impersonation Policy, Ratings etc., I thought I had it all covered until I got this email from Google assuming that my application was an impersonation of an existing website.<br />
<h2 style="text-align: left;">
</h2>
<h2 style="text-align: left;">
<br /></h2>
<h2 style="text-align: left;">
<u> Rejection#1</u></h2>
<div>
<br /></div>
<div style="background: #e2e2e2;">
Notification from Google Play<br />
<br />
Google Play Support <googleplay-developer-support+no-reply@google.com><br />
<br />
Hi Developers at ***,<br />
<br />
After review, <may app>, has been suspended and removed from Google Play as a policy strike because it violates the impersonation policy.<br />
<br />
Next Steps<br />
<br />
<ol style="text-align: left;">
<li>Read through the <a href="https://play.google.com/about/spam.html#impersonation-intellectual-property:impersonation">Impersonation</a> article for more details and examples of policy violations.</li>
<li>Make sure your app is compliant with the <a href="https://play.google.com/about/spam.html#impersonation-intellectual-property">Impersonation and Intellectual Property policy</a> and all other policies listed in the <a href="https://play.google.com/about/developer-content-policy.html">Developer Program Policies</a>. Remember additional enforcement could occur if there are further policy issues with your apps.</li>
<li><a href="https://play.google.com/apps/publish">Sign in to your Developer Console</a> and submit the policy compliant app using a new package name and a new app name.</li>
</ol>
<br />
What if I have permission to use the content?<br />
<br />
Contact our support team to provide a justification for its use. Justification may include providing proof that you are authorized to use the content in your app or some other legal justification.<br />
<br />
Additional suspensions of any nature may result in the termination of your developer account, and investigation and possible termination of related Google accounts. If your account is terminated, payments will cease and Google may recover the proceeds of any past sales and/or the cost of any associated fees (such as chargebacks and transaction fees) from you.<br />
<br />
If you’ve reviewed the policy and feel this suspension may have been in error, please reach out to our policy support team. One of my colleagues will get back to you within 2 business days.<br />
<br />
Regards,<br />
<br />
The Google Play Review Team</div>
<h2 style="text-align: left;">
</h2>
<h2 style="text-align: left;">
<br /></h2>
<h2 style="text-align: left;">
<u>My Appeal</u></h2>
<div>
<br /></div>
My initial reaction was wtf! I have created an application for my own website, why the hell would google want to reject it? But the rationale behind this rejection made sense. What if a random person uses my website and tries to monetize my application? Or myself for that matter take a bunch of existing websites and start appifying them for my personal benefits.<br />
I appealed. During the appeal, I uploaded a bunch of documents supporting that I am the owner of the website and that I have the rights to appify. The documents included - Google Analytics statistics page of the site and the Digital Ocean hosted app screenshots. Plus a small write up on claiming myself to be the owner.<br />
<br />
Google understood and accepted my appeal. This is the email I got from them afterward.<br />
<h2 style="text-align: left;">
</h2>
<h2 style="text-align: left;">
<br /></h2>
<h2 style="text-align: left;">
<u>Reinstatement</u></h2>
<div>
<br /></div>
<div style="background: #e2e2e2;">
Re: [<my case#>] Your appeal for reinstatement<br />
<br />
Hi Bragadeesh,<br />
<br />
Thanks for contacting the Google Play Team.<br />
<br />
We’ve accepted your appeal and your app <appname> has been reinstated. For the app to appear on the Play Store, you’ll need to sign into your Developer Console and click "Submit update" to submit your app again.<br />
<br />
If the option to resubmit is not available, please make a small change (such as adding and deleting a space in your Description in the Store Listings) to reactivate the button.<br />
<br />
In the future, if you have proof of permission you can submit it to our team proactively using this form:<br />
https://support.google.com/googleplay/android-developer/answer/6320428<br />
<br />
The link can also be found on your Store Listing page underneath the box for Full Description.<br />
<br />
If you're an AdMob publisher, you'll need to contact the AdMob team to re-enable ad serving:<br />
https://support.google.com/admob/contact/appeal_policy_violation<br />
<br />
The AdMob policy team will review your app(s) and decide whether to re-enable ad serving.<br />
<br />
Please let me know if you have any other questions or concerns.<br />
<br />
Thanks for supporting Google Play!<br />
<br />
Regards,<br />
<Google Engineer><br />
The Google Play Team</div>
<div>
<br /></div>
<div>
At this point, I was elated to have successfully appealed to my rejection and went ahead and resubmitted the application. However, later I found that, this feeling was short lived as I got a second rejection from Google Playstore.</div>
<h2 style="text-align: left;">
</h2>
<h2 style="text-align: left;">
<br /></h2>
<h2 style="text-align: left;">
<u>Rejection#2</u></h2>
<div>
<br /></div>
<div style="background: #e2e2e2;">
Notification from Google Play about <app name><br />
<br />
Hi Developers at ***,<br />
<br />
Thanks for submitting your app to Google Play.<br />
<br />
I reviewed <appname>, and had to reject it because of an unauthorized use of copyrighted content. If you submitted an update, the previous version of your app is still live on Google Play.<br />
<br />
Here’s how you can submit your app for another review:<br />
<ol style="text-align: left;">
<li>Remove any content owned by a third party from your app. For example, your app Store Listing contains: images of “<a celebrity>” in the Tablet 7" Screenshots. Affected Translations: en_US, en_IN</li>
<li>Read through the <a href="https://play.google.com/about/spam.html#impersonation-intellectual-property:unauthorized-use-of-copyrighted-content">Unauthorized Use of Copyrighted Content</a> article for more details and examples.</li>
<li>Make sure your app is compliant with the <a href="https://play.google.com/about/spam.html#impersonation-intellectual-property">Impersonation and Intellectual Property policy</a> and all other policies listed in the <a href="https://play.google.com/about/developer-content-policy.html">Developer Program Policies</a>. Remember that additional enforcement could occur if there are further policy issues with your apps.</li>
<li><a href="https://play.google.com/apps/publish">Sign in to your Developer Console</a> and submit your app.</li>
</ol>
<br />
What if I have permission to use the content?<br />
<br />
Contact our support team to provide a justification for its use. Justification may include providing proof that you are authorized to use the content in your app or some other legal justification.<br />
<br />
If you’ve reviewed the policy and feel this rejection may have been in error, please reach out to our policy support team. One of my colleagues will get back to you within 2 business days.<br />
<br />
I appreciate your support of Google Play!<br />
<br />
Best,<br />
<br />
<Google Engineer><br />
<br />
Google Play Review Team</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
This rejection though was totally valid. I felt so dumb to have used a celebrity picture for demonstration purposes in one of my tablet screenshots without a copyright. Google was sort of kinder and patient to me. In order, not to test their patience too much, I thought I would remove the image in question they've said and three other images as well which I thought would fall under the violative category. <span id="goog_1646398907"></span></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
I then resubmitted my application and voila! My app is now live at the play store. It was an adventurous learning because they could have blocked my entire developer account for life if I had one or two more policy strikes as many other developers have had. </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Cheers!</div>
Braga</div>
</div>
bragadeeshhttp://www.blogger.com/profile/05516264230057880613noreply@blogger.com0tag:blogger.com,1999:blog-6294663875929591018.post-17796568288378613062016-11-17T04:00:00.002-08:002017-05-06T03:12:25.327-07:00Crawl all the linkedin skills<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/AVvXsEgT8fqgNDj9u7bO3uKohA7mI9fr0RDYeNKC49w2lfxGOEJAE_qMnxvVtwrp6tb0L_WswNXEdghmyA0r7Jjc2vnZ5uKiVTV6bbzzXVUCpU5VgXwlqwLwKlgk4QGR28DASyj80VG5b_K8QTs/s1600/linkedin+crawl.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="242" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgT8fqgNDj9u7bO3uKohA7mI9fr0RDYeNKC49w2lfxGOEJAE_qMnxvVtwrp6tb0L_WswNXEdghmyA0r7Jjc2vnZ5uKiVTV6bbzzXVUCpU5VgXwlqwLwKlgk4QGR28DASyj80VG5b_K8QTs/s320/linkedin+crawl.png" width="320" /></a></div>
<br />
<br />
One of the recent problems I solved, crawling all the LinkedIn skills. Without any adieu, here is the source code.<br />
<br />
<script src="https://gist.github.com/bragboy/0bfebf3def572c41dc4c0da78d99ee71.js"></script> Well, most of it is self-explanatory. Have also attached the complete skill list used by LinkedIn for anyone <a href="https://gist.githubusercontent.com/bragboy/89777a2eacb8ca46d2c13e44bf928b7e/raw/08ea8211f833f0bb75b377c2827ea9b76ed4b814/all_linked_skills.txt" style="text-decoration: underline;">to download</a>. Note: This is something available for free on the public domain. Also, the program written is good for the current date, I could write a dynamic one that would automatically update, but then I was too lazy to do that :)<br />
<br />
<u><span style="font-size: large;">Code Explanation</span></u><br />
Line 1: Requiring <a href="https://github.com/chriskite/anemone">anemone</a> library which is a web spider framework written in ruby.<br />
Line 3-6: I am initialising the characters to pages map obtained from the URL. For example, take a look at this link https://www.linkedin.com/directory/topics-o/ Here the character O has 99 sub pages. Similarly, character x has 73 sub pages. I manually assigned it here for the crawler to go that many times<br />
Line 8: The variable all_urls consists all the possible combinations from a to z at the max each character having 99 subpages. The variable skipped_urls is to catch the URLs whose values are not crawlable because LinkedIn detected scrapping is going on. That will be collected and will be printed for recrawling later.<br />
Line 9: Mapping all the possible URLs mentioned above into the variable all_urls<br />
Line 11: Open a file called skills.txt in write mode and make it ready<br />
Line 12: Iterate over each of the URLs present in all_url variable<br />
Line 15-20: This is where the real crawling occurs. The XPath selector searches for class=column and collects all the skills in the given page and writes them directly into the file<br />
Line 22: Capture all the skipped_urls in case LinkedIn blocks the scraper (which is the program)<br />
Line 27: Print the skipped_urls using which we will have to rerun the program again - which I leave it to the reader to figure out how.<br />
<br />
Cheers,<br />
Braga</div>
bragadeeshhttp://www.blogger.com/profile/05516264230057880613noreply@blogger.com19tag:blogger.com,1999:blog-6294663875929591018.post-44184300440114941352016-09-22T04:27:00.000-07:002016-09-22T04:27:16.892-07:00State of Rails Releases<div dir="ltr" style="text-align: left;" trbidi="on">
I am dealing with multiple Rails applications at once some of which are funded right and some of which have ran into maintenance modes. I just wanted to have a pictorial representation of what is the state of each of the Rails versions, unfortunately, I cannot get one. So I spent half an hour trying to decode the Rails official releases page and came up with this.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgirtOYQnpkfxWe3VlldGEk-6a81SPiT7tLYb210vSa0S1gzHDaFNRfO7lBy7-8TxDbuuY8sQMyfYgS78DjHpBdgQuFWBAUU9cW5rMdhT9S3D0MdMxVBLVi2csX8zh08sOXaDYaa7jNt-k/s1600/Rails+Release+version+Gantt+Chart.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="99" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgirtOYQnpkfxWe3VlldGEk-6a81SPiT7tLYb210vSa0S1gzHDaFNRfO7lBy7-8TxDbuuY8sQMyfYgS78DjHpBdgQuFWBAUU9cW5rMdhT9S3D0MdMxVBLVi2csX8zh08sOXaDYaa7jNt-k/s640/Rails+Release+version+Gantt+Chart.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
If you closely observe, the Rails releases 3.0.x and 3.1.x are history (I don't even want to pull up data for releases before that). It is high time you plan to upgrade your stack to a minimum of Rails 4.2 before you loose all the goodness the Rails community has to offer. Yes, I know it is a herculean task for folks in 3.x in which case I recommend you to do a complete rewrite of your application piecemeal by piecemeal!</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Data Source: http://weblog.rubyonrails.org/releases/</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Cheers,</div>
<div class="separator" style="clear: both; text-align: left;">
Braga</div>
<br /></div>
bragadeeshhttp://www.blogger.com/profile/05516264230057880613noreply@blogger.com2tag:blogger.com,1999:blog-6294663875929591018.post-29028599268717092452016-07-26T13:53:00.002-07:002016-08-03T05:09:32.463-07:0020 Tips for an Effective Code Review<div dir="ltr" style="text-align: left;" trbidi="on">
<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/AVvXsEjyGuXCp8bwUbWZ9fiRUf-A8LBOMxplPI42yJiJouIjNgdakmOYlw0XcfuM0JmqeMSg6nKFYV8wWCHqLQyKfdqrut3rTlP2M9iuPGHD9flVCeXJBuGlabX5sMgaAtrxGmMVE4jz8h1Oe20/s1600/Code+Review.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="243" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyGuXCp8bwUbWZ9fiRUf-A8LBOMxplPI42yJiJouIjNgdakmOYlw0XcfuM0JmqeMSg6nKFYV8wWCHqLQyKfdqrut3rTlP2M9iuPGHD9flVCeXJBuGlabX5sMgaAtrxGmMVE4jz8h1Oe20/s400/Code+Review.JPG" width="400" /></a></div>
<br />
<span style="font-family: cousine;"><span style="font-size: 17.6px; line-height: 24.64px;">It is a well-established fact that most of the bugs in the Software Development life cycle could be prevented literally right at the source (code). Since Code Review is almost an inevitable process in the Agile paradigm, keep in mind these 20 tips/guidelines (in no particular order) to become an effective reviewer of code. This is not restrictive to any one language but applicable to all. I've been reviewing code for many years and one of my core successes lie in stressing these points across the team. This is also the only way to effectively nurture and scale teams across the organisation.</span></span><br />
<br />
<ol style="text-align: left;">
<li><span style="font-family: cousine; font-size: 17.6px; line-height: 24.64px;"><b>Identify the right tool:</b> Identifying the right tool is very important. Because one should not be thrown off for adding a review just because the tool is not efficient enough. There are many open source tools out there. In most cases, you may have to host it yourself or you can also opt for services that do the hosting for you. If you are an Open Source Contributor, you would know how effective Github can be which also happens to be my personal favorite.</span></li>
<li><span style="font-family: cousine; font-size: 17.6px; line-height: 24.64px;"><b>Pre-conditions/Checklist:</b> Any patch or a pull request that is submitted should have a minimum set of pre-conditions like it should have a Green build. A lot of Review tools have hooks to be configured to poll the SCM automatically and run the build. Build tools like Jenkins, Travis support these with minimal to no configuration. Ensure that you use them! Because it will definitely save you time and heartache instead of seeing stuff getting pushed to your trunk/master/production branch.</span></li>
<li><span style="font-family: cousine; font-size: 17.6px; line-height: 24.64px;"><b>Avoid Repeat Mistakes:</b> As Gustavo Fring from The Breaking Bad rightly says "Never Repeat the same mistake twice", it is crucial that repetitive patterns are broken. In the context of code review, this means the developers should not get the same review comment that they had received earlier. This ensures that with each Iteration - the Quality of the patches improves so that if at all any new review comments are there - they are only new and anything that is given in the past are assumed to have been implemented in the later ones. If this is not happening, it is up to the Reviewer to go and identify to see where the leak is.</span></li>
<li><span style="font-family: cousine; font-size: 17.6px; line-height: 24.64px;"><b>Self Review:</b> The person who is submitting the diff should first review it him/herself. Many obvious things like debugger statements, extra/missing files, ignorable files could be identified here. And I would recommend even doing a full fledged review of his/her own code as if he/she would do another one's. This culture also reduces the burden on the reviewer of concentrating on the Meat of the patch and not the obvious ones.</span></li>
<li><span style="font-family: cousine; font-size: 17.6px; line-height: 24.64px;"><b>Design Review:</b> The Reviewer should also be able to decode the design introduction/changes that the Pull Request has and should be in a position to judge and give appropriate feedback. This is very important. </span></li>
<li><span style="font-family: cousine; font-size: 17.6px; line-height: 24.64px;"><b>UI Review:</b> Although software developers look at just the code and give feedback (because that is all they can be seeing in a Pull Request or a diff), they often neglect how the end product would look in a browser or the device where the code was intended to. It is extremely difficult to guess on how it will look. I recommend everyone to go the extra mile of looking how it looks and whether it relates to the original functionality. This is going to take some extra time. In my experience, this has insane returns in terms of identity and squashing obvious UI related issues. </span></li>
<li><span style="font-family: cousine; font-size: 17.6px; line-height: 24.64px;"><b>Non-Logical Checklist:</b> Code Review does not only involve in vetting the Logical Integrity but also some non-logical things like Naming convention, Spacing/Indentation, Object oriented compliance checks. Ensure that there is such a checklist in the first place.</span></li>
<li><span style="font-family: cousine; font-size: 17.6px; line-height: 24.64px;"><b>Keeping a pulse on the industry:</b> This is true not only in this context but also on the overall wholeness of a Programmer. You should be up to date on what is going on in the Programming world, at least in the particular language you are part of. Knowledge of things like critical security patches, feature additions, language enhancements, performance improvements proves to be really powerful in assisting an effective review process.</span></li>
<li><span style="font-family: cousine; font-size: 17.6px; line-height: 24.64px;"><b>Encourage feedback:</b> One does not always have to agree with what is said in the Review. If there are some contradictions - it is best they are addressed between the Reviewer and the Reviewed (or Reviewee). I also encourage that all the review comments are responded to. This process gives confidence to the entire team that any review comment will not go unanswered. </span></li>
<li><span style="font-family: cousine; font-size: 17.6px; line-height: 24.64px;"><b>Avoid Oral Reviews:</b> When a patch or pull requested gets created that too for teams and developers co-located or sitting next to each other, it is tempting to just go through it and give all the feedback orally. This may be fine if the team is small (only 2) and they fully own the codebase. However, this has some negative effects in terms of follow up and broadcasting. What I mean by broadcast is that there could be a review comment which could be applicable for the entire team.</span></li>
<li><span style="font-family: cousine; font-size: 17.6px; line-height: 24.64px;"><b>Learn from other reviews:</b> Encourage to team members to not just read your own reviews and apply however to read the other reviews within the team. I've heard this famous quote - 'An intelligent person learns from their own mistakes, but a genius learns from the mistakes of others'. Let's make everyone in the team a Genius! </span></li>
<li><span style="font-family: cousine; font-size: 17.6px; line-height: 24.64px;"><b>Dual Reviews:</b> Similar to a Doubly refined sugar or Oil, the throughput and Quality of the code review could improve if it has a Second reviewer if that's possible.</span></li>
<li><span style="font-family: cousine; font-size: 17.6px; line-height: 24.64px;"><b>Review the Reviewer:</b> It is a bit over-zealous to expect anyone coming new to the team who is relatively younger to the software development or who has not involved in Review process in the past to quickly catch up to all the nuances in the code review process. It would be nice if these guidelines are slowly implemented and mentoring/onboarding is in the organisation's culture. In simple terms, there could be a reviewer who can review whether reviewer complies to all the best practices out there.</span></li>
<li><span style="font-family: cousine; font-size: 17.6px; line-height: 24.64px;"><b>Over Engineering:</b> At times it is tempting for Reviewers to comment on things that may look like Over Engineering work. These cases it is okay to voice your opinion to the reviewer.</span></li>
<li><span style="font-family: cousine; font-size: 17.6px; line-height: 24.64px;"><b>Enterprise Adherence:</b> An Enterprise will have an adherence in different horizontals in terms on what tools they need to use, what style guide they need to follow, what frameworks has been used across different projects. It is up to the Enterprise Architect or the Senior Member of the team to proactively absorb all these facts and ensure that the entire review process is in Adherence with the overall Enterprise. This is crucial because each Atomic commit may slowly introduce things that could stray away from what the Enterprise would want. It may not look like a problem at all in the initial phase. However, should there be a consolidation happen across various projects - having multiple stacked apps across the enterprise would result in painful Refactors and often ends up leaving a huge amount of technical debt behind.</span></li>
<li><span style="font-family: cousine; font-size: 17.6px; line-height: 24.64px;"><b>Dependency Injection:</b> Be wary of addition or removal of a new Library to the code. This again falls under the adherence of standards across the projects. Make sure that any introduction of a new library is well evaluated across the team and that it has enough support both in the near and long run. I have seen a lot of libraries which were started by individual contributors go unmaintained for years. Ensure that there is a strong community following and is very active.</span></li>
<li><span style="font-family: cousine; font-size: 17.6px; line-height: 24.64px;"><b>Against the Right branch:</b> This may seem like something that may not belong here but in my personal experience I've faced this issue multiple times where a Reviewed creates a pull request against a different (or default) branch instead of the one that it actually has to go.</span></li>
<li><span style="font-family: cousine; font-size: 17.6px; line-height: 24.64px;"><b>Tech Debt Identification:</b> During the course of the review, the reviewer may stumble upon an issue which involves a good amount of effort. In such cases, it is not advised to block it and hamper the delivery commitments. Instead, the right thing to do here is to add these things to a technical debt backlog where it could be groomed and picked up in future.</span></li>
<li><span style="font-family: cousine; font-size: 17.6px; line-height: 24.64px;"><b>Copy Paste excuses:</b> "I did not do this - it was already there - I just copied/moved it" - Yes this is a very common statement every developer says when his code is challenged - however ensure that any code that is touched has to comply to the coding standards set by the team.</span></li>
<li><span style="font-family: cousine; font-size: 17.6px; line-height: 24.64px;"><b>Make Guidelines explicit:</b> It is a very good process for all the developers on-boarding to a new team to have a set of guidelines (you could use this) explicit and review it from time to time. This could be done across the organisation.</span></li>
</ol>
<br />
<span style="font-family: cousine;"><span style="font-size: 17.6px; line-height: 24.64px;">The above list may look overwhelming. However, if you have the knack and right drive to implement some or all of these - the productivity of the Engineering team would increase by multi-folds.</span></span><br />
<span style="font-family: cousine;"><span style="font-size: 17.6px; line-height: 24.64px;"><br /></span></span>
<span style="font-family: cousine;"><span style="font-size: 17.6px; line-height: 24.64px;">Cheers!</span></span><br />
<span style="font-family: cousine;"><span style="font-size: 17.6px; line-height: 24.64px;">Braga</span></span></div>
bragadeeshhttp://www.blogger.com/profile/05516264230057880613noreply@blogger.com0tag:blogger.com,1999:blog-6294663875929591018.post-66476128827489047082016-06-08T16:45:00.000-07:002016-08-22T11:56:51.893-07:00Jenkins bump from 1.x to 2.x<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzQIKgBrVmrxm512AZm8VID3xZtJvOZPhofXd1YJRMFfaap-C1PHaoCaJi1r3W8ALTKWA8EhnW-QGrWPm8-tnL7e9M1K_sv2pCTG00Jf_uM3lp5Igb5provqHbzxHIwxbTvmtqUeI_65w/s1600/jenkins-logo.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="102" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzQIKgBrVmrxm512AZm8VID3xZtJvOZPhofXd1YJRMFfaap-C1PHaoCaJi1r3W8ALTKWA8EhnW-QGrWPm8-tnL7e9M1K_sv2pCTG00Jf_uM3lp5Igb5provqHbzxHIwxbTvmtqUeI_65w/s320/jenkins-logo.png" width="320" /></a>Jenkins is one of the amazing open source softwares especially after it forked itself from its predecessor Hudson. Amazing for multiple reasons - but the one that has really "amazed" me is the painless upgrades it provide. Trust me, I am a Rails developer and I know in & out on what a nightmare it is to perform an upgrade!<br />
<br />
Recently I had to perform an upgrade for Jenkins and it was as dead simple as replacing a .war file and I was err.... DONE! All I did was stopped and started the process whilst replacing the war file. Once I rebooted, it all just worked. They seriously think about making their installations to run the latest software which I personally consider a true value.<br />
<br />
Anyways, the reason me posting this is to help my fellow developers who are running into an issue where their slave would not start up after the upgrade process.<br />
<br />
You would face an error something like this below when you go and inspect in the slave agent.<br />
<br /></div>
<script src="https://gist.github.com/bragboy/a31477f924321bd78439e2028b26346d.js"></script>
What this error means is that it could not invoke the slave because of an outdated java running in the slave. All you've got to do is upgrade it and you should be all good to go.<br />
<br />
<script src="https://gist.github.com/bragboy/65e7b66b1492250f75dc77d2eb6b0f6f.js"></script>
This was how the overall upgrade felt like :)<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrQW0Ju7qWzxWKnk4FS8HHge7R9IrOSt0PB3YrgYj-Sg-Qvr5JQluKmITKZAVCg2S3SYX92A8tVHVcYQutVxIXDkFshAYoPjdn-L-ff3TwxN9mGK9AdD0Qrb3WJTQrKC51lhRnTVV6jt8/s1600/jenkins.jpeg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="181" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrQW0Ju7qWzxWKnk4FS8HHge7R9IrOSt0PB3YrgYj-Sg-Qvr5JQluKmITKZAVCg2S3SYX92A8tVHVcYQutVxIXDkFshAYoPjdn-L-ff3TwxN9mGK9AdD0Qrb3WJTQrKC51lhRnTVV6jt8/s320/jenkins.jpeg" width="320" /></a></div>
<br />
<br />
Cheers!<br />
Braga</div>
bragadeeshhttp://www.blogger.com/profile/05516264230057880613noreply@blogger.com0tag:blogger.com,1999:blog-6294663875929591018.post-80497325564022863762016-05-31T00:26:00.000-07:002016-06-01T22:11:02.865-07:00Responsive Email design with Rails<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGAqTpAXRzQAA8C8u6JbwJifZyvov9PxJz7pXaKUaeO2vmo7n-artshbuxOGcC68yEHbie7ft12VBiT-Y27SCOPS4jLASmj0CvhKsgt5eVZrjjNvdEdrHUYPL3I_hpSUyc__lcrk2Rg4U/s1600/responsive_email_templates_20copy.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="154" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGAqTpAXRzQAA8C8u6JbwJifZyvov9PxJz7pXaKUaeO2vmo7n-artshbuxOGcC68yEHbie7ft12VBiT-Y27SCOPS4jLASmj0CvhKsgt5eVZrjjNvdEdrHUYPL3I_hpSUyc__lcrk2Rg4U/s320/responsive_email_templates_20copy.jpg" width="320" /></a></div>
It is almost imperative in the recent times, the emails we send out are expected to be responsive with a heavy number of users preferring to read or more like skim through emails from their smartphones. To find the ideal sweet spot that aids in not only developing fully responsive emails, but also to do it quickly and easily is vital. There are lot of factors should be taken into account both from a business perspective and from a developer standpoint. I am listing them here (in no particular order)<br />
<br />
<ol style="text-align: left;">
<li>Responsive design - works consistent across all the devices from mobile layout to the most stringent Outlook Email client.</li>
<li>The UI should be consistent with ways to freeze the Headers, Footers and should follow a proper template similar to Rails Action View Layouts.</li>
<li>Should be able to easily testable in developer mode with support for Plain text view besides supporting HTML View.</li>
<li>Avoiding hardcoding of styles in each and every HTML tag. Hardcoding styles in the email has been the norm in Rails community and other web frameworks as well for a very long time.</li>
<li>Should be easily testable in all types of browsers. Even a minor modification/tweak should be tested quickly instead of painfully sending emails again and again.</li>
</ol>
<div>
The following may seem a shorter list, but believe me - to quench all the above criterions I had to go through a lot of different phases with varied learning curves. To attack all the above problems - I would suggest the following tools and libraries to make our lives super simple.</div>
<div>
<br /></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDdLvIIezn0UZy8u8s6qg55ZOHYEuzbH1pJEVVr3CxdudNVPzUqAYTIPWmhnrTM1cEbPBP0kEaIMTB-EFcUZFFl5RupPG13ujkZgQg1x_C0AJ2Aw3QKia3uy_z3TE0ES7Mmac2PXGrdqU/s1600/zurb+ink.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em; text-align: center;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDdLvIIezn0UZy8u8s6qg55ZOHYEuzbH1pJEVVr3CxdudNVPzUqAYTIPWmhnrTM1cEbPBP0kEaIMTB-EFcUZFFl5RupPG13ujkZgQg1x_C0AJ2Aw3QKia3uy_z3TE0ES7Mmac2PXGrdqU/s200/zurb+ink.jpg" width="200" /></a></div>
<ol style="text-align: left;">
<li>Zurb's "<a href="http://foundation.zurb.com/emails.html">Foundation for emails</a>" (previously called Ink) that provides with ready-made available templates to kick start and later customise on top of it to our heart's content.</li>
<li><a href="https://github.com/fphilipe/premailer-rails">Premailer-Rails</a> - A wonderful Rails pre-processor that makes the email design entirely stylesheet driven as opposed to hardcoding styles directly in the tag. Not only does it removes the pain of having hardcoded styles, it also provides a packages view to render the Plain text automagically - with 0 amount of code required from the developer.</li>
<li><a href="https://github.com/ryanb/letter_opener">Letter Opener</a> - A classical tool by Ryan to quickly preview the emails in development mode.</li>
<li><a href="https://litmus.com/">Litmus</a> - If you are into Responsvie email design, you have no reason not to subscribe to Litmus as they provide a comprehensive way to template, design and test your email in in-numerous email clients.</li>
</ol>
<div>
That is it! Combine these tools and with a slight learning curve, you can claim yourself as a fully responsive e-mail designer.</div>
</div>
<div>
<br /></div>
<div>
Cheers!</div>
<div>
Braga</div>
<br />
<br /></div>
bragadeeshhttp://www.blogger.com/profile/05516264230057880613noreply@blogger.com0tag:blogger.com,1999:blog-6294663875929591018.post-36357158644348285432016-01-22T13:19:00.002-08:002016-01-22T13:19:57.661-08:00Streaming vs Synchronus Replication in Postgres<div dir="ltr" style="text-align: left;" trbidi="on">
I recently faced one strange issue in Rails which usually questioned some of the basic Relation Database principles. It gave me almost a sleepless night until I was able to get to the Root cause of the issue.<br />
<br />
<u>The problem</u><br />
<br />
The problem was pretty straightforward. A Rake task generates an email and the email had two places where the count of documents was mentioned. Ideally they are supposed to be the same - but for some reason it was different.<br />
<br />
<u>The pain point</u><br />
<br />
The reason this particular problem was painful because this has not occurred for few years and that it occurred only intermittently. The problem with intermittency is that there is always some theory behind. Here too there was something. Here are steps I had to perform to find the Root cause.<br />
<br />
<u>The approach</u><br />
<br />
I first looked into the Rake task's log file which is outputted when my specific Email job runs. Things looked fine there - meaning it completed in under 90 seconds as expected.<br />
The next step was to look at the production logs. The logs as expected was having 30 insert statements - Check. And it also has a read statement for the insert statements before and it was a typical count(*) query. The problem occurred at this point. The count(*) should have returned 30 but instead it returned 4. There comes another count(*) somewhere below in the code - but that returned 30 as expected!<br />
<br />
The above step revealed that this problem is not with the Rails layer but something to do with our production database setup. So routed my energy towards there.<br />
The production database environment is a Master-Slave configuration with Master taking Writes and Reads and Slave purely configured to take Reads. Both these nodes are load balanced via a PG Pool server. My initial gut said to investigate some time in the PGPool but that is not much useful as all PG Pool going to do is route traffic.<br />
So I went and read about the Master - Slave Replication configuration. I read about two types of replication. One being synchronous replication and the other being Streaming Replication. Digging into that I found my root cause!<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRYvlpPpZLNiMsRsyNzCwgSZCrmqRTLNA2JQiN6rITHFxdxNiLEOZErRRmGOgNCFlO1LbEchyphenhyphen0kEI1JPw7oy_9UwJn3Ym96u2xlDf0niZLRwKTIl_hVpv6hXKWr_bok31H44vw4sl3dMY/s1600/postgres_database_replication.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRYvlpPpZLNiMsRsyNzCwgSZCrmqRTLNA2JQiN6rITHFxdxNiLEOZErRRmGOgNCFlO1LbEchyphenhyphen0kEI1JPw7oy_9UwJn3Ym96u2xlDf0niZLRwKTIl_hVpv6hXKWr_bok31H44vw4sl3dMY/s1600/postgres_database_replication.jpg" /></a></div>
<br />
<u>Synchronous vs Streaming Replication</u><br />
<br />
Assume you have two databases A and B with A being a R/W Master and B being R-only Slave. If an insert or update command is issued, it goes and writes that entry to A as its configured for write. If the database returns after it ensures that all the slaves got this write - it is called as Synchronus or 2-Safe Replication. If A does not wait for this step however acknowledge whether it wrote successfully and later streams that value to B - this is called as Streaming Replication.<br />
<br />
Both has their obvious own pros and cons. Streaming Replication is for Raw Speed and is also a very good configuration where there are too many writes. And Synchronous Replication although not as fast as Streaming provides 100% consistency. We unfortunately were in Streaming Replication mode. The 30 inserts happened so fast at A, that before even it could stream them to B, the count query intervened and read the half baked data from B. I am talking in terms of millisecond speed.<br />
<u><br /></u>
<u>How did we fix it?</u><br />
<br />
We isolated all our cron jobs to run in a dedicated node and pointed the database directly to the Master database server skipping the PG Pool in the process. In a single database configuration the concept of Streaming or Synchronous Replication does not apply. Hope this was helpful!<br />
<br />
Cheers!<br />
Braga</div>
bragadeeshhttp://www.blogger.com/profile/05516264230057880613noreply@blogger.com0tag:blogger.com,1999:blog-6294663875929591018.post-85902267058375080152016-01-07T00:30:00.001-08:002021-06-26T05:35:59.432-07:00Quick way to import a jar in Eclipse<div dir="ltr" style="text-align: left;" trbidi="on">
Following is a quick demonstration to import .jar files via Eclipse IDE<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/u5f_xQ1hw9g" width="560"></iframe></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<h2 style="clear: both;">
See Also: <a href="/2010/04/trie-in-java.html">TRIE ADT Tutorial</a></h2>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
You will need to understand why you are doing this. Any java program, for it to execute, first needs to be compiled without errors. The compilation process (using "javac") is going to convert your source code into bytecode (.class) file which you can then use the "java" executable to run. An IDE like Eclipse will do the compilation automatically in the background. That is why when you have any sort of error in the program (syntax/logical etc.,), you see it getting highlighted immediately. </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
So, when you are referencing an external library, javac executable needs to know which library you are referencing. You can do this by setting the CLASSPATH variable before executing the program if it is via command line. Eclipse makes it easier, instead of specifying the Java library file's location through the command line, you can do it through the editor by Right clicking on the project and selecting Build Path --> Configure Build Path. With the Libraries tab selected, click on "Add External Archives" and give your .jar files. Your program should now compile smoothly without errors.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Using an IDE introduces insane efficiency for designing and development. However, always have an understanding of what is going behind the scenes. Hope you learned something useful today!</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Cheers!</div>
<div class="separator" style="clear: both; text-align: left;">
Braga</div>
<br /></div>
bragadeeshhttp://www.blogger.com/profile/05516264230057880613noreply@blogger.com5tag:blogger.com,1999:blog-6294663875929591018.post-89523883207481393882015-12-31T04:47:00.000-08:002016-02-01T03:25:06.344-08:00Hotel Automation Controller - Interview coding problem<div dir="ltr" style="text-align: left;" trbidi="on">
This is one of the problems I got via a friend who recently faced a company called Sahaj Software a clone company to Thoughtworks.<br />
<br />
Problem Statement:<br />
<br />
<div class="p1" style="text-align: center;">
<span class="s1"><span style="font-family: Courier New, Courier, monospace;">Hotel Automation Controller Problem Statement</span></span></div>
<div class="p2">
<span style="font-family: Courier New, Courier, monospace;"><span class="s1"></span><br /></span></div>
<div class="p3">
<span class="s1"><span style="font-family: Courier New, Courier, monospace;">A very prestigious chain of Hotels is facing a problem managing their electronic equipments. Their equipments, like lights, ACs, etc are currently controlled manually, by the hotel staff, using switches. They want to optimise the usage of Power and also ensure that there is no inconvenience caused to the guests and staff.</span></span></div>
<div class="p4">
<span style="font-family: Courier New, Courier, monospace;"><span class="s1"></span><br /></span></div>
<div class="p5">
<span class="s1"><span style="font-family: Courier New, Courier, monospace;">So the Hotel Management has installed sensors, like Motion Sensors, etc at appropriate places and have approached you to program a Controller which takes inputs from these sensors and controls the various equipments.</span></span></div>
<div class="p4">
<span style="font-family: Courier New, Courier, monospace;"><span class="s1"></span><br /></span></div>
<div class="p6">
<span class="s1"><span style="font-family: Courier New, Courier, monospace;">The way the hotel equipments are organised and the requirements for the Controller is below:</span></span></div>
<ul>
<li class="li7"><span style="font-family: Courier New, Courier, monospace;"><span class="s2"></span><span class="s1">A Hotel can have multiple floors</span></span></li>
<li class="li7"><span style="font-family: Courier New, Courier, monospace;"><span class="s2"></span><span class="s1">Each floor can have multiple main corridors and sub corridors</span></span></li>
<li class="li7"><span style="font-family: Courier New, Courier, monospace;"><span class="s2"></span><span class="s1">Both main corridor and sub corridor have one light each</span></span></li>
<li class="li7"><span style="font-family: Courier New, Courier, monospace;"><span class="s2"></span><span class="s1">Both main and sub corridor lights consume 5 units of power when ON</span></span></li>
<li class="li7"><span style="font-family: Courier New, Courier, monospace;"><span class="s2"></span><span class="s1">Both main and sub corridor have independently controllable ACs</span></span></li>
<li class="li7"><span style="font-family: Courier New, Courier, monospace;"><span class="s2"></span><span class="s1">Both main and sub corridor ACs consume 10 units of power when ON</span></span></li>
<li class="li8"><span style="font-family: Courier New, Courier, monospace;"><span class="s2"></span><span class="s1">All the lights in all the main corridors need to be switched ON between 6PM to 6AM, which is the Night time slot</span></span></li>
<li class="li8"><span style="font-family: Courier New, Courier, monospace;"><span class="s2"></span><span class="s1">When a motion is detected in one of the sub corridors the corresponding lights need to be switched ON between 6PM to 6AM (Night time slot)</span></span></li>
<li class="li8"><span style="font-family: Courier New, Courier, monospace;"><span class="s2"></span><span class="s1">When there is no motion for more than a minute the sub corridor lights should be switched OFF</span></span></li>
<li class="li8"><span style="font-family: Courier New, Courier, monospace;"><span class="s2"></span><span class="s1">The total power consumption of all the ACs and lights combined should not exceed <i>(Number of Main corridors * 15) + (Number of sub corridors * 10) units of </i>per floor. Sub corridor AC could be switched OFF to ensure that the power consumption is not more than the specified maximum value</span></span></li>
<li class="li9"><span style="font-family: Courier New, Courier, monospace;"><span class="s2"></span><span class="s1">When the power consumption goes below the specified maximum value the ACs that were switched OFF previously must be switched ON</span></span></li>
</ul>
<div class="p4">
<span style="font-family: Courier New, Courier, monospace;"><span class="s1"></span><br /></span></div>
<div class="p3">
<span class="s1"><span style="font-family: Courier New, Courier, monospace;">Motion in sub corridors is input to the controller. Controller need to keep track and optimise the power consumption.</span></span></div>
<div class="p4">
<span style="font-family: Courier New, Courier, monospace;"><span class="s1"></span><br /></span></div>
<div class="p10">
<span class="s1"><span style="font-family: Courier New, Courier, monospace;">Write a program that takes input values for Floors, Main corridors, Sub corridors and takes different external inputs for motion in sub corridors and for each input prints out the state of all the lights and ACs in the hotel. For simplicity, assume that the controller is operating at the night time. Sample input and output below.</span></span></div>
<div class="p4">
<span style="font-family: Courier New, Courier, monospace;"><span class="s1"></span><br /></span></div>
<div class="p11">
<span class="s1"><span style="font-family: Courier New, Courier, monospace;">Initial input to the controller: Number of floors: 2</span></span></div>
<div class="p12">
<span class="s1"><span style="font-family: Courier New, Courier, monospace;">Main corridors per floor: 1</span></span></div>
<br />
<div class="p13">
<span class="s1"><span style="font-family: Courier New, Courier, monospace;">Sub corridors per floor: 2</span></span></div>
<div class="p13">
<span class="s1"><span style="font-family: Courier New, Courier, monospace;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg07MpDHD1oWY8DOjxWbOpZfnytkZQS9YBQXE1PKJW0Pdak7LpwMtaGQeEi5oFqVRL-VzCa3fzARm8jWII_BQk-5cGb9ORaGPJKV142aiJNAk7D-49FNF5ifAV1riFRyui-9Qsc1LSyVfo/s1600/pic01.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="291" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg07MpDHD1oWY8DOjxWbOpZfnytkZQS9YBQXE1PKJW0Pdak7LpwMtaGQeEi5oFqVRL-VzCa3fzARm8jWII_BQk-5cGb9ORaGPJKV142aiJNAk7D-49FNF5ifAV1riFRyui-9Qsc1LSyVfo/s400/pic01.png" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJrDBTCxm6EslqsOwQjmD_RcOAYJGgeHJgcFE3UUpyDoieSn5u9taejF_RCP_o4Cg2UjQF3VZXoWmffbFSkbSxw7eJOUMvdl1Oes930hG4PBibqocWjEkJeOm8Fn5pTZorRV0YmSGdavM/s1600/pic02.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="262" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJrDBTCxm6EslqsOwQjmD_RcOAYJGgeHJgcFE3UUpyDoieSn5u9taejF_RCP_o4Cg2UjQF3VZXoWmffbFSkbSxw7eJOUMvdl1Oes930hG4PBibqocWjEkJeOm8Fn5pTZorRV0YmSGdavM/s400/pic02.png" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdSQhWUzqj9EsrrIWUyW_MZDKe0NTPEmKQMFpf9L_mNd0ZSnMdxvnRtLI6q5AZPGDixVh8QvNMej-nv5wJY1K2TK5RdB5Z1Iip4vojTiLV8Hsahyphenhyphen0cRPrFHLcPs44ZOtexwMMciOHsrvE/s1600/pic03.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="258" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdSQhWUzqj9EsrrIWUyW_MZDKe0NTPEmKQMFpf9L_mNd0ZSnMdxvnRtLI6q5AZPGDixVh8QvNMej-nv5wJY1K2TK5RdB5Z1Iip4vojTiLV8Hsahyphenhyphen0cRPrFHLcPs44ZOtexwMMciOHsrvE/s400/pic03.png" width="400" /></a></div>
<div class="p13">
<span class="s1"><span style="font-family: Courier New, Courier, monospace;"><br /></span></span></div>
<div class="p13">
<span class="s1"><span style="font-family: Courier New, Courier, monospace;"><br /></span></span></div>
<div class="p13">
<span class="s1"><span style="font-family: Courier New, Courier, monospace;">Since the hotel management is trying this for the first time, they would be changing the requirements around which electronic equipments are controlled and the criteria based on which they are controlled, so the solution design should be flexible enough to absorb these requirement changes without significant change to the system.</span></span></div>
<br />
The solution to this problem involves approaching in an object oriented manner. Also we need to see here that we should use a Command/Strategy Pattern given there could be changes in the behavior based on external factors. I have not included the timings from the problem but from on here it should be easily extensible. <br />
<br />
Code below:<br />
<br />
<script src="https://gist.github.com/bragboy/1ac30394ad2b93a5e81b.js"></script>
<script src="https://gist.github.com/bragboy/5fc8caaccf4b33a908e6.js"></script>
<script src="https://gist.github.com/bragboy/292449376f8cd1b6d9e5.js"></script>
<script src="https://gist.github.com/bragboy/eb8d7143d10f7d1e4a9a.js"></script>
<script src="https://gist.github.com/bragboy/bc8a7430f3cbf7ea8d5a.js"></script>
<script src="https://gist.github.com/bragboy/bd4fc504c419532c0d0f.js"></script>
<script src="https://gist.github.com/bragboy/2256132c3f2a693014ee.js"></script>
Cheers!<br />
Braga</div>
bragadeeshhttp://www.blogger.com/profile/05516264230057880613noreply@blogger.com0tag:blogger.com,1999:blog-6294663875929591018.post-51707270482562536642015-11-21T07:19:00.000-08:002016-01-22T13:23:00.495-08:00Cloning remote PG database and loading in Local environment<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitvsgr11X6_An6sLlaATBVVRTS9s0ViuPi7FsNQsCw889zS9dNDBDdgFxoCb7DAaLFVi9JQrp1-nLWkeBZd4GByOq_msjcVFrtRYGVmxZJAOZOQPk7q9jwlFc1n4pvQmUMvUI6Q6uUo28/s1600/clone_remote_Database.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitvsgr11X6_An6sLlaATBVVRTS9s0ViuPi7FsNQsCw889zS9dNDBDdgFxoCb7DAaLFVi9JQrp1-nLWkeBZd4GByOq_msjcVFrtRYGVmxZJAOZOQPk7q9jwlFc1n4pvQmUMvUI6Q6uUo28/s200/clone_remote_Database.png" width="165" /></a>For projects involving small to medium sized databases one may require to copy the remote (or production) database onto local environment. I was earlier doing this for my production application using custom pg_dump and then restoring with pg_restore. It was relatively straightforward but still consumed good amount of time. I wanted to automate this using capistrano and this is how I did it<br />
<br />
<script src="https://gist.github.com/bragboy/2b7a4eff9d22da08b88e.js"></script>
You should note that this is extremely fast because it executes the command on the VPS - usually EC2 which has amazing internet speeds. And then copies it over scp as a single file. You can also add a compression step using the --format option in the pg_dump.<br />
<br />
Hope this was helpful!<br />
<br />
Cheers!<br />
Braga</div>
bragadeeshhttp://www.blogger.com/profile/05516264230057880613noreply@blogger.com0tag:blogger.com,1999:blog-6294663875929591018.post-29341583876524948732015-11-03T07:39:00.002-08:002016-01-27T01:49:17.809-08:00Stand still - and you are going backwards! <div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinMOKfOq787tp_lwQgWK5-bjvBBFjBNnc5jQNO_d1rFFssEEdBFUbG3mqQpTNNQZPUkpRXaWNQ0SiatJ98lb9A6HSZMwuCfBvSwh1VsOUNBT1gar5SrAbFOPcQXUEb9mExczaAi46Qgi0/s1600/escalator.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="133" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinMOKfOq787tp_lwQgWK5-bjvBBFjBNnc5jQNO_d1rFFssEEdBFUbG3mqQpTNNQZPUkpRXaWNQ0SiatJ98lb9A6HSZMwuCfBvSwh1VsOUNBT1gar5SrAbFOPcQXUEb9mExczaAi46Qgi0/s400/escalator.png" width="400" /></a>Imagine you are standing on a moving escalator that is supposed to take you from a Ground level to the Top level - only that its moving in the opposite direction. If you stand still on such an escalator you will hit the bottom soon. In order to not hit the bottom - you need to "at least" walk at the -ve speed of the elevator. For an observer it would still be standing still but thats the least one could do especially being in the software industry.<br />
<br />
My blog once had crossed a million page views and the most active time I was during 2010. I think looking back - that was the time I had cracked any problems thrown at me. And I enjoyed it. I still could crack em only that I realise recently I've become rusty. However, I developed a variety of different skills down the road.<br />
<br />
Alright I think I am diverging too much from what I wanted to say. In the IT world, one needs to constantly keep learning, keep pushing the limits, get hands dirty on a variety of technologies. If you are a manual tester - try poking at Automation testing. If you are an Automation Engineer - learn about performance/scalability testing. If you are an application developer - explore system development. If you are a software architect - see what is going on in that particular space and try to remain on top. That is the only way you could make sure that you are always on the 99th percentile in this industry.<br />
<br />
One has to realise doing the mundane and similar work won't scale as we have already headed and running in the First order differentiation of time (speed). Second order differentiation (acceleration) will make us even more redundant. Can't imagine what we differentiated even one more step. The only way to sustain such challenging epochs is to learn. Learn learn learn!<br />
<br />
Cheers!<br />
Braga</div>
bragadeeshhttp://www.blogger.com/profile/05516264230057880613noreply@blogger.com0tag:blogger.com,1999:blog-6294663875929591018.post-31632682106701524212015-11-03T07:02:00.000-08:002016-01-27T01:49:42.002-08:00Printing the permutation of characters from a classical mobile phone<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSurhV58ucv5kI-imBSsAp1lYMZNVeB8hPaYdlk8fdgyWPmeBAvFu12weQ8xkcCryWbz8mtZyUFh4pt2JtGuHHQPuqz0B9vXNm3UHvszGYz_DCQLFjD-Y2I7B8Rt5LOqO6jGa8ppLuQz8/s1600/keypad.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="298" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSurhV58ucv5kI-imBSsAp1lYMZNVeB8hPaYdlk8fdgyWPmeBAvFu12weQ8xkcCryWbz8mtZyUFh4pt2JtGuHHQPuqz0B9vXNm3UHvszGYz_DCQLFjD-Y2I7B8Rt5LOqO6jGa8ppLuQz8/s320/keypad.png" width="320" /></a>One of the problems I recently faced.<br />
<br />
Input: A set of numbers from a mobile keypad<br />
Output: Print all the combinations of characters for that given number.<br />
<br />
For example if the input is 26. Then possible outputs are am, an, ao, bm, bn, bo, cm, cn, co<br />
<br />
Solution:<br />
<br />
There are many ways to solve this problem. One is using a tree. Another way is to simply do it with recursion. I solved this using a linear approach. If you convert the problem from the text domain to number domain - it will seem very simple.<br />
<br />
For example - if the input is something like ['abc', 'def', 'pqrs'] (transformed from digits 237). Then the output would have a simple rule - the first character should come from the first element, second from the second and so on. Writing in an incremental number form for the indexes, you would get:<br />
<br />
0 0 0<br />
0 0 1<br />
0 0 2<br />
0 0 3<br />
0 1 0<br />
0 1 1<br />
0 1 2<br />
....<br />
2 2 3<br />
<br />
That's it - problem solved. Programatically expressed it here<br />
<br />
<script src="https://gist.github.com/bragboy/70f420d91cebffba95b7.js"></script>
</div>
bragadeeshhttp://www.blogger.com/profile/05516264230057880613noreply@blogger.com0tag:blogger.com,1999:blog-6294663875929591018.post-34097039653880659272015-08-17T07:31:00.000-07:002016-02-02T03:31:46.900-08:00VIM Cheatsheet<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
A one page printable cheat sheet for VIM in PDF Format. Direct URL: <a href="https://goo.gl/Yu2rpG">https://goo.gl/Yu2rpG</a><br />
<br />
<br /></div>
<iframe height="650" src="https://drive.google.com/file/d/0Bxy0wRAvwW1BY2ZIX2VOWlNuWDg/preview" width="100%"></iframe><br />
<br />
Source and credits to RICHARD TORRUELLAS : <a href="http://vim.rtorr.com/">http://vim.rtorr.com/</a><br />
<br />
Cheers!<br />
Braga</div>
bragadeeshhttp://www.blogger.com/profile/05516264230057880613noreply@blogger.com0tag:blogger.com,1999:blog-6294663875929591018.post-30748242554136963032015-08-08T12:55:00.000-07:002015-08-08T13:11:25.615-07:00Ransack namespace collision - The search method<div dir="ltr" style="text-align: left;" trbidi="on">
I am a big fan of <a href="https://github.com/activerecord-hackery/ransack">Ransack</a>, the Rails gem for quickly building a quick and easy Search based on pure ActiveRecord queries. For projects that require some on the fly search without having to set up dedicated Search Engines like Elastic Search, SOLR, ThinkinSphinx - this is a very juicy alternative.<br />
<br />
However I recently faced one problem when I introduced this to a project where there already was SOLR integrated. It was because of the collision of the <i>search</i> method.<br />
<br />
This simply patch did the job for me. All you have to do is include it to your initializers folder say under <i>config/initializers/ransack.rb</i><br />
<i><br /></i>
<script src="https://gist.github.com/bragboy/88786215f1ec789132a9.js"></script>
That's it, the Ransack library will no longer collide with your existing suite. As a matter of fact the method <i>search </i>deprecated already and the library itself wants us to use the Alias <i>ransack</i><br />
<i><br /></i>
Cheers!<br />
Braga</div>
bragadeeshhttp://www.blogger.com/profile/05516264230057880613noreply@blogger.com0tag:blogger.com,1999:blog-6294663875929591018.post-92123847031267645902015-06-02T10:01:00.002-07:002017-10-20T00:54:24.480-07:00Good bye Heroku !<div dir="ltr" style="text-align: left;" trbidi="on">
I primarily work on Ruby on Rails and I use to deploy one of my pet projects to Production entirely on the Heroku's free tier. It was a wonderful two years to see having my application running there during which time I had around a thumping 10 Million page views! Heroku's free tier is one of the most used around the world for quickly showcasing development applications. However, my Production application was such that all my needs felt well under Heroku's free tier.<br />
<br />
Here are some of the freebies I use to enjoy<br />
<ul style="text-align: left;">
<li>Free Dedicated (techincally not) machine with 512 MB - The reason its technically not because you are allotted a free worker that would go to sleep if the application is not up for 30 minutes. However you could easily overcome this with something like Pingdom.</li>
<li>Free Postgres Database - Although there was no specific size limit to this other than a maximum number of 5000 rows, I would still say this is one of the best things Heroku offers. Not only your application can talk to it, anything anywhere from the world can talk to the database directly. And that too 100% free!</li>
<li>Free emails via Sendgrid - A maximum 200 emails per day! Sendgrid's free Addon allows me send upto 200 emails per day. My application's requirement was in the range 20-40.</li>
<li>Unlimited Job Schedulers - Although they would take one entire and the only worker allotted to you to spin, this is a boon considering you do not have a full fledged linux machine with you. I use to have only one rake task that takes a routine back up of my data as CSV and email it to me.</li>
<li>Free PG Backup - Again, if you want to routinely backup your data, you don't have to write any complex code. Heroku provides this out of the box and for free!</li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtCcfia07rd88LUzs1FBtfTpmNGsnq6-hCDkhAspLIwTeihcUwA3TCwB7H9NzS4U_M5up8MN7_ndX54UBNQ6VeHW34_cLNDtvAm3eunLoc68aWlcotugAVZLV6zHCNB1fF0pn84Oukd-o/s1600/Screen+Shot+2015-06-02+at+10.33.52+pm.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="176" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtCcfia07rd88LUzs1FBtfTpmNGsnq6-hCDkhAspLIwTeihcUwA3TCwB7H9NzS4U_M5up8MN7_ndX54UBNQ6VeHW34_cLNDtvAm3eunLoc68aWlcotugAVZLV6zHCNB1fF0pn84Oukd-o/s640/Screen+Shot+2015-06-02+at+10.33.52+pm.png" width="640" /></a></div>
<br />
Now that Heroku is pulling down the curtain on the 24 hour availability or to pay $7 a month, I have no other option to switch to a much better alternative - that is Digital Ocean. Sign up here for a free $10 credit - <a href="https://m.do.co/c/21693a3f9c9e">https://m.do.co/c/21693a3f9c9e</a><br />
<br />
Sad to depart ways, but you made me learn a lot of stuff in these two + years.<br />
<br />
Cheers!<br />
Braga</div>
bragadeeshhttp://www.blogger.com/profile/05516264230057880613noreply@blogger.com0tag:blogger.com,1999:blog-6294663875929591018.post-74463016297971861422013-11-27T06:24:00.001-08:002015-06-02T10:14:38.174-07:00My first ruby gem horoscope is live<div dir="ltr" style="text-align: left;" trbidi="on">
I wanted to write a rubygem on my own for a long time. Never had the time really to write one. However, recently I had some spare time during which I wrote this gem called <a href="https://rubygems.org/gems/horoscope">horoscope</a>. This gem will help drafting the horoscope of a person given the birth date, time and the place. Source is hosted at <a href="https://github.com/bragboy/horoscope">Github</a>. As with every other open source project out there, feel free to fork it and add more to your liking<br />
<br />
<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/AVvXsEhJwutAyHpqITK1xeUgPPol3I75dAoxvXbqCz6KErvrlaJxOBmUYUa8Bl7pUiTkYPx0lhCQqpcvq1jRBXkDS9rVIzny1d6ZeBZd5C-bBrTxUkK3xtvY12NxeZsxLnwSP6NWLz0IHvQktiI/s1600/Screenshot.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="392" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJwutAyHpqITK1xeUgPPol3I75dAoxvXbqCz6KErvrlaJxOBmUYUa8Bl7pUiTkYPx0lhCQqpcvq1jRBXkDS9rVIzny1d6ZeBZd5C-bBrTxUkK3xtvY12NxeZsxLnwSP6NWLz0IHvQktiI/s400/Screenshot.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Screenshot at Github</td></tr>
</tbody></table>
<br />
<br />
Proud to release this and I am planning to add more features to this. Also, planning to release different gems. If you want something particular or specific, don't be shy, add it in the comments section and I would be more than happy to contribute!<br />
<br />
Cheers!<br />
Bragboy</div>
bragadeeshhttp://www.blogger.com/profile/05516264230057880613noreply@blogger.com0tag:blogger.com,1999:blog-6294663875929591018.post-45639173331434819472013-11-18T17:55:00.000-08:002015-11-12T03:23:39.136-08:00Tree Traversal in C++<div dir="ltr" style="text-align: left;" trbidi="on">
We've already seen many implementations of tree and its uses in java. Lets look at a simple implementation of traversing on a tree in C++. Code has been given below which I think is quite self descriptive.
<br />
<script src="https://gist.github.com/bragboy/b5f3c307431d0ddf216e.js"></script>
<br />
Regards,<br />
Jack
<div>
<br /></div>
<div>
<br /></div>
</div>Prabhu Jayaramanhttp://www.blogger.com/profile/11266928407768534504noreply@blogger.com0tag:blogger.com,1999:blog-6294663875929591018.post-66816603632813100282013-11-18T17:47:00.003-08:002015-08-08T13:44:51.931-07:00Write a program to find the number corresponding to a alphabet and vice-versa with the given rule<div dir="ltr" style="text-align: left;" trbidi="on">
<u>Problem:</u><br />
A = 1<br />
B = A*2 + 2<br />
C = B*2 + 3...<br />
1. Write a program to find the number corresponding to a alphabet and vice-versa.<br />
2. Given a series like GREP find the total in numbers. Given a number like 283883, find the shortest alphabetical series corresponding to it.<br />
Compute above recursively when required and do not pre-compute and store beforehand.<br />
<br />
<u>Solution:</u><br />
The solution is straightest-forward. Java code given below.<br />
<br />
<script src="https://gist.github.com/bragboy/817015a4f36c5179f868.js"></script>
Cheers!<br />
Braga</div>
BragBoyhttp://www.blogger.com/profile/01173019524783723568noreply@blogger.com0tag:blogger.com,1999:blog-6294663875929591018.post-21888044316054048252013-11-18T17:43:00.001-08:002015-08-08T13:47:07.419-07:00Write a program to build a small knowledge base about top "N" movies listed at IMDB<div dir="ltr" style="text-align: left;" trbidi="on">
This was an interesting problem that I came across with. This problem is like an open book exam and race against time. The problem had to be solved within an allocated amount of time with a technology stack that is limited only to Ruby/Python/Node.js/Perl.<br />
<br />
Few googling here and there and with some knowledge about Ruby I was able to solve this problem within an hour.<br />
<br />
<u>Problem Statement:</u><br />
<br />
Build a small knowledge base about top "N" movies listed at http://www.imdb.com/chart/top. Each movie should mention the cast written on the individual page of the movie.<br />
Given the name of a cast member, you should be able to return the movies out of the top "N" movies he/she has acted in. "N" will be passed by the user.<br />
The knowledge base should be built during the runtime and stored in a data structure of your choice.<br />
Q1. For example, if N=3, then you should parse the first 3 movies' individual pages from that page (http://www.imdb.com/chart/top) and build the knowledge base of the cast (there are about 15-20 on every page). Upon querying for "Morgan Freeman", you should return "The Shawshank Redemption". Do not use any external api for this.<br />
Use only Ruby/Python/Node.js/Perl.<br />
<br />
<u>Solution:</u><br />
<u><br /></u>
<u><br /></u>
<script src="https://gist.github.com/bragboy/a4386732bc24bc46e6c0.js"></script>
Cheers!
<br />
Braga</div>
BragBoyhttp://www.blogger.com/profile/01173019524783723568noreply@blogger.com0tag:blogger.com,1999:blog-6294663875929591018.post-18464315167135724852012-12-14T22:12:00.000-08:002015-08-08T13:50:20.159-07:00Novel finder Program<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
This was one of the problems that I had faced during one of my interviews. The problem sounded interesting and I was given 1 hour to solve it which I did quite comfortably.<br />
<br />
<b><u><span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">Problem</span></u></b><b><span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">:</span></b><br />
<br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">The <i>K-doublets</i>
of a string of characters are the ordered pairs of characters that are K
distance from each other. A string is <i>K-singular</i>
if all its <i>K- doublets</i> are different.
A string is <i>Novel String</i> if it is <i>K-singular</i> for all possible K distances.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">For e.g. take the string <b>FLBL</b>, its <i>0-doublets</i> are <b>FL</b>, <b>LB</b> and <b>BL</b>. Since all these are different, <b>FLBL</b> is <i>0-singular</i>.
Similarly, its <i>1-doublets</i> are <b>FB</b> and <b>LL</b>, since they are different <b>FLBL</b>
is <i>1-singular</i> as well. Lastly, the
only <b>2-doublet</b> of <b>FLBL</b> is <b>FL</b>, so <b>FLBL</b> is <i>2-singular</i>. Hence, <b>FLBL</b> is a Novel String.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">Note that the fact that FL is both a
0-doublet and 2-doublet is insignificant as zero and two are different
distances.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><u><span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">Input</span></u></b><b><span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">:<o:p></o:p></span></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">The input is one or more non-empty strings
of at most 100 capital letters, each string on a line by itself, followed by a
line containing only two dollars ($$) signaling the end of the input.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><u><span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">Output</span></u></b><b><span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">:<o:p></o:p></span></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">For each input line, output whether or not
it is a Novel string using the exact output format shown below.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><u><span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">Sample
Input</span></u></b><b><span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">:
</span></b><span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">(Input File: <b>novel.in</b>)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">FLBL<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">FFLL<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">ORDINARY<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">R<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">QYQRQYY<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">$$<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><u><span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">Sample
Output</span></u></b><b><span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">:
</span></b><span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">(Output File: <b>novel.out</b>)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">FLBL is a Novel string<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">FFLL is not a Novel string<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">ORDINARY is a Novel string<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">R is a Novel string<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;">QYQRQYY is not a Novel string<o:p></o:p></span><br />
<span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt; mso-bidi-font-size: 13.0pt;"><br /></span></div>
</div>
<b><u><span style="font-family: "Verdana","sans-serif"; font-size: 11pt;">Solution:</span></u></b><br />
<b><u><span style="font-family: "Verdana","sans-serif"; font-size: 11pt;"><br /></span></u></b>
<span style="font-family: Verdana, sans-serif; font-size: 15px;">To attack this problem, you first have to find all the doublets for each distance starting from 0 to the maximum distance which would string's length minus one. Then keep pushing them into a hash set. Whenever the add() method of the Set returns false, it means we are adding a duplicate hence, its not a Novel text. Here is the Java source code.</span><br />
<br />
<script src="https://gist.github.com/bragboy/86034fd6b667e56afd53.js"></script>
<br />
Cheers!<br />
Braga</div>
BragBoyhttp://www.blogger.com/profile/01173019524783723568noreply@blogger.com0tag:blogger.com,1999:blog-6294663875929591018.post-43187839813473835772012-07-27T13:06:00.001-07:002012-07-27T13:06:18.569-07:00Windows Phone 7.5 - Home button Navigation and Exit Confirmation<div dir="ltr" style="text-align: left;" trbidi="on"><div dir="ltr" style="text-align: left;" trbidi="on">While developing a windows phone application, the one which involves navigation to various pages starting from something called as a homepage would quickly become annoying. You will find yourself in deeper pages and as a means on coming back to the home page, you will keep pressing the back button so many times it will exit you out of the application.<br />
<br />
There are couple of problems associated with this. The user is forced to keep in mind how deep he has in the navigation page. The other main problem is he will not have patience to wait to go to the home page and pressing the back button on the first page will obviously throw you. This is because the navigation details are stored in a stack.<br />
<br />
It is always nice to provide a home button to the end user on all the pages so that on click of them will take it to the home. Also, you can always have a confirmation dialogue fired while exiting the application. First problem first.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9b7hxnVS5yYfMJtDPDifFD8N45eGykUWjkocHcbqn5uKv1rCgmoDAu9fzge7FxDk5yqtuJhIdzrNq_ZbUFLYTiONXB5czxnqOYNpxkXwyfFfIxCNiUr_t9gjcgX7gONq0H58Fmu3hzig/s1600/homebutton.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9b7hxnVS5yYfMJtDPDifFD8N45eGykUWjkocHcbqn5uKv1rCgmoDAu9fzge7FxDk5yqtuJhIdzrNq_ZbUFLYTiONXB5czxnqOYNpxkXwyfFfIxCNiUr_t9gjcgX7gONq0H58Fmu3hzig/s1600/homebutton.png" /></a></div><br />
<br />
This code armed with a Home button will do the job cleanly for you.<br />
<br />
<pre class="brush:java">private void Home_Click(object sender, System.Windows.RoutedEventArgs e)
{
int depth = NavigationService.BackStack.Count();
for (int i = 0; i < depth - 1; i++) { NavigationService.RemoveBackEntry(); }
NavigationService.GoBack();
}</pre><br />
The funda here is it will empty all the stack and will call the back action of the navigation service just once making sure that the next back() will empty the stack and will make you quit.<br />
<br />
As I told before adding this code to the MainPage.xaml.cs will show a confirmation popup while quitting the application so that user only deliberately quits but not accidentally.<br />
<br />
<div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMSoK5-24Vc70fFPTm-V2CW3NLfTok9cWjphn2wWYgx-a31msiKGjERxxq1OFF-YXMfVeZBX1sqYe12z8KXOQUI9O1nzATLVohd_8WWc2hgBkVZ9057IOaca3yaG-Zkb-TqvO_ivMRs58/s1600/exit+confirmation+wp7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMSoK5-24Vc70fFPTm-V2CW3NLfTok9cWjphn2wWYgx-a31msiKGjERxxq1OFF-YXMfVeZBX1sqYe12z8KXOQUI9O1nzATLVohd_8WWc2hgBkVZ9057IOaca3yaG-Zkb-TqvO_ivMRs58/s1600/exit+confirmation+wp7.png" /></a></div></div><br />
<br />
<pre class="brush:java">protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
if (MessageBox.Show("Are you sure you want to exit?", "Exit?", MessageBoxButton.OKCancel) != MessageBoxResult.OK)
{
e.Cancel = true;
}
}</pre><br />
These techniques are very simple and subtle but will improve the usability of your application by leaps and bounds.<br />
<br />
Cheers!<br />
Braga</div>BragBoyhttp://www.blogger.com/profile/01173019524783723568noreply@blogger.com0tag:blogger.com,1999:blog-6294663875929591018.post-56539128906312425082012-07-27T12:34:00.000-07:002012-07-27T12:34:13.584-07:00Windows Phone 7.5 WebBrowserTask - Simple Yet Powerful<div dir="ltr" style="text-align: left;" trbidi="on">WebBrowserTask is one of the most simple yet powerful tasks I found in Windows Mobile development. It is amazingly simple, just two or three lines of code and super tempting to include it in your project. Lets quickly see how to use it and places where you can utilize its capability at the presentation level.<br />
<br />
Enough intro, here is the code<br />
<br />
<pre class="brush:java">WebBrowserTask pptTask = new WebBrowserTask();
pptTask.Uri = new Uri("http://www.iasted.org/conferences/formatting/presentations-tips.ppt");
pptTask.Show();</pre><br />
Damn simple isnt it? You could use this in places where you need to launch or open an URL in the inbuilt Internet Explorer. And the best thing about this is it will automatically detect the attachment file types (most of them) and opens them cleanly. For example, it could read ppt, pdf, xls even videos and open them cleanly. You can make the integration look rich by providing a button in the Application bar. Following is a screenshot.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBc5JDsuxjFnjQqw6u6OXzsj3C4F-793HEXon3XtPVhoZBFZRVFtnShbf-6LHHVy6nqjTd409HQgDGdAY7yeICxSxZdXbsxrGxkWNIH3bPfX4be0rnnd0UzQup73fgMwxJ6k3unXf5mAY/s1600/webbrowser+task+windows+phone+download.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBc5JDsuxjFnjQqw6u6OXzsj3C4F-793HEXon3XtPVhoZBFZRVFtnShbf-6LHHVy6nqjTd409HQgDGdAY7yeICxSxZdXbsxrGxkWNIH3bPfX4be0rnnd0UzQup73fgMwxJ6k3unXf5mAY/s1600/webbrowser+task+windows+phone+download.png" /></a></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/AVvXsEhPpsPWzjnEJpBFk6osm9b5YT1pb5lfSCPBE-S5nR9KBG5dgFx_9robOCJdxkszf5DjMktrfLv6HwFXcVLUBgc6wYQW0Aq407m4DrBJ4hHfhOAzDBAfI1ZmBz536fmO2Oy-RQtIlh8qq2g/s1600/webbrowser+task+windows+phone+download+ppt.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPpsPWzjnEJpBFk6osm9b5YT1pb5lfSCPBE-S5nR9KBG5dgFx_9robOCJdxkszf5DjMktrfLv6HwFXcVLUBgc6wYQW0Aq407m4DrBJ4hHfhOAzDBAfI1ZmBz536fmO2Oy-RQtIlh8qq2g/s1600/webbrowser+task+windows+phone+download+ppt.png" /></a></div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">Besides opening simple URLs consider using this Task to open regular attachments and make your end application look extremely rich with just one or two lines of code.</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;">Cheers!</div><div class="separator" style="clear: both; text-align: left;">Braga</div></div>BragBoyhttp://www.blogger.com/profile/01173019524783723568noreply@blogger.com0tag:blogger.com,1999:blog-6294663875929591018.post-86031688831008453042012-07-26T13:46:00.001-07:002015-08-08T13:52:49.177-07:00Windows Phone 7.5 - ShareStatusTask's Limitations<div dir="ltr" style="text-align: left;" trbidi="on">
The Microsoft.Phone.Tasks namespace in Windows phone 7 is a neat way to access the default phone specific tasks. One such task is the ShareStatusTask. If you want to say share your status on facebook or twitter or to windows live account, you can do it in one shot.<br />
<br />
The code looks very simple,<br />
<br />
<script src="https://gist.github.com/bragboy/5dc27b5cecd7be4e2749.js"></script>
Very cool isnt it. But the usage of this kind of limited. You will have to have all the accounts configured already in your phone settings. I was looking for a direct solution to just provide a way to tweet. But it was not possible to tell the ShareStatusTask to open it only if it has Twitter. I had asked this question in <a href="http://stackoverflow.com/questions/11159020/windows-phone-7-sharestatustask-is-it-possible-to-customize-it-further">Stackoverflow</a> only to double confirm the above said point. This feature is not available in Emulator, hence posting a screenshot from a real device.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2FvxoWUd3UtMUnXt3iuMgkQIA5287rAqHosaWRsH2drEqhbk3hgluy04ciJxhQt7UKcqEHvlgb3_BKiXA-FcfZUlqxEdWjFijRwtVlFDsixMjl9t8aQKYng6dyewgtNJ1fmxl7EHjgfc/s1600/sharestatustask.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2FvxoWUd3UtMUnXt3iuMgkQIA5287rAqHosaWRsH2drEqhbk3hgluy04ciJxhQt7UKcqEHvlgb3_BKiXA-FcfZUlqxEdWjFijRwtVlFDsixMjl9t8aQKYng6dyewgtNJ1fmxl7EHjgfc/s1600/sharestatustask.png" /></a></div>
<br />
<br />
Anyways, this is one of the cool tasks available and just two to three lines will add social feature to your App, so do add it whatever be the case.<br />
<br />
Cheers!<br />
Braga</div>
BragBoyhttp://www.blogger.com/profile/01173019524783723568noreply@blogger.com0