Wednesday, February 17, 2016

Custom json parser to convert an array within an array to java.util.List of type String

package com.indrajith;

import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) {



        List<String> a=
        split("[\n" +
                "\t{\n" +
                "\t\t\"id\": \"0001\",\n" +
                "\t\t\"type\": \"donut\",\n" +
                "\t\t\"name\": \"Cake\",\n" +
                "\t\t\"ppu\": 0.55,\n" +
                "\t\t\"batters\":\n" +
                "\t\t\t{\n" +
                "\t\t\t\t\"batter\":\n" +
                "\t\t\t\t\t[\n" +
                "\t\t\t\t\t\t{ \"id\": \"1001\", \"type\": \"Regular\" },\n" +
                "\t\t\t\t\t\t{ \"id\": \"1002\", \"type\": \"Chocolate\" },\n" +
                "\t\t\t\t\t\t{ \"id\": \"1003\", \"type\": \"Blueberry\" },\n" +
                "\t\t\t\t\t\t{ \"id\": \"1004\", \"type\": \"Devil's Food\" }\n" +
                "\t\t\t\t\t]\n" +
                "\t\t\t},\n" +
                "\t\t\"topping\":\n" +
                "\t\t\t[\n" +
                "\t\t\t\t{ \"id\": \"5001\", \"type\": \"None\" },\n" +
                "\t\t\t\t{ \"id\": \"5002\", \"type\": \"Glazed\" },\n" +
                "\t\t\t\t{ \"id\": \"5005\", \"type\": \"Sugar\" },\n" +
                "\t\t\t\t{ \"id\": \"5007\", \"type\": \"Powdered Sugar\" },\n" +
                "\t\t\t\t{ \"id\": \"5006\", \"type\": \"Chocolate with Sprinkles\" },\n" +
                "\t\t\t\t{ \"id\": \"5003\", \"type\": \"Chocolate\" },\n" +
                "\t\t\t\t{ \"id\": \"5004\", \"type\": \"Maple\" }\n" +
                "\t\t\t]\n" +
                "\t},\n" +
                "\t{\n" +
                "\t\t\"id\": \"0002\",\n" +
                "\t\t\"type\": \"donut\",\n" +
                "\t\t\"name\": \"Raised\",\n" +
                "\t\t\"ppu\": 0.55,\n" +
                "\t\t\"batters\":\n" +
                "\t\t\t{\n" +
                "\t\t\t\t\"batter\":\n" +
                "\t\t\t\t\t[\n" +
                "\t\t\t\t\t\t{ \"id\": \"1001\", \"type\": \"Regular\" }\n" +
                "\t\t\t\t\t]\n" +
                "\t\t\t},\n" +
                "\t\t\"topping\":\n" +
                "\t\t\t[\n" +
                "\t\t\t\t{ \"id\": \"5001\", \"type\": \"None\" },\n" +
                "\t\t\t\t{ \"id\": \"5002\", \"type\": \"Glazed\" },\n" +
                "\t\t\t\t{ \"id\": \"5005\", \"type\": \"Sugar\" },\n" +
                "\t\t\t\t{ \"id\": \"5003\", \"type\": \"Chocolate\" },\n" +
                "\t\t\t\t{ \"id\": \"5004\", \"type\": \"Maple\" }\n" +
                "\t\t\t]\n" +
                "\t},\n" +
                "\t{\n" +
                "\t\t\"id\": \"0003\",\n" +
                "\t\t\"type\": \"donut\",\n" +
                "\t\t\"name\": \"Old Fashioned\",\n" +
                "\t\t\"ppu\": 0.55,\n" +
                "\t\t\"batters\":\n" +
                "\t\t\t{\n" +
                "\t\t\t\t\"batter\":\n" +
                "\t\t\t\t\t[\n" +
                "\t\t\t\t\t\t{ \"id\": \"1001\", \"type\": \"Regular\" },\n" +
                "\t\t\t\t\t\t{ \"id\": \"1002\", \"type\": \"Chocolate\" }\n" +
                "\t\t\t\t\t]\n" +
                "\t\t\t},\n" +
                "\t\t\"topping\":\n" +
                "\t\t\t[\n" +
                "\t\t\t\t{ \"id\": \"5001\", \"type\": \"None\" },\n" +
                "\t\t\t\t{ \"id\": \"5002\", \"type\": \"Glazed\" },\n" +
                "\t\t\t\t{ \"id\": \"5003\", \"type\": \"Chocolate\" },\n" +
                "\t\t\t\t{ \"id\": \"5004\", \"type\": \"Maple\" }\n" +
                "\t\t\t]\n" +
                "\t}\n" +
                "]","topping");

    }


    private static List<String> split(String json,String field) {

        char startChar = '{';
        char endChar = '}';


        List<String> returnList = new ArrayList<>();

        if (field != null && !field.isEmpty()) {

            json = json.split(field)[1];

        }

        for (int i = 0; i < json.length(); i++) {

            if (json.charAt(i) == startChar) {
                int count = 0;

                for (int j = 0; j < json.length(); j++) {

                    if (json.charAt(j) == startChar) {
                        count++;
                    }

                    if (json.charAt(j) == startChar) {
                        count--;
                    }

                    if(count==0){
                        returnList.add(json.substring(i,j+1));
                        i=j;
                        break;

                    }


                }


            }
        }

        return returnList;
    }
}

Sunday, February 14, 2016

How to Completely Install Oracle JDK on Linux Mint 17.3 Rosa

I followed the methods given in the below linux mint forum and I was able to successfully install oracle jdk 1.8.0_73.

http://community.linuxmint.com/tutorial/view/1839

Play HEVC video format in VLC player Linux Mint 17.3 Rosa



VLC out of the box does not play HEVC files. To fix this we need to install libde265 via PPA, which is an open source implementation of the h.265 video codec.

Open up the Terminal and run the commands below:

  • sudo apt-add-repository ppa:strukturag/libde265 
  • sudo apt-get update 
  • sudo apt-get install vlc-plugin-libde265 

VLC should now play these media files.

Source: http://www.unixmen.com/fix-vlc-not-support-audio-video-format-hevc/

Fix for wifi signal dropping with Realtek RTL8723BE wifi adapter in Linux mint 17.3 Rosa


http://forums.linuxmint.com/viewtopic.php?t=204172&f=53

In a terminal type the following commands

1. sudo apt-get install linux-headers-generic build-essential git

2. git clone https://github/com/lwfinger/rtlwifi_new

3. cd rtlwifi_new

4. make

5. sudo make install

6. sudo modprobe rtl8723be

rtl8723be was my wireless ..change rtl8723be to your model



If it's still not working...
http://www.dedoimedo.com/computers/ubuntu-trusty-realtek.html

1. sudo gedit /etc/modprobe.d/rtl8723be.conf 

2. add> options rtl8723be fwlps=N ips=N 
 
3. sudo modprobe rtl8723be


check for wifi adapter information:

lspci -vq | grep -i wireless -B 1 -A 5

modinfo rtl8723be