Wednesday, 27 February 2013

Basic Ruby On Rails (RoR) Interview Questions and Answers - Objective and Subjective

Basic Ruby On Rails (RoR) Interview Questions and Answers - Objective and Subjective

If you are going for a techincal interview on ruby on rails technology, you must prepare following list of basic interview objective and subjective questions. Following objective and subjective interview questions on ruby on rails are based upon basic introduction of Rails web application framework, components of rails, action controller, action view, action dispatch, RESTful architecture, scaffolding, helpers, filters, sessions and cookies etc. Lets have a look on following basic ruby on rails interview questions and answers.

1. What is Rails?

1. Rails is a extremely productive web-application framework written in Ruby language by David Hansson.

2. Rails are an open source Ruby framework for developing database-backend web applications.

3. Rails include everything needed to create a database-driven web application using the Model-View-Controller (MVC) pattern.
2. What are the various components of Rail?

1. Action Pack: Action Pack is a single gem that contains Action Controller, Action View and Action Dispatch. The “VC” part of “MVC”.

Action Controller: Action Controller is the component that manages the controllers in a Rails application. The Action Controller framework processes incoming requests to a Rails application, extracts parameters, and dispatches them to the intended action.

Services provided by Action Controller include session management, template rendering, and redirect management.

Action View:  Action View manages the views of your Rails application. It can create both HTML and XML output by default.

Action View manages rendering templates, including nested and partial templates, and includes built-in AJAX support.

Action Dispatch: Action Dispatch handles routing of web requests and dispatches them as you want, either to your application or any other Rack application. Rack applications are a more advanced topic and are covered in a separate guide called Rails on Rack.

2. Action Mailer: Action Mailer is a framework for building e-mail services. You can use Action Mailer to receive and process incoming email and send simple plain text or complex multipart emails based on flexible templates.

3. Active Model: Active Model provides a defined interface between the Action Pack gem services and Object Relationship Mapping gems such as Active Record. Active Model allows Rails to utilize other ORM frameworks in place of Active Record if your application needs this.

4. Active Record: Active Record are like Object Relational Mapping (ORM), where classes are mapped to table, objects are mapped to columns and object attributes are mapped to data in the table.

5. Active Resource: Active Resource provides a framework for managing the connection between business objects and RESTful web services. It implements a way to map web-based resources to local objects with CRUD semantics.

6. Active Support: Active Support is an extensive collection of utility classes and standard Ruby library extensions that are used in Rails, both by the core code and by your applications.

3. Explain about RESTful Architecture.

RESTful: REST stands for Representational State Transfer. REST is an architecture for designing both web applications and application programming interfaces (API’s), that’s uses HTTP.

RESTful interface means clean URLs, less code, CRUD interface. CRUD means Create-READ-UPDATE-DESTROY. In REST, they add 2 new verbs, i.e, PUT, DELETE.

4. Why Ruby on Rails?

There are lot of advantages of using ruby on rails.

1. DRY Principal( Don’t Repeat Yourself): It is a principle of software development aimed at reducing repetition of code. “Every piece of code must have a single, unambiguous representation within a system”

2. Convention over Configuration: Most web development framework for .NET or Java force you to write pages of configuration code. If you follow suggested naming conventions, Rails doesn’t need much configuration.

3.  Gems and Plugins: RubyGems is a package manager for the Ruby programming language that provides a standard format for distributing ruby programs and library.

Plugins: A Rails plugin is either an extension or a modification of the core framework. It provides a way for developers to share bleeding-edge ideas without hurting the stable code base. We need to decide if our plugin will be potentially shared across different Rails applications.

4. Scaffolding: Scaffolding is a meta-programming method of building database-backend software application. It is a technique supported by MVC frameworks, in which programmer may write a specification, that describes how the application database may be used. There are two type of scaffolding:

-static: Static scaffolding takes 2 parameter i.e your controller name and model name.
-dynamic: In dynamic scaffolding you have to define controller and model one by one.

5. Rack Support: Rake is a software task management tool. It allows you to specify tasks and describe dependencies as well as to group tasks in a namespace.

6. Metaprogramming: Metaprogramming techniques use programs to write programs.

7. Bundler: Bundler is a new concept introduced in Rails 3, which helps you to manage your gems for application. After specifying gem file, you need to do a bundle install.

8. Rest Support.

9. Action Mailer

