Thursday, December 27, 2012

Netbeans 7.2 and upward crash on start after installing python module.

I have installed python plugin to my Netbeans 7.2.1 and after restart the IDE it struck  in module loading step in start-up screen and then crashed.
To find the reasons i read the Netbeans Log located in


[HardDrive]:\Users\[UserName]\AppData\Roaming\NetBeans\7.2.1\var\log


And after reading the log i found out that there is a class not found exception occurred as stated below.


java.lang.NoClassDefFoundError: org.osgi.framework.hooks.bundle.CollisionHook starting from ModuleCL@2bb7f958[org.netbeans.modules.netbinox] with possible defining loaders [ModuleCL@2ae827e1[org.netbeans.libs.osgi]] and declared parents [org.netbeans.MainImpl$BootClassLoader@b98df1f, ModuleCL@5bd7a97b[org.netbeans.core.netigso], ModuleCL@2ae827e1[org.netbeans.libs.osgi]]&oq=java.lang.NoClassDefFoundError: org.osgi.framework.hooks.bundle.CollisionHook starting from ModuleCL@2bb7f958[org.netbeans.modules.netbinox] with possible defining loaders [ModuleCL@2ae827e1[org.netbeans.libs.osgi]] and declared parents [org.netbeans.MainImpl$BootClassLoader@b98df1f, ModuleCL@5bd7a97b[org.netbeans.core.netigso], ModuleCL@2ae827e1[org.netbeans.libs.osgi]]


This error cause the Netbeans IDE to crash it when it load the modules. Reason for this is because Netbeans modules use OSGI framework to wire up the modules in the start up and with the version 7.2 onwards the necessary OSGI distribution was not bundled with the Netbeans.

To fix this all we have to do is download the necessary jar files from OSGI site and copy them to Netbeans location.


  1. Download the latest OSGI core from here.
  2. Rename the jar file to :

    org.osgi.core-[version no].jar
  3. Copy it to the lib folder of Netbeans resides in following location,

    [HardDrive]:\Program Files\NetBeans 7.2.1\platform\lib



Thursday, December 20, 2012

Eclipse helios "install new software" feature lagging.

I have to use eclipse helios which is 2 versions behind the current version, thanks to our IT department few days back. When i try to download pluggins over network it start to lag after 24% completed.

After doing so many searches on google finally i found out the  problem is with the JRE version.

In my machine i have the latest Java 1.7 installed. Eclipse helios originally designed for JRE 1.6 and its "install new software" feature use a depricated sort method from java 1.7 which was originally in Java 6. So to solve the problem i have started eclipse using "Command prompt" to with passing parmeter to use JDK/JRE 1.6 as java runtime for eclipse.


D:\Eclipse\eclipse j2ee indigo>eclipse -vm C:\Java\jdk1.6.0_31\bin\javaw.exe

This solve the problem and now you can install any plugging without geting stuck and suddenly stopped the process.

Wednesday, November 21, 2012

How to create a custom mediafire search page

Search Mediafire
Search Mediafire






You might have already familiar with google query language which enable to define various kind of searches over google search. In this article i will explain how to use such an option to search inside "mediafire.com", a popular file hosting service.

Use following query. ( for anything you want to search inside any site )


<File name><space>site:<site name>


For an example if we want search for "avatar" inside "mediafire.com" we write following query in google search bar.


avatar site:mediafire.com


Also below i post a simple "html" file that has a javascript function and a html form to accomplish this task. You have to do is save this as html file in your computer and bookmark it from your browser. So you can use this search page to search inside mediafire.com anything you want.

HTML FORM

<form action="http://www.google.com/search" method="get" onsubmit="google_sitesearch(this)">
<div style="text-align: center;">
<input name="q" style="font-size: 18px; height: 35; width: 550px;" type="text" />
<br />
<br />
<input style="height: 40px; width: 150px;" type="submit" value="Search" />
</div>
</form>


JAVASCRIPT

<script type="text/javascript">
     function google_sitesearch(thisForm){
             thisForm.q.value = thisForm.q.value+" site:mediafire.com";
     }
</script>




Friday, November 2, 2012

Android HSPA settings & MMS settings for Dialog


