Wednesday, July 8, 2015

Resolving Motorola Cellphone Wi-Fi Issue


In this post I will help you resolving WiFi issues on your Motorola devices that is MOTO E/G , So lets get started I have seen many issues related to wi-fi in moto e/g that is wi-fi list not showing particular wireless network or wireless adapter not being turn off and stays on only or wi-fi not able to connect to any of the wireless network etc.

So to get rid of this issue you may need to clear your cache memory by following below steps : 
  1. Turn your phone off
  2. Press and hold the Volume Down button for three seconds, and then press the Power button keeping Volume Down button pressed and then release both
  3. The phone should now display its boot options
  4. Use the Volume Down button to scroll down to the Recovery option. Press the Volume Up button to select this option.
  5. The device might reboot at this point, which means you have taken too long to make selection. If that happens, you will need to start the process again from step 1.
  6. Wait until you see the Android distress logo, which is the Android logo with an exclamation mark
  7. Press and hold the Volume Up key for 10 to 15 seconds
  8. Keep the Volume Up button pressed and press and release the Power button
  9. You should now see more menu options. Use the Volume Down button to scroll the blue strip until it reaches on Wipe Cache Partition.
  10. Press the power button to confirm your selection
  11. Wait for the phone to reboot.
Once your phone comes up your Wi-Fi issue must have gone, and that's it you are good to use it the way you were using before.

Let me know if you any questions or suggestions for me , I will be happy to answer those.

Friday, July 3, 2015

Regular Expression Ride


In this post today I will make you understand how exactly regex works especially in python , so lets start the learning ride with one interesting example.

Before that I would like to share if you remember very basic things it will be pretty easy to understand and you will not have to scratch your head when you are working with it

So first of all why need to have regular expression?
Ans - Regular expression are mainly used to match or search a particular given string with the predefined regex format to check if string matches defined regex correctly.

To match and search you can use match() and search() method , Match objects always have a boolean value of true. Since match() and search() return None when there is no match, you can test whether there was a match with a simple if statement

For example :
I have one predefined regex stored in "pattern" variable
so consider below :
string = "prit.1.test.11.12p.com"
str="prit.1.test.11.12pr.com"
-----------------------------------------------------------
pattern = re.compile(r"prit.\d.test.11.\d+[a-z].[a-z]+")
match = re.search(pattern, string)
if  match:
//conditions
so in above code snippet the match will have value true
-----------------------------------------------------------

-----------------------------------------------------------
and consider below :
pattern = re.compile(r"prit.\d.test.11.\d+[a-z].[a-z]+")
match = re.search(pattern, str)
if match:
//conditions
In above code snippet the match will have value None
------------------------------------------------------------


So here as you can see in the above examples it compares the string and str with pattern variable
Now the pattern variable has value : prit.\d.test.11.\d+[a-z].[a-z]+

So below is the elaboration of it :
\d - matches a digit [0-9] (In example "1")
\d+[a-z] - matches one or more digit from [0-9] and match a single character present or not (In example "12p" is true but "12pr " will not match)
[a-z]+ - matches any string with one or more characters (In example "com")


There are more such characters followed by \ sign available which are listed below :

\s - Matches any whitespace character
\s+ - Matches one or more whitespace character
\w - Matches any alphanumeric character
\w+ - Matches any one or more alphanumeric character
\S - Matches any non whitespace character
\W - Matches any non-alphanumeric character i.e. symbols like (!,@,#,$,%)

Thursday, July 2, 2015

What happens if you try to access or assign array's member out of array's length?

Consider below example for better understanding:


If you have array let say : test[3] = [1,2,3]
so here the length of array is 3 i.e.(test[0],test[1],test[2])
and if you try to access member of test let say test[3] then what will be the output you will be getting  have you ever wonder it?

I have tried this with couple of languages and output was like below:

In C:
if you try to access the element test[3] then it will give me some garbage value but no error will appear

In python :
If I try to access the element test[3] then it will throw error "IndexError: list index out of range"

In Java :
If I try to access the element test[3] then it will throw "error java.lang.ArrayIndexOutOfBoundsException"

In JavaScript:
If I try to access the element test[3] then it will give me output as "undefined"

So as you can see above results indicates that there is something strange happening when we access it in C
Also after digging a little more I also came to know that running below program will not throw any error and will produce the output :

Program:
#include <stdio.h>
main()
{
 int j,i;
 int a[3];

       for(i=0;i<5;i++)
       scanf("%d",&a[i]);

     for (j = 0; j < 10; j++ )
   {
      printf("Element[%d] = %d\n", j,a[j] );
   }
     printf ("changed size: %d\n", sizeof(a) / sizeof(a[0]));
}

Output : 
Element[0] = 1
Element[1] = 2
Element[2] = 3
Element[3] = 4
Element[4] = 5
Element[5] = 0
Element[6] = -1585508667
Element[7] = 32734
Element[8] = 0
Element[9] = 0
changed size: 3

This is very strange as the length of the array is only three still I am able to assign the value to the array more than its length and yet there is no change in the length of the array and when I try to access values more than the size of its length it give me garbage

The Reason for above is explained below:

Actually in C there is no bound check available and which is the biggest drawback of it so when you will declare array it simply puts the values till its length and when you assign the values to the element more than its length it will overwrite those garbage values available in next memory addresses and display it when you print the array

Also one more important thing to note is that this behavior may lead to unusual termination of program or system hung because the values which we assign more than array size may overwrite the values of some critical system files available in those next memory blocks and it may lead to very serious issues... :)