Category: Random Thoughts
A minor update after 6 months absence
By Chee Ming on Sep 27, 2009 | In Random Thoughts | Send feedback »
I haven't written for about 6 months. My mind is just filled with so many things that I forgot that I have a place to actually vent and rant properly (other than my twitter but only 140 characters at a time).
Quite a bit has happened since.
I am working on my startup and we're constantly trying different ideas. Life is hectic and hard to predict but it can get pretty exciting like a roller coaster ride. We've raised some money and recently participated in Techcrunch50 in San Francisco. We met a lot of influential and interesting people and hope we can make our new found connections work well for us.
I feel that I've changed my view a bit about the Malaysian life in these 9 months of being back. I guess I've been poisoned by Yasmin's work. I loved Sepet, Talentime and Mukhsin. Gubra's story was a bit too dark for me. Her work reminds me of my childhood and the beauty of life here. Nothing is perfect but maybe that is beauty in itself. Oh I am getting mellow...
... listening to Okuribito soundtrack as I write ...
In my free time, I try to run and cycle a bit. I've done a bunch of quarter and half marathons. Slowly getting better each time but still far off from my target. I still can't imagine doing a full marathon yet. Running really sucks out a lot of your mental and physical energy but it also, as my close friend says, "never takes more than it gives".
I have this minor obsession with bicycles and cameras. Sometimes I can surf endlessly just reading and learning about cameras and bicycles. My current fad is looking into Russian cameras, like FED and Kiev. They are basically Leica and Contax clones.
I recently bought a FED Micron from Ebay. It is an interesting camera due to it taking half frame pictures from 35mm film. But my first roll of film was a total disaster. I think the film wasn't setup properly and only got about 10-20 shots out of 72 shots. I'll probably try again but playing with film is not as cheap as digital. My other two targets are Russian rangefinders, namely FED 2 and Kiev 4.
My recent visit to San Francisco has reignited my passion for cycling. My long distance bike touring trip (3 months on the road?) is still a naive idea in my mind. Or maybe a month long backpacking trip to quench my thirst for some travel adventure. I wish I can find the time and energy to do it in the future when I am less busy and committed to my work.
Enough writing English, need to write some Python codes now ![]()
Make your own album cover meme
By Chee Ming on Mar 6, 2009 | In Random Thoughts, Fun | Send feedback »
I read this initially from Yoon Kit's blog post.
I am lazy to repost the rules, you can check it out above.
I am no artist, so here it goes:

Not too bad I guess...
Details:
- The random wiki article (band name): http://en.wikipedia.org/wiki/Quebec_Autoroute_10
- The random flickr picture (album art): http://www.flickr.com/photos/26637167@N08/3326019488/
- The random quote (album name): http://www.quotationspage.com/quote/33751.html
Hacking Ubiquity for better Identi.ca/Twitter usage
By Chee Ming on Mar 1, 2009 | In Random Thoughts, Technical, Exoweb, Mac OSX | 2 feedbacks »
I've been using Ubiquity plugin with Firefox for quite a while, mostly for Tinyurl-ing and Identi.ca-ing/Twitter-ing.
For those who don't know what it is: it is a Quicksilver-ish clone but for Firefox and it allows you to create shortcuts for a lot of the web related tasks that you might normally perform. For example: converting a URL to tinyurl, you just need to hit a shortcut, type a command and voila, its done. No need to copy and paste or click on some button. Or send a quick tweet; no need to switch application or create a new tab and login to twitter.com.
And for those who don't know what is Quicksilver: its a very cool program launcher for the OSX and it actually does a lot more than a simple program launcher, although I don't use much of the other, more powerful functions.
Ubiquity is a pretty good idea and quite good to use, minus the bug #19 (broken growl notification) that drives me crazy, but I am getting used to it.

