Skip to content

Teguh Eko Budiarto

Web Programming and Sharing Experience

This is to note that the username for LAMPP process for MySQL and Apache is nobody. It is different than the default username for apache process which is www-data. To easily granted access for the web server apps, just change the owner of the accessed directory to nobody by using below code:

sudo chown nobody <path-to-folder>
Bookmark and Share

We are using SVN to save our works and hooking a post-commit script which one of the function is to send e-mail regarding the changes that had just made. We are using the wonderful SVN::Notify, a perl application to do the job. It already have the functionality to produce a beautifully diff colored HTML email using the SVN::Notify::HTML::ColorDiff module as the handler.

However, since we are using web based Google Apps Gmail interface as our email client, the HTML was not rendered nicely because the CSS is not applied inside the interface. We need to change the CSS to the inline style. And then I found a patch done here. Because it is a direct hack, I want it to be more generic that the user can choose the inline style or not, then I modified a little bit more. I added optional parameter –css-inline to generate CSS style directly inline with the HTML tags. I had submitted the changes to the original author hoping he will include this option in the next revision. Just in case, I also put it here.

Snippets to add the additional parameter:

package SVN::Notify::HTML;

# $Id: HTML.pm 4617 2009-03-19 17:04:53Z david $

use strict;
use HTML::Entities;
use SVN::Notify ();

$SVN::Notify::HTML::VERSION = '2.79';
@SVN::Notify::HTML::ISA = qw(SVN::Notify);

__PACKAGE__->register_attributes(
    linkize   => 'linkize',
    css_url   => 'css-url=s',
    wrap_log  => 'wrap-log',
    css_inline => 'css-inline',
);

You may download the full source below:

Bookmark and Share

Since Python is not a strongly typed programming language, you do not have to specify your variable type. This is nice but have some drawback for Netbeans, which it can not recognize the type easily so you can not have good suggestion for the intellisense feature. To fix that you have to specify the type of your variable and make sure you already import the correct module.

For example, when you have this kind of code (below code are for example purpose only)

from datetime import datetime
from django.db import models
from django.utils.translation import gettext_lazy as _

class Poll(models.Model):
    question = models.CharField(max_length=200)
    password = models.CharField(max_length=200)
    pub_date = models.DateTimeField(_('date published'), default=datetime.now)
    class Admin:
        pass
    def __str__(self):
        return self.question
    def get_choice_list(self):
        return list(self.choice_set.order_by('id'))
    def get_choice_from_num(self, choice_num):
        try:
            return self.get_choice_list()[int(choice_num)-1]
        except IndexError:
            raise Choice.DoesNotExist

class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()
    class Admin:
        pass
    def __str__(self):
        return self.choice
    def get_num(self):
        try:
            return self.poll.get_choice_list().index(self)+1
        except ValueError:
            raise Choice.DoesNotExist

For people like me, usually the first thing I do when want to use a defined variable is to hit the ctrl-space button to display the Intellisense suggestion. But in this case, when I want to use functions or variables defined in the attribute poll in Choice class, it displays :
specify type netbeans python

Which means Netbeans does’nt understand the type and the intellisense just throw all the types available to you and it become garbage, instead of suggestion. To teach Netbeans the type of the variable, just click the Specify type of [the variable name] menu, and then type your variable’s type. After that the intellisense will give you nice result, like this picture below:
specified type netbeans python

Other thing is to make sure you have imported your class in your file so Netbeans will recognized it properly. Hope it helps, Cheers! :)

Bookmark and Share

This tip is for windows XP user ( some other windows version will also have similar procedure).

If you are using an automatic configuration script for your internet setting, most probably, Python will not be able to connect to internet. This is troublesome if you want to install some packages which has dependencies which need to be fetched from the net. You need to change your internet options setting to use the proxy address directly.

