Tuesday, August 11, 2009

24 Hours of Nonstop SQL Server Training

Get ready for brain overload, 24 hours of nonstop SQL Server training by experts all around the world! And best of all it is FREE and you don't have to go anywhere to get this training. Here is the link to this training http://24hours.sqlpass.org.

Anyway the reason for my post is not to propagate about this event, though it is not a bad idea, but to share a little javascript. When I went to register for sessions, all the start times are listed in GMT and I wanted to be able to see the times in local timezone format. Here is a sample screenshot of how the start times are listed:

If you are using IE8, it is really easy to run custom javascript code on any page, you simply press F12 and go to the Script tab in the Developer Tools window and then run the following javascript code:

var sp = document.getElementById("schMeetings");
var timeSpans = sp.getElementsByTagName("span");
for (var i = 0; i < timeSpans.length; ++i)
if (timeSpans[i].id.indexOf("lblScheduletime") > 0)
var dtStr = timeSpans[i].innerText;
var dt = new Date(dtStr.substr(0, dtStr.length-"+00:00".length));
timeSpans[i].innerHTML += " [" + dt.toLocaleString() + "]";

Once I ran this javascript snippet, I can see the start times in my local timezone format as shown below:

I really like the new IE8 Developer Tools and this is just a sample of what you can do with custom javascript on any web page you visit.

Happy Coding,


Thursday, April 16, 2009

Visio Flow Diagram "Loop Limit" example/sample

I was looking for an example of how the "Loop Limit" shape can be used in a Flow Diagram and could not find any diagrams either in Microsoft documentation or on their website that show the sample usage of this shape. Most of the pages on the web are also not helpful either. Most web pages are either people asking about how to use this shape or a couple of blogs that basically rehash Visio online documentation that lists all the shapes that are available for Flow Diagrams.

After searching for a while, I finally found a PDF document by Roxaneh Chamlou on FAA site that has it. I wish Microsoft has concise sample diagrams that show how some of these non-standard shapes are intended to be used.

Here is a sample diagram that I have created taking a cue from the above PDF document:

This diagram should be self explanatory and I would love to hear what you think about it? Is there a better way to show the loop either with or with out "Loop Limit" shape?

Hope this helps someone out there.

Happy Drawing!


Friday, January 16, 2009

Checks if a given value is Number or not in Javascript

The other day I needed to check via javascript if the text entered in a textbox is a valid or not. I know I can use the built-in isNaN function, but wanted to make sure that would in work all the scenarios. So, I searched online, but I found a couple of examples on the web, but they were using regular expression to check. I am not sure why they are using regular expressions, when you have isNaN function.

I created a test function to make sure isNaN works in all the scenarios and found that it works for almost everything I tried except for three values, they are null, empty string and a string with just spaces. For these three inputs, it returns false but you really want it to return true since obviously they are not valid numbers. I wrote an helper function to get around that and the following page shows the helper method as well as the test function I wrote to validate this helper function:

// Checks if a given value is a valid number or not
// The argument could be any of the following:
// a) A number itself
// b) Number in quotes, i.e. number stored as string
// c) Number could be in scientific format
// d) An object

function isNumber(val)
  // we need to explicitly handle null values
  // because isNaN returns false when it should return true 
  if (null == val) return false;

  // if it is an empty string or a string with just spaces
  // isNaN returns false, but we really need it to return true
  // this expression will remove spaces if the given value is a string type
  if (typeof(val) == "string")
   val = val.replace(/\s*/g, "");
  if (val == "") return false;

  return !isNaN(val);

// test function to test the isNumber function
function isNumber_Test(val, expResult)

  var dblQuote = '';
  if (typeof(val) == "string")
   dblQuote = '"';

  var actResult = isNumber(val);

  var clr = 'green';
  if (actResult != expResult)
   clr = 'red';

  document.write('isNumber(' + dblQuote + val + dblQuote + ')');
  document.write('' + actResult + '');
  document.write('' + expResult + '');
By the way, I am using a Javascript utility called SyntaxHighlighter, to render this code. If you have not already used this utility, I would highly recommend you check it out.

Here are some test results of isNumber() function:

Test isNumber() Function

Expression Result Expected Result

Happy coding,