Stivlo'st in Asia

Programming and Travel

Browsing Posts published in July, 2010

My ExtJS combobox that was working with Firefox was showing this error message on IE8. The reason for this was a trailing comma in my Javascript matrix.

My data store was like this:

var shopList= [
    ['702038', 'some dude name'],
    ['1120685', 'another dude'],
];

Ok, it’s a stupid mistake, but it can happen when you delete the last option and forget to remove the comma. A way to avoid this types of mistakes is using an IDE such as Netbeans that will signal you the error immediately with a graphical hint. After removing the trailing comma it worked in IE too:

var shopList= [
    ['702038', 'some dude name'],
    ['1120685', 'another dude']
];

I’m trying out ExtJs Ajax library and the first control I tried is the combo box. I tried out Jquery UI combo box, but it wasn’t working very well when filled with hundreds of values. It kept on resetting and reloading the page. It’s not a real component but a hack and is probably not meant to be used with so many values.

I then tried ExtJs combo box and it worked well with over a thousand choices in it. The power of a combo box versus a normal select box is that it makes it easy to find a value among several hundreds. If we have only a few choices there is no added value to have a combobox with tooltips.

However I wanted to modify the original behavior of Ext.form.ComboBox to allow to search anything in the middle of the record. In my particular case I had a ComboBox filled with customers, and that could be company names or surname and names. A company name could be “Romantic Furniture of John Pollock”, it can be as natural to type “Pol” because I can remember the surname and not the shop name. This behavior, as far as I could understand could not be achieved with the configuration parameters of extJS combobox. So I had to extend the class to redefine the doQuery method.

I got a little stucked with namespaces and I could not do a general extension, so it’s coded for the particular case. I hope to find a more general way soon, but so far my attempts have failed.

So basically in the Ext.onReady function I defined the following:

Ext.onReady(function() {
    var store = new Ext.data.ArrayStore({
        fields: ['id_person', 'descr'],
        data:  shopList
    });

    function AnyMatchCombo(config) {
        AnyMatchCombo.superclass.constructor.call(this, config);
    }
    Ext.extend(AnyMatchCombo, Ext.form.ComboBox, {
        minChars:2,
        typeAhead: false,
        mode: 'local',
        triggerAction: 'all',
        emptyText: 'Scrivi o Seleziona...', //translation
        doQuery: function(q, forceAll) {
            console.info('AnyMatchCombo '+q);
        }
    });

    var combo = new  AnyMatchCombo({
        store: store,
        valueField: 'id_person',
        displayField: 'descr',
        applyTo: 'searchCB'
    });
});

Which basically works and calls my modified doQuery() function that for now just logs to the console. You need firebug to be open for the console to work. After testing it out, I can change the doQuery method with its actual implementation:

doQuery : function(q, forceAll){
    q = Ext.isEmpty(q) ? '' : q;
    var qe = {
        query: q,
        forceAll: forceAll,
        combo: this,
        cancel:false
    };
    if(this.fireEvent('beforequery', qe)===false || qe.cancel){
        return false;
    }
    q = qe.query;
    forceAll = qe.forceAll;
    if(forceAll === true || (q.length >= this.minChars)){
        if(this.lastQuery !== q){
            this.lastQuery = q;
            if(this.mode == 'local'){
                this.selectedIndex = -1;
                if(forceAll){
                    this.store.clearFilter();
                }else{
                    this.store.filter(this.displayField, q);
                }
                this.onLoad();
            }else{
                this.store.baseParams[this.queryParam] = q;
                this.store.load({
                    params: this.getParams(q)
                });
                this.expand();
            }
        }else{
            this.selectedIndex = -1;
            this.onLoad();
        }
    }
}

And after we’ve just to change line 22 as follows:

this.store.filter(this.displayField, q, true);

I’ve some troubles editing large files (over 1Mb) with Netbeans: editing gets slower and freezes for many seconds. The IDE Faq actually says: “The IDE automatically determines optimal Java VM memory settings based on the size of physical memory. Rarely you might want to change the heap size.”

Since the performance are disappointed I want to give a try anyway. In my netbeans.conf I had the following line:

netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Dapple.laf.useScreenMenuBar=true -J-Dsun.java2d.noddraw=true"

Which I changed to:

netbeans_default_options="-J-client -J-Xss2m -J-Xms256m -J-Xmx1024m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Dapple.laf.useScreenMenuBar=true -J-Dsun.java2d.noddraw=true -J-XX:+UseConcMarkSweepGC -J-XX:+CMSClassUnloadingEnabled -J-XX:+CMSPermGenSweepingEnabled"

The main changes are -J-Xms256m which tells Netbeans to start with a heap of 256Mb and -J-Xmx1024m which is the maximum heap size (1024Mb).

The bottom line: I didn’t have a performance boost and I decided to edit the very big files with Scite which does a much better job.

As I recently moved to a new house, I don’t have my DSL subscription anymore and I decided to try to share the internet connection provided by my Nokia 5230 to the whole house using a wireless router (as a switch).

I’ve installed Ubuntu with pendrivelinux on a USB memory stick. It was fast and easy to connect to the internet and share it. After installing ubuntu I’ve installed wvdial:

# apt-get install wvdial

And it comes from the USB key itself, great thoughfulness because at this stage I can’t connect to the internet yet.

After that I’ve edited /etc/wvdial.conf

[Dialer Defaults]
Modem = /dev/ttyACM0
Baud = 9600
Phone = *99#
Username = user
Password = pass
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2
Init3 =
Dial Command = ATDT

Note that username and password can be anything in my case. By typing “wvdial” the internet connection is working, but only on this computer, is not shared yet. To share it, I wrote a small script, internet_share.sh

#!/bin/sh
echo "1" > /proc/sys/net/ipv4/ip_forward
iptables -A FORWARD -i eth0 -d 192.168.1.0/24 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -s 192.168.1.0/24 -o ppp0 -j ACCEPT
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

After executing the script the connection is shared and will work, provided that other hosts of the network use the IP address of this computer as gateway. The connection is generally good and fast and I’m not missing my old DSL at all (that wasn’t that great actually).

Update: this configuration works with Smart Philippines, the configuration for Globe is a little different and I can post it if anyone is interested. I switched from Smart to Globe because Smart was stealing money from my account! Even if I was subscribed to a unlimited internet package, the account balance kept on shrinking, of several hundred pesos, despite I didn’t make any phone call or sent SMS. Globe doesn’t have this problem.

When using php setlocale() function it’s important to check the return value. I used to call it without checking it as in:

setlocale(LC_ALL, 'it_IT.UTF-8');

Without figuring out that if the locale it_IT.UTF-8 is not present in the system, the setlocale function fails and returns false.

The first idea I had to try to add the locale is calling:

$ dpkg-reconfigure locales

But nothing happens and the prompt is returned, because in my case the default question priority didn’t allow any question to be asked (like: what locales do you want to rebuild?). So I tried

$ dpkg-reconfigure -p low locales

With no improvements at all. So I resorted to the manual way editing the file /var/lib/locales/supported.d/local

and adding the entries I wanted in this case:

en_US.UTF-8 UTF-8
it_IT.UTF-8 UTF-8

So this time the reconfigure worked as I wanted:

# dpkg-reconfigure locales
Generating locales...
en_US.UTF-8... done
it_IT.UTF-8... done
Generation complete.
Powered by WordPress Web Design by SRS Solutions © 2010 Stivlo'st in Asia Design by SRS Solutions