5. What do you mean by render and redirect_to?

render causes rails to generate a response whose content is provided by rendering one of your templates. Means, it will direct goes to view page.

redirect_to generates a response that, instead of delivering content to the browser, just tells it to request another url. Means it first checks actions in controller and then goes to view page.

6. What is ORM in Rails?

ORM tends for Object-Relationship-Model, where Classes are mapped to table in the database, and Objects are directly mapped to the rows in the table.

7. How many Types of Associations Relationships does a Model have?

When you have more than one model in your rails application, you would need to create connection between those models. You can do this via associations. Active Record supports three types of associations:

one-to-one: A one-to-one relationship exists when one item has exactly one of another item. For example, a person has exactly one birthday or a dog has exactly one owner.

one-to-many: A one-to-many relationship exists when a single object can be a member of many other objects. For instance, one subject can have many books.

many-to-many: A many-to-many relationship exists when the first object is related to one or more of a second object, and the second object is related to one or many of the first object.

You indicate these associations by adding declarations to your models: has_one, has_many, belongs_to, and has_and_belongs_to_many.

8. What are helpers and how to use helpers in ROR?

Helpers are modules that provide methods which are automatically usable in your view. They provide shortcuts to commonly used display code and a way for you to keep the programming out of your views. The purpose of a helper is to simplify the view.

9. What are Filters?

Filters are methods that run “before”, “after” or “around” a controller action. Filters are inherited, so if you set a filter on ApplicationController, it will be run on every controller in your application.

10. What is MVC? and how it Works?

MVC tends for Model-View-Controller, used by many languages like PHP, Perl, Python etc. The flow goes like this:

Request first comes to the controller, controller finds and appropriate view and interacts with model, model interacts with your database and send the response to controller then controller based on the response give the output parameter to view.

11. What is Session and Cookies?

Session is used to store user information on the server side. Maximum size is 4 kb. Cookies are used to store information on the browser side or we can say client side.

12. What is request.xhr?

A request.xhr tells the controller that the new Ajax request has come, It always return Boolean values (TRUE or FALSE)

13. What things we can define in the model?

There are lot of things you can define in models few are:

1. Validations (like validates_presence_of, numeracility_of, format_of etc.)
2. Relationships (like has_one, has_many, HABTM etc.)
3. Callbacks (like before_save, after_save, before_create etc.)
4. Suppose you installed a plugin say validation_group, So you can also define validation_group settings in your model
5. ROR Queries in Sql
6. Active record Associations Relationship

14.  How many types of callbacks available in ROR?

 (1) before_validation
 (2) before_validation_on_create
 (3) validate_on_create
 (4) after_validation
 (5) after_validation_on_create
 (6) before_save
 (7) before_create
 (8) after_create
 (9) after_save

15. How to serialize data with YAML?

YAML is a straight forward machine parsable data serialization format, designed for human readability and interaction with scripting language such as Perl and Python.

YAML is optimized for data serialization, formatted dumping, configuration files, log files, internet messaging and filtering.

16. How to use two databases into a single application?

magic multi-connections allows you to write your model once, and use them for the multiple rails databases at the same time.

sudo gem install magic_multi_connection. After installing this gem, just add this line at bottom of your environment.rb require “magic_multi_connection”
17. What are the various changes between the Rails Version 2 and 3?

1. Introduction of bundler (new way to manage your gem dependencies)
2. Gemfile and Gemfile.lock (where all your gem dependencies lies, instead of environment.rb)
3. HTML5 support

18. What is TDD and BDD?

TDD stands for Test-Driven-Development and BDD stands for Behavior-Driven-Development.

19. What are the servers supported by ruby on rails?

RoR was generally preferred over WEBrick server at the time of writing, but it can also be run by:
Lighttpd (pronounced ‘lighty’) is an open-source web server more optimized for speed-critical environments.
Abyss Web Server- is a compact web server available for windows, Mac osX and Linux operating system.
Apache and nginx

20. What do you mean by Naming Convention in Rails.

Variables: Variables are named where all letters are lowercase and words are separated by underscores. E.g: total, order_amount.

Class and Module: Classes and modules uses MixedCase and have no underscores, each word starts with a uppercase letter. Eg: InvoiceItem

Database Table: Table name have all lowercase letters and underscores between words, also all table names to be plural. Eg: invoice_items, orders etc