Go to ,
Settings --> Wireless and Network --> Mobile Networks -- > Access Point Names

HSPA settings

Tap menu and select New APN.

Enter the following settings. ( for none and not set fields leave them empty )

Name: DialogBB
APN : dialogbb
proxy : none
port : none
User Name : not set
Password : not set
Server : not set
MMSC : not set
MMS proxy : not set
MMS port : not set
MCC : 413
MNC : 02
Authentication type : none
APN tpe : internet

Tap menu , tap save and tap back.


MMS settings

Tap menu and select New APN.

Enter the following settings. ( for none and not set fields leave them empty )

Name: DialogMMS
APN : www.dialogsl.com
proxy : none
port : none
User Name : not set
Password : not set
Server : not set
MMSC : http://mms.dialog.lk;3130/mmsc
MMS proxy : 192.168.122.2
MMS port : 8080
MCC : 413
MNC : 02
Authentication type : none
APN tpe : mms


Tap menu , tap save and tap back.

Wednesday, October 31, 2012

MySQLdb does not commit ???? then read this.

If you are newby for python and want to use mysql database with the language. You might have come across this weird behavior at least once in your python time.

Once you check your db after finish running sql query that insert data to your mysql db you might have surprise to see there is no data inserted at all. Actually i had seen something more weird which is first i install MySQLdb package it was ok, it inserted data as it used to be. But after i install mysql c++ headers it start to act weird (for my case, but usually this is how it should happen... you may find in a while )

The problem to not insert the data is that you have not specified it in your connection. In more simpler manner, MySQLdb is not like other database libraries in other language, you have to specifically tell at the beginning to commit your changes automatically or you have to do it manually each time u run an insert sql. Of course yes if you only use your code only to read the data you dont have to do anything at all.

So there are two ways in MySQLdb to commit the data.

First one is to tell the library to commit it after you execute insert sql statements.



con = MySQLdb.Connect(host=host,user=uname,passwd=pwd,db=db)
#your insert sql statements goes here
con.commit()


Next way is to enable auto commit mode at the beginning.



con = MySQLdb.Connect(host=host,user=uname,passwd=pwd,db=db)
con.autocommit(True)
#your insert sql statements goes here


Happy Coding !!!


Saturday, September 29, 2012

Android HSPA settings & MMS settings for Mobitel


Go to ,
Settings --> Wireless and Network --> Mobile Networks -- > Access Point Names

HSPA settings

Tap menu and select New APN.

Enter the following settings. ( for none and not set fields leave them empty )

Name: Mobitel
APN : mobitel3g
proxy : 192.168.050.163
port : 8080
User Name : not set
Password : not set
Server : not set
MMSC : not set
MMS proxy : not set
MMS port : not set
MCC : 413
MNC : 01
Authentication type : none
APN tpe : internet

Tap menu , tap save and tap back.


MMS settings


Tap menu and select New APN.

Enter the following settings. ( for none and not set fields leave them empty )

Name: MobitelMMS
APN : wapmms
proxy : none
port : none
User Name : not set
Password : not set
Server : not set
MMSC :  http://192.168.050.165
MMS proxy :  192.168.050.163
MMS port : 8080
MCC : 413
MNC : 01
Authentication type : none
APN tpe : mms


Tap menu , tap save and tap back.

Tuesday, September 18, 2012

How to activate hutch midnight packages



Hutch Srilanka has introduced a prepaid data plan that gives u a bundle of data plus talk time in two flavors.

One way to activate this package is mentioned in their web site. Where you have to reload the specific amount and the system will activate the package for you.


Other way is as follows, where you can use existing balance of your account to activate the data plans without reloading it.

  1   Type *131# on your phone                                                           
  2   Select 5 from the menu and reply                                                 
  3  Select the appropriate number for you package and reply again  
  4  You will receive a conformation message in a while                    



Or the short code type *131*5*1# for 2GB package or *131*5*2# for 4GB package and dial.



Thursday, September 13, 2012

Toward more categorized web ...

Identify to which category a URL belongs will be a crucial matter when it comes to web semantics. Also for other ongoing research areas such as unsupervised machine learning, networking systems it is a must to have a catalog of web.

