Sunday, July 3, 2011

Samrter & better than "loop statements" With JavaScript Join() function


Al salam alikom ("hi all")
   Today we'll talking about amazing JavaScript function it's the "Join()" function, and I'll explain it with an easy example & little words

before the example let's see what is the definition of (join()) 

The join() method joins all elements of an array into a string, and returns the string.
The elements will be separated by a specified separator. The default separator is comma (,).

Syntax
----------------
 
Join(separator);

separator: Optional. The separator to be used. If omitted, the elements are separated with a comma

So, if we have an array and wee need to display it in html list ("ul")
we have to options

First solution:
--------------------


var arr = ["Cairo", "Alex", "Aswan"];
var list = "<ul><li>";
for (var i = 0; i < arr.length; i++) {
    if (i !== (arr.length - 1)) {
        list += arr[i] + "</li><li>";
    }
    else {
        list += arr[i];
    }
}
list += "</li></ul>"
;

Second solution:
-------------------
 which i recommend it and it's very easy & smart

var arr = ["Cairo", "Alex", "Aswan"];      
var list = "<ul><li>" + arr.join ("</li><li>") + "</li></ul>";

The two solutions have the same out and you have the choice to use any one of them, but i think (2) lines of code are better than (11) ;)

Sunday, June 26, 2011

(IF, ELSE IF and ELSE) with (? :) syntax

Al salam alikom ("hi all")
          all of us know how to write the IF : ELSE with this syntax 

(Condition) ? IF action goes here : Else action goes here;

today I'll explain how to write  IF, IF Else, and Else with this syntax with very simple sample :)



//Java Script
var x = 0;
(x < 0) ? alert("Error: Number can't be minus...!") : (x >= 1) ? alert(x) : alert("Zero");



// C#
int x = 0;
string result = (x < 0) ? "Error: Number can't be minus...!" : (x >= 1) ? x.ToString() : "Zero";

Easy and simple, wish you like it.

Thursday, April 28, 2011

List of reserved ports that preferred to avoid use it when creating a new web site for "share Point"


Each "SharePoint" developer or administrator know the issue of opening a website hosted on another port of  "80" on any different browser than "IE" Like (Chrome, FireFox, Safari, Opera, ...etc). 
At the past I used to search for a way to open these blocked ports for the different browsers, but once when I was searching for a solution for this issue for safari I found a very important piece of information that made me realize I was mistaken when I believe that those ports that I use are non-reserved, 
This info is a list of the reserved ports that we must avoid use it when creating a website for "SharePoint" or any website that use port number different than "80", and here is the ports list with a hint for each port reserved for



// The blocked port list matches the port blocking mozilla implements
// See http://www.mozilla.org/projects/netlib/PortBanning.html for more information
1,    // tcpmux        
7,    // echo    
9,    // discard        
11,   // systat  
13,   // daytime        
15,   // netstat
17,   // qotd            
19,   // chargen
20,   // FTP-data
21,   // FTP-control      
22,   // SSH            
23,   // telnet  
25,   // SMTP    
37,   // time    
42,   // name    
43,   // nicname
53,   // domain
77,   // priv-rjs
79,   // finger  
87,   // ttylink
95,   // supdup  
101,  // hostriame
102,  // iso-tsap
103,  // gppitnp
104,  // acr-nema
109,  // POP2    
110,  // POP3    
111,  // sunrpc  
113,  // auth    
115,  // SFTP    
117,  // uucp-path
119,  // nntp    
123,  // NTP
135,  // loc-srv / epmap        
139,  // netbios
143,  // IMAP2
179,  // BGP
389,  // LDAP
465,  // SMTP+SSL
512,  // print / exec        
513,  // login        
514,  // shell        
515,  // printer        
526,  // tempo        
530,  // courier      
531,  // Chat        
532,  // netnews      
540,  // UUCP      
556,  // remotefs  
563,  // NNTP+SSL
587,  // ESMTP
601,  // syslog-conn
636,  // LDAP+SSL
993,  // IMAP+SSL
995,  // POP3+SSL
2049, // NFS
4045, // lockd
6000, // X11      
0

And if you need more information go  there