Model: The model is named using the class naming convention of unbroken MixedCase and always the singular of the table name.

For eg: table name is might be orders, the model name would be Order. Rails will then look for the class definition in a file called order.rb in /app/model directory. If the model class name has multiple capitalized words, the table name is assumed to have underscores between these words.

Controller: controller  class names are pluralized, such that OrdersController would be the controller class for the orders table. Rails will then look for the class definition in a file called orders_controlles.rb in the /app/controller directory.

21. What is the log that has to seen to check for an error in ruby rails?

Rails will report errors from Apache in log/apache.log and errors from the ruby code in log/development.log. If you having a problem, do have a look at what these log are saying.

22. How you run your Rails application without creating databases?

You can run your application by uncommenting the line in environment.rb
path=> rootpath conf/environment.rb
config.frameworks- = [action_web_service, :action_mailer, :active_record

23. How to use sql db or mysql db without defining it in the database.yml?

You can use ActiveRecord anywhere
require “rubygems”
require “active_record”
               :adapter=> ‘postgresql’, :user=>’foo’, :password=> ‘abc’, :database=>’whatever’})

24. GET and POST Method?

GET is basically for just getting (retrieving) data, whereas POST may involve anything, like storing or updating data, or ordering a product, or sending E-mail.

Online Best Young Cheap Car Insurance Comparison and Quotes for Young Drivers and Students

Online Best Young Cheap Car Insurance Comparison and Quotes for Young Drivers and Students

If you are a young student having age between 18-21, you must have some different kind of car insurance targeting to young drivers and students. You must have a valid driving license before applying for car insurance. But young car insurance is always costly as compared to other car insurances. So, we will help you in finding and choosing the best young cheap car insurance especially for students. 

Normal car insurance is cheaper as compared to the car insurance for young drivers or students. It is assumed that in young age your mind is not well prepared to drive a car as you may get an accident easily as compared to a mature driver. As a young driver, it is assumed that you are more prone to damage your car by accidents, overspeeding, harsh driving, violating traffic rules etc. So car insurance companies charge more car insurance premiums to young drivers.

So, if you are going to take car insurance for young driver or student, you will have to pay big premiums as compared to other car insurance policies.

So as a young driver and student, you should avoid using costly cars which have high car insurance premiums.

If you are going to take car insurance for young driver, you must go through different car insurance quotes provided by several car insurance companies online. You must read the reviews of insurance holders of that insurance company. Cheaper car insurance does not mean poor car insurance always. You have to compare online different car insurance policies for young drivers and students. Just read down car insurance quotes carefully and keep in mind different features of car insurance for young drivers. There are a lot of websites available which help you to compare different kind of young car insurance policies of different companies. Just do a thorough research before applying for online car insurance.

Online Car Insurance Comparison - Best Car Insurance Companies - Car Insurance Claim Settlements and Quotes

Online Car Insurance Comparison - Best Car Insurance Companies - Car Insurance Claim Settlements and Quotes

If you are going to purchase your dream car, don't forget to choose a right car insurance bank or company which insures any type of car accident and provides quick services for your car accident claims. You should make a detailed comparison between different car insurance companies and choose the best. Read carefully the car insurance quotes provided by different car insurance companies. Your car insurance policy document is the most important document as your car is not only a mean of transport to you but also your second home becaues you spend a lot of time in your car everyday while travelling. So don't always go for cheap insurance companies, go for better service. Try to get different quotes from different car insurance companies and compare them and then take any decision. Always check the age of your car insurance companies and reviews made by its customers.

How to choose best car insurance company? What should be covered in Car Insurance Policy?

Choosing a best car insurance company may be a hectic task as there are a lot of car insurance companies available in the market.

We have highlighted some key features of car insurance policy which you should confirm before applying for car insurance to any company. A company which would be fulfilling following requirements, can be a great car insurance company for you.

1. Your car insurance company should provide detailed coverage against any kind of damage to your car in any kind of car accident you met anywhere. Fire, explosion, self-ignition or lightning, earthquake, flood, typhoon, hurricane, storm, tempest, inundation, cyclone, hailstorm, frost, landslide and rockslide should also be covered in your car insurance policy. Your car insurance policy should also cover burglary, theft, riot, strike, malicious act, accident by external means, terrorist activity, any damage in transit by road, rail, inland waterway, lift, elevator or air.

