Here is a simple steps to install JSON for PHP in *nix server. The sample command below are running under Centos OS.

yum update "*php*"

Make sure you have install PHP Pear.
yum install php-pear

and The pecl command can then be found at /usr/bin/pecl

Then, we can start install PHP JSON.
pecl install json
cd /etc/php.d/
echo “extension=json.so” >> json.ini
service httpd restart

If you are using JQuery with JSON, take a look at this JQuery Json Library. Easy to use and simple.

Advertisements

ImageMagick PDF to Image conversion or Vice versa

Using Linux version of ImageMagick to convert PDF to Image

convert -density 140 test.pdf -resize 25% -quality 100 -colors 256 test.png

You can even use PHP ImageMagick library to convert pdf to image file.

For more information can be view from here :

Allow Apache PHP to access Unix Command or software.

Recently i was working with ImageMagick software (Open Source), basically a very powerful image suite to create, edit, and compose bitmap images. It can manipulate any sort of image just by using command line. Image using Photoshop with command line.

But calling an ImageMagick command using PHP Web pages required some configuration in the visudo files. Apparently, by default unix os will restrict any call or process that do not have any permission to access the internal command. If you wish to execute ImageMagick, you either required to use root user or user who is allowed externally to access the command. One of the way is to enable apache user, remove the Required TTY with visudo and add this to line into visudo (APACHE ALL = (ALL) NOPASSWD). I won’t say this is the only way, but this is one of the most easier. You can either use the PHP ImageMagick library or create and assign a group for apache that are only allowed it to access certain thing in the unix.

But the problem with using ImageMagick PHP library packages is that you can’t have much flexibility and control compare of using the command line.

THIS STEPS BELOW ARE NOT RECOMMENDED IF YOU DO NOT WANT TO RISK YOUR WEB SERVER.THIS SOLUTION ARE ONLY FOR TEMPORARILY RELIEVED UNTIL YOU FOUND A SAFER SOLUTION.

1. Open up your sudo configuration using visudo command.
2. Find the line Required TTY and comment it out using #Required TTY
3. Add another line that remove required password when apache trying to use the command. : APACHE ALL = (ALL) NOPASSWD
4. Restart your apache and you are done with service httpd restart. Check your apache error log if you still can’t run the command to access ImageMagick.

Here are the list of ImageMagick PHP Packages :
———————————————-
MagickWand for PHP (PHP)
IMagick (PHP)

Launching Ecomjunction.com

Finally after several months of planning, handwork, and delay with my founder Arya. We finally launched our PayPal Payment Integration on 15/May/2010 with any website that wish to use PayPal as one of their paying methods. We also offer other services such as CMS management, Wed design and development, Usability and SEO advice, and as well as limited free services for non-profit organisation. Check out the web site at Ecomjunction.com

Malaysia BarCampKl 2010 April 24-25 is here.

BarCampKL 2010

Have been waiting BarcampKl for a while since i went back to Malaysia. As mention before in the previous post, BarCampKl is almost the same as BarCamp Melbourne which held in an un-conference way of events. There are no specifics schedule for any topics.

On the day itself, the topics will be posted on the wall and people can choose to attend and discuss together. If one of the audience is not interested, he/she can freely leave the room in order to respect the presenter rather to sit there uncomfortable.

Anyway, this time the BarCampKL 2010 will be held in Segi College Subang on 24 April – 25 April 2010. (Sat and Sun). For more information, you can visit their official blog. BarCamp KL. Can’t wait for the day.

Higlighting Table row in JQuery

Recently when refactoring the JQuery old code, about a year ago and i found an old and un-JQuery solution where using inline Javascript in HTML. Inline Javascript are bad which are the curse of HTML.

For example :

 <table> 
    <tbody>
       <tr onclick="rowClick('carID') onmouseover=rowOver('carID') >
          <td>whatever here </td>
       </tr>
   </tbody>
</table>

1. Above inline Javascript will not be cache. Every time when the user refresh the page, it have to be reloaded again.
2. Hard to maintain and read something. You have to write everything in 1 line if the line is too long else you will get an error message like this “unterminated string literal” due to line break.
3.It is bad for javascript handling because it wont be able to access event object and
by reading you cant decide what this references to

One of the way to improve the code using jquery and using html class attribute.

<table> 
    <tbody>
       <tr class="carDetails">
          <td>whatever here </td>
       </tr>
   </tbody>
</table>

Since the mouse over event are tie to “this” object, we can get or do anything that are wraped around this object.

$(document).ready(function() {

   $('tr.carDetails').mouseover(function(e) {
       $(this).closest('tr').addClass('highlightSelectedRow');
   });

});

To get the selected row index you can follow the example. Using JQuery closest is one of the way :

    //this will return the row index
    var rowIndex = $(this).closest('tr').parent()[0].sectionRowIndex;

or

    //this will return the row index as well
    var rowIndex = $(this).closest('tr').removeClass('highlightSelectedRow').prevAll().length;

In the above example, when the user move the mouse over the table row, the tr will be added with css class ‘highlightSelectedRow’ to highlight the row color. You can see that we are using JQuery traversing/closest which are available in JQuery 1.3. The new version of JQuery 1.4, allowed array to be passed in. What it does are it get a set of elements containing the closest ancestor element that matches the specified selector, the starting element included.

New example :

<div id="a">
   <div id="b"><b class="carName">ABC</b>
   <div id="c"><b class="carName">CDE</b>
   <div id="d"><b class="carName">DEF</b>
</div>
$(document).ready(function() {

   $(".carName").mouseover(function() {
      //return id of div b or c or d which depends on the text that the mouse event is trigger.
      var id = $(this).closest("div").attr("id"); 
   });

});

Quote from JQuery website :

Closest works by first looking at the current element to see if it matches the specified expression, if so it just returns the element itself. If it doesn’t match then it will continue to traverse up the document, parent by parent, until an element is found that matches the specified expression. If no matching element is found then none will be returned.

Saving MySql from Oracle.

Since Oracle take over MySql due to SUN MircoSystem acquisition, I worried that Oracle will kill MySql slowly or make MySql as commercial products. Who knows? Do you know? No. I have used MySql since my study in University and to my today worklife. Why? It is easy to set-up, work well with cross OS platform, and huge support developer community. This does not mean that i do not wish to use other dabatase products, but worried that I cannot no longer used free and powerful database server as what MySql have offered.

Oracle have this massive big huge of complicated database system which is hard to use (configuration for small and medium size projects) by the way. I will continue support the creator of MySql to fight Oracle to release MySql to the public as how it does before.

Please help to spread the world to free MySql from Oracle or at least leave MySql development to public. Or else all MySql user have a price to pay.

Read more from the MySql creator site : Monty
To sign up petition : SaveMysql