Pages

Tuesday, August 20, 2013

Removing the special chaters from a string using user defined function using PHP

1) Function
DELIMITER //
CREATE DEFINER=`platformuser`@`localhost` FUNCTION `fn_RemoveSpecialChars`(`pString` CHAR(50)) RETURNS char(50) CHARSET latin1
    DETERMINISTIC
BEGIN
  DECLARE i, len SMALLINT DEFAULT 1;
  DECLARE CleanString varchar(1000) DEFAULT '';
  DECLARE c CHAR(1);
  DECLARE regx INT(1);

  IF pString IS NULL
  THEN
    RETURN "";
  END IF;

  SET len = LENGTH( pString );
  REPEAT
    BEGIN
      SET c = MID( pString, i, 1 );
      SELECT c REGEXP '[^a-zA-Z0-9 /t/-/_]' into regx;
     
      IF c="" THEN
          SET CleanString=CONCAT(CleanString,' ');
      ELSEIF regx =0 THEN
        SET CleanString=CONCAT(CleanString,c);
      END IF;    
     
      SET i = i + 1;
    END;
  UNTIL i > len END REPEAT;
   RETURN CleanString;
END//
DELIMITER ;

---------------------------------------------------------------------------
output

 SELECT fn_RemoveSpecialChars('welcone world !#@#@');

 Result: welcome world

Thursday, July 18, 2013

How to Solve Port 80 Problems When Running Apache on Windows

There are a number of well-known Windows programs which use port 80:
IIS
The most likely culprit is Microsoft Internet Information Server. You can stop the service from the command line on Windows 7/Vista:
net stop was /y
or XP:
net stop iisadmin /y
SQL Server Reporting Services
SSRS can remain active even if you uninstall SQL Server. To stop the service:
  1. Open SQL Server Configuration Manager.
  2. Select “SQL Server Services” in the left-hand pane.
  3. Double-click “SQL Server Reporting Services”.
  4. Hit Stop.
  5. Switch to the Service tab and set the Start Mode to “Manual”.
Skype
Irritatingly, Skype can switch to port 80. To disable it, select Tools > Options > Advanced > Connection then uncheck “Use port 80 and 443 as alternatives for incoming connections”.

What’s Using Port 80?

Further detective work is necessary if IIS, SSRS and Skype are not to blame. Enter the following on the command line:
netstat -ao
The active TCP addresses and ports will be listed — locate the line with local address “0.0.0.0:80″ and note the PID value.
Now right-click the task bar and select Start Task Manager. Navigate to the Processes tab and, if necessary, click View > Select Columns… to ensure “PID (Process Identifier)” is checked. You can now locate the PID you noted above. The description and properties should help you determine which application is using the port.
The Task Manager allows you to kill the process, but be a little wary about doing that — especially if it’s “NT Kernel & System”.

Microsoft-HTTPAPI/2.0

NT Kernel & System is an essential service. Stopping it will probably stop Windows in a blue-screeny-like way. Therefore, enter the following at the command line:
telnet 127.0.0.1 80
If you’re faced with a blank screen, type “GET” and hit return. The chances are, you’ll see a line stating that Microsoft-HTTPAPI/2.0 is listening on port 80. If that’s the case, open Services from Administrative Tools and locate “Web Deployment Agent Service”. Stop the service and set it’s startup type to “Manual”.
The Web Deployment Agent Service is deployed with WebMatrix and was the cause of my woes. It may also be distributed with other applications installed using Microsoft’s Web Platform Installer.
That caused me a few frustrating hours so I hope it solves your Apache or WAMP start-up problems.

Wednesday, July 10, 2013

kill a Windows process from the command line with taskkill

The ability to perform tasks from a system’s command line allows those tasks to be used in batch files. This recipe describes several uses of taskkill to terminate Windows processes.

If you know the name of a process to kill, for example notepad.exe, use the following command from a command prompt to end it:
taskkill /IM notepad.exe

