PHP json_encode and jQuery json

Ajax requests using jquery is pretty easy. All you have to do is to specify the URL for request, data sent along with the request, the data type returned, and the callback function. I choose datatype json because it’s much easier to modify with javascript. Here is the example:

Your PHP script, located at http://your/url/to/php/script/:

<?php
$array = array(
  'name' =>; 'alex',
  'fruit' =>; 'apple'
);
echo json_encode($array);

Your javascript Script, with jQuery supported:

$.get(
  'http://your/url/to/php/script',
  {your: data_to_send}, // ignore this for now
  function(returned_data) {
    //do something with the data returned
    console.log(returned_data.name); // will output 'alex'
    console.log(returned_data.fruit); // will output 'apple'
  },
  'json'
);

It won’t output anything on the page, but in the Javascript console instead. Firebug and Webkit-devtool users can see the console output using the “Inspect Element” tool. As far as I know, IE8-9 also has developer tools (press F12), as well as Opera Dragonfly.

HgIgnore for PyroCMS

TortoiseHgPyroCMS
PyroCMS bundle includes .gitignore file. But since I’m using TortoiseHg, I need to find an .hgignore equal for it. Here is what I translated from .gitignore:

glob:.DS_Store
glob:.buildpath
glob:.project
glob:.settings
glob:system/pyrocms/cache/*_m/*
glob:system/pyrocms/cache/*_lib/*
glob:system/pyrocms/cache/dwoo/compiled/*.php
glob:system/pyrocms/cache/simplepie/*.spc
glob:system/pyrocms/cache/twitter/*
glob:system/pyrocms/config/database.php
glob:system/pyrocms/logs/log-*.php
glob:nbproject/*
glob:uploads/*
glob:documentation/*

Hope it’s useful for PyroCMS users who uses TortoiseHg. Enjoy!

[Linux] Setting Permissions on ntfs-3g Disks

If you’re originally a Windows user and going to migrate to Linux, you may still want to use your data formerly on your NTFS harddisk. This is my experience using Kubuntu 10.04, migrating from Windows XP. Please take note that the word ‘migrating’ here does not mean I delete my Windows OS. I’m just doing dual-boot. Continue reading “[Linux] Setting Permissions on ntfs-3g Disks”

Perceptions and Judgement

This is just a note summarizing a lecture. I found this topic interesting and useful, so I dig more.

As we’ve known well, humans make decisions by how they perceive, which is influenced by the events, people, and things around them. Generally humans cannot see something as a whole thing – they just know some part of it.

We don’t see things as they are, we see things as we are.
Continue reading “Perceptions and Judgement”