Monday, August 29, 2011

MS SQL: query to add column

ALTER TABLE {TABLENAME}
ADD {COLUMNNAME} {TYPE} {NULL|NOT NULL}
CONSTRAINT {CONSTRAINT_NAME} DEFAULT {DEFAULT_VALUE}

i.e:

ALTER TABLE Protocols ADD ProtocolTypeID int NOT NULL DEFAULT(1);

Friday, August 26, 2011

HTML DOM: Remove all items(childrens) from div

myDiv = document.getElementById('light');

while (myDiv.hasChildNodes()) {
    myDiv.removeChild(myDiv.lastChild);
}

Reference:

Thursday, August 25, 2011

HTML DOM with Javascript: why DOM instead innerHTML

DO NOT use innerHTML, use DOM.

Althought innerHTML is supposed to be faster than DOM, there are some reasons that make DOM the best option to use HTML documents:
  • innerHTML IS NOT A STANDART, it is a Microsoft own (also outerHTML is).
  • It's supposed that in the future innerHTML won't work propertly in xHTML based on MIME type application/xhtml+xml documents.
  • One of the main diferences between innerHTML and DOM is that innerHTML is a string and DOM is a hierarchical object structure (tree). Insert a string in an object is a complete "botch"
  • Using and innerHTML string, the interaction with the object is lost.


Creating an element:

// innerHTML
document.getElementById("contenedor").innerHTML =
                    "<div id=\"capa\" >Texto<!--comentario--></div>";

// DOM
div = document.createElement("div");
div.setAttribute("id", "capa");
texto = document.createTextNode("Texto");
div.appendChild(texto);
div_comentario = document.createComment("comentario");
div.appendChild(div_comentario);
document.getElementById("contenedor").appendChild(div);



Getting text of an element:

//innerHTML
texto = document.getElementById("contenedor").innerHTML

//DOM
texto = document.getElementById("contenedor").firstChild.nodeValue;


Creating multiple elements:

//innerHTML
data = new Array("one","two","three");
mHTML = "<ul>";
for(i=0; i<data.length; i++) {
mHTML+="<li>" + data[i] + "";
}
mHTML+="</ul>";
document.getElementById("contenedor").innerHTML = mHTML;

//DOM
data = new Array("one", "two", "three");
eUL = document.createElement("ul");
for(i=0; i<data .length; i++) {
eLI = document.createElement("li");
eLI.appendChild(document.createTextNode(data[i]));
eUL.appendChild(eLI);
}
document.getElementById("contenedor").appendChild(eUL);

Source:
http://alfonsojimenez.com/uncategorized/no-uses-innerhtml-usa-dom/

Thursday, August 18, 2011

Excel 2007 Formula : count values in range

The objective of the formula is to count how many values of the column B (B2:B11) are between some specific values i.e 1,2 and 1,3:

The formula of the cell F2 is 

=CONTAR.SI($B$2:$B11;CONCATENAR(">=";D2)) - CONTAR.SI($B$2:$B$11;CONCATENAR(">=";E2))



Tuesday, August 16, 2011

windows 7: Hide/show disk partitions

Hide:
1.Type “diskpart” in run command box without quotes. (A command window will get opened)
2.Then type “list volume“. (Your hard disk partitioned volumes will be listed)
3.Now type “select volume <volume number>” – (Volume number is the numeric variable which is shown in the volume listing)
4.Type “remove letter <volume letter> – (Volume letter is the alphabetic character of the drive such as C,D,E,F…Z)

Show:
1.Type “diskpart” in run command box without quotes. (A command window will get opened)
2.Then type “list volume“. (Your hard disk partitioned volumes will be listed)
3.Now type “select volume <volume number>” – (Volume number is the numeric variable which is shown in the volume listing)
4.Type “assign letter <volume letter> – (Volume letter is the alphabetic character of the drive such as C,D,E,F…Z)

Reference:
http://www.ethicalhackers.in/downloads/articles/how-to-hide-hard-disk-partitions-in-windows.html

Thursday, August 11, 2011

ExtJS (2.2.1): select item on a ComboBox Programmatically


//The store's data definition must have at least a data.id field defined  
set_combobox_value_from_store = function (combobox, valueField, value) {
//Get a reference to the combobox's underlying store
var store = combobox.getStore();
store.load({
    callback: function () {
        //Find item index in store
        var index = store.find(valueField, value, false);
        if (index < 0) return;
        //Get model data id
        var dataId = store.getAt(index).data.Id;
        //Set combobox value and fire OnSelect event
        combobox.setValue(dataId);
    }
});

watch out the change I made on the last line from que reference link:
// before
combobox.setValueAndFireSelect(dataId); // throws setValueAndFireSelect methos doesn''t exist
// value
combobox.setValue(dataId);

reference:
http://www.humbug.in/stackoverflow/es/extjs-combobox-despues-de-reload-tienda-dont-valor-de-conjunto-3781767.html

Wednesday, August 10, 2011

Java: String trim method


import java.lang.*;

public class StringTrim{
  public static void main(String[] args) {
  System.out.println("String trim example!");
  String str = " RoseIndia";
  System.out.println("Given String :" + str);
  System.out.println("After trim :" +str.trim());
  }
}

Output:


String trim example!
Given String :  RoseIndia
After trim :RoseIndia


Source:
http://www.roseindia.net/java/beginners/StringTrim.shtml

Tuesday, August 2, 2011

Java: iterate List


          String sArray[] = new String []{"Array 1", "Array 2", "Array 3"};

 //convert array to list
 List lList = Arrays.asList(sArray);

          //iterator loop
 Iterator<String> iterator = lList.iterator();
 while ( iterator.hasNext() ){
     System.out.println( iterator.next() );
 }

          //for loop
 for (int i=0; i< lList.size(); i++)
 {
 System.out.println( lList.get(i) );
 }

          //while loop
 int j=0;
 while (j< lList.size())
 {
 System.out.println( lList.get(j) );
 j++;
 }
Source:
http://www.mkyong.com/java/how-do-loop-iterate-a-list-in-java/

Java: iterate info from ResultSet


ResultSet rs = stmt.executeQuery(query);
      ResultSetMetaData rsmd = rs.getMetaData();

      PrintColumnTypes.printColTypes(rsmd);
      System.out.println("");

      int numberOfColumns = rsmd.getColumnCount();

      for (int i = 1; i <= numberOfColumns; i++) {
        if (i > 1) System.out.print(",  ");
        String columnName = rsmd.getColumnName(i);
        System.out.print(columnName);
      }
      System.out.println("");

      while (rs.next()) {
        for (int i = 1; i <= numberOfColumns; i++) {
          if (i > 1) System.out.print(",  ");
          String columnValue = rs.getString(i);
          System.out.print(columnValue);
        }
        System.out.println("");
      }

Source:
http://www.java2s.com/Code/Java/Database-SQL-JDBC/Outputdatafromtable.htm