User login
Navigation
Recent blog posts
- Ubuntu mirrors up and improved!
- Google-jstemplate: Iterate object with unknown properties
- nginx https proxypass for php apps
- sugarcrm & memcache: Doing it Wrong
- subversion and https in Ubuntu Karmic
- Drupal: Views block delta converted to md5 hash
- Ubuntu Server install requires PAE
- Installing Drupal from command line
- Drupal: Handling form field weight through CCK
- minify javascript using Google Closure Compiler
angch's location
angch twitter
kamal's blog

Google-jstemplate: Iterate object with unknown properties
kamal — Wed, 21/04/2010 - 17:17
Iterating over list of object (array) is easy. Given the following template:-
<ul id="city">
<li jsselect="$this" jscontent="$this"></li>
</li>and our data (in json):-
var cities = [
"KL",
"KB",
"JB"
];
var processingContext = new JsEvalContext(cities);
var template = document.getElementById("frm-edit");
jstTemplate(processingContext, template);$this in the template refer to the object that we pass to JsEvalContext constructor.

Drupal: Views block delta converted to md5 hash
kamal — Fri, 08/01/2010 - 17:03
Find out this only through reading the views.module code. In case of your views block display has a long name (> 32 chars)(the views name would be used as delta in block table), Views would hash it through md5. You can get the list of hashed names stored in the variable table as views_block_hashes. For example, mine:-
Array
(
[ba843477361f490ca5c9e42548f0127d] => imagegallery_block_latest_images-block_1
)
The related code is in line 298 of views.module.

Installing Drupal from command line
kamal — Tue, 08/12/2009 - 19:04
Using twill because until Drupal 7, there's no way you can install Drupal without opening the browser.
#debug http 1
go http://192.168.1.6:12000/install.php?profile=pulut&locale=en
code 200
find "To set up your Pulut database, enter the following information."
#show_cookies
fv 1 db_type pgsql
fv 1 db_path gmp
fv 1 db_user kamal
fv 1 db_pass abc123
submit op
find "All necessary changes to <em>./sites/default</em> and <em>./sites/default/settings.php</em> have been made. They have been set to read-only for security."
fv 1 site_mail kamal@bytecraft.com.my
fv 1 account[name] admin
fv 1 account[mail] kamal@bytecraft.com.my
fv 1 account[pass][pass1] abc123
fv 1 account[pass][pass2] abc123
fv 1 update_status_module1 0
submit op
find "Congratulations, Pulut has been successfully installed"
clear_cookies
go http://192.168.1.6:12000/
fv 1 name admin
fv 1 pass abc123
submit op
find "Log out"It's pretty crude at the moment but I guess a good start. Couple with some other tools I'm working on, installing Drupal can be fully automated. The next step is to convert this twill script into Python equivalent to be more flexible.
Update
Here some good and better explanation on this from Lin Clark's blog.

Drupal: Handling form field weight through CCK
kamal — Tue, 01/12/2009 - 16:23
If you have custom field added to the node form (probably using hook_form_alter), you have to manually set the #weight properties to order the element the way you want on the node form. CCK user definitely would miss the 'drag and drop' UI to rearrange CCK fields.
Turn out it possible to somehow 'register' your custom fields so that it can be rearranged using the CCK UI. Cool. I first found this in an old issue queue. Further 'googling' lead me to this blog post which describe it further.
The key is the hook_content_extra_fields that you can implement to return an array of fields to be managed by CCK. Then function content_extra_field_weight($node_type, $fieldname) can be use to set the weight properties on hook_view or hook_nodeapi view op.

Drupal urlencode: Dealing with ampersand in filename
kamal — Mon, 09/11/2009 - 10:31
A bug poping out with some files failed to download, returning 404. Looking closer at the issue, turned out the files that failed contained ampersand "&" in the filename. PHP would translate the "&" in request path as a key in $_GET variable. So something like:-
$ wget http://www.somesite.com/system/files/fm/somefile_with_&_ampersand.pdfwould result in PHP $_GET as:-
array(
[q] => system/files/fm/somefile_with_
[_ampersand] =>
)urlencode'ing' the path is not enough because PHP would still translate that to an ampersand.

Debugging WSGI Application
kamal — Thu, 05/11/2009 - 09:09
One thing everyone like in PHP, print statement just work. You don't need any fancy debugger.
DebuggingTechniques does explain it well on how to debug your WSGI apps. It also explain why print would not work, all for good reason. My favorite debugger is the web debugger from Werkzeug but as explained in the wiki, to make it work with mod_wsgi you must make sure subsequent request from the debugger end up in the same process that trigger the error. That mean:-
StartServers 1 ServerLimit 1

Build Debian package for Python modules
kamal — Fri, 14/08/2009 - 10:20
Just a note for future references. Tools to build Debian package for Python modules:-
Stdeb is not in Ubuntu Hardy repo so we need to build a package for itself first.

PHP CLI Segmentation Fault With pgsql
kamal — Mon, 13/07/2009 - 14:09
"Segmentation fault"
Got this every time running PHP from the command line, especially when working with Drupal. It doesn't caused any harm (script working just fine) and that's why I never look into it. But accidentally found this post and the suggested fix did remove the "Segmentation fault" message from appearing.
- Commented pgsql in pgsql.ini
- Load pgsql extension in curl.ini, before the curl extension.

Drupal: Where's my CCK content get stored in db ?
kamal — Tue, 16/06/2009 - 12:10
Wrote about internal CCK storage in my personal blog sometimes ago but looking through issues coming up recently in our issue tracker suggest that some of developers here still not sure where their CCK content are stored in the database. Briefly revising this topic to give some clue on where to look after when something goes wrong with our CCK related content.

Drupal: Namespace your CCK fields
kamal — Wed, 03/06/2009 - 15:34
Not aware of this until it was too late. All CCK field was stored in a flat container in table node_field. It's not unique per content type. That means you cannot have two fields with a same name although that field was used in different content type. From the UI, if you create field with a same name, it'll just append an arbitrary number such as _0, _1 to make it unique.
