Install Android 5.0 – Lollipop in Samsung Galaxy S3

Lately, I have been  facing a lot of performance-related problems with my Samsung Galaxy S3. I know the phone is  old when compared to the ones that are available in the market today. Snow White Jr.,(that is what  I call my S3) started to perform very slow. To read a Whatsapp message, I had to wait for forty to fifty seconds. When I turn on the Wi-Fi, for next thirty seconds the screen freezes.

To make my weekend productive, and to get rid of the slowness of my phone. I planned to install Lollipop on my mobile. To do that, I had to first root my phone. Only then was I able to come out of the restriction that Samsung has built into the phone.

Rooting Snow white Jr.

Steps that I followed:

1. I pressed the Volume Down, Home Center, and Power buttons together for about 20 seconds until the phone reset itself and showed an option to get into recovery mode.

2. Once in recovery mode, I connected the micro-USB cable from Geno (my laptop) to Snow White Jr.

3. Next, I downloaded GalaxyS3Root.zip from http://downloadandroidrom.com/file/GalaxyS3/rooting/GalaxyS3Root.zip and unzipped it.

4. I opened the odin3 .exe file that was in the unzipped folder to start ODIN. As per the instruction, the application must highlight the COM number but it didn’t get any at first. So I unplugged the Micro USB and re-plugged it. Then there was a yellow highlighted box with a COM number.

odin3

5. In the “PDA” file option, I uploaded the “CF-Root-SGS3-v6.1.tar” file in the GalaxyS3Root folder.

6. In about 10 seconds, Snow White Jr. rebooted and went into ClockworkMod Recovery. And that the ODNI app showed a “PASS!”.

7. After rebooting the phone, I could see “SuperSU” , which is the Superuser app.

8. I verified the root permission by running a rooted app(Titanium Backup) and found it was running alright.

9. I can now get into ClockworkMod Recovery anytime by holding down Volume Up, Center Home, and Power button together for 20 seconds.

Upgrading the OS:

And by now, I have crossed only half the issue. To install the custom OS:

1. I downloaded the following files

a. The OS image file from https://www.androidfilehost.com/?fid=95916177934549433

b. Google play file from https://www.androidfilehost.com/?fid=95784891001614559

2. Then I copied those files to my external SD card, because if I wiped the memory of the phone, I would not be able to access files that are not in the SD card.

3. Now, I again went into  Recovery mode and performed the “wipe data / factory reset” and “wipe cache partition” operations. This action removed the old OS files. There comes the shock, but, thankfully, I have already backed up my photos and app data. So I continued without any problem.

20150405_194133

4. Then I chose “Install zip from SD card” and selected the OS image file for installation. This is the ‘hero’ step and it took less than a minute to finish.

5. After successfully installing the OS, I went to the previous step and chose “gapp” zip file and installed it.

6. Tada!! I got Lollipop running on my phone.

After installing the new OS, I found a lot of interesting features that were available in the update. I will write about these next weekend.

Learn you node – Part 1

learn_you_node

Thought of learning node and started searching for tutorials on Google. And I finally ended up with “Learn you Node”, which was actually funny, simply and informative. I immediately dived into it and made my hands dirty.

Here is the best solutions for each of the exercises.

Exercise 1: Hello World

Write a program that prints the text “HELLO WORLD” to the console (stdout).

Solution:

console.log('HELLO WORLD')

It is a tradition to write “Hello World” as the first program, while learning a new programming language.

Exercise 2: BABY STEPS

Write a program that accepts one or more numbers as command-line arguments and prints the sum of those numbers to the console (stdout).

Solution:

var total = 0;
 process.argv.forEach( function(e, i) {
 if (1 < i) {
 total += +e;
 }
 });
 console.log(total);

To receive the arguments passed to the program, use “process.argv”, where “process” is the global object in node with argv property which has the complete command-line. Output of “process,argv” will be

[ 'path/to/your/node.exe',
 'path/to/your/program.js',
 '30',
 '76',
 '28',
 '47',
 '92',
 '59',
 '2',
 '64' ]

Always the first value will be the path of the node file and the second will have the path of the file that is executed currently. To add the arguments sent to the file, start accumulating from the second index. So comes the line

if (1 < i)

Finally, echo the total.

Exercise 3: My First I/O

Write a program that uses a single synchronous filesystem operation to read a file and print the number of newlines it contains to the console (stdout), similar to running cat file | wc -l.

Solution:

var fs = require('fs');
var file = fs.readFileSync(process.argv[2]);
console.log(file.toString().split('\n').length - 1);

Here the real serious programming starts, node has tons of extensions and modules. One such modules is “fs”, which stands for filesystem that comes from the node core library. As learned from the previous example, here we get the name of the file to read from “process.argv[2]”, because first two arguments to argv is occupied by path to node and the program file.

