Javascript execute function having name in string format

If you want to execute the function having name in string format use the following code.

Sample 1

 
var fn = 'functionName';
if(typeof fn === 'function') {
    fn.call(parameter1,parameter1,..,..,..);
}

Sample 2

 
var fn = window['functionName'];
if(typeof fn === 'function') {
    fn(parameter1,parameter1,..,..,..);
}	

MySQL – FOREIGN KEY Constraints i.e RESTRICT | CASCADE | SET NULL | NO ACTION

This post contains the information about the MySQL – FOREIGN KEY Constraints i.e RESTRICT | CASCADE | SET NULL | NO ACTION, you will get more information on http://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html

  • CASCADE: Delete or update the row from the parent table, and automatically delete or update the matching rows in the child table. Both ON DELETE CASCADE and ON UPDATE CASCADE are supported. Between two tables, do not define several ON UPDATE CASCADE clauses that act on the same column in the parent table or in the child table.
    Note: Currently, cascaded foreign key actions do not activate triggers.
  • SET NULL: Delete or update the row from the parent table, and set the foreign key column or columns in the child table to NULL. Both ON DELETE SET NULL and ON UPDATE SET NULL clauses are supported.
    If you specify a SET NULL action, make sure that you have not declared the columns in the child table as NOT NULL.
  • RESTRICT: Rejects the delete or update operation for the parent table. Specifying RESTRICT (or NO ACTION) is the same as omitting the ON DELETE or ON UPDATE clause.
  • NO ACTION: A keyword from standard SQL. In MySQL, equivalent to RESTRICT. The MySQL Server rejects the delete or update operation for the parent table if there is a related foreign key value in the referenced table. Some database systems have deferred checks, and NO ACTION is a deferred check. In MySQL, foreign key constraints are checked immediately, so NO ACTION is the same as RESTRICT.
  • SET DEFAULT: This action is recognized by the MySQL parser, but both InnoDB and NDB reject table definitions containing ON DELETE SET DEFAULT or ON UPDATE SET DEFAULT clauses.

XAMPP – Add virtual domain name to your localhost

1. First go to the location C:\Windows\System32\Drivers\etc
2. Open “hosts” file in notepad
3. Add following line at the end of file

   127.0.0.1       mydomain.com
   

4. Now test the virtual domain by typing the “mydomain.com” in browser url. You will see XAMPP main page. If not the check this porcess again.

Point your website folder to your virtual host (XAMPP Steps)
1. Open your httpd-vhosts.conf file in conf directory of Apache webserver folder

D:\xampp\apache\conf\extra\httpd-vhosts.conf

2. Edit the file using Notepad/ Edit Plus & add following line at the end of file.

	<VirtualHost *:80>
	    ServerAdmin webmaster@dummy-host2.example.com
	    DocumentRoot "D:/xampp/htdocs"
	    ServerName localhost
	    ##ErrorLog "logs/dummy-host2.example.com-error.log"
	    ##CustomLog "logs/dummy-host2.example.com-access.log" common
	</VirtualHost>

	<VirtualHost *:80>
	    ServerAdmin webmaster@dummy-host2.example.com
	    DocumentRoot "D:/xampp/htdocs/project_folder_name"
	    ServerName mydomain.com
	    ##ErrorLog "logs/dummy-host2.example.com-error.log"
	    ##CustomLog "logs/dummy-host2.example.com-access.log" common
	</VirtualHost>
	

3. Save this file. Restart your XAMPP server. Now type http://mydomain.com You’ll see the index page of your project.

Apache Processes

  • When you start apache, you are invoking a single process which will be denoted in Linux as the parent process.
  • This parent process will be owned by root and it will spawn some set number of child processes these children will be owned by the apache user as denoted by this directive (it is usually named apache)
  • Whenever a request arrives, it is serviced through one of the available child processes note: we refer to the parent and children as threads instead of processes as they are all running the same executable code but have their own internal data/stack space
  • At any one time, there may be dozens or more children running children threads are persistent – they do not die as soon as they finish a request but instead may persist until they have been around for awhile, or until the parent thread kills it off
    To establish the number of children that should be available at any time, use the directives on the next slide

List of points need to take care while configuring Apache

  • ServerRoot – this specifies location in the Linux file system where the httpd.conf file will be found.
  • Document Root – DocumentRoot – this specifies the location in the Linux file system where the html files and other web documents will be stored.
  • ServerName – this is the IP alias of the server.
  • DirectoryIndex – a list of files that the server will attempt to find in a given directory if no file name is given in the URL.
  • User, Group – define the user and group that will own the apache processes.
  • ServerSignature – this specifies whether a “signature” should be attached to a web page returned as the result of an error or directory listing.
    MIME is Multipurpose Internet Mail Extension
  • Listen – to specify (and alter) the IP address(es) and port(s) that apache will listen to for incoming requests
  • Other TCP directives include
    • KeepAlive – on or off
    • MaxKeepAliveRequests – defaults to 100
    • KeepAliveTimeout – default is 15 (seconds)

HTML5 Server-Sent Events like nodejs but one directional

HTML5 Server-Sent Events allow a web page to get updates from a server. Same as websocket (nodejs). Only difference is websocket is bidirectional & HTML5 Server-Sent Events single direction (from server) uses HTTP protocol.

I have come across two site where you got the detail explanation about HTML5 Server-Sent Events
http://www.w3schools.com/html/html5_serversentevents.asp
http://www.html5rocks.com/en/tutorials/eventsource/basics/

