Oct 12 2019

Digital Inheritance and Data Donor

Software companies like Facebook, Apple, Google, and the like are collecting and amassing large amounts of personal information about each of us.  A large portion of this information is posts, tweets, texts, pictures we’ve taken and published.  Additionally, there is a large about of derived and meta data such as our search history and geo-location data as we go throughout our day.

Much of the public discussions around personal information is around privacy.  But as of late, I’ve been concerned about being able to leave our digital footprint onto our descendants or in the public domain.  For example, I’ve taken over 500,000 photographs in the last 10 years, admittedly I’m sure most of them are not great, but this data set of images can be useful in a historical context.

Companies like Facebook and Apple should enable features to allow their users to designate how their data can be used, and ultimately shared, after death.  It should be possible to build the means to determine what type of data to either share with our descendants or public domain at a specified time after we’ve passed.

Of course, a feature that allows for data, and even accounts, to be inherited is not trivial.  This task is made even more difficult because there is some data we would not like to reveal even after we’ve been dead and gone.  And of course, no one wants to manually sort thousands of posts, hundreds of thousands of photos, millions of text messages for potentially embarrassing or possibly misunderstood items.  Such system needs to work effortlessly behind the scenes.

 


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