Then to count the number of chars in the file, convert the Buffer object to string and split it into array with newline character and count the words.

Exercise 4: My first async I/O!

Write a program that uses a single asynchronous filesystem operation to read a file and print the number of newlines it contains to the console (stdout), similar to running cat file | wc -l.

Solution:

var fs = require('fs');
var file = fs.readFile(process.argv[2], function (err, data) {
 if (!err) {
 console.log(data.toString().split('\n').length - 1);
 }
});

Here use the same “fs” module to read the file but this time with “readFile” method to read the file asynchronously. Since the file fetch happens asynchronously, we cannot expect the content of the file in the next line. Use callback to get it and do as done earlier.

Exercise 5: Filtered LS

Create a program that prints a list of files in a given directory, filtered by the extension of the files. You will be provided a directory name as the first argument to your program (e.g. ‘/path/to/dir/’) and a file extension to filter by as the second argument.

var fs = require('fs');
var path = require('path');
var file = fs.readdir(process.argv[2], function (err, list) {
 if (!err) {
 list.forEach( function(file, i){
 if (path.extname(file) === '.' + process.argv[3]) {
 console.log(file);
 }
 });
 }
});

This program adds spices to our delicious feast. Use “readdir” to get the list of files in a given directory and walk through each file and find its file type with file extension using the “path” module.

Ever wondered to know thoughts of an animal?

From my childhood, I always use to guess what a pet animal will think about its owner. We the owner of that pet think we are kind to that animal and we give it healthy food and love regularly. But I am not sure all the pets will understand the love of the owner towards it. Personally I feel the freedom of that animal is restricted by making it a pet. I may be wrong because I too never heard any animal speak my language. I am simply curious to know how they think and how will it respond to our reactions.

I know that most of us would have had the same kind of curiosity to know the thought process of animals. Recently I came across a technology developed by a group of Scandinavian visionaries, who call themselves as “Nordic Society for Invention and Discovery”.

dog_looking_down_microscope

 

No More Woof” is the product that they have developed to hear what your pet talks. The project is in its cradle stage now, they don’t even have a working prototype of what they have envisioned. But the initiative was good. Right now they are only concentrating only on dogs. Since its quite obvious that dogs are the best friend of man. That’s why cats choose to turn deaf ears to their owner’s voice, even after recognizing it, a Japanese scientist recently invented.

It will be really fun and very informative to know how the other animals talk. The technology that is used to read the animal’s thoughts is by detecting the electrical signals generated in the brain for feelings.  Lets see how this comes out.

Localize Your Site Contents with Google Translate Gadget

Google was providing the API to translate the website contents for free but now it has been updated to Google translate v2 and the service is no more given out for free. But there is a alternate way to translate your site into any Google translate supported languages by using the gadget they provide.

To do that go to the below link

https://translate.google.com/manager/website/add

There you can find the step-by-step procedure to add the widget to your website.

In the first step: “Website Info” enter the website url where you need the translate script to run and choose the original language in which the website carries the contents.

In the next step “Plugin Settings” choose the options as per your requirement.

On completing these two steps finally you will get two tags to be inserted into your source files.

Place the given meta tag before the close of the head tag in your files and place the below snippet where you’d like to display the Website Translator plugin on your page.

You are done now!!!

View demo Here:

Extract – MySQL command to play with DATETIME

Ever wanted to split a datetime into date, time, seconds or hours in MySQL command instead of bringing it into php and processing it? here comes the solution in PHP we have simple date command to do this.

 string date ( string $format [, int $timestamp = time() ] )

Where date() return the current time or the any time given in timestamp into required format such as

date(‘d’) – returns the present date of the month

date(‘n’) – returns the month in numeric

In the same way MySQL also carries a similar command to parse the date into required format.

EXTRACT(unit FROM date)

this  function is used to return a single part of a date/time, such as year, month, day, hour, minute, etc.

the input for ‘unit’ can be anything of the below.

Unit Value
MICROSECOND
SECOND
MINUTE
HOUR
DAY
WEEK
MONTH
QUARTER
YEAR
SECOND_MICROSECOND
MINUTE_MICROSECOND
MINUTE_SECOND
HOUR_MICROSECOND
HOUR_SECOND
HOUR_MINUTE
DAY_MICROSECOND
DAY_SECOND
DAY_MINUTE
DAY_HOUR
YEAR_MONTH

So in a table ‘order’ where it has a column named ‘OrderDate’ with the order creation date in the format ‘YYYY-mm-dd’.

SELECT EXTRACT(YEAR FROM OrderDate) AS OrderYear,
EXTRACT(MONTH FROM OrderDate) AS OrderMonth,
EXTRACT(DAY FROM OrderDate) AS OrderDay,
FROM Orders
WHERE OrderId=1.

The above command will return the year, month and day from the db seperately.

Change the title of 404 page in wordpress

