Heartbleed

image

Image | Posted on by | Leave a comment

[Imagemagick on RHEL 6 x86_64] troubleshoot small deligate issues during installation

ImageMagick is a fantastic command line utility to create/play around with all different supported Image file formats. Being such a nice utility requires some workout to get it working on RHEL 6 (x86_64) and other unix systems. ImageMagick has quite some binary releases also for RHEL 5.8, RHEL 6 does not have a binary release yet. Also the rpms for some unix systems still gives a lot of dependency resolution problems during rpm installation. It is quite some work.

So i went about installing ImageMagick from source on RHEL 6. From the link here it seems to be quite simple right configure-make-make install, But when i tried to use the command line utility like convert with a jpeg or png file format. it gives a lot of deligate not found errors.

like for example if you try to run the test command:

/usr/bin/convert logo: logo.jpg

it gives numerous errors like following for each file format :

convert: no decode delegate for this image format `logo.jpg' @ error/constitute.c/ReadImage/544.

Most of the times these errors are there due to libxxxx not installed on the system for example for PNG file format libpng is not installed. One can install this by just typing following command:

yum install libpng libpng-devel

And rebuild imagemagick again. With RHEL 6 it installs all all turbo libraries like libpng-turbo… etc. After the rebuild the test command(/usr/local/bin/convert logo: logo.png) for PNG works.

But in my case i still had the problem running the test command for JPEG, it gave me the following error event after installing libjpeg-turbo and libjpeg-turbo-devel:

undefined reference to `jpeg_default_qtables’

ImageMagick has a lot of deligates which can be downloaded here and installed, so i downloaded and installed “jpegsrc.v9a.tar.gz” but still the error came again and again. After googling some i finally found a chinese blog website http://blog.csdn.net/zwfcan/article/details/16963375 which mentioned a installation with specifying a path. Following are the steps to install JPEG deligate from that blog

  1. tar -xzvf jpegsrc.v9.tar.gz
  2. cd jpeg-9
  3. ./configure
  4. make libdir=/usr/lib64
  5. make libdir=/usr/lib64 install

So i did the steps above and then rebuild the ImageMagick again and Voila! it works.

Further Reading:

http://www.imagemagick.org/

http://blog.csdn.net/zwfcan/article/details/16963375

Posted in Thechy Stuff | Tagged , , , , | 2 Comments

Multi-Threading in browsers

What a sign of relief for Javascript programmers when you say something like that “Threading in Javascript”. Brendan Eich the creator of javascript is totally against the implementation of Multi-Threaded architecture in Javascipt due to the problems it has like deadlock, race-conditions…etc and he strongly believes that even with smater programming these cannot be totally eradicated. But with the advent of Gears API by Google there was a way-out on multi-threading in Javascript. But to get things done it needed the Google Gears plugin-in to be installed on the browsers. With recent HTML5 advancements towards a better web, web-workers are here for rescue. Web Workers work on the similar concept as that of Gears API [but the coding style differs a lot]. To avoid all those problems of multi-threading a message passing way is implemented in web-workers. Also the web-worker is not allowed to access the parent page DOM. Following is a basic simple example of Web Workers.

var worker = new Worker(js/myworker.js);
worker.onmessage = function(e){
        console.log(“Processed Message from Web-Worker : ” + e.data);
}
var somejsontoprocess = ‘{“name” : “Dominic”, “lastname” : “Dsouza”}’;
worker.postMessage(somejsontoprocess);
 
====contents of js/myworker.js=====
onmessage = function(e){
        var jsonfrommainthread = e.data;
        console.log(“Message from Main Thread : ” + jsonfrommainthread);
        //SOME LENGTHY PROCESS WHICH TAKES >10sec TO PROCESS
        postMessage(jsonfrommainthread);
}
==========================

Following is the pictorial representation of the above code:

webworkers

As shown in the above example, Parent thread passes a message to web-worker and the web-worker in turn does some lengthy process and replies with a processed message to the parent thread. So Due to web-workers the lengthy process is run in a different thread handled by the OS and the Main/Parent thread is left free and still active accepting inputs from user with no freezing of the browser.

In the above example if we remove web-workers and do a standard javascript programming with no setTimeouts, the browser window would freeze for the time the lengthy process is underway or may give an error to stop the lengthy script.

So to conclude: Web Workers will change the way we think about threading in Javascript and would reduce user waiting times and would make the browser more responsive.

FURTHER READING:

