Archive for November, 2011

I’ve been working with JSon services quite a bit these days, and one of the big issues with JSon to Javascript translation is the Date element from server side. Since JSon doesn’t return a valid Javascript date object (which in my mind, was a very poor design at the implementation of the JSon form factor), it is up to the developer to make this happen. I have written a simple Javascript function that translates from the JSon format to a user-friendly format here:


Code Snippet
  1. function formatDate(dateToFormat){
  2.     var d = new Date(parseInt(dateToFormat.substr(6)));
  3.     var day = d.getDay();
  4.     var m = d.getMonth() + 1;
  5.     var month = (m < 10) ? '0' + m : m;
  6.     var yy = d.getYear();
  7.     var year = (yy < 1000) ? yy + 1900 : yy;
  8.     var hour = d.getHours();
  9.     var min = d.getMinutes();
  11.     return (day + "/" + month + "/" + year + " " + hour + ":" + min);
  12. }


Javascript usage is as follows:



This function can be modified to fulfill pretty much any date requirement you have, and can also just return a dynamic JS Date object if you would like.


Recently, when I was working on a project that contained a WCF service that I was having problems with. i deleted the service, but forgot the delete the reference to the service within my web.config file. Funny thing though, Visual Studio will let this compile (if you have two independent references to the same service, for configuration) The thing is, though, when you try to consume the service, you will come upon errors included the that of which you can see at the top of this article.

The solution to this was easy, just delete the old reference, and ensure there is only a single reference to the service in question. A simple solution to a problem that could have easily been avoided when I replaced my service.

Just something to watch out for, if you come upon it, you may want to check your service declarations within your web.config and make sure you’re declaring the reference, only once.

I am working on troubleshooting an aspect of one program, and had a situation where I wanted to remove all text in between parenthesis (from an output block), and leave the text within the parenthesis intact, and each on it’s own line. Obviously, this can be done manually, but I had a ton of records, and prefer finding find/replace solutions for situations like this. I ended up creating a wildcard: \)*\(*\(

The replace keyword I used was ^p, which inserts a new line in place of the text it replaces.

The first and last record must be manually removed, but this did the majority of the work for me, and I’m happy. I don’t claim to be a regular expression expert in any way, so I’m sure there may be a better way about this, but I figured I would share anyways.