2. Your car insurance policy should also provide personal accident covers for co-passengers available.

3.  Your car insurance company should provide third party legal liability. It means car insurance company should provide you protection against legal liability due to accidental damages resulting in the permanent injury or death of a person, and damage caused to the surrounding property.

4. Your car insurance policy should also cover electrical and non electrical items fitted in your car like fog lights, music system, AC, mag wheels, seat cover, CNG Kit and Bi-Fuel system etc.

5. The procedure of car accident claim should be straight forward. There should be hassle free claim settlement. Car insurance quotes should be clear and simple.

6. Your car insurance company should provide 24X7 support.

Cheap Car Insurance vs Quality Car Insurance Policy

If you are comparing different car insurance quotes from different car insurance companies, do not only see the cheap rates, but also compare the above points about car insurance. But it does not mean that you always go for high rate car insurance.There may car insurance companies which provide you all the features of car insurance in cheap rates as compared to another car insurance company. You have to research a lot for cheap car insurance companies and the features they provide in their car insurance policy. Cheap car insurance does not always mean poor car insurance policy. So search for cheap car insurance quotes and compare them. Read online reviews from the policy holders of that cheap car insurance company.

Car Insurance Claim Settlements

Before purchasing any car insurance policy, please confirm the car insurance claim settlement procedures. Car insurance claim settlement should be easy and less time consuming. If at any point, you come to know that claim settlement procedure is hectic and involves a lot of paper work, just ignore that car insurance company.   

Monday, 25 February 2013

Commonly Used Phrases and Sentences By Software Developers

Commonly Used Phrases and Sentences By Software Developers

In a software company, while developing application, software developers come under different circumstances in which they have to save themselves and blame others(blame game), they have to boast and bluff, they have to fool testers and managers in order to save their back. :) Here is the list of commonly used phrases and sentences by software developers in different situations.(This might not be the case with all, but I am taking in general...)

1. Thats not my code: A bug has been found in your application; you get afraid and start debugging the code to know where is the error. Error is coming in a function which you have not developed, you get delighted and run to your manager and say "Thats not my code. Please catch my colleague who made this function".     

2. It works on my machine: You developed a code and now it has gone to testing team. Tester has produced a scenario in which he is getting errors. You run same scenario on your developer machine and its running fine. You get delighted and reply to his mail "Its running on my machine".

3. Thats all from my side: While concluding the meeting, we developers / managers normally say "Thats all from my side".

4. But I did not make any change in that module: Error is coming in a functionality. Your manages says that error is coming in your module. You try to save yourself and say "But I did not make any change in that module".

5. I am almost done: Your manager asks you how much work is done? You don't clearly say that a lot of work is pending, a lot of errors are coming. You simply say "I am almost done".

6. End of Day: End of Day is commonly used by developers when they are asked when can they complete this code?

7. You f**king tester: Well! the rivalary between developer and tester is natural. Nobody will like that someone should find out and highlight limitations in his hard work. When any tester is finding out any silly mistakes in you application just for the sake of increasing the count of number of bugs in your code, "You f**king tester" is obvious on your tongue.  
8. It will take only a minute: Sometimes when you have a small bug in your code and you already know where you have to change to fix the bug, you say to your manager "It will take only a minute" in hurry without realizing that there could be some complex scenario also appear by making that change and instead of minutes, it might take a day.

9. Documentation is done: Developers only want to code not document. When they are forced to document also, they do it just for the sake of doing without any interest and miss a lot of details and say to managers "Documentation is done". If that document is not reviewed, it goes smooth for him otherwise....

10. Thats not a bug but functionality: This is used by developers to fool the testers.

Friday, 22 February 2013

How to Redirect URLs using Apache .htaccess File in PHP?

How to Redirect URLs using Apache .htaccess File in PHP?

In this apache .htaccess tutorial, we will learn how to redirect urls in PHP using .htaccess file?

.htacces is a configuration file in apache. The .htaccess file is a small text document that generally sits in the same location as your index.php or index.htm pages. It gives you the ability to interact with Apache on an individual domain-to-domain and directory-to-directory basis.

You can place the htaccess file anywhere where you'd like to control the flow of visitors. So for instance you can protect directories and redirect the traffic visiting those pages. This page will show you how to use the .htaccess file to redirect your visitors in different ways.

