Thursday, November 29, 2012

ExtJS ComboBox with local store and change action listener.

new Ext.form.ComboBox({
    fieldLabel: '',
    id: 'searchtypeforcontacts',
    name: 'searchtype',
    x:200,
    labelSeparator :'',
    editable: false,
    store: new Ext.data.SimpleStore({
        fields: ['id', 'header'],
        data: [
            ['id', 'Contact Id'],
            ['first_name', 'Given Name'],
            ['email', 'Email'],
            ['country', 'Country'],
            ['state', 'State'],
            ['suburb_city', 'Suburb/City'],
            ['post_zip_code', 'Post/Zip Code']
        ]
    }),
    displayField: 'header',
    valueField: 'id',
    emptyText:'Search Contacts',
    typeAhead: true,
    mode: 'local',
    anchor: '40%',
    triggerAction: 'all',
    allowBlank: false,
    selectOnFocus: true,
    blankText: 'Select search type',
    listeners:{
        'select':function() {
            if (this.value == 'status') {
                //statusCombo.show();
                searchText.hide();
                $(".customerSearch").css({'margin-left':'210px','width':'auto'});
            } else {
                //statusCombo.hide();
                searchText.show();
                $(".customerSearch").removeAttr("style").css("width:auto;");
            }
        }
    }
})

Tuesday, November 27, 2012

How to find the length of a chinese phrase in a MySQL database with SQL

create table word(
  en_word text null,
  zh_word text null
);

insert into word values('Internet', '互联网');
insert into word values('Hello', '你好');

INVALID QUERY:
select
  LENGTH(en_word) as 'English Length',
  LENGTH(zh_word) 'Zh word length'
from word;

VALID QUERY:
select
  CHAR_LENGTH(en_word) as 'English Length',
  CHAR_LENGTH(zh_word) 'Zh word length'
from word;


















LENGTH returns length in bytes (and chinese is multibyte)
Use CHAR_LENGTH to get length in characters

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_char-length
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_length

phpWhois -base class to do whois queries with php

Code block:
        $pathMain = WWW_ROOT."..\\libs\\phpwhois\\whois.main.php";
        $pathUtils = WWW_ROOT."..\\libs\\phpwhois\\whois.utils.php";
        if(file_exists($pathMain) && file_exists($pathUtils)) {
            include_once($pathMain);
            include_once($pathUtils);
            $whois = new Whois();
            $whois->non_icann = true;
            $result = $whois->Lookup("yourcause22.com");
            print_r($result);
        }

Download WHOIS from:
http://www.phpwhois.org/
http://sourceforge.net/projects/phpwhois/?source=dlp

jQuery Back Button (go to previous page)

You can check history length by jQuery and if can not possible to go back you can remove it.

First in html page introduce a hyperlink:
<a href="javascript:void(0)" class="back_link">Back</a>

Then add the jQuery code block:
<script type='text/javascript'>
    if(history.length <= 1) {
        jQuery(".back_link").remove();
    }
    jQuery(".back_link").bind("click", function() {
        if(history.length > 1) {
            parent.history.back();
        }
        return false;
    });
</script>

Saturday, November 24, 2012

Get xml from a php webservice url using android

public String getXML(){
    String line = null;
    try {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet httpPost = new HttpGet("http://example.com/a.php");

        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        line = EntityUtils.toString(httpEntity);
    } catch (Exception ex) {
        Log.d("Error reading xml", ex.toString());
    }
    return line;
}
 
But if u are using your local host as test purpose then use 10.0.2.2
instead of localhost/127.0.0.1  

Replace a string in file using shell script

Suppose my file a.conf is as following
Include /1
Include /2
Include /3
I want to replace "Include /2" with a new line, I write the code in .sh file : 
line="Include \\/2"
rep=""
sed "s/${line}/${rep}/g" /root/new_scripts/a.conf > /tmp/a.conf-new
 
mv /tmp/a.conf-new /root/new_scripts/a.conf 

Encrypt a file using bash shell script

openssl des3 -salt -in /pritom/input.sql -out /pritom/output.pk -pass pass:pritom
 
where:
 /pritom/input.sql is the input file
 /pritom/output.pk is encrypted output file
 -pass pass: pritom (pritom is used as password)