Saturday, 28 April 2012

Get Selected Text From a Text Box Using JavaScript

There are times when you need to process the selected text from long text inside a text area or a text box. This can be easily implemented in JavaScript. The starting index and ending index of the selection can be obtained using "selectionStart" and "selectionEnd". The JavaScript function implementation using this is shown in this post.

Guide to Good Programming Habits

From a novice programmer to a veteran, there are a few rules to be followed so that the code you write has a professionalism in it. These might be simple things like adding comments or using proper variable names, but following it in a systematic way will make your code more easy to develop, test, debug and deploy. These rules are applicable to any programming language and making it a habit will help you in the long run. In this post, I will explain a few rules that could be followed.

Sorting Numbers Using Bubble Sort

There are a lot of algorithms available for sorting a set of numbers. Here I will give you the logic behind bubble sort and a c++ function implementing the same. The bubble sort can be used to sort a given set of numbers either in ascending order or in descending order in minimum number of iterations. Bubble sort starts by comparing the first two numbers and arranging them in the correct order, then the next two numbers and again arranging them. This process is repeated for all the numbers in the list a number of times until the list is sorted.

Tuesday, 24 April 2012

Factorial Using Recursion

Recursion can be used instead of looping statements to find the factorial of a number. Recursion can be defined in simple terms as a function calling itself. Factorial of a number is the product of all numbers from 1 to the number itself. Example: Factorial 5 written as 5! = 5*4*3*2*1 = 120. Here let us see a simple program that uses recursion to find the factorial of a number. I will be using C++ syntax, but you may take the logic and change the syntax to suit any programming language. In some programming languages, you might get a stack overflow error if you use too much recursion.

Sum of First n Natural Numbers Using Recursion

Whenever you call a function inside the body of the same function, it is called recursion. This technique can be utilized instead of looping statements to find the sum of first n numbers. In this post, I will show you how to implement this. I will be using C++ syntax, but you may take the logic and change the syntax to suit any programming language. In some programming languages, you might get a stack overflow error if you use too much recursion.

Swap two numbers without using a temporary variable

It is a common question in interviews which involve some algorithmic or programmatic requirements. Even though this logic has got nothing much to do in the real world programming, it helps to check the ability of a candidate to form simple logic.
Swapping two numbers means interchanging the value present in the two variables. Normally it can be done using a third variable using the following algorithm.

Wednesday, 18 April 2012

Samsung Galaxy Y, A Smart Choice

If you are looking for an entry level smart phone running on android, then the Samsung Galaxy Y is a perfect option. Priced slightly under Rs8000 in the Indian market, this phone is worth the price. Packed with features, yet simple and elegant, this phone is gaining serious attention. This phone with a 3 inch TFT screen and a full touch bar form factor, weighs under 100g and runs on the Android 2.3 (Gingerbread) OS.

Why choose Android?

Android is an open source software stack for mobile devices under Google Inc. The maintenance and development of Android open source code is led by Google. As android is open source, no manufacturer can control the innovations of another. The mistakes of one manufacturer in the code gets corrected by another and hence get improved each time. Major manufacturers like Samsung, LG, Motorola, HTC choose Android OS for their smart phones. Smart phone users also choose Android OS ahead of its rivals. With millions of devices running on android and unlimited android apps available for download, it became the best selling smart phone platform in the world.

Tuesday, 17 April 2012

How to Face An Earthquake

Earthquakes are highly unpredictable and occur without any warning. This causes panic among the people and they run around not knowing what to do. This can some times cause more damage than the earthquake itself. People living in earthquake prone areas like Japan regularly experience earthquakes and they are accustomed to it. They know exactly what to do during an earthquake. India is a country which is not in the list of earthquake prone areas, but things seems to have changed in the past few years.

Common Email Protocols

A protocol can be defined as a set of rules or language for performing a specific task. E-mail has it's own set of rules or protocols to control its travel over the Internet. In order to deal with your email you must use a mail client to access a mail server. The mail client and mail server can exchange information with each other using a variety of protocols. The most common of these e-mail protocols are listed below.

