Development Journal
A few handy Javascript Methods
Nov 6th
So I’ve been doing a LOT of Javascript programming in the last few days and I ran into a few limitations of the language or constructs within the language. For example, certain versions of IE do not support the Array.indexOf() method. Another problem I ran into is that the Javascript language does not contain a method for performing deep copies on objects. So after some Googling I found a few ways around the aforementioned problems. The first one (indexOf) is as follows:
!Array.indexOf ? function (o) {
var l = this.length + 1;
while (l–) {
if (this[l - 1] === o) return l – 1;
}
return -1;
} : function (o) { return (this.indexOf(o) !== -1); }
);
The above code will add the ‘findObject’ method to your Array objects. Then you can use that instead of indexOf() and be guaranteed that it will work regardless if the browser supports indexOf or not.
The second one (deep copying) can be circumvented by creating a helper method which will perform the copy for you:
//public method
getCloneOfObject: function(oldObject) {
var tempClone = {};
if (typeof(oldObject) == "object")
for (prop in oldObject)
// for array use private method getCloneOfArray
if ((typeof(oldObject[prop]) == "object") &&
(oldObject[prop]).__isArray)
tempClone[prop] = this.getCloneOfArray(oldObject[prop]);
// for object make recursive call to getCloneOfObject
else if (typeof(oldObject[prop]) == "object")
tempClone[prop] = this.getCloneOfObject(oldObject[prop]);
// normal (non-object type) members
else
tempClone[prop] = oldObject[prop];
return tempClone;
},
//private method (to copy array of objects) – getCloneOfObject will use this internally
getCloneOfArray: function(oldArray) {
var tempClone = [];
for (var arrIndex = 0; arrIndex <= oldArray.length; arrIndex++)
if (typeof(oldArray[arrIndex]) == "object")
tempClone.push(this.getCloneOfObject(oldArray[arrIndex]));
else
tempClone.push(oldArray[arrIndex]);
return tempClone;
}
};
Just thought I’d share those with everyone. Credit for the majority of the deep copy code goes to http://blog.pramatiservices.com/deep-copy-in-javascript/ and credit for the findObject code goes to someone other than me, but I didn’t bookmark the link so I can’t find it again. Sorry
FIX: When you undock some windows or change the window layout in the Visual Studio 2008 Service Pack 1 IDE, the IDE crashes
Oct 27th
I just thought I re-post this incase anybody stumbled upon my blog before they landed on the Microsoft page that had the fix for IDE crashes. I experienced this only one time when I was moving/undocking windows.
Enjoy.
Templatize Tool
Jul 18th
I recently wrote up a template engine tool called Templatize. It started as a tool for my girlfriend so she could quickly generate HTML pages from CSV rows for use on eBay, but then quickly grew into a more robust template tool.
Basically it takes a set of input data, containing multiple entities (rows), each with multiple properties (columns), formatted from some type of delimited text file. Then it takes in a master template file and spits out multiple “data-injected” versions of that template.
View the full page here.
CTask-Lite on GitHub
Jul 2nd
Alright, I’ve finally put my open-source project website woes to rest. I successfully published the first version of CTask-Lite out on GitHub. It can be found here: http://github.com/cdunlap/ctask-lite
CTask-Lite is an easy to install, configure, theme, and use task management system. It is aimed at tiny teams working on ‘open’ projects. What I mean by open is that they don’t care who sees what (because there is no user/role management capability in it).
The Wiki for CTask-Lite is here: http://wiki.github.com/cdunlap/ctask-lite
Spread the word! Download it, use it, mangle it, hack it, fork it, etc.
Why is open source project hosting annoying and not playing nice with me?
Jul 2nd
I wrote a neat little web-based task system in PHP, jQuery, and SQLite last night and wanted a place to put it so I could give it to the world (and maintain my source code).
I checked out Google code, where I have placed several projects of mine. I successfully created a project, but when I’d try to check in the code, the SVN server wasn’t available. At the same time, I’d try to click the “Source” tab on the project that I just created and I’d get an HTTP 500 from Google (which is incredibly rare). So I marked that project for deletion from Google Code.
Then I went over to Source Forge. Source Forge is having issues. I couldn’t get their site to load at the time that I tried, again, HTTP 500 errors. Though I did get an email from them a few days ago saying they were going to be pushing a new UI to their site soon. The email said the service interruptions were only going to be for a few minutes at the most. Lets just say it was more than a few minutes, so I scrapped that idea.
Then I remembered a guy at work recommended GitHub. I’m really new to Git and so far I don’t like it. I find it more difficult to use than SVN–though it is faster by far. So I get the code put up on GitHub just fine, but now I can’t edit the repository details in the admin area. Every time I try to change the project website or description it responds with “Name is already taken”. Ok, minor annoyance. Ignoring that, I went over to the downloads area to upload my ZIP containing the final v1.0 build of the project. It gets 100% done and then I get a HTTP 500 from GitHub. I try to go back to the project page but now I’m getting a HTTP 500 error anytime I try to do anything with my project. Not all of GitHub… my project page. I seem to be the only one affected by this.
So, I’m a bit frustrated at the moment. I guess I’ll start working on one of my closed-source projects and call it a night.