Tuesday, November 25, 2014

Stop overflowing a HTML table and its content

If your HTML table and its content are overflowing, try this CSS combination.

table
{
            table-layout:fixed;
            width:100%;
            word-wrap:break-word;
}

Ref - http://www.456bereastreet.com/lab/table-layout-fixed/example-3.html

Saturday, November 22, 2014

.contains is undefined in JAVASCRIPT

String.contains(String) returns undefined in JS in most browsers except Mozilla firefox. We can replace above function with String.indexOf(String).

"Mycars".contains("My") returns true
"Mycars".contains("My1") returns false

"Mycars".indexOf("My") returns the index of the first character of 'My' within 'Mycars'
"Mycars".contains("My1") returns  -1

Sunday, August 24, 2014

How to Validate a Server

Validate a Server can be an important task when you are going to install a commercial applications with license only for specified servers. To validate a server we have to identify unique attributes related to servers. We can find unique attributes for a server both from software and hardware levels. Hardware level validation can be more reliable than software level since software level data can be easily fraudulently changed than the hardaware level data. But your selection may dependent on your requirements.
With this post I am describing how you can validate a server with hardware information. Simply you can access to Systems' hardware informations. As an example in Linux operating systems you can execute "dmidecode" and get the system information list (you can implement an application to execute those command programmatically using any programming language).
Then you can identify unique data elements related to a server like Serial Key, UUID, MAC etc.
You have to do a strign manipulation and retrive the those required values from the System information list.
Then for the best security we can  encrypt that value and also create a hash value from it. Now, we have a pre created and authenticated hash value. When ever we need to validate the server, what we have to do is dynamically create the hash value and compare with our stored pre-validated hash value.
If the two hashes are equal then the server validation is passed. If not server validation is false.

Thursday, July 3, 2014

How to update a table when there is a Foreign Key Constraint

When there is a foriegn key constraint, tables cannot be updated easily in MySQL. A solution for that is disable the foreign key constraint option in the particular MySQL server and do the update. Finally we can enable the foreign key constraint in the particular MySQL server. An important thing to remember is when you disable the foreign key constarint in the server, it affects to each and every table in the MySQL server.  

//Disable the foreign key constraint option 
SET FOREIGN_KEY_CHECKS=0 

//Enable the foreign key constraint option 
SET FOREIGN_KEY_CHECKS=1 

 //Check the state of the foreign key option in the MySQL server 
//0 means Disabled, 1 means Enabled 
SELECT @@FOREIGN_KEY_CHECKS

Saturday, May 10, 2014

How to copy a file from a remote server via SSH using commands

Terminal Syntax  

scp user_name_of_remote_server@IP_of_remote_server:absolute_location_of_the_file_to_copy absolute_path_to_directory_to_where_to_copy  

Example Command

scp root@xxx.xxx.xxx.xxx:/root/Desktop/LOGSERVEER/backup_final/file_to_be_copy.txt /home/directory_where_to_copy

Saturday, April 26, 2014

Shell script to record linux top to a text file continuously after a given time

We can record the whole top or a specific process with a process ID or process name. You can customize this code with existing shell commands related to linux shell command options relate with top "top".  Refer to http://linux.about.com/od/commands/l/blcmdl1_top.htm

Replace
[1] with the name of the process.
[2] with the name of the text file where the output is need to be recorded.

while [ 1 ] 

     do top -n 1 -p $(pidof firefox[1]) -b >> topoutput.txt[2]

     sleep 0.1 

done 


If you need to track the process just with the process id use below script.

Replace
[3] with the id of the process.

while [ 1 ] 

     do top -n 1 -p 2304[3] -b >> topoutput.txt[2]

     sleep 0.1 

done 

Write above codes with your favourite text editor and save it with .sh

To start this batch process via shell type

bash <file name of the shell script>.sh

Tuesday, April 22, 2014

Saturday, April 5, 2014

Simple check box list in Android


From this post I am going to describe a simple way to design a custom check box list for an Android application. I have presented

  • AllergyFood.java- Which is the activity that included the check box list
  • allergy_food.xml- Which is the layout file for check box list
  • strings.xml- Which is the resource file that used for extract the values for the check box list.

What I am doing here is cerating a custom check box list with the values from the string.xml. Then let the user to put checks for their prefered values. Finally all the selected values will be stored in a string array by a button click event.

  • User interface is looks like below image.

  • strings.xml file is included below string array.
<string-array name="allergy_foods">
      
        <item>Peanut</item>
        <item>Tree Nut</item>
        <item >Milk</item>
        <item>Egg</item>
        <item>Soy</item>
        <item >Wheat</item>
        <item>Fish</item>
        <item>Shell Fish</item>
        <item >Tomato</item>
        <item >Strawberry</item>
       
 </string-array>




  • allergy_food.xml Layout file for check box list  
    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="332dp"
        android:layout_weight="3.38" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Next Step" />




  •  AllergyFood.java Activity file that is included the check box list layout

import android.app.ListActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;

import android.content.Intent; 

public class AllergyFood extends ListActivity{

String checkedValues="";

  @Override
    protected void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);
        setContentView(R.layout.allergy_food);
      
      setListAdapter(new ArrayAdapter<String>(this,          android.R.layout.simple_list_item_multiple_choice,getResources().getStringArray(R.array.allergy_foods)));
        
        Button nextStep=(Button) findViewById(R.id.button1);

        final ListView listView1=(ListView) findViewById(android.R.id.list);
        listView1.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); 


    listView1.setOnItemClickListener(new OnItemClickListener() {

      @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3)

{

                int counter=0;
                checkedValues="";
       while(listView1.getCheckedItemPositions().size()>counter){                      if(listView1.getCheckedItemPositions().valueAt(counter)==true)

          {                                                                       checkedValues=checkedValues+"|"+listView1.getItemAtPosition(counter); 
                    }
                    counter++;
                }            
            }
           
        });

}