Monday, 16 April 2012

Database - Primary Key And Foreign Key

The primary key of a table uniquely identifies each row in a table. In a table, only one field can be assigned as a primary key. The primary key will be guaranteed as unique in the entire table, that is no two rows in a table will have the same primary key. The foreign key field of a table is used to match the primary key field of another table.

Sunday, 15 April 2012

Basics of IP Address

Every machine connected to a network has a unique identifier. Computers use this unique identifier to send data to specific computers on a network. Most networks today, including all computers on the Internet, use the TCP/IP protocol as the standard for communication on the network. In the TCP/IP protocol, the unique identifier for a computer is called its IP address.
There are two standards for IP addresses: IP Version 4 (IPv4) and IP Version 6 (IPv6).

Friday, 13 April 2012

Random String Generator in PHP

There are many occasions where you might require a random string in your application. It may be used for generating a key for an encryption algorithm or just to supply a random password to a user. Here a simple PHP function gen_rand_str() is given which can meet these requirements.

MAC Address - A brief Note

A MAC Address or Media Access Control Address is a unique number given to every Network Interface Card (NIC) which forms the interface between the network and the hardware. It is usually a 48bit number which is hard coded into the hardware during manufacturing. MAC address is written in hexadecimal format and is divided into 6 octets. Typically a MAC address looks like 00:0A:FF:C3:5B:88 or 00-0A-FF-C3-5B-88. It is a globally unique number, that is no two devices will have the same MAC address.

Thursday, 12 April 2012

Validation - Client or Server Side

Whenever data is transferred from a client to the server, it is extremely important to validate the data so as to ensure the secure and successful completion of the process. The question lies with whether the validation has to be done in the server alone or in both server and client side. Which one will be the better and efficient choice. Obviously validation in the client side alone is not at all an option because it can be easily bypassed.

Wednesday, 11 April 2012

Basics of Photography - Histogram

Digital cameras from simple point-and-shoot cameras to professional DSLRs comes with an option to display histogram on the LCD screen. Ever wondered what this graph indicates and how can it be useful in photography? If your answer is yes then go on. You can get your photography skills improved.

Tuesday, 10 April 2012

Common HTTP Status Codes

When a browser sends a request to a server, the server responds with a corresponding HTTP Status Code. This status code can be used to identify the status of the request. You might have seen error messages like 403 forbidden which means you don't have the required authority to view the page or 404 page not found error. A list of commonly seen HTTP status codes and their meaning are listed here.

Saturday, 7 April 2012

MySQL tips for Better Performance

MySQL is one of the most popular database management system preferred by web developers around the world. The ease with which queries can be written and the seamless integration with various web scripting languages is the primary reason for this popularity. Most of the web programmers would have a hands on experience with MySQL. Complex database operations can be written quite efficiently with this open source database management system. This is true for low traffic web applications. But what happens when the traffic goes up? Will your applications perform well at high demands?

Friday, 6 April 2012

Password Strength Indication Using JavaScript

It is a good practice to indicate the strength of the passwords that the users of your website choose so that they can make a secure choice. You can make a password strength indication for your website using JavaScript. A simple JavaScript function to accomplish this is discussed below. It gives a visual indication of the strength using a progress bar and also a textual description.

Progress Bar Using JavaScript

A simple progress bar can be created using JavaScript and HTML which shows graphically the percentage of work completed along with numeric indication. A user defined JavaScript function prog_bar is used here.

On - Screen Number Pad Using JavaScript

It would be quite interesting if you provide an option to enter numbers using an on-screen number pad in your website. Since most of the new mobile devices doesn't  come with a separate number pad, it is difficult to enter numbers fast. So providing an on-screen number pad would be a good alternative.
Here I have described a simple on-screen number pad developed using CSS, HTML and JavaScript.