Sunday, May 31, 2015

Tricks to Save Internet Data Usage

Internet is part of our lives and this Internet isn't cheap at all. All over the world prices for Internet are rising & especially on mobile internet, data is so much costly.

Here are some ways to save some data usage.

Browsers : 
If you are doing heavy browsing, try using browsers that supports page compression & Image compression
eg. Opera browser's Turbo Mode

Downloads:
Other than videos,Images,audio:
If you are downloading documents,files then first try to compress them online by tools like CloudConvert.
eg. If you need to download file of 100MB -> Get it compressed by CloudConvert (7z has highest compression ratio) & download compressed one. I am sure you will save atlest 20-30MB's on this.

Use Download Managers;
If you are downloading big files try to use download managers like Free Download Manager, because many built in download managers in popular browser dont have proper download resuming capabilities on download failure. You can also add multiple peer locations(mirrors) to speedup download.

Many times download site has heavy load & even using downloaders you may endup in currupted download, in this case first convert that download to torrent by "Burnbit" & download that file by using torrent. So evenif some chunks of file gets currupted torrent will altomatically redownload it. This will save your re-download attempt.

Torrent Movie Downloads:
Now instead of downloading avi,mp4 format movies, try to download movies in mkv format.
Internally they use different video,audio codecs & compression schemes this makes mkv files considerably smaller than that of mp4 or avi file
eg. avi,mp4 file of 1GB may have same audio-video quality in 500-700MB mkv file

YouTube Downloads:
Instead of downloading youtube videos in mp4 or avi format, try to download them in webm or mkv format
You will have smaller filesize with same quality as mp4,avi video.

So to save some data on video-audio files try to download video compressed with VP8,VP9 Codecs & audio with vorbis audio.

Installing Debian Jessie ( i.e Debian 8 ) on Intel BayTrail Tablets

Recently I purchased Croma 8 Tablet which comes with Intel BayTrail Chipset.
This tablet has pre-installed Windows 8.1.

Intel Bay Trail Tablets have 32bit UEFI & 64bit Intel Atom Quad Core Processor & many Linux doesn't supported these tablets until Debian Jessie 8.

Debian Jessie natively supports booting on 32bit UEFI devices & shockingly it works nice.

Steps:
  1.  Download debian Jessie 32bit ( i386) or 64 bit iso. I downloaded LXDE Edition.
  2.  Format Pendrive with FAT32 Filesystem & Extract files from iso & copy them to pendrive.
  3.  Now boot from Pendrive & Start setup.
  4.  After Installation done, Reboot & make sure you edit grub2 entry of debian 8 & add "nomodeset" option  at last of linux line in entry else screen will go blank.
Now there are several things which are not working. As there tablets are new so hardware support is very limited.

On My Tablet:
Working:
  • Touchscreen

Not Working:
  • Wifi
  • Bluetooth
  • Battary level
  • 3D accelaration
  • Audio
  • HDMI
  • Sensors ( Device Orientation & others )
  • Power Management 


Saturday, April 4, 2015

Filtering JSON – A Simple Way

 

Lets say you have some JSON data coming from some application and you want only some of it should go outside,filtering sensitive or irrelevant parts of it.

So overall you want :-

Input JSON  ->  Filtering Logic  -> Output JSON

Now how to do this? Well there is simple & fast library called minimal-json.

 

Input JSON Structure:

input.json

 

Output JSON Structure :

output.json

So from above pictures you can see we need to filter input json & restructure it to form an output json.

Steps:

1) Create a maven project & add minimal-json dependency to it.

2) Now read Input json to string

    String input = new Scanner(new File("input.json")).useDelimiter("\\Z").next();

3) Now create JSON parser from it.

    JsonObject injsonobj = JsonObject.readFrom(input);

4) JsonObject outjson = new JsonObject(); as output json object

5) You can easily add json nodes to output json object which is outjson here

     eg. outjson.add("totalcount", injsonobj.get("hits").asObject().get("total").asInt());
           outjson.add("perpage",20);

6) Now library is very effective for parsing JSON nodes as Java Datatypes. Inorder to get JSON nodes it provides get(“name of node”) method which returns JsonObject as ouput,this JsonObject can be parsed as Java Datatype by asDouble(),asInteger().

7) If you want to get JSON Array there is a method called asArray() which returns JsonArray object. From this object you can get individual object from get(index_number) method

JsonArray jhits2 = jhits.get("hits").asArray();
       
        for(int i=0;i<jhits2.size();i++)
        {
            JsonObject source = jhits2.get(i).asObject();
            double score = source.get("_score").asDouble();
            source = source.get("_source").asObject();
            JsonValue prod_details = source.get("productdetails");
            prod_details = ((JsonObject)prod_details).add("score", score);
            outprodarray.add(prod_details);
        }

8) Now at end when full filtering & restructuring done, you can now produce JSON output as outjson.toString()

To produce output from input of ~30KB it took less than 10 ms.(average 7ms) on 2GHz dual core machine. Well that means system can serve ~100 requests per second.