You can use .htaccess to redirect users to a different URL. The most basic .htaccess looks for any request for a specific page and if it finds that request, it forwards it to a new page you have specified. The syntax is:

redirect accessed-file URL-to-go-to

There are 3 parts;

(1) the Redirect command,
(2) the location of the file/directory you want redirected, and
(3) the full URL of the location you want that request sent to.

These parts are separated by a single space and should be on one line.
Contents of .htaccess file

1. 301 (Permanent) Redirect:

301 redirect is the most efficient and Search Engine Friendly method for webpage redirection. It's not that hard to implement and it should preserve your search engine rankings for that particular page. If you have to change file names or move pages around, it's the safest option. The code "301" is interpreted as "moved permanently".

Point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the "" domain:

# This allows you to redirect your entire website to any other domain
Redirect 301 /

2. 302 (Temporary) Redirect: Point an entire site to a different temporary URL. This is useful for SEO purposes when you have a temporary landing page and plan to switch back to your main landing page at a later date:

# This allows you to redirect your entire website to any other domain
Redirect 302 /

3. Redirect index.html to a specific subfolder:

# This allows you to redirect index.html to a specific subfolder
Redirect /index.html

4. Redirect an old file to a new file path:

# Redirect old file path to new file path
Redirect /olddirectory/oldfile.html

5. Redirect to a specific index page:

# Provide Specific Index Page (Set the default handler)
DirectoryIndex index.html

Precautions to use before using .htaccess file:

1. Even the slightest syntax error (like a missing space) can result in your content not displaying correctly or at all.

2. Since .htaccess is a hidden system file, please make sure your FTP client is configured to show hidden files. This is usually an option in the program's preferences/options.

3. Create an empty text file using a text editor such as notepad, and save it as htaccess.txt. The reason you should save the file as htaccess.txt is because many operating systems and FTP applications are unable to read or view .htaccess files by default. Once uploaded to the server you can rename the file to .htaccess.

Monday, 18 February 2013

How to Create and Use INI Files in Delphi XE2?

How to Create and Use INI Files in Delphi XE2?

Create an INI file (config.ini) which will have your application configuration settings like database connection settings, log settings, email settings etc. INI file is must for a big delphi application as you need to change various settings for application time to time. If you maintain INI file then you don't have to go in delphi code or database to change the settings everytime, you can just open INI file and make your changes.

Suppose you have created following INI file (config.ini)

ABC = 10
XYZ = 'Hello User'

Now, you have one integer value and one string value in ini. Lets create an delphi function to read this simple ini file.

You will have to use TIniFile delphi component from VCL. Declare object of this component.

IniValues : TIniFile;

procedure TMyForm.ReadINIFilesDelphi;
 ABCValue : Integer;
 XYZValue : String;
    IniValues := TIniFile.Create('config.ini');
    ABCValue := IniValues.ReadInteger('ConfigSettings','ABC',0);
    XYZValue := IniValues.ReadString('ConfigSettings','XYZ','');

    on E : Exception do
      ShowMessage('Error occured in function ReadINIFilesDelphi: ' + E.Message);

Above delphi procedure used ReadInteger and ReadString to read from INI files. It assigns 0 as default value to ABCValue and '' to XYZValue.

How to Send Email with Attachments in Delphi XE2 using Indy Clients?

How to Send Email with Attachments in Delphi XE2 using Indy Clients?

This delphi programming language tutorial is based on sending email with attachments using indy clients in delphi XE2. Indy Clients provide TIdSMTP and TIdMessage delphi components using which we can send email easily.

First of all, you will have to declare the objects of TIdSMTP  and TIdMessage like following:

MailMessage: TIdMessage;

Now you have to initialize Host and Port for SMTP. You can use default emailing port as 25.

After this you have to initialize MailMessage with From Address, To Address, CC Addresses, Subject and Body of the email.
Lets have a look at the following very simple delphi program to send email with attachments.