Below is how to do that:

  • Go to Control Panel
  • Open Internet Options
  • Open Connection Tab
  • Click on LAN Settings button
  • Check the Use a proxy server for your LAN…
  • Enter the proxy IP Address and its port. If you do not know where it is, ask your network administrator or just open the configuration script to find out where is the IP you need to use.
  • Press OK until all the setting windows are closed.

Below is the screen shot of the internet options screen.

Windows XP Professional Internet Options Screen

Windows XP Professional Internet Options Screen

Bookmark and Share

I wrote this post in my journey to adapt Python with Django framework as my tool in the next project. A little bit skeptical and some holding back since I had background in PHP and C# .Net. But, I have no choice because Python is already team’s decision for new projects. So, here I go with learning new language and framework again.

In the way, sometimes I can not find a distributable package for your Python version. In one case, I would like to install setuptools to install other packages, soaplib which I need to build a SOAP web service. This is because most of our legacy applications are using C# which using SOAP to interface with web services, otherwise, I prefer to create REST based web service. Anyway, this is just my beginner way of thinking.

So, enough with the mumbling, below is how it is:

  • Unpack the source into a folder.
  • Using command prompt, go to the folder and run command below ( I assume that you already set your python PATH and can run Python command from command prompt).
  • python setup.py bdist_wininst
  • Voila! An executable installer for your installed Python version will be available in dist sub folder.

Very easy isn’t it? Yeah, if it is that easy for me to find how in the first place, I would’nt write this post.

Bookmark and Share

I just upgraded my laptop harddisk. It is not that I need more space, but the old harddisk was failed several times, in a very critical moment when having tele-screen-sharing-conference with my client :( . Anyway, that was a different story. The story here is that I have to re-install my computer, and unfortunately, I haven’t got image backup of my HDD yet…another big mistake. However, I managed in a single, almost sleepless night to make it ready for to code again, and now already create the image for clean backup :) .

One of the main application I used to code is Netbeans. I love this editor. However, I am using Japanese as my windows locale, so as default, Netbeans will use that setting and display japanese menu. Even though until now, I am already living in Japan for 5 years, I still prefer English as my application menu language, so I don’t have to bother searching difficult kanji which can waste my productive time.

I did the setting before to change the locale to English after some time searching the web for the correct setting. And now, I have to do it again, but I don’t know where to find it anymore since I did not write about it anywhere. So, here it is. You may change the configuration of Netbeans, following instructions from this Netbeans Wiki.

To change the locale, you need to add text below after the last configuration in netbeans_default_options.

-J-Duser.language=en -J-Duser.region=US -J-Dfile.encoding=UTF-8

This is valid for Netbeans 6.5, and 6.71 when this post is written. I hope this can be useful for somebody besides me :) .

Bookmark and Share

I was using JQuery autocomplete from Jörn Zaefferer to finish a small project for Computer Telephony – IPX PBX user interface. I think this is an awesome plugin ad it is suited very well for my project.

For the project, I need the autocomplete to be able to search all data containing words which begins with the text being typed in the input textbox. However, after browsing through the documentation and try the possible combination of matchContains and matchSubset options of the plugin, it seems that it was not able to do what I want it to do. So, I decided to debug the javascript and go into the code to modify the search algorithm.

When I look into the code, I found this part of code:

function matchSubset(s, sub) {
		if (!options.matchCase)
			s = s.toLowerCase();
		var i = s.indexOf(sub);
		if (options.matchContains == "word"){
			i = s.toLowerCase().search("\\b" + sub.toLowerCase());
		}
		if (i == -1) return false;
		return i == 0 || options.matchContains;
	};

In the fifth line of the function, there is a value check for matchContains option which implies that it received “word” value besides boolean true or false. The code uses the javascript search function with regex using \b tag which means word boundary. This means that it already have the functionality to search for subset contained in each word of the search data.
I immediately changed my code to try to use the option by adding this line:

matchContains:"word"