In WordPress its very simple to create a 404 page, place a file with your design and name it as ‘404.php’. That’s it, very simple your custom 404 page is ready. By default, the title of the 404 page will be showing “Page not found”. If you want to customize that and change that and have your own custom title for the 404 page.

Then open the header.php, file which has the code to generate the html title. you can find the following line in the file.

wp_title( '|', true, 'right' )

Now replace the above line with

if( is_404() ) {
    echo '404 message goes here | ';
} else {
    wp_title( '|', true, 'right' );
}

And you are done, Now you can see your custom 404 error on the browser title bar.

Localize Your Site Contents with Google Translate API

 

UPDATE:Google translate API v1 is not available any more and the update version of Google translate is a paid service. To use Google translate gadget for free, please visit: Localize Your Site Contents with Google Translate Gadget

 

Information shared on a website is public and anyone on the web can get the information. But it is not certain that everyone reaching your site is familiar with the language used in your website. You need not lose your visitors merely because of language conflict. Google comes with a very handle and simple Translator API tool, to translate your site’s contents using AJAX technology(without reloading the page) on changing into any language.

On adding the Google translator API, a dropdown selectbox will be added to your site with list of languages supported by Google Translator. First place the following ‘div’ in your page whereever you like to display the drop down.

 

Then we need to include jQuery plugin and jquery.translate plugin.

 

Following script adds the language dropdown and calls the translate function with the selected language parameter from the dropdown on change.

jQuery(function($){ //when DOM is ready
	jQuery.translate(function(){  //when the Google Language API is loaded
		jQuery.translate.ui('select', 'option')
			.appendTo('#translator') //insert the element to the page
			.change(function(){ //when selecting another language
				translateTo( $(this).val() );
				return false; //prevent default browser action
			 })
		 });
});

After completely loading the page, the API loads the translate script and on success it intializes the UI functions to create the language dropdown with the language list. Along with that a onChange event handler is also defined. Through with the translate function is called with the selected language value.

    function translateTo( destLang ){ //this can be declared in the global scope too if you need it somewhere else
	jQuery('body').translate( 'english', destLang, {   //translate from english to the selected language
		not: '.jq-translate-ui',  //by default the generated element has this className
		fromOriginal:true   //always translate from english (even after the page has been translated)
	 });
    }

You can set the the default language in which the current site has the contents. You can also specify the HTML elements, whose contents need not be translated with their css selector by passing those values in ‘not’ parameter. ‘formOriginal’ parameter makes sure that the contents are translated from the default language always, even after translating the contents into other language, if it was set TRUE.

By default Google will add all the language names in the dropdown in the alphabetic order, so the first language ‘Arabic’ will be displayed in the dropdown box even when the contents arre in the default language. So you can dynamically add text like ‘Please Select’ or ‘Select Language’ as the first element of the drop down to avoid confusions.

    jQuery('
Select Language
 
').prependTo("#translator select");

This works fine when you are using a single page website, if your website has more pages, then you need to translate the contents manually by changing the selected language in the dropdown. We can use cookies to store and reterive the language selected in the previous page. For that you need to download the jQuery Cookie plugin and include the script. To set the cookie for the selected language value add the following code inside the onChange event

    $.cookie("galang", $(this).val(), { expires : 10 });

Then to set the selected language in the dropdown from cookie value add the following line inside the jQuery.translate() function

    jQuery("#translator select").val($.cookie("galang"));
    translateTo($.cookie("galang"));

Thats it. Now your fullsite is localized to most of the familiar languages. Here is the full code.

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><script type="text/javascript" src="http://jquery-translate.googlecode.com/files/jquery.translate-1.3.7.min.js"></script><script type="text/javascript" src="jquery.cookie.js"></script><script type="text/javascript">// <![CDATA[
	jQuery(function($){ //when DOM is ready
 
	jQuery.translate(function(){ //when the Google Language API is loaded
 
	function translateTo( destLang ){ //this can be declared in the global scope too if you need it somewhere else
 
	jQuery('body').translate( 'english', destLang, { //translate from english to the selected language
 
	not: '.jq-translate-ui',//by default the generated element has this className
 
	fromOriginal:true //always translate from english (even after the page has been translated)
 
	});
 
	}
 
	jQuery.translate.ui('select', 'option')
 
	 .appendTo('#translator') //insert the element to the page
 
	 .change(function(){   //when selecting another language
 
	     translateTo( $(this).val() );
 
	     jQuery.cookie("galang", $(this).val(), { expires : 10 });
 
	     return false; //prevent default browser action
 
	 });
 
	 jQuery('
<option value="">Select Language</option>
 
').prependTo("#translator select");
 
	jQuery("#translator select").val($.cookie("galang"));
 
	translateTo($.cookie("galang"));
 
	});
 
	});
// ]]></script>

Don’t forget to comment on the post. :)