This will cause the program to terminate gracefully, asking for confirmation if there are unsaved changes. To forcefully kill the same process, add the /F option to the command line. Be careful with the /F option as it will terminate all matching processes without confirmation.
To kill a single instance of a process, specify its process id (PID). For example, if the desired process has a PID of 827, use the following command to kill it:
taskkill /PID 827

Using filters, a variety of different patterns can be used to specify the processes to kill. For example, the following filter syntax will forcefully kill all processes owned by the user Quinn:
taskkill /F /FI "USERNAME eq Quinn"

Monday, June 24, 2013

Using Putty to check Linux system memory

There are three another way to check memory on Linux

1:- free -t -m
2: vmstat
3: top

Wednesday, June 19, 2013

Local File Size using java

import java.io.*;
String dFilePath = "D:/Talend/Rathna/NPPES_Data_Dissemination_May_2013.zip";
File file =new File(dFilePath);
    System.out.println(" Local file Size: " + file.length());

Remote File Size using Java

Remote File Size

Question:
How can I discover the size of a remote file stored on an HTTP server? Answer:
The HTTP protocol supports the transfer of extra information about the content referenced by a URL. This information is stored in the HTTP header fields. The Content-Length header provides the size of the object referenced by the URL. Not all web servers will provide this information, so you should not develop your client code to rely on its availability.

The java.net.URLConection class provides access to any arbitrary HTTP header field through the getHeaderField() method, which will return the value of header as a string. Two other methods, getHeaderFieldDate() and getHeaderFieldInt(), will return the values of fields containing dates or integers as Date and int types respectively. They are convenience methods that save you the trouble of parsing the header field. URLConnection also provides convenience methods for accessing commonly used header fields, such as Last-Modified, Content-Type, and, yes, even Content-Length. The value of the Content-Length header is directly returned as an integer by getContentLength(). If the header value does not exist, the method returns -1.

Before querying the value of a header, you first need to establish a connection. The normal way to do this is to create a URL instance that points to the object you want to access, and then create a URLConnection with openConnection(). The following example demonstrates how to open a URLConnection and obtain the byte length of the content referenced by the URL.

import java.io.*;
import java.net.*;

public final class URLFileSize {
  public static final void main(String[] args) {
    URL url;
    URLConnection connection;
    int fileSize;

    if(args.length != 1) {
      System.err.println("Usage: URLFileSize ");
      return;
    }

    try {
      url = new URL(args[0]);

      connection = url.openConnection();
      fileSize = connection.getContentLength();

      if(fileSize < 0)
 System.err.println("Could not determine file size.");
      else
 System.out.println(args[0] + "\nSize: " + fileSize);

      connection.getInputStream().close();
    } catch(IOException e) {
      e.printStackTrace();
    }
  }
}

Thursday, June 13, 2013

How to backup and restore MySQL database

Two ways to take backup of existing MySQL database:

1. Exporting tables to text files using MySQL dump.
2. Copying database files. (within same version) not recommended.
 
Exporting tables to text files using MySQL dump:
 
This is the best solution to keep backup of database so that we can restore it to any version of MySQL in any platform.
 
Syntax for exporting database to text files:
mysqldump -u root -p --all-databases > C:\MySQL_Backup.sql

Syntax for restoring database:
mysql --user=root --password=password < c:\ MySQL_Backup.sql
Copying database files:
 
MySQL stores all the tables in data directory which is divided table-wise, where table and table indexes are represented in the form of files. This approach is only valid for moving data between same version of MySQL.
 
Keep a copy of data directory so that we can just place it while restoring database. This process is valid only for moving database within same version.
 
Note: Unix file names are case sensitive whereas windows are not. So tables with names in mixed case are corrupted when we move database and tables from window to UNIX. If we use mixed case names in database and tables then it might not work properly. For best results ALWAYS use lower case names.