But the problem is that it is hard to find affordable such catalog. Also when it comes to categorizing web, human interfere is preferred rather than using computer algorithms to do so. But to find such a man made web category which is affordable is hard. Where the www.dmoz.org comes in.

Dmoz is also called as the "Open Directory Project", named after its original domain name "direcotory.mozilla.org". This is owned by netscape which still maintained by lot of  human participation.

Dmoz has a catalog over 2 million URLs which has been categorized in to 605228 categories and growing. RDF dumps of the dmoz has been available  under open directory license and from 2011 it started  to use creative common license.

RDF

RDF known as "resource description framework" is one of W3C specification which has been used as a meta data model. This has been used as a method to model web resources. Also RDF is XML based language.

Dmoz RDF dumps.

RDF dumps of the dmoz is available at the this URL.

But for me it was bit harder to process RDFs since no proper library with documentation available for me in python so i use this script with some modifications to convert RDF dump to a SQL dump. (Modifications has to be done since the script us old PHP versions. So if you use new PHP interpreter please check the script for deprecated functions etc. )





Sunday, August 12, 2012

When nvidia driver update make a mess of your Ubuntu ...

I have to face this issue after i update my nvidia graphics card driver in my Dell xps L502 which set the resolution of the display to 640X480 with 4:3 ratio.

I have tried almost all the things that could find in google but nothing work for me other than removing all the nvidia drivers, which include "nvidia current" and others.

After removing all nvidia drivers it still did not fixed the issue.

So i rename the xorg.conf in "/etc/X11" directory and then it worked for me.

PS: before doing that i also followed the instructions in below post also.

http://askubuntu.com/questions/127851/change-boot-screen-resolution


  1. We will have to edit grub configuration. Open a terminal and paste this:
    sudo gedit /etc/default/grub
    Hit Enter. It will open grub preferences in Gedit.
  2. Locate the line "# GRUB_GFXMODE=800x600" (resolution may be different).
