Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Friday, September 06, 2013

How to find which application is using a TCP port in Windows

If a port is already in use by some unknown program and when you try to use the same port , you get a lot of errors like "Port already in use" , "Bind Exception" , "Port 80 already in use" etc. So in such case, You have to find out which process is already using this port and you can kill that process.

Steps to find which application is using a TCP port in Windows

  1. Type the command to find the Process ID
  2. Go to Run -> cmd and Type
     netstat -ano | more 

Saturday, January 19, 2013

Active Directory Authentication for APACHE Web Server

For authenticating users against their Active Directory account in APACHE Web Server, you have to edit the /etc/apache2/httpd.conf .

Notes

  1. You should bind some other common AD account with LDAP
  2. Provide LDAP URL of you Domain Controller . Here I assume the Domain is DC.EXAMPLE.COM and IP of the Domain Controller is 192.168.40.1 .
  3. I am binding with another account guest@example.com . So give FQDN of this acount .
  4. You should enable the authnz_ldap module for apache.

Sunday, January 13, 2013

PHP-MySQLi Class

What is MySQLi

MySQLi (MySQL improved) is a driver used in PHP to access MySQL databases. PHP 5.5.0 deprecate the use of old mysql driver and it gives warning that old driver will be removed in the future versions. Also it recommends the use of MySQLi or PDO_MySQL extension.

PHP-MySQLi Class

https://github.com/ajillion/PHP-MySQLi-Database-Class/blob/master/MysqliDb.php provides a good PHP class for MySQLi, MySqliDb Class . Go get the code. Now import the Class into your project:

String to MySQL date format in PHP

String to Date in PHP

Sometimes when I export some MS Excel/ MS Access data to MySQL , It is required to convert some date in string to MySQL compatible date format. You can use DateTime class to convert the string to date in any format you want. The code is below.
function _mk_date($str)
{
 $temp = new DateTime($datestr);
 return date_format($temp, 'Y-m-d');
}

Thursday, August 04, 2011

Compressing or Decompressing of Javscript Code

If the javscript code is huge in size, it will affect the loading time of your website. So you can compress the javscript code inorder to
  • transmit JavaScript faster,
  • Reduce the number of HTTP requests etc.

How to Compress Javascript code ?

Use Packer.

Friday, July 29, 2011

Programming language Syntax highlighter in Javascript

Syntax highlighter is a fully functional code syntax highlighter written in Javascript by Alex Gorbatchev ( Syntax highlighting is the feature where the source code written in different programming languages are displayed in different colours and fonts according to the grouping in that language.
Example: Syntax highlighting for a javascript code:

Saturday, April 17, 2010

PHP script for getting tweet updates

Here is the php script to get updates from a twitter account.

   $uname = "YourUserName";
   $url = "http://twitter.com/statuses/user_timeline/$uname.rss";
   $rss = @file_get_contents($url);

  if($rss)
  {
          $xml = @simplexml_load_string($rss);
          if($xml !== false)
           {
                 foreach($xml->channel->item as $tweet)
                  {
                       echo $tweet->pubDate."\n";
                       echo substr($tweet->description,10)."\n";
                   }
            }
           else
             {
                   echo "Error: RSS file not valid!";
             }
       }
       else
      {
          echo "Error: RSS file not found, Invalid username";
      }
?>