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

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

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

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

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;