Sunday, March 30, 2014

A method to sort an primitive type array to descending order in JAVA

    public void sortDescending(double[]numbers){
        System.out.println("Array values in descending order ......");
        Double[] objDouble=new Double[11];
// Double object array initialization
       
        for(int counter=0;counter<11;counter++){
            objDouble[counter]=Double.valueOf(numbers[counter]);
// Converts the primitive type values of the primitive array into object type and assigning to the Double object array
        }
       
        Arrays.sort(objDouble,Collections.reverseOrder());
//Sort the Double object array
       
        for(Double nums:objDouble){
            System.out.println(nums);
        }

    }

Friday, January 31, 2014

How to change the URL of moved Wordpress site

If you have just developed a Wordpress site and uploaded it to a remote server, you may end up with a problem of redirecting your site to your localhot though you try to access your site by typing the remote site's URL.
The reason for this problem is URLs of your posts and other pages are still not changed from 'localhost' to your remote server's address. You can do the conversion as follows.

Go to your database and browse 'wp_option' table. Then change the values of 'siteurl' and 'home' in 'option_name' field to your current remote server's address.

Finally go to 'wp_posts' table and go to SQL command tab in your PHPMyAdmin. Type the following query
UPDATE wp_posts
SET guid =
REPLACE(
guid,
"olddomain.com/wordpress",
"www.newdomain.com"
);

Change the  "olddomain.com/wordpress" and "www.newdomain.com" with relavant old domain address (as an example http://localhost/wordpress) and new domain address (as an example http://www.test.com).

Sunday, January 26, 2014

How to unlock Dialog i43 security pattern

Recently my Dialog i43 phone was locked due to trying the wrong security pattern on the display more than 20 times by a kid. I was stucked and was unable to access to any function and the great problem was I had turned off the data and wi-fi which is the default method to solve the problem
How ever I knew Dialog i43 is actually an Alcatel phone. So, I googled my problem and found the solution and it worked well for me. Given below is a quoated solution which is in online.

Refer - http://www.askmefast.com/How_to_unlock_alcatel_one_touch_after_too_many_pattern_attemps-qna2962509.html

You can either change or remove the pattern, please follow these instructions to fix your phone.

►Change the Pattern.
 •Google has a feature when things like this happen. But this feature only works when the phone has internet connection either 3G or WiFi. You can change your pattern by logging in your Google account. To change the pattern:
1. Try guessing the pattern until Google account log in appears.
2. Log in your Google Account.
3. The phone will now ask you to put a new pattern.
4. Put a new pattern and do not forget it again.

►Hard Reset. •If your phone is not connected to the internet you can`t change the pattern using your Gmail Account. Your last option is to hard reset your phone. Hard reset is factory resetting the phone using a combination of hardware buttons. This process will also delete all data on your device. To hard reset your Phone: Because you did not put the exact model name of your Alcatel phone I need the to put the two different methods to hard reset Alcatel phones. Hard reset for Alcatel that doesn`t have recovery menu: (Note: This will delete all data on your phone.)

1. Turn off your phone.
2. Remove the battery for 5 sec.
3. Put it back again, but do not turn on the phone yet.
4. Press and Hold Volume Up and Power button at the same time till you see the Android Logo.
5. Now the phone will reset by by itself, just wait for it to reboot.

Hard Reset for Alcatel Phone with recovery menu: (Note: This will delete all data on the phone.)
1. Turn off your phone.
2. Remove the battery for 5 sec.
3. Put it back again, but do not turn on the phone yet.
4. Press and Hold Volume Up and Power button at the same time till you see the the recovery menu.
5. Touch screen will not work on the recovery menu, use volume key to move up and down, and power button to a select from the options.
6. Select Wipe Data/Factory Reset form the menu.
7. On the next menu select yes.
8. When the reset is done, select reboot system now.

Wednesday, January 8, 2014

ASP.net page methods with argument passing

Related to ASP.net, in some cases we need to call server side methods using client side javascript functions with Ajax. The most efficient way to implement that facility is called page methods. I have found a very successful Blog by related to implementing this page methods. This blog is a small extension of the above mentioned blog.
In practical situations we may need to pass parameters to the server-side from client-side. How can we do that using the same example described in the above mentioned blog.

Let's assume that we need to add two numbers. The numbers are going to input by the user via a text input in HTML.Addition will be done in server-side (by a C# method in ASP.net) after we click a button. (Ajax technology will be used)

  • Define 2 text inputs in HTML

<input id="Text1" type="text" />
<input id="Text2" type="text" />

  • Define a HTML button and calls to a function in the onclick event

<input id="Button1" type="button" value="button" onclick="inputNum()"/>

  • Define a ASP.net script manager in client-side (just drag and drop the controller from the tool box)

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True" EnablePartialRendering="true"> </asp:ScriptManager>

  • Define following functions in the client-side using Javascript. (Here I use an array to pass the two numbers as arguments to the server-side method)

function inputNum() {

            var nums = new Array();
            nums[0] = document.getElementById("Text1").value;
            nums[1] = document.getElementById("Text2").value;
            GetInputNumFromServer(nums);
        }

        function GetInputNumFromServer(numsArray) {
            PageMethods.GetSum(numsArray, OnSuccess, OnError);

            return false;
        }

        function OnSuccess(response) {
            alert(response);
        }
        function OnError(error) {
            alert(error);
        }



  • Define the C# method in the server-side. (You have to use the System.Web.Services reference)

 [WebMethod]
        public static int GetSum(int[] arr)
        {
            return arr[0]+arr[1];
        }



That's All.