Thanks to w3schools & Eric Bidelman for these articles.

Install SSL certificate on WAMP Server.

During installing the SSL on WAMP server, I got best article on http://www.phpjoel.com/2011/04/07/installing-ssl-using-openssl-on-a-wamp-localhost/ & I refer this articles & described the process in details.

Detail steps are as follows.

1. Install OpenSSL
First of all, you need OpenSSL for this to work. OpenSSL comes with wampserver and can be found in the following folder.

D:\wamp\bin\apache\Apache2.4.4\bin\openssl.exe

If wamp server does’t contains OpenSSL then you have to download & install it.

2. GENERATE KEY
In the command prompt, go to D:\wamp\Apache2\bin and run the following command

D:\wamp\bin\apache\Apache2.4.4\bin>openssl req -new > webserver.csr

Processing Result:

Loading 'screen' into random state - done
Generating a 1024 bit RSA private key
...++++++
..++++++
writing new private key to 'privkey.pem'
Enter PEM pass phrase: Enter password
Verifying - Enter PEM pass phrase: Enter password
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]: Add your country code
State or Province Name (full name) [Some-State]: Add your state name
Locality Name (eg, city) []:Add your City
Organization Name (eg, company) [Internet Widgits Pty Ltd]: Add your Company Name
Organizational Unit Name (eg, section) []: Add your Unit Name
Common Name (e.g. server FQDN or YOUR name) []: Add your Domain Name
Email Address []: Add your Email Address

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:Enter password
An optional company name []:Enter optional company name

When the command finishes, it has created several files, including privkey.pem, in

D:\wamp\bin\apache\Apache2.4.4\bin

3. REMOVE PASSPHRASE
Run the following command:

D:\wamp\bin\apache\Apache2.4.4\bin>openssl rsa -in privkey.pem -out webserver.key

Processing Result:

Enter pass phrase for privkey.pem:
writing RSA key

You will be prompted for the pass phrase from the previous step. The RSA key is written and the file webserver.key is now available in the folder.

4. CONVERT INTO SIGNED CERTIFICATE

Run the following command to create a certificate which expires after one year:

openssl x509 -in webserver.csr -out webserver.cert -req -signkey webserver.key -days 365

Processing Result:

Loading 'screen' into random state - done
Signature ok
subject=/C=country code/ST=state name/L=city name/O=orgnization name/OU=orgnization unit name/CN=localhost/emailAddress=email address
Getting Private key

5. STORE CERTIFICATE FILES

Create a folder D:\wamp\OpenSSL with the following subfolders:

/certs
/crl
/newcerts
/private

Copy the following files to /certs/:

webserver.cert
webserver.csr
webserver.key

Copy the following files to /private/:

.rnd
privkey.pem

6. MODIFY HTTPD-SSL.CONF (D:\wamp\bin\apache\Apache2.4.4\conf\extra)

Change the following lines, adjusting the email address and the paths to your settings:

<VirtualHost>
SSLCipherSuite HIGH:!aNULL:!MD5
#SSLCipherSuite RC4-SHA:AES128-SHA:HIGH:MEDIUM:!aNULL:!MD5
#SSLHonorCipherOrder on 
SSLPassPhraseDialog  builtin
DocumentRoot "c:/Apache24/htdocs"
ServerName www.example.com:443
ServerAdmin admin@example.com
ErrorLog "D:/wamp/logs/mysecuresite_error_log"
TransferLog "D:/wamp/logs/mysecuresite_access_log"
SSLCertificateFile "D:/wamp/OpenSSL/certs/webserver.cert"
SSLCertificateKeyFile "D:/wamp/OpenSSL/certs/webserver.key"
SSLCARevocationPath "D:/wamp/OpenSSL/crl"
CustomLog "D:/wamp/logs/ssl_request_log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>

7. MODIFY OPENSSL.CNF (D:\wamp\bin\apache\Apache2.4.4\conf)

Modify the base directory:

dir	 = D:/wamp/OpenSSL

8. MODIFY HTTPD.CONF

Uncomment following lines.

Include conf/extra/httpd-ssl.conf
LoadModule ssl_module modules/mod_ssl.so

Check that port 443 is open by running the following in the command prompt:

netstat -an | more

9. Restart Apache.

Create XML from array. (Array to XML)


function arrayToXml($root_element_name,$array){
	$xml = new SimpleXMLElement("<?xml version=\"1.0\"?><{$root_element_name}></{$root_element_name}>");
	
	function createXml($xml, $array){
		if(is_array($array) && count($array) > 0){
			foreach($array as $key => $value){
				if(is_array($value)){
					$xml=$xml->addChild($key);
					createXml($xml, $value);
				}else{
					$xml->addChild($key, $value);
				}
			}
		}
	}
	
	createXml($xml, $array);
	return $xml->asXML();
}

$array = array('node1Key' => 'nodeV1','node2Key'=> 'nodeV2', 'node3Key' => array('node3childNode1Key' => 'node3CV1'));
echo arrayToXml('apiResponse',$array);

Output

<?xml version="1.0"?>
<apiResponse>
	<node1Key>nodeV1</node1Key>
	<node2Key>nodeV2</node2Key>
	<node3Key>
		<node3childNode1Key>node3CV1</node3childNode1Key>
	</node3Key>
</apiResponse>