function TMyForm.SendEmailDelphi : Boolean;
  FileName : String;
    Result := False;
    FileName := 'myfile.txt';
    //Setup SMTP
    SMTP := TIdSMTP.Create(nil);
    SMTP.Host := 'XXX.XXX.XXX.XXX';
    SMTP.Port := 25; //Default email port
    MailMessage.From.Address :=;
    MailMessage.Recipients.EMailAddresses := + ',' +;
    MailMessage.Subject := 'Test Email from Delphi XE2';
    MailMessage.Body.Text := 'Hi! This is test email from delphi XE2';
    //Attach a file
    if FileExists(FileName) then
      TIdAttachmentFile.Create(MailMessage.MessageParts, FileName);
    //Send email
        Result := True;
        on E:Exception do
          ShowMessage('Cannot send E-Mail: ' + E.Message);
          Result := False;
      if SMTP.Connected then SMTP.Disconnect;
    on E : Exception do
      ShowMessage('Error in the function SendEmailDelphi: ' + E.Message);
      Result := False;

Sunday, 17 February 2013

How to format and update datetime in Javascript?

How to format and update datetime in Javascript?

There are a lot of datetime formats in which you can display the date and time on your webpage using javascript. There are a lot of javascript datetime functions available. In this javascript datetime tutorial, I will show you how to display the date on your webpage and keep on updating datetime every minute.

I have to show the javascript datetime in following format:

Monday, February 18, 2013 12:18

I will keep this time updating every minute without refreshing my webpage.

For this, I will make two arrays. One array will contain the names of the months and other array will contain the names of the days. I will use setInterval function which will keep on calling myDateTimer function after every minute.

Lets look at this javascript datetime code:
var myVar=setInterval(function(){myDateTimer()},1000);
function makeArray()
 for (i = 0; i<makeArray.arguments.length; i++)
 this[i + 1] = makeArray.arguments[i];
