Tuesday, December 2, 2014

Special Pythagorean triplet problem

Another coding challenge from projecteuler.net

A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a2 + b2 = c2
For example, 32 + 42 = 9 + 16 = 25 = 52.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.


outermost: for (double a = 1; a < 1000; a++) {
    double aProduct = Math.pow(a, 2);
    for (double b = 1; b < 1000; b++) {
        double bProduct = Math.pow(b, 2);
        double c = Math.sqrt(aProduct + bProduct);
        if (Math.floor(c) == c && a + b + c == 1000){
            System.out.println("Pythagorean triplet: a:" + a +  " b:" + b + " c:" + c);
            System.out.println("answer: " + (a * b * c));
            break outermost;

Fell off the blogging wagon

It is so easy to fall into a rut.  It takes effort to keep putting in that extra effort.  Just like going to the gym if you keep to a schedule you are fine but once you break that routine you often completely fall off the wagon.  That is what has happened to this blog and I need to get back on track.

Monday, October 27, 2014

JQuery refresher

The sprint is wrapping up so why not spend a bit of time polishing my skillset... so lets do the code school course about JQuery.  The thing I have always loved about JQuery is the documentation.  The documentation of the library is a shining example for all other open source libraries.

Neat things I didn't know about even though working with JQuery for years well these are actually CSS things:

  • The child selector - Select only the child elements not all matching descendants.
    • Example: $("#destinations > li");
    • This is very cool.  I knew it was that easy to do.  Normally I would just give everything and id of class to get around this but I like this method of getting the children or use JQuery traversal.
    • Actually this is a CSS selector I did not know about.
  • Select multiple items - You can use one selector to select multiple items with different criteria.
    • Example: $(".promo, #france");
    • Again very cool.  This is something I likely could have used in the past when I used multiple selection statements or gave all the elements the same class.
    • Actually this is a CSS selector I did knew about but never thought about applying in JQuery.

I heart Code School.

Wednesday, October 15, 2014

Argument against Ternary Conditional Operators

Time to get up on my soapbox...

I was just doing the CodeSchool JavaScript best practices course and the very first item in is it something I could not disagree with more.

The Ternary Conditional Operator is one of the worst things to allowed in common programming language syntax.  Unless you trying to write your code to be as minimalist as possible to save every possible byte in your source files it should not be used.  The reduction of readability and maintainability when using the ternary operator far out weighs the advantages  of being less verbose and requiring less lines of code.

var isHero = true;
var canFly = true;

//normal if else 
var name;
if (isHero && canFly) {
   name = "Superman"
} else {
   name = "Vader"

//ternary conditional operator
var name = isHero && canFly ? "Superman" : "Vader";

Yes, it the ternary conditional operator is quicker and dare I say easier.  However I will wager that 100% of the engineers in the world can understand the standard if/else and just a glance where as with the ternary operator some of them will confuse the result and the majority will have to pause for a second or two to try to make sure the way ternary operators work in their head.  Does it mean you are smarter than the rest of the your team if you use ternary operators? No. It just means like pavlov's dog you have been trained to translate the syntax into an if/else without needing to think about it.  When debugging a complex important issue the majority of people do not wish to waste time translating code so they can understand it.  It slows the team down and frankly increases the chances of defects.  I would love it if I could ban ternary operators from use in all languages but Assembly.

...stepping off my soapbox.

Monday, October 13, 2014

my CoffeeScript intro

Always Be Learning

Let's learn CoffeeScript today.

What is CoffeeScript?  Well it is a front end script language that gets compiled down to Javascript.  It was developed with the goal of making Javascript more readable and understandable.

So Code School here we come... (course)

The fact that it has a command line compiler that compiles into Javascript is very interesting.  I like the feature of being able to set up a service to watch your code and auto compile it.

The Code School course initially does not seem as well developed as the one for AngularJS in terms of the challenges.  You can tell the CoffeeScript was made earlier.

Not a fan of:

  • @ symbol used in the place of 'this' keyword.
    • although it is slick when getting this.properties
      • @name
  • Optional brackets ( )  for function arguments; arguments are one of those things I like being explicit about.
  • Intenting aka whitespace is very important since it takes the place of brackets, commas, semicolons, and more.  This concerns me cause I know how character encoding can vary between operating systems and editors.  I can foresee this being a very tricky thing to get to the bottom of when trying to debug unexpected behavior. 

A fan of:

  • automatic creation of variables, no need to declare them explicitly
  • the code around conditionals seems human readable.
    • Examples:
      • if paid() and coffee() is on then pour()
      • addCaffeine() if not Decaf()
      • addCaffeine() unless Decaf()
    • This is something I like in my unit test code but not sure how I will feel about it later in my production code.
  • they way object orientation and inheritance is written in CoffeeScript in my opinion is more intuitive
  • "the fat arrow"... google it

Overall I think CoffeeScript is nice but I am not sure I see more value in it than I do just knowing JavaScript very well.  I would have to see it in an enterprise setting most likely to really see its value.

Friday, September 26, 2014

Secret Shame

My secret shame as a software engineer is that I am horrible at setting up projects from scratch.  Career wise I always seem to join a team mid way through the project so I never am starting from square one.

I am going to make an effort to create templates for myself to follow and commit them to github.

My initial projects I added was a Spring MVC project:

After that I made Spring Rest implementation
After that I made Spring Rest with a Hibernate backend implementation

Wednesday, September 24, 2014

Spring Rest Tutorial

Starting at the beginning... again.

As part of my efforts to freshen up my fundamentals I am going through core reference tutorials.  The next one I am doing is the "Designing and Implementing RESTful Web Services with Spring" tutorial found at on the spring website. 

The code I wrote for it can be found here

My hope was to use Gradles when building this project but its interactions are blocked by the proxy I am currently behind so I am going to try to convert the project to maven.

I enjoy how the tutorial follows the TDD pattern when stepping you through creation of the project. 

Besides the Gradles issue one issue I have with these Spring tutorials is that everything is just handed to you.  There is not a single point in where they say now complete the code in this method but if you get stuck the answer is here.

Along with the Maven conversion I also updated my project to use Jetty vs the Gradles embedded tomcat.  I did run into one issue though.  A new version of jetty is required that supports Servlet 3 with is Jetty 8+.  I had to update the settings.xml (~/.m2/settings.xml) with the following entry:

<pluginGroups>     <pluginGroup>org.mortbay.jetty</pluginGroup> </pluginGroups>

Monday, September 22, 2014

Code School review

I just completed my first course on Code School and I was very pleased with it.  The course I went through was 'Shaping up with AngularJS' which as you can guess with an introduction to AngularJS.  This was a much more pleasurable experience to get a nice little Hello World view of AngularJS than your typical tutorial.  The course provided video content teaching you the how and why with follow up challenges that you could actually put what you learned into practice.  All of the slides covered in the course is available for download.  The coding challenges were done entirely in the browser with tips and suggestions to get you through it.  Over the entire course I only encountered one instance where the directions provided were not clear enough to me to complete the step with ease.  I got just enough out of the course to give me a foundation to build on and go through other AngularJS tutorials and start to learn it.

There is more content on Code School that I don't have access to because I only have been viewing free material at this time.  I do not know however if the $29 a month charge for full access to the site is worth it.  It matches with the way I enjoy learning but will it be a good return on my investment is another question.  Code School remains in the running for a resource that I will keep coming back to and possibly invest in a subscription.

Friday, September 19, 2014

A month at the new job

It has been a month at the new job working as a contractor... wow already!  It has been a very different experience working as a contractor.  At times I have to stop myself from getting too invested and just roll with what ever the full timers have in mind.  This is a world I am not trying to save or make better I am just trying to contribute to the team in whatever way I can.  My personal goals here are to grow my skill set, contribute to the team enough to have them renew my contract and provide me with good references, and generally expand my horizons.  It has been a great experience so far and I hope it continues.

Things I can already add to my resume

There might me more things I can add but new stuff is coming at me fast and furious.  There are some teams doing AngularJS around me that I hope to help out at a very superficial level so I can add that as a nice bullet point on my resume and time here.

Wednesday, September 17, 2014

Engineering, Sewing, Construction, Legos, and more...

A few nights ago my wife was amazed my latest project which was to sew a couple little heating pads which my daughter now likes to snuggle with at night.  My passion and what excites me is building things.  For my career I am a software engineer; I take little commands and stack them up to do something cool.  Software engineering is no different in my mind that building something out of Legos which I used to love to do as a kid (admittedly as an adult as well).  In software engineering you are small commands like i++ to accomplish a bigger task like in the snippet below where I say hello to you five times in JavaScript:

for (var i = 0; i < 5; i++) {
     console.log("hello world");

  • I like to code because I like to build software that accomplishes a task.
  • I like to work with wood and do construction because I like to build or repair things to make my home a little nicer for my family.
  • I admitted do not shy away from the manly art of sewing for the same reason.  With a few cuts and a few passes on the sewing machine I have created something for my family. 
When I sew I play with power tools.  There is no difference in my brain between a scissors and a handsaw just like there is no difference between a nail gun and a sewing machine. I like to build things.

Too much to learn so little time

Wow there is so much to learn in the world of Software Engineering.  I could easily spend 20 hours a week just learning new tech and still feel as though there is so much I need to study.  As a family man with a couple kids trying to stay on top of things is a daunting task. It is important to focus on the most valuable and applicable technology first.  Also it is a little counter intuitive but I think pursing technology that you aren't using at the moment in career but that you would like to work with is crucial.  The technology you are using now with be acquired organically by pursuing your current need for understanding of a task assigned to you.  My advice to those with limited amounts of time to study and learn new technology is to prepare yourself for the next technology hurdle.

There are plenty of good resources available that I would recommend:

If you have other sites which you have found valuable for the pursuit of knowledge of software technology please share them.

Next on my list to learn is:
On my list to learn organically by doing:
  • Spring

Monday, September 15, 2014

Code Academy Review Part 1

I started looking into learning new technology through Code Academy.  So far I have just done the first part of the JavaScript beginner course so my review will be limited to initial impressions.

The UI through Code Academy is wonder.  You are given instructions, a text area to code in (with syntax highlighting), and an output console.  This makes the effort of going through the lessons painless.  Each lesson from what I have seen is limited in scope to just one bit of information and a tiny exercise to try it out.  Everything I have gone over so far has been pure review but I can imagine being fresh to the language wouldn't increase the difficultly too much.

Languages covered on the site

  • HTML & CSS - 7 hour course
  • JavaScript - 10 hour course
  • jQuery - 3 hour course (not really a language but it is listed as such)
  • PHP - 4 hour course
  • Python - 13 hour course
  • Ruby - 9 hour course
Advanced topics available are focused on using API for a particular language for things like Mandrill, Evernote, and Twitter.

Tracking progress is being done with on each course and earning badges for lessons completed which can be shared using social media.

Overall impressions are that Code Academy is that it does exactly what its mission claims; which is to make learning how to program with web technologies accessible and non intimidating.  I would recommend it too anyone especially teenagers looking to learn how to get a taste for this coding thing.

Sunday, September 14, 2014

Extreme Mocking

Recently I have been told about an aspect of unit testing using mock objects taken to an extreme I have never seen before.  I am a huge proponent of Test Driven Development and Unit Testing.  The first task I did when I started as a software engineer was to write unit tests for existing code on a project to increase code coverage. In my opinion some tests at the class level are useful while others being less strict about boxing in the code interacted have their merits as well.  This new type of mocking I have been exposed to take testing at the class level to a new extreme, all objects interacted with including the POJOs (Plain Old Java Objects) you pass as arguments should be mocked.

This is an extreme because you are not even trusting yourself.  Think about it all the objects you use to interact with your code need to be mock objects unless they are primitives.  So if you have an objects with type properties you need to create a mock object for it and its getters and setters.  In essence you are not trusting any part of the code even the most basic and everything is considered suspect.

Extreme mocking seem like it is going to far until you get into a situation where you are responsible for a code base helpless subject to the whims of other libraries.  For example you are workings on a system where one team owns the models that feed are used to interface with your system, several other teams are responsible for the data that your code interacts with, and a host of other teams interact act with your code your stuck in the middle and easy to blame.  To protect yourself you mock EVERYTHING to help triage, cover your rear-end, and insulate you from volatile systems.  The idea of not owning the models and objects that your code base is using for foreign to me as a full stack developer until I encountered it but now this idea makes sense in the situations where it is warranted. 

Try it yourself take a bit of code and mock everything it interacts with besides primitive. It is an interesting challenge.  

Saturday, September 13, 2014

Largest product in a series Problem

Here is another little problem.  I threw me for a few minutes until I changed from using an int to a long for storing the product. Silly me an overflowing the primitive type.


The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832.
Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?

public static void main(String[] args) {

    StringBuffer testBuffer = new StringBuffer();
    String test = testBuffer.toString();
    long largestProduct = 0;
    for (int i = 0; i + 13 <= (test.length()); i++) {
        String numberSet = test.substring(i, i + 13);
        long product = 1;
        for (int j = 0; j < numberSet.length(); j++) {
            int num = Integer.parseInt(String.valueOf(numberSet.charAt(j)));
            product = product * num;
        if (product > largestProduct) {
            largestProduct = product;

    System.out.println("result: " + largestProduct);

Friday, September 12, 2014

5 things you probably didn't know about Javascript

I have been working with JavaScript since maybe 1997 in some capacity.  Like most people it was something that you used used to solve a task and move on without any formal training so the fundamentals of the language escape most people who develop it.  Over the years JavaScript as been an increasingly powerful language with more and more processing being done client side.  I dream of one day having a job where my focus is on JavaScript so I have a reason to invest in developing an in depth understanding of the language.  Here is a list of five things that I recently learned about JavaScript that blew my mind even after over nearly 20 years coding it.

  1. JavaScript has a spec! BOOKMARK IT ASAP
  2. Really JavaScript isn't wild and free like the cowboys of yesteryear. Of course it had to be defined in a spec somewhere but have you ever seen it or even considering looking for it?
  3. JavaScript, I am not joking, has a spec and it is readable and user friendly.  If you do not understand something the spec seems to have a well laid out definition for everything.
  4. JavaScript has a spec that very well defined.  It isn't wild and free and depending on the browsers playing nice with it.
  5. JavaScript is versioned; the spec is available for past versions and versions that are not support yet.. 

Other candidates that did not make the list
  • JavaScript is a compiled language.  
    • I always thought it was up to the browsers to interpret it at run time.
    • Understand how the compiler and engine work in order to rule the world. mwhahaha
  • JavaScript can be run server side
    • What do you mean there are uses for JavaScript beyond client side the web browser!?!
  • The way the code work is enough to blow your mind
    • Example: 
      • Why does it go in the if block if it is false?
        if ('true') {
            'true' == true  // returns false
            'true' == false // returns false
      • Answer: In the if check 'true' is coerced into being a boolean using ToBoolean (check the spec) which equates any of the following values to be 'falsey' if not they will result in a true boolean value.
        • empty string ("") (does not even include whitespace)
        • false
        • 0
        • NaN
        • undefined
        • null
  • Edit any web (you cannot publish it back to the server) by executing the following line of code in your web console.  This is not so much something crazy you didn't know but a cheesy parlor trick to amuse your friends.  It is easy to remember to at least temporarily make your new intern in awe of you.
    • document.designMode='on';

Wednesday, September 10, 2014

Palindrome Product Challenge

Yet another coding challenge: A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit numbers.


int maxProduct = 0;

String product = "";
String productReverse = "";
for (int i = 1; i < 1000; i++) {
    for (int j = 1; j < 1000; j++) {
        product = Integer.toString(i * j);
        productReverse = (new StringBuffer(product)).reverse().toString();
        if (product.equals(productReverse)) {
            if (maxProduct < (i * j)) {
                maxProduct = i * j;
System.out.println("result is: " + maxProduct);

Even Multiple Challenge

Yet another challenge from http://projecteuler.net


2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

int sum = 0;

for (int i = 1; i < 1000; i++) {
    if ( i % 5 == 0 || i % 3 == 0) {
        sum += i;

Tuesday, September 9, 2014

Fibonacci sequence challenge

Another coding challenge from projecteuler.net

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
                    1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.


int n1 = 1;
int n2 = 2;
int sum = 0;
while (n1 + n2 <= 4000000) {
    int next = n1 + n2;
    n1 = n2;
    n2 = next;
    if ((next % 10) % 2 == 0) {
        sum += next;
System.out.println("result is: " + (sum + 2));

Display a natural number as text

This is an interview question I was given a while ago that I thought was an interesting challenge.  Personally I felt it was a little too long of a question to work well in an interview but it was a nice little puzzle to figure out.  The solution provided is just to solve the problem using core functionality with no effort made to be elegant in the solution. You will note in my solution that I do not provide a text value for anything over a billion because it just seemed purely academic to go beyond.

The problem:

Display any natural number as text?

       input: 123
       output: one hundred twenty three

The source code and an interactive demo is available at http://jsfiddle.net/jtSdv/

Here is the javascript code itself for the link above:

var textValues = {};

function intAsText(value) {
    var result = "";
    if (isNaN(value)) {
        result = "n/a";
    } else {
        var intValue = parseInt(value);
        result = getText(value);

function getText(intValue) {
    var result = "";
    if (20 >= intValue) {
        result = textValues[intValue];
    } else if (1000 > intValue) {
        var firstDigit = intValue % 10
        var tensDigit = (intValue - firstDigit) % 100;
        var hundredsDigit = (intValue - tensDigit - firstDigit) / 100;
        if (hundredsDigit != 0) {
            result = textValues[hundredsDigit] + " " + textValues[100];
        if (tensDigit != 0) {
            result = result + " " + textValues[tensDigit];
        if (firstDigit != 0) {
            result = result + " " + textValues[firstDigit];
    } else {
        var chunks = {}
        var workingValue = intValue;
        var multiple = 1000;
        var numChunks = 0;
        while (workingValue >= 1) {
            var chunk = workingValue % multiple
            chunks[numChunks] = chunk;
            workingValue = (workingValue - chunk) / multiple;
        if (chunks[0] > 0) {
            result = getText(chunks[0]);
        for (var i = 1; i < numChunks; i++) {
            if (chunks[i] > 0) {
                result = getText(chunks[i]) + " " + 
                    textValues[Math.pow(multiple, i)] + " " + result;
    return result;

$(document).ready(function () {
    textValues[0] = "zero";
    textValues[1] = "one";
    textValues[2] = "two";
    textValues[3] = "three";
    textValues[4] = "four";
    textValues[5] = "five";
    textValues[6] = "six";
    textValues[7] = "seven";
    textValues[8] = "eight";
    textValues[9] = "nine";
    textValues[10] = "ten";
    textValues[11] = "eleven";
    textValues[12] = "twelve";
    textValues[13] = "thirteen";
    textValues[14] = "fourteen";
    textValues[15] = "fifteen";
    textValues[16] = "sixteen";
    textValues[17] = "seventeen";
    textValues[18] = "eighteen";
    textValues[19] = "nineteen";
    textValues[20] = "twenty";
    textValues[30] = "thirty";
    textValues[40] = "forty";
    textValues[50] = "fifty";
    textValues[60] = "sixty";
    textValues[70] = "seventy";
    textValues[80] = "eighty";
    textValues[90] = "ninety";
    textValues[100] = "hundred";
    textValues[1000] = "thousand";
    textValues[1000000] = "million";

Other Coding Challenges:

Largest Prime Factor Challenge

I was tempted not to post this solution because I am not happy with it at all but it solves the promblem


long testNum = 600851475143l;
int largestFactor = 0;
long loopMax = 17425170l; //largest known prime 
for (int i = 3; i * i <= loopMax; i++) {
    boolean isPrime = true;            
    for (int j = 2; j < i; j++) {
        if (i % j == 0) {
            isPrime = false;
    if (isPrime && testNum % i == 0) {
        System.out.println("prime factor: " + i);
        largestFactor = i;
        loopMax = (testNum / i) + 1;
System.out.println("result is: " + largestFactor);

Monday, September 8, 2014

Software Engineer or good Googler?

Some times you wonder am I actually good at this software development stuff or am I just good at googling for the solution to the latest roadblock I have encountered.  As part of this blog I am going to start trying to solve randomly encountered coding challenges and blog the question and answer here.  I will not be looking for the most efficient or elegant solution just the solution.  Maybe other software engineers like my wife and friends will be kind enough to review the solutions for me.

For a quick and easy problem I did one from http://projecteuler.net


Find the sum of all the multiples of 3 or 5 below 1000.

int sum = 0;

for (int i = 1; i < 1000; i++) {
    if ( i % 5 == 0 || i % 3 == 0) {
        sum += i;

Saturday, August 30, 2014

New Job = New Tech Stack

Every software engineer has been here, you start a new job and get introduced to the companies tech stack and either do not know or out of practice with half of it.  When you encounter this situation you are forced to choose where to start investing your time learning it.  Some things you are going to pick up just going about your day to day activities and others you need to work at.   The question is where to start.

Here is the parts of the tech stack that I need to learn or get more familiar with:

So where do I start?  The first thing that needs to be done is assess what makes a something important to learn which is a combination of usefulness and personal marketability in the software engineering community. I can immediately eliminate things like Mercurial, Confluence, and Rally because those are just something you figure out as you go unless there is need to become an admin.  There are other things that I can rule out due to them being easy to knock off when the need arises to accomplish a task like mockito, WireMock, and Jackson.  That leaves me effectively with two options Spring and AngularJS.  AngularJS is a very valuable skill ATM and Spring is the defacto standard Java framework that I haven't been exposed to yet in a professional setting.  Spring has a more immediate need so I will start there for my day to day activities.  So I will be reading up on the basics of Spring and doing tutorials while getting an environment setup to do AngularJS work as well. 

How to you figure out what technology to learn first when you start a new position?

Friday, August 29, 2014

Open Source Development Contribution Fail

As part of my efforts get more involved in the software engineering community and improve my personal brand I have been making an effort to get involved in an open source development project or two.  On one of my first days a new job I ran into a situation where I needed a utility method for a collection which was not handled by Apache Commons. Perfect opportunity to contribute back, right?  The change would have been a failure straight forward utility method so I went to the Apache Get Involved page and signed up for their Jira instance.  I wrote the code and was ready to submit my diff back to the community when I found it.  Someone else wrote a method very similar to mine and had an open ticket to have it merged in.  So close but a couple weeks too late.  The story won't end here I will find an opportunity to contribute back and write about my experiences doing it.

If anyone is involved in an open source project and wishes to pull me into it please contact me.

Monday, August 18, 2014

Contracting aka Betting on Myself

Today I starting working as a software engineer contractor.  It is a big change for me.  My entire career has been spent at two companies.  The first job at Kemper Insurance was where I saw myself working the duration of my time in the workforce like my father who is still working there.  However I moved to Boston with my now wife and Kemper was kind enough to lay me off and outsource my position on the same day I was interviewing at the company in Boston I would later work for.  Working for Safari Books Online, now going by just Safari, was an amazing company to work for.  They showed just what I should expect from an employer in terms of company culture.  In order to make sure my kids were in a good school district we had to move far enough away from the city that made my commute untenable so it was time to move on.  That leads me to here; contracting at ADP spending less than half the time I was commuting into the south Boston.  My goals as a contractor are to round off my resume, acquire a few new skills, and set myself up to land a great job.

A couple things I want to keep in mind while working as a contractor:

  • Be flexible.  It is not my code in any way shape or form.  Go with the flow.
  • Be positive.  There are team members who have been struggling with the project before you joined this team and they will be struggling after you leave. Just be a positive element on the team to help keep things moving.
  • Find a way to contribute in a meaningful way that your coworkers can remember you for.

This blog was started after I read another blog titled "Why software engineers should maintain a blog" by Chase Seibert so I am going to try to keep this blog active.  I have started a half dozen blogs over the years but hopefully I can stick with this one.