Skip to main content

Posts

Bluetooth modem in Ubuntu 10.04

Finally work with my Samsung GT-E2230M. Although I'll not be using this since there're abundant of much cheaper and faster 3G connections, who know I'll need it some day so it's good to know that it could. The blueman package in the standard repositories so far provided all the bluetooth functionalities that I need so far. Connecting up to PPP with the handphone as a modem is as simple as right click the respective phone in the bluetooth manager and navigate to "Serial Ports" => "Dial Up Networking". First time trying this it managed to established the connection but subsequent tries greet me with socket error. Then I have a good luck by clicking the setup assistant (the gear icon) and go through the 2 step wizard. Once connected, I can see the ppp0 interface is up with IP address assigned but I can't ping any public IP address. Checking the route, the routing table is empty. Try adding some default gateway " route -a [ppp0 ip addres]  ...

Formatting floats in Python

Not really straightforward since there are number of issues. In this SO question , Alex Martelli simply suggested using the rstrip() string method to remove the zero. Others suggested the "g" flag, such as "%.1g". One issue with "g" flag is if the number to be formatted is larger than the format width specify, it would display it in scientific notation. It can be fixed by using large enough width such as "%.99g". Django has floatformat template filter and it seem to use different approach in django.core.template.defaultfilters def floatformat(text): """ Displays a floating point number as 34.2 (with one decimal place) -- but only if there's a point to be displayed """ try: f = float(text) except ValueError: return '' m = f - int(f) if m: return '%.1f' % f else: return '%d' % int(f)

Pycon Apac 2011

Pycon APAC 2011 in Singapore finally end this evening and this is some quick recaps on the event for the past few days. Day 1 (Tutorial) This is tutorial day only. The conference actually started on the second day. I took the Python 102 class. Initially I want to attend Practical Django project by Jacob Kaplan Moss but since my boss already took that class and we didn't want to attend the same class I picked Python 102. I thought this could be somewhat 'formal' Python class for me. Turn out it really meant for beginner. I don't know what they touched in 101 but it look to me just a repetition of what in 101 class. But I still manage to know few things that I'm not aware off. It some kind of basic but I never learn Python in formal, I just picked up the specific part of the language that can solve problem at my hand. Use negative (-) sign to apply string formatting backward. Use double, triple and so on colon in list slicing as step. Really nice feature. Enumerate to...

Planning

There are so much things that I want to write down but can't find out a time to do it. Lately my time management seem to be the worst ever. So I'll try to jot down first what in my head and hopefully I can write about it soon. Understanding Django Content Type framework - I've been working on application that require me to use Django's Content Type framework (at least I decided to use contenttype to accomplish the task). Along the way I started to understand how Django implemented it. Content type concept not really unfamiliar to me since Drupal also using the concept for their Information Archictecture (IA). Django Content Type however seem much more flexible (compared to pre Drupal 7) and simpler to understand (compared to Drupal 7 similar concept). Using Django's haystack app for search in your website/application - I decided to use haystack to provide search in another application I've developing and quite excited to see how simpler and fast I can get sea...

Django transaction.commit_manually mask uncaught exception

Update 2012-08-27 I've created a wrapper to the decorator that catch, rollback transaction and reraise the exception:- http://tech.marimore.co.jp/2012/08/django-transactioncommit_manually-wrapper.html This has happened number of times for me. There's a 3 year old ticket on this actually but since I want to be quick and no time yet to look into the ticket, the solution is to wrap all my function with a decorator that can catch the exception and exit immediately. I'm doing this in a batch script so what I want is either the script succeed or fail immediately, showing the error. YMMV.

Tree structures in relational database

Into Tree again. I'm a fan of Materialized Path but a bit worried with the limitation to the number of branches. It's ok for something like gov ministry where most of the time the number of agency and department already expected and doesn't change/grow much but with MLM kind of system, we should expect it to expand as wide and depth as possible. Think better start with adjacency model first (and maybe combined with mat path for easy retrieval). From there it's still possible to move to other models. http://www.sqlteam.com/article/more-trees-hierarchies-in-sql http://stackoverflow.com/questions/2797720/sorting-tree-with-a-materialized-path http://www.ibstaff.net/fmartinez/?p=18

Better pager for psql/mysql client

Very nice tips I found today - http://merlinmoncure.blogspot.com/2007/10/better-psql-with-less.html If you used psql or mysql client on the console a lot, it always a problem browsing through result set that much wider that your console width. export PAGER=less export LESS="-iMSx4 -FX" Then just make sure your psql/mysql use the correct pager. For mysql, \P would set pager to "less".