Saturday, March 9, 2013

jQuery - checking for "null" objects...

In day to day Object Oriented programming we used to check whether an object is null by comparing it with the null keyword supplied by the programming language. For an example in Java or javascripts we can use

1:  object == null  

So what we use to do with jQuery  is like below,

1:  $("#id") == null  

This is wrong. The reason is that even there is no any HTML elements that has id of "id", $("#id")  will return an empty object. (or empty array object,). So this will always make the above expression to evaluate to false.

So how we get to know whether above object (element) exist before using that object in complicate logic ???

You can use the following code.

1:  $("#id").length > 0  

Now where does this length property come to HTML element. The reason is jQuery objects wrap around DOM objects and they are having their own methods and attributes. When we accessing HTML elements using jQuery, it will return an array of such elements. So if there is only one object returned we can directly access that object. If there are more than one object we can use normal array indexes to access them. But if there is no object or 0 object for what we asked, what jQuery does is return an empty array object. So what we can do to check if there is no object relevant what we have asked is to check the length of the array return by jQuery. If length of the array is not greater than 0 means there is no object to be return (only the empty array object is there).



Tuesday, February 19, 2013

When jQuery form submission not works , Work arounds.

Let us consider the below form and various ways to do a form submission in client side programming.

1:    
2:  <form id="formId" name="formName" class="form-class" action="" method="post">  
3:  </form>  

Before introducing jquery, the famous but harshful way to access DOM is using the popular getElementByID() method in javascript so accomplish a form submission we can use it like below,

1:    
2:  document.getElementById("formId").submit();  
3:    

Also if there is no id for the form we can still use the form name to do a form submission as below,

1:    
2:  document.getElementsByName("formName")[0].submit();  
3:    

But with jQuery life has become much easier and we can use either form ID in the way we use them to decorate using CSS or either CSS classes to pick elements. Below is how we can do a form submit using form ID

1:    
2:  $("#formID").submit();  
3:    

And we can use the class selectors to access forms as well. This method returns an array of elements which has the same style class. (In our example we have only one element, and it is our form.)

1:    
2:  $(".form-class")[0].submit();  
3:    

Finally we can use elements itself to access themselves. This method will return an array of same elements. (According to our example we only have one element of type "form".)

1:    
2:  $("form")[0].submit();  
3:    


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 !!!