Monday, August 27, 2007

Installing RMagick on Ubuntu

Well, I ran into this when I was trying to use the attachment_fu plugin from techno-weenie.

Even though RMagick was a little more heavy on the memory comparing to the other alternatives, I still chose it, as a lot of people are using RMagick, and I can find a lot of help on the web if I just google it.

But things aren’t always as easy as it seems ;-)

I got errors like this on my first attempt to install the RMagick gem:
# gem install rmagick
Building native extensions. This could take a while...
configure: error: Can't install RMagick. Can't find Magick-config or GraphicsMagick-config program.

ERROR: While executing gem ... (RuntimeError)
ERROR: Failed to build gem native extension.
Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/rmagick-1.15.9 for inspection.

Results logged to /usr/lib/ruby/gems/1.8/gems/rmagick-1.15.9/gem_make.out

Thanks to google and ruby community ;-) I found this reference in less than 10 seconds on google!

Basically, you need to install “libmagick9-dev” package to your ubuntu first.

That’s it!

Thursday, August 23, 2007

Using Javascript to parse XML text

As I was and still am heavily involved in my company’s next major product release, I a kinda slacked off on writing valuable things down when I encounter them.

To make it up, here is something that I was trying to do yesterday.

I need to parse a complex data structure in JSON, and inside the JSON, I would have to deal with some values that are xml, So xml within JSON ;-)

First thing I thought is to create a node using document.createElement, and set the innerHTML of the element to be the value of the JSON xml, then I should be able to access the nodes inside the element that I created just like normal node traversing. (parentNode, childNodes, firstChild, etc…).

It worked with Firefox ;-), but not IE.

I remembered that the library sarissa can do the xslt transformation, so I should be able to find the code in there which handles the string to traversable xml tree conversion.

Guess what, I didn’t have enough time to look through all of the docs to see exactly how it was done, and something else hit me when I was searching through the web.

I was so glad that I don’t have to copy over the 23k lib just to turn the text into xml in IE after reading XML Parser.

So here is the code snippets:
    if (window.ActiveXObject) { // ie
xml=new ActiveXObject("Microsoft.XMLDOM");
xml.async="false";
xml.loadXML(XMLSTRING);
} else { // mozilla
var parser=new DOMParser();
xml=parser.parseFromString(XMLSTRING,"text/xml");
}