Wednesday, June 18, 2014

Bill Gate's Bookshelf

I find the best way to improve yourself is to find role models. People who have done what you want to do, whose footsteps you can follow in. Not to discredit those who go their own way, as it can be just as rewarding, but to highlight the works of savants.

http://www.gatesnotes.com/books


Monday, June 9, 2014

ng-options 50 states $scope variable

$scope.states = ["AL","AK","AZ","AR","CA","CO","CT",
          "DE","DC","FL","GA","HI","ID","IL",
          "IN","IA","KS","KY","LA","ME","MD","MA",
          "MI","MN","MS","MO","MT","NE","NV",
          "NH","NJ","NM","NY","NC","ND",
          "OH","OK","OR","PA","PR","RI","SC",
          "SD","TN","TX", "UT","VT","VA","WA",
          "WV","WI", "WY"];

Monday, June 2, 2014

Google Authenticator lost phone workaround

This won't do much good if you have already lost your phone, but if you still have it and want to take extra precautions for the potential loss of your phone, check out the backup codes that Google offers. These will allow you to gain access to your account even after your phone has been lost.

Friday, May 30, 2014

How to do null-safe Integer comparison in Java

result = ObjectUtils.compare(firstComparable, secondComparable)

commons-lang3 has a useful null-safe compare method between two Comparables. This comes in-handy for non-primitives like Integer, Long, Boolean, etc.

Tuesday, March 25, 2014

10 Most Controversial Programming Opinions

What's your most controversial programming opinion?


  1. Programmers who don't code in their spare time for fun will never become as good as those that do.
  2. The only "best practice" you should be using all the time is "Use Your Brain".
  3. Most comments in code are in fact a pernicious form of code duplication.
  4. XML is highly overrated.
  5. Not all programmers are created equal.
  6. If you only know one language, no matter how well you know it, you're not a great programmer.
  7. Performance does matter.
  8. Print statements are a valid way to debug code.
  9. Your job is to put yourself out of work.
  10. Getters and Setters are Highly Overused.

Tuesday, March 11, 2014

Getting the most out of Fitnesse Suites

Fitnesse offers the ability to use scripts inside tests and suites as well as use REST calls following their API. This is handy because it gives us the chance to write JavaScript/jQuery hacks to improve the utility of Fitnesse.

When writing a suite, I will create tables to put similar tests together. I start with the test name, then a description, and the current status. The script uses the test name to query the restful service, which returns the latest test result and populates the status cell based on the result. This provides a range of benefits:
  • Allows to skip running the suite, which can be time consuming on the machine it is running (as well as blocking for other test suites)
  • Get immediate results for each test instead of waiting for the suite
  • Easier to navigate than the suite test page

Example



1. Update the ajax url parameter with your url, leading up to the suite with the following period. As long as the testnames in the first column are valid, it will automatically populate the current status column with the last data.

JavaScript

<!--[if lt IE 7 ]> <span id="ie" class="ie6"></span> <![endif]-->
<!--[if IE 7 ]>    <span id="ie" class="ie7"></span> <![endif]-->
<!--[if IE 8 ]>    <span id="ie" class="ie8"></span> <![endif]-->
<!--[if IE 9 ]>    <span id="ie" class="ie9"></span> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <span id="ie" class=""></span> <!--<![endif]-->
<script>
"use strict";
// These values count up each of the tests statuses. Display for a summary of the suite.
var passingTests = 0;
var failedTests = 0;
var exceptionTests = 0;
var ignoredTests = 0;

$( document ).ready(function() {
// For each tr that is not the first
$('table tr:not(:first-child) td:first-child').each(function() {
// get the name of the test out (from >Test Name)
     var testname = $(this).text().substring(1);

// Make the rest call
$.ajax({ url: "http://yoururl.yourSuite."+testname+"?pageHistory&resultDate=latest&format=xml", cache: false, type: "GET", dataType: "xml", context: this, success: function(data) { var output = ""; //IE doesn't support innerHTML element if($("#ie").is('.ie6, .ie7, .ie8, .ie9')){ var correct = $(data).find("counts")[0].firstChild.text; var wrong = $(data).find("counts")[0].firstChild.nextSibling.text; var ignored = $(data).find("counts")[0].firstChild.nextSibling.nextSibling.text; var exception = $(data).find("counts")[0].firstChild.nextSibling.nextSibling.nextSibling.text; } else { // For everyone else var correct = $(data).find("counts")[0].childNodes[1].innerHTML; var wrong = $(data).find("counts")[0].childNodes[3].innerHTML; var ignored = $(data).find("counts")[0].childNodes[5].innerHTML; var exception = $(data).find("counts")[0].childNodes[7].innerHTML; } output += "<span class=\"correct\">right: " + correct + "</span><br/>"; if(wrong != "0") { output += "<span class=\"wrong\">wrong: " + wrong + "</span><br/>"; $(this).closest("tr").addClass("testFailed"); } if(wrong != "0" && exception == "0"){ failedTests++; } if(ignored != "0"){ output += "<span class=\"ignored\">ignored: " + ignored + "</span><br/>"; ignoredTests++; } if(exception != "0"){ output += "<span class=\"exception\">exception: "+ exception +"</span>"; $(this).closest("tr").addClass("testException"); exceptionTests++; } if(wrong == "0" && exception == "0" && correct != "0") { passingTests++; $(this).closest("tr").addClass("testPassed"); } // Append to status td $(this).closest("td").next().next().append(output); } }); }); }); </script>


CSS
<style>
.testPassed {
background-color:#CDFECD;
}

.testFailed {
background-color:#FFCCCC;
}

.testException {
background-color:#FFFFCC;
}

.correct { 
color:green;
font-weight:bold;
}

.wrong { 
color:red;
font-weight:bold;
}

.exception { 
color:#FFCC00;
font-weight:bold;
}

.ignored { 
color:grey;
font-weight:bold;
}
</style>