Thursday, June 12, 2014

Validate Email Domain in PHP

        $email_domain = preg_replace('/^.+?@/', '', $email).'.';
 if(!checkdnsrr($email_domain, 'MX') && !checkdnsrr($email_domain, 'A')){
    echo $email.' doesnot exist';
 } else {
  echo 'Email Domain '.$email_domain.' exists! ';
 }

Tuesday, April 22, 2014

Sublime Text - Parse CSV - Find Nth and N-1 th comma from EOL


In Sublime Text - Do A Find [using regular expression] - Apply the below expression


,(?=(?:[^,]*,){16}[^,]*$),(?=(?:[^,]*,){15}[^,]*$)

Tuesday, August 21, 2012

Problem with File.renameTo in java file io


renameTo method in java.io.file may not work always [For eg: During File Upload - if destination and source is in different file system, renameTo fails]
As per the documentation of java.io.file -

renameTo

public boolean renameTo(File dest)
Renames the file denoted by this abstract pathname. Many aspects of the behavior of this method are inherently platform-dependent: The rename operation might not be able to move a file from one filesystem to another, it might not be atomic, and it might not succeed if a file with the destination abstract pathname already exists. The return value should always be checked to make sure that the rename operation was successful.



Alternative approach is you can use org.apache.commons.io.FileUtils .

copyFile



public static void copyFile(File srcFile,
                            File destFile)
                     throws IOException
Copies a file to a new location preserving the file date.This method copies the contents of the specified source file to the specified destination file. The directory holding the destination file is created if it does not exist. If the destination file exists, then this method will overwrite it.

Overriding struts validate method for showing custom error message

Overriding struts validate method for showing custom error message during FileUpload
 @SuppressWarnings("unchecked")  
      public void validate()  
      {  
       List<String> uploadErrors = (List<String>)getActionErrors();  
       if (getFieldErrors().get("upload") != null)  
       {  
        uploadErrors.addAll((List<String>)getFieldErrors().get("upload"));  
       }  
       for (String err : uploadErrors)  
       {  
        if ( err.startsWith("Enter the Error Message to be overridden"))  
        {  
         clearErrorsAndMessages();  
         addActionError("Enter new error message");  
         break;  
        }  
       }  
      }  

Tuesday, August 07, 2012

Sunday, August 28, 2011

GrabText Chrome App

Check out Chrome App GrabText we developed
GrabText Chrome App


GrabText V 0.1 is a Free Chrome App to Grab the Text to your phone.

Scan the QR Code and Grab the Text. 
An easy way to copy any text in webpages to your smartphone.

This is based on HTML5/JS/Chrome Handle/Google Infographic charts.

Please download and write your review for the app

Version 1.0 is under construction. V1.0 will have feature to categorize phone number/url/email/text

Logo Designed By KK (http://twitter.com/#!/KK_Webdesigner)

Monday, July 11, 2011

Dimensions for Android

dp
Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi (dots per inch) screen, so160dp is always one inch regardless of the screen density. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. You should use these units when specifying view dimensions in your layout, so the UI properly scales to render at the same actual size on different screens. (The compiler accepts both “dip” and “dp”, though “dp” is more consistent with “sp”.)
sp
Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user’s font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and the user’s preference.
pt
Points - 1/72 of an inch based on the physical size of the screen.
px
Pixels - corresponds to actual pixels on the screen. This unit of measure is not recommended because the actual representation can vary across devices; each devices may have a different number of pixels per inch and may have more or fewer total pixels available on the screen.
mm
Millimeters - based on the physical size of the screen.
in
Inches - based on the physical size of the screen.

To make it absolutely clear – never use any of the above but sp or dp unless you absolutely have to. Using sp / dp will make your Android applications compatible with multiple screen densities and resolutions.

Ref: -http://developer.android.com/guide/topics/resources/more-resources.html#Dimension

Monday, September 13, 2010

Print Mysql Database Structure Using PHP

 <?php  
 $HOSTNAME          = 'localhost';  
 $USERNAME          = 'root';  
 $PASSWORD          = '';  
 $DBNAME               = 'rizvi_test_db';  
  mysql_select_db($DBNAME, mysql_connect($HOSTNAME, $USERNAME, $PASSWORD)) or die(mysql_error());   
  $result = mysql_query("SHOW TABLES;") or die(mysql_error());   
   while($row = mysql_fetch_array($result)){  
  echo $row[0]; //print the table name  
  $result2 = mysql_query("DESCRIBE ".$row[0].";") or die(mysql_error()); //get details schema for each table  
  echo "<table border='1' width='70%'>";  
  echo "<tr><td>Field</td><td>Type</td><td>Null</td><td>Key</td><td>Default</td><td>Extra</td>";  
  while($row2 = mysql_fetch_array($result2)){  
  for($i=0; $i<6; $i++){   
   if($row2[$i] == "" || $row2[$i] == NULL){  
   $row2[$i] = " ";  
   }  
  }    
  echo "<tr>";  
  echo "<td>".$row2[0]."</td><td>".$row2[1]."</td><td>".$row2[2]."</td><td>".$row2[3]."</td><td>".$row2[4]."</td><td>".$row2[5];  
  echo "</tr>";  
  }  
  echo "</table>";   
  echo "<br/>";  
 }  
 ?>