Welcome to my website. I am always posting links to photo albums, art, technology and other creations. Everything that you will see on my numerous personal sites is powered by the formVistaTM Website Management Engine.

icon.linkedin.jpgicon.twitter.jpg

  • Subscribe to this RSS Feed
  • Accessing JSON Data Under IE7
    06/02/2011 1:57PM

    Given the following JSON object:

    var var_affectedAreas = {
    ??? ??? 'areaCount' : 6,
    ??? ??? 'areasList': [
    ??? ??? ????????????? {'enum': 'FILE', 'val': 'F'},
    ??? ??? ????????????? {'enum': 'REGISTRY', 'val': 'R'},
    ??? ??? ????????????? {'enum': 'PROCESS', 'val': 'P'},
    ??? ??? ????????????? {'enum': 'MEMORY', 'val': 'M'},
    ??? ??? ????????????? {'enum': 'NETWORK', 'val': 'N'},
    ??? ??? ????????????? {'enum': 'OTHER', 'val': 'O'}
    ??? ??? ]
    };

    You would think (and rightly so, at least under Firefox) that you would be able to access data in this object via the following:

    areaCell = var_affectedAreas.areasList[var_areasCount].enum;
    areaCell = eval("var_affectedAreas.areasList[" + var_areasCount + "].enum");
    areaCell = eval("var_affectedAreas.areasList['" + var_areasCount + "'].enum");

    However, IE7 does not like that syntax and throws syntax errors.

    The following syntax works under both IE7 and Firefox.

    areaCell = var_affectedAreas["areasList"][var_areasCount]["enum"];


  • Setting up Cygwin, Linux Command Line, on a Windows Box
    05/23/2011 3:59PM

    For all of you Linux (and Unix) users who are used to the Linux command line there is an application called Cygwin.? Not only does it allow you to use the familiar command line commands but it also includes the ability to execute bash and csh shell scripts on a Windows machine.

    When installing it, here are a few additional packages you'll probably want to include:

    vim, ncurses, tcsh

    Simply type them into the search field and then check off those packages.

  • Applying Order to JSON Data When Rendering to a Page
    05/20/2011 9:31AM

    It is very convenient to pass JSON data from client to server and between different server-side components.? However, JSON data is an inherently unordered data structure and in many cases a developer will want to render a list of items in some specified order.

    One way that I found to do so is to append an integer to the keys in your data when generating the JSON data.? For example, you might be iterating through a database result set and want to maintain the order in which the result was returned.? When adding your keys append '_n' to the string.

    Then, when you access the JSON data (with JavaScript, and jquery, and assuming a reference to your JSON data is 'data') first get a count of the number of objects in your JSON container:

    $counter = 0;

    $.each(data, function(key, value) {

    ? ?? $counter++;

    ???? alert(key + ': ' + eval(value.id));

    });

    Now we have a count of the number of items in the object and run a for loop using the $counter variable.

    for(var $rowCounter = 0; $rowCounter < $counter; rowCounter++) {

    ? ?? // Access your data using the $rowCounter value

    ? ?? alert("row " + $rowCounter + " = " + eval("data.row_" + $rowCounter));

    }

  • Opening a New Window From a Web Page with Javascript that is SEO Friendly
    05/05/2011 11:01AM

    The days of <a href="#" target="_blank"></a> are long gone.? The way to open a new window with a link is to do it using the javascript window.open() method via an onclick callback.

    However, you still want to make your pages SEO friendly, so you don't want to go about generating links with href="#".? The way to do it is as follows:

    Javascript:

    <script>

    function openNewWindow(url) {

       window.open(url);

    }

    </script>

    HTML:

    <a href="someURL.html" onclick="openNewWindow('someUrl.html');return false;">Link</a>

    When implementing links this way, you still include the url in the href attribute making the page SEO friendly and implement the new window functionality via your javascript function.? You must make sure to include return false; in your onclick attribute so that the link doesn't load in the window from which the original click was issued.

  • Using bash Shell to Rename Files With Spaces
    04/20/2011 10:01AM

    The following is a shell command that you can use to rename any file that contains spaces.? Without the quotes surrounding the $file reference and the echo command it will fail.

    In this example, we rename anything that is .htm to .html

    for file in *.htm ; do mv "$file" "`echo "$file" | sed 's/\(.*\.\)htm/\1html/'`" ; done

Advanced Search

Categories

Archives