function myDateTimer()
 var months = new makeArray('January','February','March','April','May',
 var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
 var date = new Date();
 var day = date.getDate();
 var month = date.getMonth() + 1;
 var yy = date.getYear();
 var year = (yy < 1000) ? yy + 1900 : yy;
 var hours = date.getHours();
 var minutes = date.getMinutes();
 var finaldate = days[ date.getDay() ] + ", " + months[month] + " " + day + ", " + year + " " + hours +" : " + minutes;

Thursday, 14 February 2013

How to use FieldName and FieldValue in Delphi XE2?

How to use FieldName and FieldValue in Delphi XE2?

In this delphi programming tutorial, we will come to know how to use FieldName and FieldValue in delphi. Sometimes while coding in delphi, we need to get the field or column name of the table depending upon some certain conditions. In this case FieldName and FieldValue come into play.

In the following delphi code, we have created a delphi function which will fetch various columns from a table in database and will return the name of that column. For example, following delphi program gets ColA, ColB, ColC, ColD from a table named tblABC. After getting all the columns, it iterate through the column list and finds out which one is null and returns it. If it finds no column which is null, it returns empty string.

(Note: ColA, ColB, ColC, ColD are numeric columns, so I am checking for null. If your columns are varchar, you can use '' for checking empty column)

Delphi Program to show usage of FieldName and FieldValue
function TForm.MyDelphiFunction : String;
  i : integer;
    Result := '';
    with qryABC do
      SQL.Text := 'SELECT ColA, ColB, ColC, ColD FROM tblABC WHERE ID = :ID';
      ParamByName('ID').AsString := anyID;
      if RecordCount > 0 then
        for i:=0 to FieldCount -1 do
          if (Fields[i].Value) = Null then
             Result := Fields[i].FieldName;
    on E : Exception do
      Showmessage('Error occured in function MyDelphiFunction: ' + E.Message);
      Result := '';

What is DNS (Domain Name Server)

What is DNS (Domain Name Server)

DNS (Domain Name Server) is used to translate a domain name into IP address. This makes it possible for a user to access a website by typing in the domain name instead of the website's actual IP address. DNS is similar to a telephone directory.

Meaning of COM, NET, ORG etc.

COM -- commercial Web sites, though open to everyone
NET -- network Web sites, though open to everyone
ORG -- non-profit organization Web sites, though open to everyone
EDU -- restricted to schools and educational organizations
MIL -- restricted to the U.S. military
GOV -- restricted to the U.S. government
US, UK, RU and other two-letter country codes -- each is assigned to a domain name authority in the respective country

Domain Names should be unique

A registrar is an authority that can assign domain names directly and register them with InterNIC, a service of ICANN, which enforces uniqueness of domain names across the Internet. Each domain registration becomes part of a central domain registration database known as the whois database. Network Solutions, Inc. (NSI) was one of the first registrars, and today companies like offer domain registration and many domain management services.

How DNS (Domain Name Server) works?

1. If it has the domain name and IP address in its database, it resolves the name itself.

2. If it doesn't have the domain name and IP address in its database, it contacts another DNS server on the Internet. It may have to do this multiple times.

3. If it has to contact another DNS server, it caches the lookup results for a limited time so it can quickly resolve subsequent requests to the same domain name.

4. If it has no luck finding the domain name after a reasonable search, it returns an error indicating that the name is invalid or doesn't exist.
Registering a domain

Each domain name must have at least two name servers listed when the domain is registered. These name servers are commonly named and, where "servername" is the name of the server. The first server listed is the primary server, while the second is used as a backup server if the first server is not responding.

Name servers are a fundamental part of the Domain Name System (DNS). They allow websites to use domain names instead of IP addresses, which would be much harder to remember.

What is Parked Domain?

Using the DNS servers from your registrar or hosting company means that you have a parked domain. This means that someone else owns the computer hardware for the DNS servers, and your domain is just part of that company's larger DNS configuration.

What is Domain Propagation?

Domain Propagation is the period of time, or delay, involved in sending your domain’s address information to all the other name servers in the world. Name servers intentionally keep track of addresses for domains in their memory for a specific period of time which is defined by the administrator of the name server. This speeds up the process of looking up an address for a domain name. Unfortunately this “cached” information also stays in the name servers when it has been changed at the source of the original information (the domain’s registrar).

Name servers refresh themselves from once an hour to once a day. Generally 2-3 days time is a good estimate when a domain’s DNS information is changed at the domain registrar, after which everyone in the world can see the change.

Monday, 11 February 2013

PHP Form Validation Script: PHP GET and POST Methods

PHP Form Validation Script: PHP GET and POST Methods

Form validation in PHP is very easy. Whenever you submit any form in PHP, you must validate the input data before storing that in database. Basic validations which you can put on your input data might be trimming the input form data, stripping the slashes from form data, handling special html characters and various functional things depending upon the need of your PHP application. Below is the PHP Form Validation Script using POST method.


<form action="validateForm.php" method="post">
Name: <input type="text" name="name">
Email: <input type="text" name="email">
<input type="submit">

PHP Script to Validate Form

$name = validateData($_POST['name']);
$email = validateData($_POST['email']);

function validateData($data)
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;

Now lets discuss PHP Get and POST methods in detail:

PHP GET Method

The PHP GET method sends the encoded user information appended to the page request. The page and the encoded information are separated by the ? character.

PHP Script to illustrate GET Method

<form action="index.php" method="get">
Name: <input type="text" name="name">
<input type="submit">

When the user clicks the "Submit" button, the URL sent to the server will look like this:

The index.php file can now use the $_GET variable to collect php form data (the names of the form fields will automatically be the keys in the $_GET array):

Hello <?php echo $_GET["name"]; ?>

The PHP provides $_GET associative array to access all the sent information using PHP GET method.

Limitations of PHP GET Method:

1. When using method="get" in HTML forms, all variable names and values are displayed in the URL. So, PHP GET method should not be used when sending passwords or other sensitive information.

2. The PHP GET method is not suitable for very large variable values. It should not be used with values exceeding 1024 characters.

3. PHP GET method can't be used to send binary data, like images or word documents, to the server.

Advantages of PHP GET Method:

1. Because the variables are displayed in the URL, it is possible to bookmark the page.

PHP Post Method

The POST method transfers information via HTTP headers. The information is put into a header called QUERY_STRING.

PHP Script to illustrate POST Method

<form action="index.php" method="post">
Name: <input type="text" name="name">
<input type="submit">

When the user clicks the "Submit" button, the URL sent to the server will look like this:

The index.php file can now use the $_POST variable to collect form data (the names of the form fields will automatically be the keys in the $_POST array):

Hello <?php echo $_POST["name"]; ?>

Advantages of PHP POST Method

1. No limit to send data. There is an 8 MB max size for the POST method, by default (can be changed by setting the post_max_size in the php.ini file).

2. Variables are not visible in URL. So one can easily send passwords and critical information using POST method.

3. You can even post binary data using PHP Post Method.

Limitation of PHP POST Method

1. You cannot bookmark a specific page unlike GET method.

Saturday, 9 February 2013

Online PHP Programming Tutorial: Learn Basics of PHP Scripting With Simple PHP Code and Examples (Part 1)

Online PHP Programming Tutorial: Learn Basics of PHP Scripting With Simple PHP Code and Examples (Part 1)

Introduction to PHP: PHP stands for Hypertext Preprocessor. PHP is a server scripting language and is used for creating dynamic web pages. PHP is an open source scripting language. We will discuss some similarities and differences between PHP and ASP.NET later in this tutorial.

Learning PHP Programming

Learning PHP programming and development is very easy. PHP has very simple syntax. In this online PHP tutorial, we will learn PHP step by step by simple PHP examples using short and simple PHP scripts and codes. Lets start learning PHP scripting now:

1. Simple PHP Code Snippet

echo "Lets learn PHP Programming!";

Some basic things to note in PHP scripting:

1. A PHP script starts with <?php and ends with ?>.
2. Each code line in PHP must end with a semicolon.
3. PHP files have a default file extension of ".php".
4. In PHP, there are two basic statements to output text in the browser: echo and print.

2. Comments in PHP Programming

//PHP Single Line Comments
Multi Line Comments

3. Rules for PHP Variables

1. PHP variable starts with the $ sign, followed by the name of the variable
2. PHP variable name must begin with a letter or the underscore character
3. PHP variable name only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
4. PHP variable name should not contain spaces
5. PHP variable names are case sensitive ($y and $Y are two different variables)
6. PHP has no command for declaring a variable
7. PHP variables can be local, global and static
8. PHP string variable is used to store and manipulate text. When you assign a text value to a variable, remember to put single or double quotes around the value.

PHP Variables Example

echo $z;

4. PHP is a Loosely Typed Language

You don't have to declare data type the variable in PHP. PHP automatically converts the variable to the correct data type, depending on its value. In a strongly typed programming language, we will have to declare datatype of the variable before using it.

Consider the following simple PHP example:

$txt="PHP is a loosely typed language";

After the execution of the statements above, the variable txt will hold the value Hello world!, and the variable x will hold the value 5. When you assign a text value to a variable, put quotes around the value.

5. Types of Array in PHP

In PHP, there are three types of arrays:

Indexed arrays - Arrays with numeric index
Associative arrays - Arrays with named keys - Associative arrays are arrays that use named keys that you assign to them.
Multidimensional arrays - Arrays containing one or more arrays

Similarity and Differences between PHP and ASP.NET

PHP is a strong competitor of Microsoft ASP.NET. PHP goes ahead of ASP.NET in some case like:

1. PHP runs on different platforms likeWindows, Linux, Unix, Mac OS X, etc. ASP.NET on the other hand, only runs fine on Windows.

2. PHP is compatible with both Apache, IIS while ASP.NET has compatibility only with IIS. You can configure ASP.NET to run on Apache, but that is cumbersome.

3. PHP is open source and free. No license required for using PHP for commercial purposes.
Similarity between ASP.NET and PHP

1. Both ASP.NET and PHP are used for dynamic webpage development.

2. Both ASP.NET and PHP are easy to learn and understand.

3. Both ASP.NET and PHP have support for a wide range of databases.

4. Both ASP.NET and PHP have large online developer forums to support web development. For example, you will find a large community of ASP.NET and PHP developers on

Sunday, 3 February 2013

How to use Conditional Operators in Delphi XE2?

How to use Conditional Operators in Delphi XE2?

Conditional operators look so attractive because they let you write short and concise code. But delphi does not provide any conditional operators.

Lets have following example of conditional operators.

if a>b then
c:= 1
c:= 0;

I want to conclude it in one line using conditional operators like in C/C++.

c := (a > b ? 1 : 0);

But no, this is not possible in delphi. I don't know why? Why conditional operators are not included in delphi?

Workaround of Conditional Operators in Delphi?

Delphi provides a set of IfThen functions in the Math and StrUtils units. Delphi prism provides the utility of Iif that only evaluates one of its two value parameters. For example:

c:= Iif(a > b, 1, 0);

There are a number of available simple type handles on the overloaded IFTHEN function.

StrUtils.IfThen (String)
Math.IfThen (Integer)
Math.IfThen (Int64)
Math.IfThen (Double) (works for TDateTime as well)

Having or not having conditional operators don't make any difference because conditional operators have some drawbacks like less readability: Delphi is more centered on readability than the C Syntax languages which are more centered on character power (as much information per character as possible). The conditional operator is powerful but not readable.