Monthly Archives: July 2010

How to test HTTPS CURL in development server?

HTTPS is secure HTTP communication based on SSL protocol (HTTP over SSL). Generally all sensitive info (like passwords, financial details, etc.) are sent over this transport. Common example: your gmail login is done through HTTPS channel and different payment gateway.
So here in this deal –

CURLOPT_SSL_VERIFYHOST is off. This allows you to test the CURL in your dev server without having HTTPS. PHP/Curl will handle the http request.


What is CSS Image Sprites?

An image sprite is a collection of images put into a single image.

What is advantage of using image sprite?

  1. Reduce multiple server requests.
  2. Sprites reduce the number of server requests and save bandwidth.
  3. Another advantage of sprites is that you can keep all your images in one location and in some cases it makes more sense (for menus and so on).

A real life Example
If you use sprites for a “mouse over” display, the user won’t experience image disappear for a second… and it looks really good when you have heavy graphics in your site.
If you change the image instead of just moving the sprite around it will load a new image and the loading time can be visible to the end user.

CSS Image Sprites Example Code

You can use Adobe Photoshop or any other image editing software to determine which area needs to be display.


JavaScript Refrence

JavaScript Variable Manipulation Functions

As shown in the following table, you can use these JavaScript statements in your own code to create and modify variables in your JavaScript functions.

Element Description
var myVar = 0; Creates a variable with given starting value. Type is determined dynamically.
stringVar = prompt(“message”) Sends message to user in a dialog box, retrieves text input from user and stores it in stringVar.
stringVar.length Returns the length (in characters) of stringVar.
stringVar.toUpperCase(), stringVar.toLowerCase() Converts stringVar to upper- or lowercase.
stringVar.substring() Returns a specified subset of stringVar.
stringVar.indexOf() Returns location of a substring in stringVar (or -1).
parseInt() Converts string to int.
parseFloat() Converts string to float.
toString() Converts any variable to string.
eval() Evaluates string as JavaScript code.
Math.ceil() Converts any number to integer by rounding up.
Math.floor() Converts any number to integer by rounding down.
Math.round() Converts any number to integer by standard rounding algorithm.
Math.random() Returns random float between 0 and 1.

Basic I/O Commands in JavaScript

JavaScript programmers commonly use the commands shown in the following table for controlling dialog-based input and output in programs to be used on the Web.

Element Description
alert(“message”); Creates a popup dialog containing “message.”
stringVar = prompt(“message”) Send message to user in a dialog box, retrieve text input from user and store it in stringVar.

JavaScript Conditions and Branching Code Structures

Look to the following table for JavaScript control structures you can use in your program code to add branching and looping behavior to your JavaScript programs.

Element Description
if (condition){

// content

} else {

// more content

} // end if

Executes content only if condition is true.

Optional else clause occurs if condition
is false.

switch (expression)

case: value;





Compares expression against one or more values. If expression
is equal to value, runs corresponding code.

Default clause catches any uncaught values.

for(i = 0; i < count; i++)


} // end for

Repeats code i times.
While (condition){


} // end while

Repeats code as long as condition is true.
Function fnName(paramaters) {


} // end function

Defines a function named fnName and
sends it parameters. All code inside the function will execute when
the function is called.

Add JavaScript Comparison Operators to Condition Statements

JavaScript uses comparison operators inside conditions to make numeric or alphabetical comparisons of variables to other variables or values. Using these operators, you can determine whether a variable is greater than, less than, or equal to another variable or value. You can also use combinations of these comparison operators.

Name Operator Example Notes
Equality == (x==3) Works with all variable types, including strings.
Not equal != (x != 3) True if values are not equal.
Less than < (x < 3) Numeric or alphabetical comparison.
Greater than > (x > 3) Numeric or alphabetical comparison.
Less than or equal to <= (x <= 3) Numeric or alphabetical comparison.
Greater than or equal to >= (x >= 3) Numeric or alphabetical comparison.

Create JavaScript Structures and Objects

JavaScript allows you to put together code lines to create functions and variables to create arrays. You can put functions and variables together to create objects.

Element Description
function fnName(parameters) {


} // end function

Defines a function named fnName and
sends it parameters. All code inside function will execute when the
function is called.
var myArray = new Array(“a”,
“b”, “c”);
Creates an array. Elements can be any type (even mixed
Var myJSON = {




Creates a JSON object. Each element
has a name/value pair, and can contain anything, including an array
(with square braces) another JSON object,
or a function.
Var person = new Object(); =

Creates an object. You can add ordinary variables (which become
properties) or functions (which become methods).

Change Your Web Page with JavaScript Document Object Model Methods

The Document Object Model methods shown in the following table offer you a great way to access and modify your Web pages through your JavaScript code.

Element Description
myElement =
Gets an element from the page with the specified ID and copies
a reference to that element to the variable myElement.
myElement.innerHTML =
Changes the value of the element to “value”.
document.onkeydown = keyListener When a key is pressed, a function called keyListener is automatically activated.
document.onmousemove =
When the mouse is moved, a function called mouseListener is automatically activated.
setInterval(function, ms); Runs function each ms
myArray =
Returns an array of objects with the current name (frequently
used with radio buttons).

What is ajax synchronous and asynchronous?

Synchronous – Script stops and waits for the server to send back a reply before continuing. There are some situations where Synchronous Ajax is mandatory.

In standard Web applications, the interaction between the customer and the server is synchronous. This means that one has to happen after the other. If a customer clicks a link, the request is sent to the server, which then sends the results back.

Because of the danger of a request getting lost and hanging the browser, synchronous javascript isn’t recommended for anything outside of (onbefore)unload event handlers, but if you need to hear back from the server before you can allow the user to navigate away from the page, synchronous Javascript isn’t just your best option.

Synchronous AJAX function Example using GET.

Synchronous AJAX function Example using POST.

Asynchronous – Where the script allows the page to continue to be processed and will handle the reply if and when it arrives. If anything goes wrong in the request and/or transfer of the file, your program still has the ability to recognize the problem and recover from it.
Processing asynchronously avoids the delay while the retrieval from the server is taking place because your visitor can continue to interact with the web page and the requested information will be processed with the response updating the page as and when it arrives.


What is Ajax?

Ajax (sometimes called Asynchronous JavaScript and XML) is a way of programming for the Web that gets rid of the hourglass. Data, content, and design are merged together into a seamless whole. When your customer clicks on something on an Ajax driven application, there is very little lag time. The page simply displays what they’re asking for.

Ajax is a way of developing Web applications that combines:

  • XHTML and CSS standards based presentation
  • Interaction with the page through the DOM
  • Data interchange with XML and XSLT
  • Asynchronous data retrieval with XMLHttpRequest
  • JavaScript to tie it all together

JSON: The 5 minute lesson

What is Json ?

JSON stand for  JavaScript Object Notation.
It is a lightweight text-based open standard designed for human-readable data interchange.
It is derived from the JavaScript  programming language for representing simple data structures and associative arrays, called objects.
Despite its relationship to JavaScript, it is language-independent, with parsers available for virtually every programming language. The JSON filename extension is .json.

It is easy for humans to read and write. It is easy for machines to parse and generate.


Squiggles, Squares, Colons and Commas

1. Squiggly brackets act as ‘containers’ { }
2. Square brackets holds arrays [ ]
3. Names and values are separated by a colon. :
4. Array elements are separated by commas. ,