Jul 6 2012

StackOverflow Traffic

There is nothing more that I like than to received a comment to some post I wrote years ago on how it helped someone out. Like this, I’ve come to know that small chunks of code I’ve freely made available are used in production at a variety of sites. It is my hope that the tutorials, examples, and code I write here is of help to others. Even though I like writing tutorials and code to help out my fellow developers, I’ve never answered or posted a question on StackOverflow. My technical blog is really a labor of love and I post around my busy schedule, I’ve never tried to do more than just write about the technology that I use. But even though I don’t use StackOverflow I recently found out from looking at my analytics that I receive a nice amount of visitors from the question and answer site.

StackOverflow Stats

StackOverflow Stats

It always surprises me which posts are the most visited. It’s always the one that you least expect. Either way, I’m always grateful that others have found them useful enough to share on sites like StackOverflow.


Jun 26 2012

Pure JavaScript Charting Library

Most business applications display some amount of data in charts and graphs. If a picture is worth a thousand words, then a clean visual representation of business data is worth a lot more. Business charts can condense a lot of data points into a easy to understand graph.

Recently, I was tasked with updating the graph solution of a financial application with a HTML5 friendly charting tool or library. I looked at about half a dozen JavaScript chart libraries and eventually narrowed the selection down to two based on features and functionality: Google Charts and jQuery chart plugin jqPlot. Both Google Charts and jqPlot support a large number of chart types, from the basic bar and pie to more advance features such as multiple y-axis and and zoom. Both libraries support HTML5 graphics, the legacy chart solution I was to replace generated a pixelated image. Google Charts and jqPlot both draw the graph into div tag instead by using HTML5 graphics and don’t anti-aliasing issues.

For this particular project, we picked jqPlot over Google Charts for the following reasons. Google Charts is not open sourced and it uses a loading mechanism that requires you to be online to load the JavaScript source files from Google’s servers. This is great if you are always online, but the project owners wanted a HTML5 charting solution that works offline. jqPlot is a freely available open source JavaScript library which can be hosted alongside with the other application resources. jqPlot, like Google Charts, has a large number of chart types it supports including line, area, bubble, bar stacked, pyramid, pies, donuts, gauges, and much more.

jqPlot JavaScript Chart Library

jqPlot JavaScript Chart Library


Jun 8 2012

JavaScript StackTrace With The console Object

Error handling and debugging had been made difficult in JavaScript because the lack of tools and the language itself. Unlike Java, that has a strong type and hierarchy of exception classes, JavaScript didn’t even have a direct approach to print the execution stack trace. For years I used a workaround to navigate around stack trace of a method call in JavaScript by using the Function arguments property. In JavaScript, all functions have an arguments property defined. The arguments property is available even if the function is defined with no explicit function parameters. The function arguments property behaves like an array and you can iterate through the argument parameters used to call the function but it also has a reference to the caller via the arguments.callee property. The arguments.callee property references the currently executing function itself, which has a caller property to that of the previous function call in the execution stack.

function basicFunction() {
   var isTrue = arguments.callee == basicFunction; // true
   var callingFunction = arguments.callee.caller; 
}

In the above code, the callingFunction variable holds a reference to the Function object that called the basicFunction.

The caller property returns a Function object or null, so you can chain these until you get to the root of the call stack. You can iterate through a call stack in JavaScript with code similar to the following.

function basicFuction() {
   var caller = arguments.callee.caller;
   while(caller != null) {
      console.log(caller);
      caller = caller.caller;
   }
}

Unfortunately, there is no clean way to get the function name out of the Function object returned by the caller property. This is made slightly more difficult because somethings functions don’t have names if they are created anonymously. If you print or log a Function object, it displays the function definition in its entirety.

Fortunately, the JavaScript console object provides a trace function that will log to the web console the JavaScript stack trace.

function basicFunction() {
   console.trace();
}

If the above function is invoked from an on click event, the whole JavaScript track trace from the on click to the basicFunction function is logged out in the web console. In addition to the function names, the web console in Safari, Chrome, and Firefox have a link to navigate to the exact location your web application where the functions were called.


Jun 7 2012

The Cost of Doing it Wrong

As the saying goes, if a thing is worth doing, it’s worth doing well. It has been proven that doing a thing right the first time is most efficient and cost effective. But what is the cost of doing something wrong? In terms of money, I’ve seen cases where something is done incorrectly and then had to redone at a loss of $100k. In terms of time, you can model it in the following thought experiment.