You have to change the resolution to actual resolution of your screen, for example mine is 1240x1024. Next step is to uncomment this line (remove the # and and the empty space if is, so the letter G of the word GRUB will be the first letter in this line). After u r done, save the file and close.
3 . Now paste this line in terminal:
sudo gedit /etc/grub.d/00_header .
Hit Enter. It will open a text file with a lot of stuff. Use the search option at the top of the window to locate this line:
gfxmode=${GRUB_GFXMODE} 
After u successfully find it, u will have to add this line: "set gfxpayload=keep" (of course without the " sign) just under the gfxmode=${GRUB_GFXMODE}. Make it look like this:
set gfxmode=${GRUB_GFXMODE}
set gfxpayload=keep
Now, save the file and close.
4 . In terminal paste:
sudo update-grub 
Hit enter, it will generate new grub.cfg file so the changes u made will be saved.
Reboot and enjoy your new boot screen resolution.
In case u don't know what is your screen resolution
Go to System settings - Displays

Sunday, June 24, 2012

Stop browsing facebook From windows OS

I m sure most of you guys have fed up with facebook already. No doubt it is a huge waste of time. You waste your time that you have for reading, watching movie or most probably time for do studies to browse facebook.

As from medical aspects doctors have recognize the highly addiction to facebook is a mental illness and i m sure most of the facebook users like us have this since we waste approximately 3/4th of our day on facebook.


For me when i logged in to my windows or linux operating systems and start the browser, first thing i do is, type www.facebook.com, go there and see what are the news, status updates and photos of my friends. Then somebody come online and chat with me, some one else join to the chat and so on. Which make my 5 minutes browsing session goes on for more that 6 hours sometimes.

I dont to deactivate my account neither, because it is the only medium that connect all the friends i know since i was in nursery to university. And temporarily deactivation is humiliating since its like you log out and login by blocking your account.

Most of the time i use windows as my operating system (it is dual boot machine). So i did blocked facebook to my windows OS by the operating system level. There are software like anti virus programs which let you do this in more easy way, but it is very easy to undone that too. That is why i used the hard way because no body wants to do the hard things again and again, humans are lazy from their nature.

Let us stop facebook hardway ....

This is a simple method, for non IT people we do little mapping to facebook URL to our localhost so when you type the an URL starting from www.facebook.com it will give you 403 error saying "access forbidden to the content you request" because there in no facebook.com in our local machine. So lets start little hacking then,

1. Go to the location "C:\windows\system32\drivers\etc\"



2. Copy the file named "hosts" to desktop (also copy and back up this file to separate location in case things gone wrong.)

3. Open the copied hosts file with your favorite editing program (notepad, wordpad, notepad++ ) and add the following line to the end of the file and save it back to the desktop.

                    127.0.0.1         www.facebook.com                                 



3. After editing and saving the file back to the Desktop, copy the edited file back to the "C:\windows\system32\drivers\etc\"  location and replace the original file.

4. Check if everything is ok by typing the "www.facebook.com" into your browser's address bar. If things were alright it will give you HTTP 403  or ACCESS FORBIDDEN error. 




Monday, June 4, 2012

UnPlug - No more guarding , when your phone is charging




UnPlug mobile security is a free tool that has been written for android platform version 2.1 and above. This app is simply guarding your phone in a public place when you want to charge the phone. 

Imagine a scenario such that you are in your office, gym or even in airport and you want to charge your phone. Before UnPlug mobile security you have to wait beside the phone for 3 or 4 hours until it gives you 100% charged notification. But with UnPlug you can get your life along while the phone is charging.

Yes.. No more guarding while your phone is charging. You do not need to afraid bout those phone thieves anymore, UnPlug mobile security will take care about your phone even you are not there. 

How this happens ? Its a very simple answer. When a power  source connected, UnPlug mobile will identify the power connected event and it will keep watching your phone's back.  Before the phone is disconnected from the power source you have to enter the password and unlock the phone because if not the phone will start a loud siren which will take the attention of each and every living being in that area and also it will self generate a message and send it to your back up phone number that has been given to the app at it's installation process. 

You can download it from android market ( click here ).










Sunday, May 6, 2012

Mysql Connector/C++ build and install from source

1. Install Cmake build tool


sudo apt-get install cmake


2. Install libmysqlclient16-dev library



sudo apt-get install libmysqlclient16-dev



3. Install squeeze (stable) Build platform



sudo apt-get install squeeze




4. Go to the Mysql download page and download the source for c++ connector, extract it and go into the folder using terminal.

5. Set the following  environment variables


export CC=gcc
export CFLAGS=-O1-g
export CPPFLAGS=-DNDEBUG
export CXX=g++
export CXXFLAGS=-O1-gexport CC=gcc
export CFLAGS=-O1-g
export CPPFLAGS=-DNDEBUG
export CXX=g++
export CXXFLAGS=-O1-g
export LDFLAGS=-static-libgcc
export PICOPT=-fPIC
export LDFLAGS=-static-libgcc
export PICOPT=-fPIC


6. Edit file in following locations and add missing includes.

   i.  Add #include <cstdio>  to driver/mysql_art_resultset.cpp 
   ii. Add #include <stdio.h>  to driver/mysql_resultbind.cpp 
   iii. Add #include <stdio.h>  to test/unit/classes/resultsetmetadata.cpp

7.  Run


cmake .
make 
make install






Saturday, May 5, 2012

Ubuntu Cmake issue with mysql c++ connector

I have encountered an error while i try to follow the installation instructions on this page for compiling mysql c++ client. One of the errors was the misleading info in download link of the page . It direct you to linux generic code page and if you download the linux generic code you are dhoomed (you will get bunch of libraries and nothing to compile).

So first you have to download the source code for the connector ( not the linux generic code ).

Then i encountered this weird problem when i try to compile things.


-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/cc
-- Check for working CXX compiler: /usr/bin/cc -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- ENV{MYSQL_DIR} = 
CMake Error at FindMySQL.cm:165 (MESSAGE):
  mysql_config wasn't found, -DMYSQL_CONFIG_EXECUTABLE=...
Call Stack (most recent call first):
  CMakeLists.txt:55 (INCLUDE)


CMake Error at FindMySQL.cm:167 (MESSAGE):
  Cannot find MySQL.  Include dir: MYSQL_INCLUDE_DIR-NOTFOUND library dir:
  cxxflags:
Call Stack (most recent call first):
  CMakeLists.txt:55 (INCLUDE)


-- Configuring incomplete, errors occurred!

Here I can see more than one problems, in tutorial you have no instruction to declare a variable named MYSQL_DIR. But here you need a one so type 

Which mysql

and export it as

export MYSQL_DIR=/usr/bin/mysql

Then for the configuration file missing error you have to install libmysqlclient16-dev library to have mysql_configure file in your system. So type,


sudo apt-get install libmysqlclient16-dev

How to handle octave configure error in package instalation

If you try to install a package in Octave programming language using


pkg install package_name.tar.gz


you might encounter this error which stops the installation of package.

example :

configure: WARNING: no mkoctfile found on path
./configure: line 2918: conftest.cc: command not found
configure: error: Could not run 
the configure script returned the following error: checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for mkoctfile... no
error: called from `pkg>configure_make' in file /usr/share/octave/3.2.4/m/pkg/pkg.m near line 1240, column 2
error: called from:
error:   /usr/share/octave/3.2.4/m/pkg/pkg.m at line 714, column 5
error:   /usr/share/octave/3.2.4/m/pkg/pkg.m at line 287, column 7

For me the reason was i have not installed the octave header files when i m installing octave on my linux (ubuntu 11.10). So installing the headers for my octave version fixed the problem.

In linux terminal type,

sudo apt-get install octave3.2-headers libncurses5-dev

And after the installation finished run octave in super user mood to install the packages.

sudo octave





Thursday, May 3, 2012

How to copy a google chrome cache flash video in linux

I wanted to copy a flash video which is playing in my google chrome browser. In windows this can be achieved using simple tool called video cache viewer. But in linux story is much more different as it is difficult.

So with this article i will explain how to achieve this task.

1. open a terminal and type


ps -ef | grep flash

this will show the process id of you flashplayer (make sure to select the flash process which used by chrome browser)


2. then go to "/proc" directory and go into the folder named by the process id that you have obtained in     step 1. And go into the "fd" folder.


ex: lets assume that the process id of the flash used in chrome is 2424
now you should be inside "~/proc/2424/fd" directory

3. then type


ls -al | grep *flash*


this will show all the flash file descriptors  like below

lrwx------ 1 user user 64 2012-05-02 23:15 21 -> /tmp/FlashXXtD6PiG (deleted) lr-x------ 1 user user 64 2012-05-02 23:15 27 -> /tmp/FlashXXrotLjm (deleted) lrwx------ 1 user user 64 2012-05-02 23:15 3 -> socket:[22151] lrwx------ 1 user user 64 2012-05-02 23:15 4 -> socket:[25121]


Ones that has been highlighted in orange  color are the file descriptors of the flash files that have been opened. Walah!!! we r done copy them to where ever folder you want by simple


cp <file_des_no> destination




Tuesday, May 1, 2012

SQL join and optimization experience

I came across my sql join few days ago. The database i created was a temporary one and it is not for a product or something, this just used to store some web  logs that i used for my final year research.

So what i wanna do was join two tables that has about 100 thousand records in both of the tables. But with my simple inner join query it took more than 10 hours but still did not complete.

So i was searching for the ways to increase the performance of the join query and found out that introducing indexes increase the performance in considerable amount of time.

two things i have done was,


  1. Adding primary key constrains 
  2. Adding foreign key constrains 
to my two tables which i have not add previously because this was just temporary tables.

And then the query resulted within 2 minutes for the same number of records.


Saturday, March 31, 2012

Writing custom cursor adapter to use data from a SQLITE database with AutoCompleteTextView

In this post i am going to discuss how to implement a custom cursor adapter that take the data from a sqlite database and populate the  AutoCompleteTextView on the fly.

First let us write our database code which return a cursor. ( Here i only display the related method to return cursor. You have to write a new class extending  "android.database.sqlite.SQLiteOpenHelper" and write the database initialization and open logic in the class. )



1:  public synchronized Cursor getAutoCompleteCursor(String prefix){  
2:         Cursor c = null;  
3:         if(prefix.compareTo("")==0){  
4:              c = myDataBase.query("dict", new String[]{ID_COLUMN_NAME},   
5:                     ID_COLUMN_NAME+" like '' || ? || '%'",   
6:                     new String[]{"*"},   
7:                     null,   
8:                     null,   
9:                     null);  
10:         }else{  
11:              c = myDataBase.query("tableName",   
12:                        new String[]{COLUMN_NAME},   
13:                     ID_COLUMN_NAME+" like '' || ? || '%'",   
14:                     new String[]{prefix},   
15:                     null,   
16:                     null,   
17:                     null);  
18:         }  
19:         if(c == null & c.getCount() <= 0){  
20:              new Exception("Cursor " + (c==null?"null":" fill with wrong data"));  
21:         }  
22:         return c;  
23:    }  





Here "tableName" is the name of the table and "COLUMN_NAME" is the name of the column in table you want to bind with auto complete view.

My database is a very large one so when query for empty string it returns a large number of rows. This will lead to throw an exception in GPU level (creating a view larger than 40000 rows). So i used a conditional check to verify the empty string and at the initial point i query for a string that is not in database to retrieve a empty cursor and on the second letter enter and onward it will query for the prefix and get suggestion list. Another method i used to overcome this memory issue is to use a threshold in  AutoCompleteTextView so it will start to display suggestions only after the number of characters exceed threshold.

Then we write a class extending CursorAdapter class and implementing the filterable interface to include the view generation logic with the listening to key events in background and query the database to obtain suggestion words.


1:  
2:  import android.content.Context;  
3:  import android.database.Cursor;  
4:  import android.view.LayoutInflater;  
5:  import android.view.View;  
6:  import android.view.ViewGroup;  
7:  import android.widget.AutoCompleteTextView;  
8:  import android.widget.CursorAdapter;  
9:  import android.widget.Filterable;  
10:  import android.widget.TextView;  
11:  public class CustomCursorAdaptor extends CursorAdapter implements Filterable {  
12:       private DatabaseHelper dbHelper;  
13:       private LayoutInflater inflater ;  
14:       public CustomCursorAdaptor(Context context, Cursor c) {  
15:            super(context, c);  
16:            this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
17:            this.dbHelper = DatabaseHelper.getDatabaseHelper(context);  
18:       }  
19:       @Override  
20:       public void bindView(View view, Context context, Cursor cursor) {            
21:            String keyword = cursor.getString(cursor.getColumnIndex(DatabaseHelper.ID_COLUMN_NAME));  
22:      TextView tv = (TextView) view.findViewById(R.id.sugestionTextView);  
23:      tv.setText(keyword);  
24:       }  
25:       @Override  
26:       public View newView(Context context, Cursor cursor, ViewGroup parent) {  
27:            return inflater.inflate(R.layout.list_item, null);            
28:       }  
29:     @Override
31: public CharSequence convertToString(Cursor cursor) {
32:  
33:  return cursor.getString(cursor.getColumnIndex(DatabaseHelper.DICT_ID_COLUMN_NAME));
34: }
35:       @Override  
36:       public Cursor runQueryOnBackgroundThread(CharSequence constraint) {  
37:            //return super.runQueryOnBackgroundThread(constraint);  
38:            if(getFilterQueryProvider() != null){  
39:                 return getFilterQueryProvider().runQuery(constraint);  
40:            }  
41:            String filter = "";  
42:            if(constraint != null){  
43:                 filter = constraint.toString();  
44:            }  
45:            return dbHelper.getIdCursor(filter);  
46:       }  
47:  }  

Here at the construct i initialize the LayoutInflater and obtain the reference to my DatabaseHelper class which was written by extending the SQLiteOpenHelper and included the getAutoCompleteCursor method.

We have to override two abstract methods in the class which are newView and bindView.

In newView  write our code to use the inflater and populate a view return it to current cursor position. Here i used this method to populate my custom written "list_item" layout and return a view of that layout.

1:  <?xml version="1.0" encoding="utf-8"?>  
2:  <TextView xmlns:android="http://schemas.android.com/apk/res/android"  
3:    android:id="@+id/sugestionTextView"  
4:    android:layout_width="fill_parent"  
5:    android:layout_height="fill_parent"  
6:    android:padding="10dp"  
7:    android:textSize="16sp"  
8:    android:textColor="#000">  
9:  </TextView>  

"list_item.xml" file

In bindView we used to populate an existing view that is being reused with data in our cursor. Here i get a string from the cursor, create a text view by finding a sugestionTextView which is located in my "list_item" xml file and set the text view with the string i obtained from the cursor.

In the method runQueryOnBackgroundThreadhas been used to run a background thread each time a new character been entered to AutoCompleteTextView and obtain a cursor with the prefix text that is in the AutoCompleteTextView at that point.

Finally in the Activity class write the following code inside onCreate method to initialize the new CursorAdapter implementation class and set the adapter to AutoCompleteTextView.


1:  autoText = (AutoCompleteTextView) findViewById(R.id.autoCompleteEnglishWordText);  
2:  autoText.setThreshold(2);  
3:  CustomCursorAdaptor cursurAdaptor = new CustomCursorAdaptor(this, null);  
4:  autoText.setAdapter(cursurAdaptor);


Tuesday, March 20, 2012

Python list comprehensions for string sub listing

I am still learning python language which apparently needed for implement some tools regarding my research. And i came through this amazing feature in python lists.
Although i know python can do amazing stuff that no other popular languages can do, this thing suprised me a lot.

So what is this list comprehensions ?
A list comprehension is a way to describe a list. If you have taken mathematics basic class you might be familiar with set theories and for each of set we use we have a definition for that set.

For an example lets say a list that has all the even numbers. We can write this definition in mathematical way like below.

E = { x | x%2=0}
This means set s has all the x values that suppress the condition of "remaining of x by 2 is 0".

When it comes to set of strings, we can define those sets in the same way.

Alphabet = { x | x in 'a' to 'z'} 
V = { a , e , i , o , u }

So in python language it has been facilitated to use the similar notation we used in mathematical definitions.

Say we want to obtain a separate list of items from a main list that has a special string within it.

prefix = "http"
dirListing = os.listdir(sys.argv[1])
httpList = [x for x in dirListing if prefix in x]

Above python sample code demonstrate how to sub list the set of strings that contains "http" within the strings from set of strings.
Here we say that "httpList" list should contain all the x values where x is in "dirListing" list and x contains "dnsString" within it.





Sunday, March 18, 2012

Configure manually Apache HTTPD and PHP in your machine.

There are "WAMP" and "XAMP" softwares that install all three apache httpd web server, php interpreter and mysql server, and automate the configuration process with just few clicks. But just  think of a situation where you have previously installed mysql instance running !


Either you have to uninstall the current instance of mysql server and install one of above "three in one" packs or change the port number of the newly installing my sql server. But what is the point of running two mysql instances at the same machine ???? (adding another service to windows means resources will be eaten more). Even though you uninstall current mysql server and install WAMP or XAMP there might be high chance that you will end up those installations not working due to some conflict with previously installed and now removed mysql instance and the one in WAMP or XAMP.


So it is always better to keep the current mysql instance and configure the other two with the existing one. And after all it is fun! and you can  be proud of your self about what you have done because almost all the php developers depends on wamp and when it comes to the server configuration and deployment environment you cant depend on a WAMP ! its just a development tool (and what if you do you client wants MS SQL server instead of mysql offer in WAMP ? ). So be an adult and do things by your self.


Ok enough talking lets start the work.


First download the latest releases of Apache HTTPd web server, PHP interpreter from the links. (Please download the executable files since that will be helpful with some auto configurations )


Then create a directory called "web" in the location c drive "c:\web". (name of the directory can be anything you like but without spaces, we dont install to "program files" because of the space in file path, try to avoid spaces in file path.)


Installing apache httpd server


Launch the setup (double click on setup.exe) and choose custom. Then choose the directory as "c:\web\apache" and enter the information of your server in to the following window.
( I prefer,
Network Domain - localhost
server name - localhost
Email Address - anything@you.want  If you intend to use the server in local development)


apache-install 
  Click next and choose content to install as showed in below.


apache-install-2 


And finish the setup.


Installing PHP setup.


Launch the setup and when prompt to select a location select the "c:\web\php" as the location.


In next window select the server which u wish to configure the PHP interpreter with shown as below. ( here we choose apacheXXX where XXX is the version of the apache httpd server that you have downloaded and installed previously)


php-install-2 


In next prompt choose the apache configuration directory in our case "c:\web\Apache\conf". 


On next window choose the libraries you wanted to install with PHP.


(Caution!!! some of the modules will not be compatible with the current PHP interpreter version that we are installing this might give us errors when we run the interpreter. If you are a newby most of the time you will miss understand this errors as miss configurations. So its better to leave not installing modules for now since we can add modules by editing "php.ini" manually later.)


Configuring apache server


First you have to add the a map to localhost and your server name if it is not "localhost" that you have entered in the beginning of apache server installation process. To do this open the host file in the "c:\windows\system32\drivers\etc\hosts" location using text editor (Most of the time if you are not in the administrator account you wont be able to save the edited host file. In that case copy the host file to Desktop edit it, save it there and copy back to the location of the original host file by overwriting it).



127.0.0.1 localhost
127.0.0.1 yourDomain


Then we are going to edit apache configuration files. ( keep in mind to use forward slash '/' instead of back slash '\' in file paths ).

(First of all copy and backup the "c:\web\apache\conf\httpd.conf" file in case of things gone wrong)

Open "c:\web\apache\conf\httpd.conf" and search for the lines.

1. DocumentRoot
DocumentRoot "c:/web/Apache/htdocs"

change this to any directory you prefer to use to  store your html and php files. (lets say "c:\web\www").

DocumentRoot "c:/web/www"
2. Then change 

<Directory "c:/web/Apache/htdocs">
to
<Directory "c:/web/www">

3. Add entry for php in the apache configuration file.
#BEGIN PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
PHPIniDir "C:/web/PHP"
LoadModule php5_module "C:/web/PHP/php5apache2_2.dll"
AddType application/x-httpd-php .php
#END PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL

4. Include index.php to apache directory index files.
DirectoryIndex index.html index.htm index.php




Configuring PHP

(First of all copy and backup the "c:\web\php\php.ini " file in case of things gone wrong) 

Edit php.ini file located in "c:\web\php\php.ini".

1. Change the display errors on.
display_errors = Off
to
display_errors = On

2. Copy all the "php5apache2_2.dll" in php root directory and ext directory to "c:\windows\system32" directory with edited php.ini file.


Adding or removing modules to php.ini

Edit php.ini file and add entries for required modules.

Eg:

[PHP_MCRYPT]
extension=php_mcrypt.dll
[PHP_MYSQL]
extension=php_mysql.dll
[PHP_MYSQLI]
extension=php_mysqli.dll
[PHP_OPENSSL]
extension=php_openssl.dll
[PHP_PDO]
extension=php_pdo.dll
[PHP_SOAP]
extension=php_soap.dll
[PHP_SQLITE]
extension=php_sqlite.dll
[PHP_XMLRPC]
extension=php_xmlrpc.dll
[PHP_ZIP]

Adding MySQL support to PHP


Here i assumed that you have already installed mysql server and configured it. Do not store your mysql host, user and password fields in php.ini file even though php mysql configuration allows to store them.

[MySQLi]

; Maximum number of links.  -1 means no limit.
mysqli.max_links = -1

; Default port number for mysqli_connect().  If unset, mysqli_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order).  Win32 will only look
; at MYSQL_PORT.
mysqli.default_port = 3306

; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
mysqli.default_socket =

; Default host for mysql_connect() (doesn't apply in safe mode).
mysqli.default_host =

; Default user for mysql_connect() (doesn't apply in safe mode).
mysqli.default_user =

; Default password for mysqli_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with PHP access can run 'echo get_cfg_var("mysqli.default_pw")
; and reveal this password!  And of course, any users with read access to this
; file will be able to reveal the password as well.
mysqli.default_pw =

; Allow or prevent reconnect
mysqli.reconnect = Off

Testing
 



Write the following php code. Store it as index.php in your webroot location. ( here we use "c:\web\www" ).

<?php phpinfo(); ?>



Then open a browser and type localhost in address bar. You will get a similar page as below.