Posts

Showing posts from 2011

Convert int to String

public class  ConvertIntToString  {    public static  void  main ( String []  args ) {           int  aInt =  1 ;           String aString = Integer.toString ( aInt ) ;         } }

Convert double to string

public class  ConvertDoubleToString  {    public static  void  main ( String []  args ) {      double  aDouble =  0.11 ;      String aString = Double.toString ( aDouble ) ;    } }

Convert string to double

public class  ConvertStringToDouble  {    public static  void  main ( String []  args ) {      String aString =  "78" ;      double  aDouble = Double.parseDouble ( aString ) ;           System.out.println ( aDouble ) ;    } }

Convert String to int

public class  ConvertStringToInt  {    public static  void  main ( String []  args ) {      String aString =  "78" ;      int  aInt = Integer.parseInt ( aString ) ;           System.out.println ( aInt ) ;    } }

Writing a newline in a file using BufferedWriter in Java

This is a writing to include a newline in a file using BufferedWriter in Java. import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; public class WritinginFile {                  public void writingToFile(String fileName){                              BufferedWriter bufferedWriter ;                                      try {                                        bufferedWriter = new BufferedWriter( new FileWriter(fileName));                     ...

Techniques to include other file in case of .htaccess file

If you want to call your .htaccess file something else, you can change the name of the file using the AccessFileName directive. For example, if you would rather call the file .config then you can put the following in your server configuration file, that is, in the httpd.conf file:   AccessFileName .config

Examples on mod_rewrite

1. Description – Your current pages are called using index.php with parameter of url i.e http://www.example.com/index.php?url=category and instead of this URL, you want a nice and easy to read URL like http://www.example.com/category Solution – Put the following lines in your .htaccess file. RewriteEngine on RewriteRule ^([^/\.]+)/?$ /index.php?url=$1 [L] Note : If the .htaccess file already contains a line ‘RewriteEngine on’ then you don’t need to put it again unless it was set to off before you putting in your lines. 2. Description – Your current URL is http://www.example.com/index.php?cat=category&subcat=subcategory which you would like to see as http://www.example.com/category/subcategory Solution – Put the below lines in your .htaccess file RewriteEngine on RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /index.php?cat=$1&subcat=$2 [L] 3. Description – You want to have many sub categories or categories like http://www.your-domain.com/category/subcat1/subcat2/su...

Information on .htaccess

Limiting Number of simultaneous connections To limit the number of simultaneous connections to a directory or your entire site , use the below line. If you place it in a directory other than the root directory, then it will limit the connections to that directory and its sub-directories only . Placing it in htaccess file of root directory will implement it for entire site . Syntax: MaxClients < number-of-connections> Examples: MaxClients 40 MaxClients 100 Allow/Disallow certain visitors from accessing your site To accomplish it use the following lines. Look at the syntax first: Syntax: Order allow,deny Deny from < incoming -address > Allow from < incoming -address> The first line [Order allow,deny] tells what should be done first. The second line tells about denying incoming-addresses [could be a single IP, an IP block, domain name and all] and third line tells about the incoming-addresses [could be a single IP, an IP block, domain name and all] thos...

Does your web server support mod_rewrite?

Ensure that you are using Apache web server and mod_rewrite module is installed in your web server. To check this you can either contact your hosting service provider or check it yourself using these simple step. Step1 . Create a blank text file using notepad or any other editor. Step2 . Put <?php phpinfo(); ?> in the file. Step3 . Save as ‘info.php’ . Step4 . Upload the file to your web server’s root or any other folder. Step5 . Call the file in the url – http://your-domain.com/info.php and check if you see mod_rewrite in ‘Apache loaded modules’ section. If NOT, then please contact your hosting provider and request them to install/enable mod_rewrite.

Important Information about .htaccess file

Allow/Deny Directory Browsing When directory browsing is on, people accessing a URL from your site with no index page or no pages at all, will see a list of files and folders. To prevent such directory access , just place the following line in the .htaccess file. IndexIgnore */* Many hosting companies, by default deny directory browsing and having said that, just in case someone need to enable directory browsing , place the following line in the .htaccess file. Options +Indexes Redirect visitors from one page or directory to another It’s quite simple. Look at the example lines below and place similar lines in the .htaccess file of the root folder and it will do the rest. [Remember to use permanent keyword in the line to tell the search engines that the old link has moved to the new link]. You can also setup multiple redirects using htaccess. Syntax : Redirect permanent [old directory/file name][ space ][new directory/file name] Redirect permanent /olddirectory /newdirectory Re...

Puzzle

Facts: 1: There are 5 villas in 5 different colors  2: In each villa lives a person with a different nationality.  3: These 5 owners drink a certain beverage, smoke a certain brand of cigar and keep a certain pet.  4: No owner has the same pet, smoke the same brand of cigar or drink the same drink.   Hints: 1: The British lives in a red villa.  2: The Swede keeps dogs as pets  3: The Dane drinks tea  4: The green villa is on the left of the white villa (it also means they are next door to each other)  5: The green villa owner drinks coffee  6: The person who smokes Pall Mall rears birds  7: The owner of the yellow villa smokes Dunhill  8: The man living in the villa right in the center drinks milk  9: The Norwegian lives in the first villa  10: The man who smokes Blend lives next to the one who keeps cats  11: The man who keeps horses lives next to the man who smokes Dunhill  12: The owner who smokes Blue...

Windows Services Start(Contd.)

Commands for some Management Consoles (msc extension required) Entry for Run Function ciadv.msc Manages the Indexing Service compmgmt.msc Computer Management Console. It contains a number of the other consoles devmgmt.msc Device Manager dfrg.msc Disk Defragmenter diskmgmt.msc Disk Management gpedit.msc Group Policy Editor. Not available in Windows Home editions services.msc Manages the many services involved in Windows and installed software

Windows Services Start

Entry for Run Function calc Opens calculator cmd Opens command prompt window explorer Opens Windows explorer magnify Screen magnifier accessory msconfig System Configuration Utility mshearts Opens Hearts game msinfo32 System Information applet mspaint Opens graphics accessory Paint notepad Notepad accessory regedit Registry editor sol Opens Classical Solitaire game 

Linux Shell Programming

I had a little bit experience in Liunx Shell Progrmming through my undergraduate course work. At that time we used to create simple shell script with using only cp, grep, head, tail, mv, rm command of Shell Programming. I had never encounter with the problem of script writing for which I need to debug the script in undergraduate course. While working with some problems of shell programing in Exling LLC, I encounterd a buggy script for which I need to debug a script. At that time, I learned some features of debugging a script. I had gained a pretty well idea on debugging a script. It is much easier and essential feature of shell scripting. It solves many problems for which people may have to wait and work for many days. I am including the buggy script first to show the  debugging features here: #!/bin/bash # a.sh # This is a buggy script. # Where, oh where is the error? a=37 if [$a -gt 27 ] then   echo $a fi  exit 0 There are two ways to debug a script f...