Thursday, May 21, 2009

‘break’ and ‘continue’ for jQuery loop


jQuery functions like $.each( Object obj, Function fn ) or $().each() are not loop rather these are iterative functions. $().each() is used to iterate over a jQuery object and you can use $.each( Object obj, Function fn ) to iterate over anything (for example, an array). As they iterate over something we call them loop.


So jQuery loops are not like javascript loops.


We use ‘break;’ and ‘continue;’ inside a loop. These will not work inside a jQuery loop (like $.each()). So what you will do, if you need the same functionality for a jQuery loop. Fortuitously there is another way. You can use ‘return false;’ inside a jQuery loop to break it. The idea is simple. jQuery loops are functions. So when you ‘return false;’ from a function, it will immediately stop execution of that function and will not continue. Which will work as ‘break;’. Similarly if you write ‘return;’ (without an argument) it will work as ‘continue’;


Here are two examples:-



$("#tblId tr").each(function(i, obj) {

    If($(obj).attr('id')==’idBreakHere’) {

        return false; //this is equivalent of 'break' for jQuery loop

    }

}



$("#tblId tr").each(function(i, obj) {

    If($(obj).attr('id')!=’idToFind’) {

        return; //this is equivalent of 'continue' for jQuery loop

    }

}



Cheers,

Thursday, July 10, 2008

Thursday, December 20, 2007

Is 3 tier architecture and MVC same?

Today, Rishan (sommohon) ask me this question while chatting with him. I gave him the answer in one sentence but I myself was not satisfied with the answer. I thought I should write something about this in short.

After a long period I am writing to my blog. As I am in vacation right now at last I got some time to write something. I can continue writing if you guys help me by requesting topics to discuss and also post reply to this topics.

Now what is the answer.

If you say yes, I think that is correct. If you say no, I think that is also correct. You wonder how? Let’s see the simple similarities and dissimilarities.

Both n-tier architecture and MVC have the same root, or same basic idea that they separate the responsibilities among different parties to make your application more robust, more flexible, more scalable and easier maintainable.

MVC is a design pattern for GUI. A design pattern shows us how to separate responsibilities between VIEW and DATA at the presentation tier. Most web application framework is based on the MVC pattern (MVC Model 2).

N-tier architecture is about how to design your application or system architecture pattern, the basic idea is to separate the responsibilities among different tiers (Presentation tier responsible for UI or User Interface, BL or Business Logic tier responsible for business logic, DAL or Data Access Layer tier responsible for data, Service layer for Service etc.)

So about MVC and N-tier we can say that concepts are same but implementation is different. This is my simple understanding.

I hope to learn and write about this more. Any comments or suggestions?

Thursday, May 3, 2007

[Google Tips]: Use Gmail as a Hard Drive

Gmail is providing you more than 2 GB space. So, why not to use this space? You can use Gmail as a network drive on your PC. Yes!

It looks and feels just a regular hard drive. And it’s as simple to use as you might hope, if you are Windows user.

Go to http://www.viksoe.dk/code/gmail.htm and download a copy of GMail Drive. After downloading extract and install the files. You will see a GMail Drive in your My Computer. Click on that drive and you will be prompted for login as show in the picture:-

Copy and paste your files from your local hard drive to GMail Drive.


And your files will appear in your gmail inbox as mails.


Happy GMailing to all Googlians!

Monday, April 30, 2007

Rickshawala

I usually travel by bus while returning from office. There are two ways to return from my office to home. There is a direct bus service from Gulshan-2 to Mohammadpur. And another way is to take 27 no bus from Kakoli upto Asad gate then the rest to Mohammadpur by Rickshaw. My office is at Banani 27 no road, middle of Gulshan 2 and Kakoli.

Yesterday I took the second way. From Asad gate I took a Rickshaw. I rode on the rickshaw and asked the rickshawala, ‘What is the fare upto Mohammadpur Shiya Mosque?’

’15 taka’, he replied.

‘It should be 12 taka, why you are charging more?’

‘If you compare the fair with the previous days then it is not fair. In previous we had to pay 25 taka per day to the owner and now we are paying 80 taka per day’

‘I see. The government set fixed charge for the taxi owners and did not set any constraint for the rickshaw owners’

‘The owners are not responsible for this. They have to buy a tire for 250 taka while they bought it for 150 taka in the past.’ – Rickshawala’s quick reply

I was astonished hearing the rickshawala saying on behalf of the rickshaw owners. I guessed that he himself is the owner and asked the rickshawala to be sure.

‘Hey, stop. Are you the rickshaw owner?’

He smiled, looked at me and said ‘yes sir, I have only one rickshaw’

Who does not like to speak for himself?

Wednesday, April 25, 2007

SEO Tips

What *NOT* to do?

Don’t submit multiple URLs to Google database for the same site. e.g. mysite.com and mysite.com/index.html are two different URLs.

Don’t do cloaking. Cloaking is a way to keep two different pages. One is optimized for the search engine another is optimized for user.

Doorway pages are another way of cloaking. This is the trick to fill your home pages with keywords and keeping a link for user optimized page.

Hidden texts and hidden links with same color as page background color are often used in doorway pages and are cause to ban from search engines.


How to use MySQL Aggregate Function GROUP_CONCAT()

Few days ago, I got a mail from one of my friend. The mail was asking a question like below:-

Answer the following question within 10 sec and without the help of a calculator.

If 1 = 5, 2 = 25, 3 = 625, 4 = 390625, then 5 = ?

Answer is hidden here


I asked this question to some other friends. They also replied the wrong answer. The answer is very simple. But sometimes we make complex and wrong solutions of simple problems. This happens due to lack of proper understanding the 'system'.

Here is similar problem, which occurs frequently in our day to day programming.

Let you have team_member table data like below:-