Programming Quick Reference « verdure
Programming Quick Reference
Friday, March 27th, 2009

This is a list of items that I use infrequently enough to have to lookup, but frequently enough that I feel it worthwhile to save a note to myself here.



    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


  • const:

    in ECMAScript edition 3 const is only future reserved. However Netscape’s respectively now Mozilla’s JavaScript implementation for JavaScript 1.5 and later already supports const e.g.

  • multidimensional arrays:
    var i;
    var myBox = new Array(3); // note the Cap A
    for (i = 0; i < myBox.length; i++)
    myBox[i] = new Array("a", "b", "c")
  • select / options:
    var n = mySelect.length;
    var optionValue =

    add(newoption, beforeoption) : beforeoption should be an object reference to an option except in IE, where it must be an integer representing the index of the option instead. To add an option to the end of the list, do not include any second parameter for IE, but enter null for FF.
  • try {
    document.myForm.mySelect.add(new Option(text, value, defaultSelected, selected), null);
    } catch (e) {
    document.myForm.mySelect.add(new Option(text, value, defaultSelected, selected));

  • assigning CSS classes to an object:
    mySelect.options[myIndex].className = "myNiftyStyle";
    IE (ver 6 at least) has limited support for styling form elements. Font color works. Padding and bolding does not. FF will strip spaces in javascript (and frustratingly displays &nbsp; literally), but supports more style properties.


  • nobr replacement class: .nobr {white-space: nowrap;}


  • Operator precedence:
    &&, ||, ? :, = += -=..., and, xor, or
    This leads to
    // "||" has a greater precedence than "or"
    $e = false || true; // $e will be assigned to (false || true) which is true
    $f = false or true; // $f will be assigned to false
  • constants:
    have global scope and by default are case sensitive. Only scalars may be defined as constants.
    $n = 8;
    define("MYSTRCONST", "a successful test");
    define("MYNUMCONST", $n); // assigning a constant via a variable
    $sum = 2 + MYNUMCONST + 3; // $sum stores 13
    echo "This is... " . MYSTRCONST . " ?"; // displays "This is... a successful test ?"
    echo "already added: " . $sum . " ?"; // displays "already added: 13 ?"
    echo "adding inline: " . (2 + MYNUMCONST + 3) . " ?"; //displays "adding inline: 13 ?"

    Note that the parentheses in the last line are required, else funny things happen, such as failing to display everything before the constant. “constant() is useful if you need to retrieve the value of a constant, but do not know its name. I.e. it is stored in a variable or returned by a function.”

    define("MAXSIZE", 100);
    $c = "MAXSIZE"; // store name of constant as a string
    echo MAXSIZE;
    echo constant($c); // same thing as the previous line

SQL, MySQL, SQL Server


  • Basics:
    C-n means hold down the Ctrl key while press the n key. M-n means hold down the Alt key while pressing the n key.

    • C-x C-f : open a file
    • C-x C-s : save current file
    • C-Shift-_ : (dash/underscore key) undo
    • C-x C-s : save current file
    • C-g : quit the command you were in the middle of
  • search/replace across multiple files
    • Create TAGS file in a terminal (defines which files to search through): etags –no-members source1.php source2.php source3.php
    • In emacs, create initial search/replace (regex) with M-x tags-search or M-x tags-query-replace.
    • Continue search of the same criteria with M-x tags-loop-continue, and then M-, for each continuation afterwards (that’s Alt plus comma) All files listed in TAGS will be looped through



Comments are closed.