Wednesday, November 30, 2005

removeAllChildNodes, getImmediateChildren (JavaScript)

Two functions for working with nodes via the W3C DOM (while they have only been tested on web pages, there is no reason why they won't work (with minor modifications) with anything that implements the W3C DOM and uses JavaScript/ECMAScript).

function removeAllChildNodes(node)
  if(!node || !node.childNodes) return;
  var nodeCount = node.childNodes.length;
  for(var i=nodeCount-1;i>=0;i--)
function getImmediateChildren(node, tagName)
  if(!node || !node.childNodes) return;
  if(!tagName) tagName = "*";
  var elements = document.getElementsByTagName(tagName);
  var nodeCount = elements.length;
  var children = new Array();
  for(var i=0;i<nodeCount;i++)
    if(elements[i].parentNode == node)
      children[children.length] = elements[i];
  return children;

Imagine the following HTML:

<div id="foo">
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3
        <li>Item 3.1</li>
        <li>Item 3.2</li>
    <li>Item 4</li>

If you then did removeAllChildNodes(document.getElementById("foo")) you would end up with an empty <div id="foo"></div>.

var foo = document.getElementById("foo");
var ul = foo.getElementsByTagName("ul")[0];
var ulitems = getImmediateChildren(ul, "li");

Would return the list items Item 1, Item 2, Item 3 and Item 4 (not Item 3.1 and Item 3.2 as they are not directly descended from ul)

Tags: ,

Saturday, November 26, 2005

The Uniform Server - Portable Apache / MySQL / PHP/Perl

The Uniform Server - run a web server off your external drive (for Windows based PC's). A useful way of developing your websites, no matter what PC you are using. No need to install anything. Server is Apache and includes MySQL, PHP and Perl. Can be used as a production/live web server (just copy the files over to the server hard drive).

Edit (17-Jan-06): Site is down, but you can still get it from Uniform Server.

Tags: , ,

Friday, November 25, 2005

ipconfig /all

If you run ipconfig /all in the command prompt in Windows it shows detailed info about your network adaptors. You may want to then print that information off. However it is in a command prompt window (where copying and pasting isn't exactly easy). Here is a batch file that opens up notepad with the information. When you close notepad, it then deletes the ipconfig.txt file that was created.


ipconfig /all > ipconfig.txt & start /wait notepad ipconfig.txt & del ipconfig.txt

Edit (27 Nov 2005):

This can be set up as a doskey macro to replace existing command, can pass on parameters that ipconfig accepts. So if you run this in the command prompt window, then type in ipconfig /?, it will show the help in notepad.

doskey ipconfig=ipconfig $* $g ipconfig.txt $T start /wait notepad ipconfig.txt $T del ipconfig.txt

Tags: ,

Wednesday, November 23, 2005

Validating with the W3C

The W3C has several useful validation services. Most are for the standards they have developed, but there is also one for web feeds (Atom / RSS). These are the ones I know of.

  • (X)HTML / MathML (plus some favelets you can add to your bookmarks)
  • Link Checker (checks for broken links)
  • CSS (Cascading Style Sheets)
  • Feeds (Atom / RSS)
  • P3P (Platform for Privacy Preferences)
  • RDF (Resource Description Framework)
  • XSV (XML Schema Validator)
  • SVG (Scalable Vector Graphics)

Tags: ,

Tuesday, November 15, 2005

Portable Development

There are quite a few freeware applications that run on an external drive. These sites have a list of them. The advantage of them is that you do not need to install anything (except maybe to get the files to copy to the drive). When you use these applications you can develop your applications or websites on any (Windows 2000/XP) PC that can read your drive.

An example of how portable development can be done is web development. If you follow the instructions at Apache/MySQL/PHP on a usb flash drive, you can run an Apache Server off of your drive, so you have a portable web development environment. If there is a text editor you like and it is portable (for example SciTE) you can edit your pages and test them with PortableFirefox without ever installing anything, then upload them to your site using PortableFileZilla.

Console is also a good application that improves you experience with the command prompt, mostly cosmetic changes (tranparent console background, background image, change font). You can set a batch script to run when it loads (by creating a batch script containing start \Console\console.exe -c "/e:on /f:on /k \Console\config.cmd", so you can add macros (that you could use to run your portable applications).

Example config.cmd

@echo off
doskey /insert
doskey filezilla = %cd%PortableApps\PortableFileZilla.exe $*
doskey firefox = %cd%PortableApps\PortableFirefox.exe $*

Another example of a useful application is MPUI - it allows you to play many video and audio formats, regardless of codecs installed on the host PC.

Tags: ,

Tuesday, November 08, 2005

The Ultimate getElementsByClassName

The Ultimate getElementsByClassName. Originally written by Jonathan Snook, this function has been improved by Robert Nyman. A very useful function if you want to get elements that all have the same class name. Supports searching for elements with multiple class names (i.e. class="one two").

Tags: , ,

Monday, November 07, 2005

PDF Database Report (MyGeneration)

PDF Database Report is a template for the MyGeneration code generator. It uses iTextSharp to generate the document. The report includes tables, foreign keys, indexes and views. Details for each column (name, data type, is nullable etc) is shown for each table and view selected.

Tags: , ,