1. Even Faster Web Sites by Steve Souders [http://stevesouders.com/efws/] — second chaper explains everything gears, web workers.

2. Web Workers By Ido Green [http://shop.oreilly.com/product/0636920024446.do] — explains in-depth about Web Workers, types of web workers, techniques of message passing… etc. nice book!.

Posted in Thechy Stuff | Tagged , , , | Leave a comment

Convert JSON String into Map using Streaming API of Jackson

Jackson is a good performance rich java library for JSON processing (parsing/generation). more about Jackson at github home page. The Streaming API of Jackson library is the fastest way to parse/generate a JSON. While using JSON there is sometimes a requirement to convert JSON String into a Object. For small string this seems to be a piece of cake, but for long and complex JSON strings things get a bit hairy when using streaming API. Jackson library has a ObjectMapper which does this job very simple but if you like using Streaming API for parsing JSON String following is some piece of code for you:

Following code was compiled using jackson-core-2.2.3.jar which can be downloaded here.

===================JsonStreaming.java============================

package test;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
/**
 *
 * @author dominic
 */
public class JsonStreaming {
    public static void main(String[] args) {
        String JSONString = “{\n”
                + ” \”name\”:\”dominic\”,\n”
                + ” \”age\”:29,\n”
                + ” \”messages\”:[\”msg 1\”,\”msg 2\”,\”msg 3\”]\n”
                + “}”;
        JsonStreaming jsontest = new JsonStreaming();
        Map<String, Object> jsonmap = jsontest.parseComplexJSON(JSONString);
        for (String key : jsonmap.keySet()) {
            if (jsonmap.get(key) instanceof ArrayList) {
                ListIterator litr = ((ArrayList) jsonmap.get(key)).listIterator();
                System.out.println(key + “:”);
                while (litr.hasNext()) {
                    System.out.println(“:: ” + litr.next());
                }
            } else {
                System.out.println(key + ” : ” + jsonmap.get(key));
            }
        }
    }
    public Map<String, Object> parseComplexJSON(String jsonstr) {
        Map<String, Object> respdata = new HashMap<String, Object>();
        JsonFactory jfac = new JsonFactory();
        try {
            JsonParser jParser = jfac.createParser(jsonstr);
            while (jParser.nextToken() != null) {
                if (jParser.getCurrentToken() == JsonToken.START_ARRAY) {
                    respdata.put(“result”, readJSONArray(jParser));
                } else if (jParser.getCurrentToken() == JsonToken.START_OBJECT) {
                    return readJSONObject(jParser);
                } else {
                    respdata.put(jParser.getCurrentName(), jParser.getText());
                }
            }
            jParser.close();
        } catch (Exception ex) {
            System.out.println(“Excpetion : ” + ex);;
        }
        return respdata;
    }
    public Map<String, Object> readJSONObject(JsonParser jParser) {
        Map<String, Object> jsonobject = new HashMap<String, Object>();
        int jsoncounter = 1;
        if (jParser.getCurrentToken() == JsonToken.START_OBJECT) {
            try {
                while (jParser.nextToken() != JsonToken.END_OBJECT) {
                    if (jParser.getCurrentToken() == JsonToken.START_OBJECT) {
                        Map<String, Object> subjsonobj = readJSONObject(jParser);
                        if (jParser.getCurrentName() != null && !jParser.getCurrentName().trim().isEmpty()) {
                            jsonobject.put(jParser.getCurrentName(), subjsonobj);
                        } else {
                            jsonobject.put(jsoncounter + “”, subjsonobj);
                            jsoncounter++;
                        }
                    } else if (jParser.getCurrentToken() == JsonToken.START_ARRAY) {
                        List<Object> subjsonarray = readJSONArray(jParser);
                        if (jParser.getCurrentName() != null && !jParser.getCurrentName().trim().isEmpty()) {
                            jsonobject.put(jParser.getCurrentName(), subjsonarray);
                        } else {
                            jsonobject.put(jsoncounter + “”, subjsonarray);
                            jsoncounter++;
                        }
                    } else {
                        jsonobject.put(jParser.getCurrentName(), jParser.getText());
                    }
                }
            } catch (Exception ex) {
                System.out.println(“Excpetion : ” + ex);;
            }
        }
        return jsonobject;
    }
    public List<Object> readJSONArray(JsonParser jParser) {
        List<Object> jsonarray = new ArrayList<Object>();
        if (jParser.getCurrentToken() == JsonToken.START_ARRAY) {
            try {
                while (jParser.nextToken() != JsonToken.END_ARRAY) {
                    if (jParser.getCurrentToken() == JsonToken.START_OBJECT) {
                        Map<String, Object> subjsonobj = readJSONObject(jParser);
                        jsonarray.add(subjsonobj);
                    } else if (jParser.getCurrentToken() == JsonToken.START_ARRAY) {
                        List<Object> subjsonarray = readJSONArray(jParser);
                        jsonarray.add(subjsonarray);
                    } else {
                        jsonarray.add(jParser.getText());
                    }
                }
            } catch (Exception ex) {
                System.out.println(“Excpetion : ” + ex);;
            }
        }
        return jsonarray;
    }
}

===================JsonStreaming.java============================

I haven’t tested the above code for very complex JSON strings but it works for most of them. In the code above parseComplexJSON takes in as parameter JSON string and returns a java.util.Map<String, Object> the Object here can be ArrayList to denote corresponding JSONArray. The code uses a lot of recursion to parse JSON String. All JSONObject are converted to Map<String, Object> and all JSONArray are converted to ArrayList<Object>.

Happy Coding!

Further Reading:

http://wiki.fasterxml.com/JacksonStreamingApi  [Streaming API of Jackson]

http://wiki.fasterxml.com/JacksonHome

http://wiki.fasterxml.com/JacksonInFiveMinutes [Jackson Overview in 5 minutes]

Posted in Thechy Stuff | Tagged , , , , , | Leave a comment

Droplets of cloud with DigitalOcean

digitalocean

Image | Posted on by | Leave a comment

Intel Galileo for DIYer’s

Intel Galileo

Image | Posted on by | Leave a comment

Feature Increment operator on Notepad : Notepad++

I had mentioned in very short in past about Notepad++ here and hinted some about macros in Notepad++. Following is short desc about plugins in Notepad++.

NotepadplusplusAs you see above Notepad++ has tons of plugins to make a programmers life easy. Well I needed to view and format a JSON. Now it is simple to view and understand a JSON if it is very small but the huge ones require some viewer like above. So here is what I did just looked for a JSON viewer in the Plugin Manager, installed it to Notepad++(needs a notepad++ restart after that), then just paste the json in the notepad++ and hit the menu Plugins -> JSON viewer -> Show JSON viewer and there it was!. JSON the way i wanted to see it.

Further Reading:

http://notepad-plus-plus.org/

Posted in Thechy Stuff | 1 Comment

JavaOne

javaone

Image | Posted on by | Leave a comment

Chromecast for $35

marquee-product[1]

Image | Posted on by | Leave a comment

Apple WWDC

wwdc13-about-main

Image | Posted on by | Leave a comment