Since I am a programmer I guess I should hack on more code to make my life easier (Hmmm, maybe I should fix that bug #19). I've been using Identi.ca to post my tweets and because I was lazy I wanted to do it in Ubiquity and I got a Ubiquity script from the Ubiquity Firefox Google Groups that would do the trick.
I've been using it for quite a while and realised I have the tendency to make a mistake when replying to tweets (using @nickname) in Ubiquity. So I thought that it would be useful to change the script to make the experience slightly better.
Before I start, I would like to just talk about my micro-blog setup: I have setup my Identi.ca to post my tweets to Twitter. And my normal use case is to tweet using Identi.ca and then check the feed with all those that I following in Twitter since I have more activity there. So if I see anything interesting that I would like to reply to or retweet I can just type in the username in my status message. But the problem I have is that I might type wrongly so I just wanted a way to make it less error prone.
So what I did was to hack the original Identi.ca script and added a simple check when I type the @ symbol in my message. It will extract all the Twitter usernames from the current active webpage when I activated the Ubiquity command prompt and then display in the Ubiquity preview panel as a list of candidates.

As I slowly complete the nickname, it will drill down the list of candidates based on the character by character matching. If I make a typo, then there would be no candidate names in the list. Its just a very simple hack but I think it would make my replying a bit less error prone. The next step would be to have an easy way to match the reply to the correct tweet. I wonder if there is a way to do it in my case, since I am using Identi.ca. I haven't really explored the API at all.
Because of this small itch I managed to learn a bit about hacking Ubiquity and I have to say that its really straightforward and the fact that I can use jQuery makes programming in Javascript almost fun. I would rather code in Python but I think I can live with this.
So if anyone wants to try out the hack I made, the code is hosted as a Gist in GitHub. Do give me some feedback, whether you find it useful or useless.
JSON response in Django views with jQuery
By Chee Ming on Feb 21, 2009 | In Random Thoughts, Technical, Exoweb, Python, Django | Send feedback »
I have been looking for a more elegant way to code and structure a Django view so that it will support rendering of responses encoded in either HTML or JSON.
I do this because I want to add some AJAXy usability to my HTML forms while retaining some backwards compatibility for non-Javascript enabled Web browsers.
First, lets look at a simple Django view:
def foo(request):
if request.method == 'POST':
form = Form1(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/foo/success/')
else:
form = Form1()
return render_to_response('app1/template1.html', {'form': form})
I was lazy and did some hacky stuff like this to support JSON response.
def foo(request):
if request.method == 'POST':
form = Form1(request.POST)
if form.is_valid():
form.save()
if request.POST.get('type', '') == 'json':
data = {} # define your own data structure
return HttpResponse(simplejson.dumps(data),
mimetype='application/json')
else:
return HttpResponseRedirect('/foo/success/')
else:
form = Form1()
return render_to_response('app1/template1.html', {'form': form})
And for the HTML form, I needed some Javascript (using jQuery) like this:
$("#id_cmd_submit").click(function(){
$.post("/foo/", {type: "json"},
function(data) {
alert(data);
}, "json");
});
I was thinking to myself that this type parameter is kinda of ugly and not necessary. The HTTP protocol actually has a Accept header that you can use to define what encoding the HTTP response from the server can be and this is automatically added when you use the $.post() from jQuery using the json type.
If you examine the HTTP headers in the Django view through request.META['HTTP_ACCEPT'] you will see values like this:
application/json, text/javascript, */*
So to make the hacky method a bit less hacky, I did this:
def foo(request):
if request.method == 'POST':
form = Form1(request.POST)
if form.is_valid():
form.save()
if 'application/json' in request.META.get('HTTP_ACCEPT', '')
data = {} # define your own data structure
return HttpResponse(simplejson.dumps(data),
mimetype='application/json')
else:
return HttpResponseRedirect('/foo/success/')
else:
form = Form1()
return render_to_response('app1/template1.html', {'form': form})
And the Javascript now looks like this:
$("#id_cmd_submit").click(function(){
$.post("/foo/", {},
function(data) {
alert(data);
}, "json");
});
Of course the code is still not very pretty and there are better ways to structure it better. In fact, all I did was just to make the API more "conforming" to HTTP and thus the Javascript code slightly cleaner. The Python code is somewhat the same.
As for the Python code, I see that someone has tried to make this style a bit prettier but I am not too sure if it will fit with all my use cases and I don't like the additional complexity.
I did read a bit about Adrian Holovaty's take on this AJAXy stuff. Its definitely cleaner than my approach but I wish Django have better support for HTTP's Accept header since I like the approach of using the Accept header. I found a middleware in Django snippets that can abstract away the complexity a bit in a more elegant way.
There is a good writeup on REST worst practices by Jacob Kaplan-Moss which touches a bit on using the Accept header instead. Malcolum Tredinnick also though on this a bit in an article about content types on this blog.
So I guess I did not bark up the wrong tree. And surprisingly, those blog articles that I found were quite recent. At least I am not outdated. ![]()
Cycling: Kuala Lumpur vs Beijing
By Chee Ming on Feb 14, 2009 | In Random Thoughts, Travel, China | Send feedback »
Happy Valentine's Day!
I wish I could spend some time with my girl but its alright because I managed to talk to her a bit over Skype. I finally went for my first proper cycling session, though short, since arriving back in KL for about a month. Today wasn't that hot so it wasn't that bad in terms of the heat. My body overheat and sweat too easily.

I took the Sprint highway from where I stayed and headed for Sri Hartamas and then Bukit Kiara to stop by at a friend's place. I did about 10km in 30 minutes when I was heading there. Not too bad for my first time. It was just a bit hilly and I am not so good yet for those hill climbs. But I realised that I had a bit more power in my legs during those nice straight paths. It could be due to the jogging sessions I have been doing for the past weeks. Coming back was much better, only 26 minutes. It could be due to the route having more downhill.
Cycling in Beijing is much more relaxed because its flat like a pan. KL goes up and down and up and down, though its mostly gradual. Another downside of cycling in KL is that it rains fairly often and although its only a drizzle, the road will spit water at you as you cycle past those patches of water. Not fun but nothing a good shower will not fix. Oh yes, I should add on mud guards, but my bike will look fugly.
Beijing has nice bike lanes and its more bike friendly. It can be dangerous cycling in KL, especially next to the highway, which is why you need a bit more planning and try to cycle on those roads with less cars and no blind corners.
Due to the lack of bicycle lanes, I have to cycle at the side of the road which is not so flat, at times and you can easily bump on to small rocks. Because of that my wrist aches a bit. So I still have a bit of getting used to, but its fun nevertheless.
I need to get proper cycling shorts and cycling shoes & pedals, when I get some extra cash on hand
.
