“Neglected” would be an understatement in this case. Though I launched Freally in mid-2010, it was left to itself without much improvement over the years. Well, I finally went off my butt and did something about it and I am happy to announce that it’s nearly time for the re-launch. I cannot wait! And hopefully this time, I will learn from my mistakes and try to take a better care for it.
Apply natural sorting on MySQL or Postgres
If you have a table with a varchar or text column, which may or may not contain text-based integer values, it’s sometimes hard to do natural sorting on MySQL or Postgres. By that what I mean is, if you have
col1
——
a1
a2
a10
a20
and if you apply “order by col1″, the sorting result would be something like
col1
——
a1
a10
a2
a20
The easiest way to go around this is to first order by the length of the value and then the actual value. So in MySQL, you will have
… order by LENGTH(col1) ASC, col1 ASC
and in Postgres
.. order by CHAR_LENGTH(col1) ASC, col1 ASC
WA~LA~ saved me time.
SimplePie & ‘ampersand’ invalid XML error
I was using one of the APIs to process their XML file using SimplePie, but it happens so that their XML document was invalid since one of the fields contained the ampersand character.
How did I resolve it? SimplePie accepts “set_raw_data($feed_string)” as one of its options. This means that you don’t have to use the URL to parse the feed.
So first, download the content of the XML through file_get_contents() method in PHP, then replace the string using str_replace(‘&’, ‘&’, $feed) and then you are safe to go.
I’m not entirely sure what other implications this has, but it’s serving me well so far.
Happenic is the mashup of the day at PW!

Woo hoo!
Happenic has been voted as the mashup of the day at programmableweb.com! NNIICCEE.
Latest SimplePie 1.2.1 and CodeIgniter 2.1.0 working together.
SimplePie is a popular RSS parser and it was always easy to integrate it with other PHP frameworks.
However, I was not able to find the latest SP (1.2.1) integrated with the latest CI (2.1.0). So I decided to upload it to GitHub and make it available for all to use. The repo is available at
There are two things I did to make this work, which weren’t too difficult.
First is to ensure that SP references are correctly fixed up when porting to CI. This is well documented with links in
Secondly, when I was running this, it was giving the following error.
cURL error 6: name lookup timed out
It seemed like cURL was timing out when trying to access the remote RSS feed. The value for timeout is set to 10 seconds by default. Maybe this is a bit too strict. I changed this to 20 and it worked well.
Finally, here’s the snippet of my code to get this thing working. Make sure you include Simplepie.php in your libraries folder and also set your “cache” folder as writable.
public function aus_conf()
{
$this->load->library('Simplepie');
$this->simplepie->set_cache_location(APPPATH.'cache');
$this->simplepie->set_feed_url('http://feeds.feedburner.com/TheAustralianArt?format=xml');
$this->simplepie->init();
$this->simplepie->handle_content_type();
foreach( $this->simplepie->get_items(0, 5) as $item)
{
echo $item->get_title() . '
';
echo $item->get_description();
}
}
What’s Happenic!
Today I am launching Happenic v0.1. This is the second iteration of this project, yet I spent last 4 weeks refining the primitive first iteration.
The interface now boasts full-screen calendar and event listing with easy-to-use search features and best of all, now I don’t have to go and search for all different sites to get what is happenic (get it get it?) around my city.
For now, I am making it available for Australian cities, obviously, I will slowly expand the site to include other cities.
Calendar v2?

Calendar web app was something I was working on for about 4 weeks now. This is actually the second version I am trying to release.
After the intitial one, I re alised how “slow” it was due to some serious novice Javascript coding. I spend few weeks refreshing my knowledge in JS, plus kicking myself with Backbone and things are finally looking a-ok.
Small fixes to CodeIgniter, Facebook FQL via Graph with cURL (Phil Sturgeon’s library)
I went absolutely bonkers on trying to get CodeIgniter with Facebook Graph API via cURL.
Firstly, the problem here was the fact that everything was indeed working fine. Then when I tested my code again, things started breaking. Here’s my scenario.
I am using CodeIgniter 2.1.0 (the latest one) and I am trying to get the list of all the albums I have on Facebook via Facebook Graph API. In particular, I am running FQL to get these data, since I only need a few data fields.
In addition, I am also using Phil Sturgeon’s cURL library, so I don’t have to worry about all the nitty gritty details.
Here are TWO fixes I had to implement in my code to get things rolling.
- Specify “http_build_query” in Curl.php to handle ampersand character correctly. According to the PHP site, this is what it states.
As noted before, with php5.3 the separator is & on some servers it seems. Normally if posting to another php5.3 machine this will not be a problem. But if you post to a tomcat java server or something else the & might not be handled properly. To overcome this specify: http_build_query($array, ”, ‘&’).
Looks like when interacting with Facebook Graph, you need to specify this.
- Specify options in cURL – Previously, I called a “simple_get( URL, array(‘q’ => my_fql, ‘access_token’ => my_access_token))”. When talking to FB, you need to specify the following options
$this->curl->option(CURLOPT_SSL_VERIFYPEER, false);
A little bit strange, since I didn’t have to do this before. But if Facebook is tweaking their systems all the time, which I imagine they do, we just need to adapt.
Hope that alleviates pain for some people who are doing similar things as me.
Hello VPS!
I wouldn’t call myself much of a Linux admin, but I’m glad to say I have finally managed to set up my own VPS and have begun my process of transferring all my sites. It’s a big sigh of relief, since the shared hosting gave me too many headaches (it’s supposed to be the other way around right?). Anyway, here’s to my first post on my blog from my VPS.
..