So, the whole code to activate the autocomplete textbox is as below:

 $("#searchInput").autocomplete(json.Data, {
                    cacheLength:1,
                    delay:0,
                    formatItem: function(row)
                    {
                        var sShow = row.Name + " - (" + row.TypePhone + ") " + row.Phone;
                        return sShow;
                    },
                    matchContains:"word",
                    matchSubset:true,
                    max:100,
                    minChars:1,
                    width:285,
                    selectFirst:true,
                    scrollHeight:"100px"
                });

After that, I try to find in the author’s website and JQuery documentation where in the world that option is being documented. At last I found it in the change log for the latest version 1.1 (per this post date). It should be also written in the JQuery plugin documentation, since it is a very useful feature, at least for me at the time :) . I hope the author would update the documentation accordingly soon.

Bookmark and Share

Today I had experienced a weird problem with my Joomla upload. After uploading to live server, my mod_smoothgallery from OsCandy was not displaying and StopPress Module that should be appear on top all other content was not displaying but was blocking all other so they can not be clicked. When I enter administration site, the menu was not displaying either. Because of that, I thought the problem was only effecting JavaScript related components and also related to files/folder permission mode. I tried to change mode the files and folders, but still there was no effect. And then I installed another instance of Joomla using Elefante Installer, an automated script installer provided by the hosting provider.

After installing fresh copy of Joomla, I check the administration menu bar, and there it was. And when I check the files permission are the same with the one I had. So, I tried to copy all the files to overwrite my site with no good result. Finally I found the problem was with the SQL export-import. I export SQL from my localhost development server by using HeidiSQL and apparently it gives incompatible format so when I import to the live server it was not importing properly. Thank goodness I was using Apace2Triad which comes with PhpMyAdmin so I just re-export from there and re-import from the live server’s PhpMyAdmin. Voila! it worked perfectly again. So, the site can run smoothly from now.
Please visit the site at www.chinese-studies.org. We will updating more content in the future, so please visit often for you guys who interested in chinese cultures ;)

Bookmark and Share

I needed a pivot table to display a report to the user in my company, so I tried googling the best and practical way to do that. At first, I was interested in using MS Office components and just pass the data to the component and refresh the template so it will display the data I need. But, the thing is I will need the component also to be installed in the server, and this is not a really high priority apps to put the server in risk to not working for some time if there is anything wrong with the installation or the components it self. So, I decided using the data table manipulation and I found a good example on how to do that in weblogs of sql team here.

However, there is small modification I need to do since the function written there only accommodate single key column. After modified it, I was planning to put the update in comments of the page so I can contribute somehow. Unfortunately the comments is already closed, so I decided to put it here. Find it below. This pivot function is placed in a web service which is going to return a dataset containing the pivot table. After receiving it in the web app, I format the datagrid so it will display as the user need. Yay! Alhamdulillah. Hope it will be useful for other people who need it.

/// 
/// Transform a table to a pivot table based on the given information.
/// 
/// 
/// The table which is going to be transformed to pivot table. The table should be sorted by the key colums, starting from most left part.
/// 
/// 
/// Array of String which contains the columns in dataValues that is going to be used as a keyColumn for display
/// 
///

/// The Column name of the dataValues which is going to be displayed as pivot table's column
///
///