If a task takes x amount of time to complete and it is done wrong the first time, how long does it take to fix it?  More than 4x. It takes to x amount of time to complete the task the first time, probably at least x amount of time to find out it was done wrong, another x amount to figure out what the first guy did, and finally x amount to fix it correctly.

We all can agree that time is money and if a task is done incorrectly it may cost at a minimum as much as four times as much as it would cost if done correctly the first time around.


May 29 2012

Formatting an Integer to String in Java

There are times when you need to format a integer or double value into a String, with the comma for values larger than a thousand. If you need to format a numeric value correctly based on the local formatting rules for numbers use the NumberFormat class. Different locales have different formatting rules, for example in France they use the comma as a decimal point where in the United States the comma is used for delimiting large numbers.

double val = 123456.78;
System.out.println(val); // 123456.78

// Use default locale to format string
String localFormat = NumberFormat.getNumberInstance().format(val);
System.out.println(localFormat); // 123,456.78
		
String frenchFormat = NumberFormat.getNumberInstance(Locale.FRANCE).format(val);
System.out.println(frenchFormat); // 123 456,78

May 16 2012

Retweet April 2012

From time to time I just blast tweets about software development, project planning, team dynamics, or whatever else comes to mind. Here is a synopsis of recent tweets and rants. If you want to follow the conversation follow me at techknow and/or juixe.

Software Development

  • Too often I’ve seen code that made me lose my lunch.
  • Sometimes source code is like the sausage factory where you don’t want to look what goes into an application.
  • One developer’s corner case is another user’s daily workflow.
  • Application logs are like money, you can always use more… Unfortunately they are like pennies, the more you have the more difficult it is.
  • Fix the problem, not the symptom. Some developers prefer to fix the symptom because they don’t know how to find the root cause itself.

Team Leadership

  • It is important to lead the way and then immediately get out of the way.
  • If it doesn’t make sense to me it is because you are not explaining it correctly.
  • Everyone has a right to their opinions but not everyone’s opinion is right.
  • Great ideas don’t belong to any one person. Great ideas are not unique to anyone. Great ideas stand on their own.
  • If you are safe in your comfort zone you’ll never be in the zone.
  • Even when I think outside the box, I am still in the zone.
  • There are no easy answers without hard choices.
  • It’s one thing to make sense and a completely different thing to be clear.
  • There are some things in life that are not meant for you to understand but to accept.

Product Placement

  • Things Apple should buy: Evernote, app TLD, Square, and my blog.
  • The Notes app on the iPhone badly needs an to support the undo and redo feature.
  • The new Google+ is the new New Coke.
  • If Google would have invented Polaroid, the film would be free but full of ads and a copy would be uploaded to the cloud.
  • Some of Google’s UI often looks and feels like the uncanny valley of design, it has a plastic aspect to it.
  • My other Tumblr is a Moleskine.
  • So much of the content I see in Pinterest seems to come from Tumblr…
  • Instagram has no ads, only available on mobile, Android support just added, not profitable, no web presence… Obviously worth $1 billion.
  • Instead of paying a billion in cash and stock why didn’t Facebook just pay a billion in Facebook Credits and likes.
  • Silicon Valley back of the envelop valuation math: Tumblr + Camera+ > Instagram therefore Tumblr + Camera+ = $10,000,000,000++.
  • I don’t understand @McDonalds economics… A whole McChicken sandwich costs $1 but ask for an extra BBQ sauce and you get charged $0.50.

Silicon Angels

  • Is it possible for the whole of Silicon Valley to jump the shark? If and when it does there will be a large splash.
  • Silicon Valley valuations are relative to previous largest valuation.
  • The Internet is paved with high valuations.
  • Frothyness is the new truthyness.
  • Frothy does a body good.

Randumb

  • I want to see the world in HD.
  • What do we want? Our way. When do we want it. All the time.
  • If someone says something that is factually untrue, it doesn’t mean they lied… It means you lied to yourself by believing it. #truth
  • One persons guest house is a other persons mansion.
  • Some people build walls, others bridges, I build BS radar detection systems.
  • Retweet, reblog, repin, remix, rinse, and repeat!
  • I think in numbers.
  • All language is a metaphor.
  • Trolls shall inherit the earth.