/// The Column name of the dataValues which is going to be used to fill the value for the pivot table's column
///
/// 
public static DataTable Pivot( DataTable dataValues, string[] keyColumn, string pivotNameColumn, string pivotValueColumn)
{
	try
	{
		DataTable tmp = new DataTable();
		DataRow r;
		string[] LastKey = new string[keyColumn.Length];
		int i,keyColumnIndex, pValIndex, pNameIndex;
		string s;
		bool FirstRow = true;
		bool keyChanged = false;

		// Add non-pivot columns to the data table:
		pValIndex = dataValues.Columns.IndexOf(pivotValueColumn);
		pNameIndex = dataValues.Columns.IndexOf(pivotNameColumn);

		for (i = 0; i <= dataValues.Columns.Count - 1; i++)
			if (i != pValIndex && i != pNameIndex)
			{
				tmp.Columns.Add(dataValues.Columns[i].ColumnName.ToString(), dataValues.Columns[i].DataType);
			}
		r = tmp.NewRow();

		// now, fill up the table with the data:
		foreach (DataRow row in dataValues.Rows)
		{
			// see if we need to start a new row
			keyColumnIndex = 0;
			keyChanged = false;
			if (!FirstRow)
			{
				while (!keyChanged && keyColumnIndex < keyColumn.Length)
				{
					if (row[keyColumn[keyColumnIndex]].ToString() != LastKey[keyColumnIndex])
					{
						keyChanged = true;
					}
					keyColumnIndex++;
				}
			}
			else
			{
				for (keyColumnIndex = 0;keyColumnIndex<= dataValues.Columns.Count - 3; i++)
				{
					r[i] = row[tmp.Columns[i].ColumnName];
				}
				FirstRow = false;

				for (keyColumnIndex = 0;keyColumnIndex 0)
			{
				if (!tmp.Columns.Contains(s) && s != null)
				{
					tmp.Columns.Add(s, dataValues.Columns[pValIndex].DataType);
				}
				r[s] = row[pValIndex];
			}
		}
		// add that final row to the datatable:
		tmp.Rows.Add(r);

		// and that's it!
		return tmp;
	}
	catch (Exception)
	{
		return null;
	}
}
Bookmark and Share

Sometimes ago, I had my HTC unlocked, and it was already able to use other mobile operator connection, but I was still getting the locking screen when I inserted other SIM than Softbank. At first, I only research how to remove the annoying screen, but I found better thing, not only I can remove the annoying screen, I also should be able to upgrade to windows mobile 6, which is very cool. Thank you guys in XDA developers forum! Certainly I already put links to your pages/threads below.

I bought my X01HT on September 2006 so I do not have any problem with ROM and radio version. I will describe below how I made my Japanese Softbank X01HT to an English Unlocked Smartphone with Japanese input and proprietary MMS capability (MMS not fully worked, I will update again if I already solve the problem).

  1. Unlock the operator restriction so it can use all GSM SIM all over the world using Hermes unlocker by POF. Follow this link to find downloadable zip file, download, extract and follow the instructions found in the text file
  2. Flash WM6 mobile ROM cooked wonderfully by Schaps to have an English OS in your smartphone. Download the executable file and run it with active sync active. If you can not download from the link, try this page. Congratulations! Now you already have an unlocked english version windows mobile smartphone. Let’s continue.
  3. Time to make your phone displays Japanese, download this Zip file, extract and copy the cab file to your device and run inside it.
  4. Download this MMS Lite, extract and run the CAB file in your device and enjoy Softbank’s proprietary MMS.
  5. For the input, eventhough it is said that you can have other type of input, I prefer IME input which it had before. You can download from here, copy the cab to the phone and run it.

The phone is ready to go! You now have an English, Unlocked, Japanese capable Smartphone, with Softbank’s proprietary MMS enabled. Congratulations!

Make sure you follow the instructions for each step in each manual found carefully. But, if not you can always start again from the beginning. Don’t worry about breaking your phone since step 1 and 2 which is the most dangerous are already equipped with Hard-SPL/SSPL flashing which is said can protect from bricking the phone. That is my opinion, but for more cautious guy, you may want to check the XDA forum first. Furthermore, my X01HT is before Dec 2006 version, so I do not have too much obstacle.

Next step is installing softwares for my phone so I can be more productive and have fun with it. My choice of free powerful softwares to be first installed are :

  1. Mobipocket to read e-books – you can also easily make/convert ebooks from other formats using Mobipocket Creator as simple as drag and drop and synchronize with your device seamlessly.
  2. MS Reader – for ebook with lit format
  3. Pocket Islam – complete package so I can hear Quran while reading the meaning. The sound is linked with the text, it will highlight the ayat that is being played in reciter sound. Cool!
  4. TCPMP with divx, flv codecs - complete multimedia solution. You can play many format of videos and music

Credits:

Bookmark and Share