Thursday, December 15, 2011

Fancybox : The requested content cannot be loaded Error - Resolved

When adding a fancybox popup you may encounter a common issue, which shows the below error message, while clicking the link.

"The requested content cannot be loaded.
Please try again later."

This error is due to the misconfiguration of the link class.
  1. If image popup is used, then it may be the issue with the image extension, make sure the extensions are all small letters. Ex: image.jpg instead of image.JPG
  2. In case of href url, then you must add class fancybox.iframe, otherwise the page may not load resulting the error.
    Ex: Demo
    changes to
    Demo
Hope this will work for you.

Tags: fancybox broken, broken fancybox image, broken fancybox page, fancybox iframe broken, fancybox not working

Thursday, December 1, 2011

FTP Filezilla - 421 Sorry, cleartext sessions are not accepted on this server. [Resolved]

Some times when  you connect to the webhost via FileZilla you may encounter this error message.
"421 Sorry, cleartext sessions are not accepted on this server."

Solution:
Just add a ftpes:// before the domain name

Old One,
host : domain.com
username : xxx
pass : yyy
port : 21


New,
host : ftpes://domain.com
username : xxx
pass : yyy
port : 21

Advanced Option,

Login to  Web Host Manager
Go To : Service Configuration
Go To : FTP Server Configuration
Check that  :
TLS Encryption Support : set to  “Optional”

Try that, it will work.





Thursday, November 17, 2011

PostgreSQL - Fatal error: Call to undefined function pg_connect() - Solved

If anyone using PostgreSQL may encounter Fatal error: Call to undefined function pg_connect() initially. This is because the PostgreSQL module has not been initialized properly. I will tell you the steps for setting up PostgreSQL module in xampp

Steps
  1. Open php.ini 
  2. Find ;extension=php_pgsql.dll and replace the initial semi colon
  3. Find ;extension=php_pdo_pgsql.dll and replace the initial semi colon 
  4. Save the file
  5. Restart apache

Done !!
Share, if it helps you...

Running PHP5 in XAMPP - Solved

Similar Problem - I have installed XAMPP on a Windows machine but cannot seem to get my PHP5 extensions working. If I go to a page http://localhost/contact.php everything displays fine but if I change the filename to contact.php5 and then try to browse to http://localhost/contact.php5 all I see is my code. My host requires me to specify the .php5 file extension. I've installed XAMPP Apache server and put my website into htdocs. I've started Apache server. On my website I've got files with extension PHP and with extension PHP5.The difference is that when I type in into browser localhost/file.php - I see a parsed website. But when I type localhost/file.php5 (i have this file on server), than browser asks me if I want to download or open this file. And if I choose open than I see PHP code of file.php5!

If you also have trouble in running php5 files in Xampp. Then this will help you. 

Steps
  1. Open C:\xampp\apache\conf\extra\httpd-xampp.conf file in text editor
  2. Below LoadModule php5_module modules/php5apache2_2.dll
    You can see,

    SetHandler application/x-httpd-php


    SetHandler application/x-httpd-php-source
  3. Replace the above set with the below one,

    SetHandler application/x-httpd-php


    SetHandler application/x-httpd-php-source
     
  4. Find this set of code,

    AddType text/html .php .phps
  5. Replace the above set with this one,

    AddType text/html .php .phps .php5
  6. Done !!!
     
    Share, if it works.

Thursday, November 10, 2011

Handy code for City, State, Zip, Country selector via JS


Today I got a new project to work on the client needs a registration form having Country, City, State and Zip Code including the Geo Location and Latitude. There was a location based searching for the system, so what we needed was to do a full validated geo fields without any kind of errors. I tried to do it via Ajax and so that  it will be the best for validation as well as interactive to the user also.
While searching  I got something which is very handy from geonames. I tried to do API calls to their web services so that I can get whatever details I want from them.

Sample API Call


The result obtained was a JSON string, 

jQ({"totalResultsCount":1,"geonames":[{"alternateNames":[{"name":"তিরুবনন্তপুরম","lang":"bn"},{"name":"ত্রিবানদ্রাম","lang":"bpy"},{"name":"Thiruvananthapuram","lang":"de"},{"name":"Thiruvananthapuram","lang":"en"},{"name":"Thiruvananthapuram","lang":"eo"},{"name":"Thiruvananthapuram","lang":"fi"},{"name":"Thiruvananthapuram","lang":"fr"},{"name":"तिरुअनन्तपुरम्","lang":"hi"},{"name":"Thiruvananthapuram","lang":"id"},{"name":"ティルヴァナンタプラム","lang":"ja"},{"name":"http://en.wikipedia.org/wiki/Thiruvananthapuram","lang":"link"},{"name":"തിരുവനന്തപുരം","lang":"ml"},{"name":"Trivandrum","lang":"nl"},{"name":"Trivandrum","lang":"pl"},{"name":"Thiruvananthapuram","lang":"pt"},{"name":"Thiruvananthapuram","lang":"ro"},{"name":"Тируванантапурам","lang":"ru"},{"name":"तिरुवनंतपुरम","lang":"sa"},{"name":"Thiruvananthapuram","lang":"sv"},{"name":"திருவனந்தபுரம்","lang":"ta"},{"name":"特里凡得琅","lang":"zh"}],"countryName":"India","adminCode1":"13","fclName":"city, village,...","score":28.883577346801758,"countryCode":"IN","lng":76.9166667,"adminName2":"","adminName3":"","fcodeName":"seat of a first-order administrative division","adminName4":"","timezone":{"dstOffset":5.5,"gmtOffset":5.5,"timeZoneId":"Asia/Kolkata"},"toponymName":"Thiruvananthapuram","fcl":"P","continentCode":"AS","name":"Thiruvananthapuram","fcode":"PPLA","geonameId":1254163,"lat":8.4833333,"adminName1":"Kerala","population":784153}]});

This API call can be used as an auto-suggestion for a text field which will be very handy for the developer instead of typing all the city, state, country data to the database.

You can also use the web services of geonames for geo location extraction,
http://www.geonames.org/export/web-services.html



GeoNames is mainly using REST webservices.

And finally the AIO,

Important:

I’m sure that this will be the best for the one who seeks this.

Tuesday, November 8, 2011

WordPress code snippets - Cheat Sheet

Here is a list of WordPress Code Snippets that can be used in your every day coding phase. If you take a print out of it then it will be the best so that you can keep it your self and distribute among others. 
 
PHP Snippets for Header
Title of the site < ?php bloginfo(’name’); ? >
Title of specific post or page < ?php wp_title(); ? >
The style.cssfile's theme location < ? php bloginfo(’stylesheet__url’); ? >
Pingback URL for the site < ?php bloginfo('pingback_url');? >
Location for the site's theme file < ?php bloginfo(’template_url');? >
Wordpress version for the site < ?php bloginfo('version');? >
Atom URL for the site < ?php bloiginfo('atom_url');'? >
Exact URL for the site < ?php bloginfo('rss2_url');? >
Name of the site < ?php bloginfo('name');? >
Html version of the site < ?php bloginfo('htm1_type');? >
Charset parameter of the site < ?php bloginfo('charset');? >

Basic Template Files
Style sheet file style.css
Homepage file index.php
Single post page file single.php
Archive/category file a1-chive.php
Search form file searchform.php
Search content file search.php
Error page file 404.php
Footer content file footer.php
Comments template file comments.php
Header content file header-.php
Sidebar content file sideba:-.php
Single page file page.php

Extra Stuff
Custom permalinks /%postname%/
Include any file < ?php include(TEMPLATEPATH .‘/x’); ? >
Value for search form < ?php the_search_query(); ? >
Prints out message < ?php _e(’Message’); ? >
Displays the register link < ?php wp_register(); ? >
Displays the login/logout link < ?php wp_loginout(); ? >
Divides the content into pages
Cuts of" the content <1--more-->
Meta for administrators < ?php wp_meta(); ? >
Time to load the page < ?php timer_stop(1); ? >
Queries to load the page < ?php echo get_num_queries(); ? >

PHP Snippets for Templates
Author of a specific post or page < ?php the_author(); ? >
Content of the posts < ?php the_content(); ? > ‘
ID of a specific post or page < ?php the_ID(); ? >
Checks if there are posts < ?php if(have_posts()) : ? >
Link to edit a specific post or page < ?php edit _post_link(); ? >
Shows posts if posts are available < ?php while(have__posts()) : the _post(); ? >
Links from the blogroll < ?php get_links_list(); ? >
Closes the 'while' PHP function < ?php endwhile; ? >
Comment.php files content < ?php comments_template(); ? >
Closes the 'if PHP function < ?php endif; ? >
List of pages of the site < ?php wp_list_pages(); ? >
Header.php file's content < ?php get_header(); ? >
List of categories for the site < ?php wp_list_cats(); ? >
Sidebar.php files content < ?php get_sidebar(); ? >
Url to the next post < ?php next _post_link(' %link ') ? >
Footer.php file's content < ?php get_footer(); ? >
Url to the previous post < ?php previous _post_link('%link') ? >
The date in '08-18-07' format < ?php the_time('m-d-y') ? >
The built-in calendar < ?php get_calendar(); ? >
Link for the comments on the post < ?php comments_popup_link(); ? >
List of archives for the site < ?php wp_get_archives() ? >
Title of a specific post or page < ?php the_title(); ? >
Next and previous post link < ?php posts_nav_link(); ? >
Url of a specific post or page < ?php the _permalink() ? > ‘
Site’s description < ?php bloginfo(’description’); ? >
Category of a specific post or page < ?php the_category(', ') ? > ‘

Thursday, October 27, 2011

Be careful while writing codes

Lessons From A JavaScript Code Review

On to the review.
A developer recently wrote in, asking me to review their code and provide some useful suggestions on how they might improve it. While I’m certainly not an expert on reviewing code (don’t let the above fool you), here are the problems and solutions that I proposed.

Problem 1

Problem: Functions and objects are passed as arguments to other functions without any type validation.
Feedback: Type validation is an essential step in ensuring that you’re working only with input of a desired type. Without sanitization checks in place, you run the risk of users passing in just about anything (a string, a date, an array, etc.), which could easily break your application if you haven’t developed it defensively. For functions, you should do the following at a minimum:
  1. Test to ensure that arguments being passed actually exist,
  2. Do a typeof check to prevent the app from executing input that is not a valid function at all.
if (callback && typeof callback === "function"){
    /* rest of your logic */
}else{
    /* not a valid function */
}
Unfortunately, a simple typeof check isn’t enough on its own. As Angus Croll points out in his post “Fixing the typeof operator,” you need to be aware of a number of issues with typeof checking if you’re using them for anything other than functions.
For example, typeof null returns object, which is technically incorrect. In fact, when typeof is applied to any object type that isn’t a function, it returns object, not distinguishing between Array, Date, RegEx or whatever else.
The solution is to use Object.prototype.toString to call the underlying internal property of JavaScript objects known as [[Class]], the class property of the object. Unfortunately, specialized built-in objects generally overwrite Object.prototype.toString, but you can force the generic toString function on them:
Object.prototype.toString.call([1,2,3]); //"[object Array]"
You might also find Angus’s function below useful as a more reliable alternative to typeof. Try calling betterTypeOf() against objects, arrays and other types to see what happens.
function betterTypeOf( input ){
    return Object.prototype.toString.call(input).match(/^\[object\s(.*)\]$/)[1];
}
Here, parseInt() is being blindly used to parse an integer value of user input, but no base is specified. This can cause issues.
In JavaScript: The Good Parts, Douglas Crockford refers to parseInt() as being dangerous. Although you probably know that passing it a string argument returns an integer, you should also ideally specify a base or radix as the second argument, otherwise it might return unexpected output. Take the following example:
parseInt('20');       // returns what you expect, however…
parseInt('020');      // returns 16
parseInt('000020');   // returns 16
parseInt('020', 10);  // returns 20 as we've specified the base to use
You’d be surprised by how many developers omit the second argument, but it happens quite regularly. Remember that your users (if permitted to freely enter numeric input) won’t necessarily follow standard number conventions (because they’re crazy!). I’ve seen 020, ,20, ;'20 and many other variations used, so do your best to parse as broad a range of inputs as possible. The following tricks to using parseInt() are occasionally better:
Math.floor("020");   // returns 20
Math.floor("0020");  //returns 20
Number("020");  //returns 20
Number("0020"); //returns 20
+"020"; //returns 20

Problem 2

Problem: Checks for browser-specific conditions being met are repeated throughout the code base (for example, feature detection, checks for supported ES5 features, etc.).
Feedback: Ideally, your code base should be as DRY as possible, and there are some elegant solutions to this problem. For example, you might benefit from the load-time configuration pattern here (also called load-time and init-time branching). The basic idea is that you test a condition only once (when the application loads) and then access the result of that test for all subsequent checks. This pattern is commonly found in JavaScript libraries that configure themselves at load time to be optimized for a particular browser.
This pattern could be implemented as follows:
var tools = {
    addMethod: null,
    removeMethod: null
};

if(/* condition for native support */){
    tools.addMethod = function(/* params */){
        /* method logic */
    }
}else{
    /* fallback - eg. for IE */
    tools.addMethod = function(/* */){
        /* method logic */
    }
}
The example below demonstrates how this can be used to normalize getting an XMLHttpRequest object.
var utils = {
    getXHR: null
};

if(window.XMLHttpRequest){
    utils.getXHR = function(){
        return new XMLHttpRequest;
    }
}else if(window.ActiveXObject){
    utils.getXHR = function(){
        /* this has been simplified for example sakes */
        return new ActiveXObject(’Microsoft.XMLHTTP’);
    }
}
For a great example, Stoyan Stefanov applies this to attaching and removing event listeners cross-browser, in his book JavaScript Patterns:
var utils = {
    addListener: null,
    removeListener: null
};
// the implementation
if (typeof window.addEventListener === ’function’) {
    utils.addListener = function ( el, type, fn ) {
        el.addEventListener(type, fn, false);
    };
    utils.removeListener = function ( el, type, fn ) {
        el.removeEventListener(type, fn, false);
    };
} else if (typeof document.attachEvent === ’function’) { // IE
    utils.addListener = function ( el, type, fn ) {
        el.attachEvent(’on’ + type, fn);
    };
    utils.removeListener = function ( el, type, fn ) {
        el.detachEvent(’on’ + type, fn);
    };
} else { // older browsers
    utils.addListener = function ( el, type, fn ) {
        el[’on’ + type] = fn;
    };
    utils.removeListener = function ( el, type, fn ) {
        el[’on’ + type] = null;
    };
}

Problem 3

Problem: The native Object.prototype is being extended regularly.
Feedback: Extending native types is generally frowned upon, and few (if any) popular code bases should dare to extend Object.prototype. The reality is that there is not likely a situation in which you absolutely need to extend it in this way. In addition to breaking the object-as-hash tables in JavaScript and increasing the chance of naming collisions, it’s generally considered bad practice, and modifying it should only be a last resort (this is quite different from extending your own custom object properties).
If for some reason you do end up extending the object prototype, ensure that the method doesn’t already exist, and document it so that the rest of the team is aware why it’s necessary. You can use the following code sample as a guide:
if(typeof Object.prototype.myMethod != ’function’){
    Object.prototype.myMethod = function(){
        //implem
    };
}
Juriy Zaytsev has a great post on extending native and host objects, which may be of interest.

Problem 4

Problem: Some of the code is heavily blocking the page because it’s either waiting on processes to complete or data to load before executing anything further.
Feedback: Page-blocking makes for a poor user experience, and there are a number of ways to work around it without impairing the application.
One solution is to use “deferred execution” (via promises and futures). The basic idea with promises is that, rather than issuing blocking calls for resources, you immediately return a promise for a future value that will eventually be fulfilled. This rather easily allows you to write non-blocking logic that can be run asynchronously. It is common to introduce callbacks into this equation that execute once the request completes.
I’ve written a relatively comprehensive post on this with Julian Aubourg, if you’re interested in doing this through jQuery, but it can of course be implemented with vanilla JavaScript as well.
Micro-framework Q offers a CommonJS-compatible implementation of promises and futures that is relatively comprehensive and can be used as follows:
/* define a promise-only delay function that resolves when a timeout completes */
function delay(ms) {
    var deferred = Q.defer();
    setTimeout(deferred.resolve, ms);
    return deferred.promise;
}

/* usage of Q with the 'when' pattern to execute a callback once delay fulfils the promise */
Q.when(delay(500), function () {
        /* do stuff in the callback */
});
If you’re looking for something more basic that can be read through, then here is Douglas Crockford’s implementation of promises:
function make_promise() {
  var status = ’unresolved’,
      outcome,
      waiting = [],
      dreading = []; 

  function vouch( deed, func ) {
    switch (status) {
    case ’unresolved’:
      (deed === ’fulfilled’ ? waiting : dreading).push(func);
      break;
    case deed:
      func(outcome);
      break;
    }
  };

  function resolve( deed, value ) {
    if (status !== ’unresolved’) {
      throw new Error(’The promise has already been resolved:’ + status);
    }
    status = deed;
    outcome = value;
    (deed == ’fulfilled’ ? waiting : dreading).forEach(function (func) {
      try {
        func(outcome);
      } catch (ignore) {}
    });
    waiting = null;
    dreading = null;
  };

  return {
    when: function ( func ) {
      vouch(’fulfilled’, func);
    },
    fail: function ( func ) {
      vouch(’smashed’, func);
    },
    fulfill: function ( value ) {
      resolve(’fulfilled’, value);
    },
    smash: function ( string ) {
      resolve(’smashed’, string);
    },
    status: function () {
      return status;
    }
  };
};

Problem 5

Problem: You’re testing for explicit numeric equality of a property using the == operator, but you should probably be using === instead
Feedback: As you may or may not know, the identity == operator in JavaScript is fairly liberal and considers values to be equal even if they’re of completely different types. This is due to the operator forcing a coercion of values into a single type (usually a number) prior to performing any comparison. The === operator will, however, not do this conversion, so if the two values being compared are not of the same type, then === will just return false.
The reason I recommend considering === for more specific type comparison (in this case) is that == is known to have a number of gotchas and is considered to be unreliable by many developers.
You might also be interested to know that in abstractions of the language, such as CoffeeScript, the == operator is completely dropped in favor of === beneath the hood due to the former’s unreliability.
Rather than take my word for it, see the examples below of boolean checks for equality using ==, some of which result in rather unexpected outputs.
3 == "3" // true
3 == "03" // true
3 == "0003" // true
3 == "+3" //true
3 == [3] //true
3 == (true+2) //true
’ \t\r\n ’ == 0 //true
"\t\r\n" == 0 //true
"\t" == 0 // true
"\t\n" == 0 // true
"\t\r" == 0 // true
" " == 0 // true
" \t" == 0 // true
" \ " == 0 // true
" \r\n\ " == 0 //true
The reason that many of the (stranger) results in this list evaluate to true is because JavaScript is a weakly typed language: it applies type coercion wherever possible. If you’re interested in learning more about why some of the expressions above evaluate to true, look at the Annotated ES5 guide, whose explanations are rather fascinating.
Back to the review. If you’re 100% certain that the values being compared cannot be interfered with by the user, then proceed with using the == operator with caution. Just remember that === covers your bases better in the event of an unexpected input.

Problem 6

Problem: An uncached array length is being used in all for loops. This is particularly bad because you’re using it when iterating through an HTMLCollection.
Here’s an example:
for( var i=0; i
Feedback: The problem with this approach (which I still see a number of developers using) is that the array length is unnecessarily re-accessed on each loop’s iteration. This can be very slow, especially when working with HTMLCollections (in which case, caching the length can be anywhere up to 190 times faster than repeatedly accessing it, as Nicholas C. Zakas mentions in his book High-Performance JavaScript). Below are some options for caching the array length.
/* cached outside loop */
var len = myArray.length;
for ( var i = 0; i < len; i++ ) {
}

/* cached inside loop */
for ( var i = 0, len = myArray.length; i < len; i++ ) {
}

/* cached outside loop using while */
var len = myArray.length;
while (len--) {
}
A jsPerf test that compares the performance benefits of caching the array length inside and outside the loop, using prefix increments, counting down and more is also available, if you would like to study which performs the best.

Problem 7

Problem: jQuery’s $.each() is being used to iterate over objects and arrays, in some cases while for is being used in others.
Feedback: In jQuery, we have two ways to seamlessly iterate over objects and arrays. The generic $.each iterates over both of these types, whereas $.fn.each() iterates over a jQuery object specifically (where standard objects can be wrapped with $() should you wish to use them with the latter). While the lower-level $.each performs better than $.fn.each(), both standard JavaScript for and while loops perform much better than either, as proven by this jsPerf test. Below are some examples of loop alternatives that also perform better:
/* jQuery $.each */
$.each(a, function() {
 e = $(this);
});

/* classic for loop */
var len = a.length;
for ( var i = 0; i < len; i++ ) {
    //if this must be a jQuery object do..
    e = $(a[i]);
    //otherwise just e = a[i] should suffice
};

/* reverse for loop */
for ( var i = a.length; i-- ) {
    e = $(a[i]);
}

/* classic while loop */
var i = a.length;
while (i--) {
    e = $(a[i]);
}

/* alternative while loop */
var i = a.length - 1;

while ( e = a[i--] ) {
    $(e)
};
You might find Angus Croll’s post on “Rethinking JavaScript for Loops” an interesting extension to these suggestions.
Given that this is a data-centric application with a potentially large quantity of data in each object or array, you should consider a refactor to use one of these. From a scalability perspective, you want to shave off as many milliseconds as possible from process-heavy routines, because these can build up when hundreds or thousands of elements are on the page.

Problem 8

Problem: JSON strings are being built in-memory using string concatenation.
Feedback: This could be approached in more optimal ways. For example, why not use JSON.stringify(), a method that accepts a JavaScript object and returns its JSON equivalent. Objects can generally be as complex or as deeply nested as you wish, and this will almost certainly result in a simpler, shorter solution.
var myData = {};
myData.dataA = [’a’, ’b’, ’c’, ’d’];
myData.dataB = {
    ’animal’: ’cat’,
    ’color’: ’brown’
};
myData.dataC = {
    ’vehicles’: [{
        ’type’: ’ford’,
        ’tint’: ’silver’,
        ’year’: ’2015’
    }, {
        ’type’: ’honda’,
        ’tint’: ’black’,
        ’year’: ’2012’
    }]
};
myData.dataD = {
    ’buildings’: [{
        ’houses’: [{
            ’streetName’: ’sycamore close’,
            ’number’: ’252’
        }, {
            ’streetName’: ’slimdon close’,
            ’number’: ’101’
        }]
    }]
};
console.log(myData); //object
var jsonData = JSON.stringify(myData);

console.log(jsonData);
/*
{"dataA":["a","b","c","d"],"dataB":{"animal":"cat","color":"brown"},"dataC":{"vehicles":[{"type":"ford","tint":"silver","year":"2015"},{"type":"honda","tint":"black","year":"2012"}]},"dataD":{"buildings":[{"houses":[{"streetName":"sycamore close","number":"252"},{"streetName":"slimdon close","number":"101"}]}]}}
 */
As an extra debugging tip, if you would like to pretty-print JSON in your console for easier reading, then the following extra arguments to stringify() will achieve this:
JSON.stringify({ foo: "hello", bar: "world" }, null, 4);

Problem 9

Problem: The namespacing pattern used is technically invalid.
Feedback: While namespacing is implemented correctly across the rest of the application, the initial check for namespace existence is invalid. Here’s what you currently have:
if ( !MyNamespace ) {
  MyNamespace = { };
}
The problem is that !MyNamespace will throw a ReferenceError, because the MyNamespace variable was never declared. A better pattern would take advantage of boolean conversion with an inner variable declaration, as follows:
if ( !MyNamespace ) {
  var MyNamespace = { };
}

//or
var myNamespace = myNamespace || {};

// Although a more efficient way of doing this is:
// myNamespace || ( myNamespace = {} );
// jsPerf test: http://jsperf.com/conditional-assignment

//or
if ( typeof MyNamespace == ’undefined’ ) {
  var MyNamespace = { };
}
 
 
Courtesy : SmashingMag

Wednesday, October 19, 2011

How MySQL Transaction works ?

A transaction is a sequential group of database manipulation operations, which is performed as if it were one single work unit. In other words, a transaction will never be complete unless each individual operation within the group is successful. If any operation within the transaction fails, the entire transaction will fail.

Practically you will club many SQL queries into a group and you will execute all of them together as a part of a transaction.
You can not use transactions directly, you can but they would not be save and guaranteed. If you plan to use transactions in your MySQL programming then you need to create your tables in a special way. There are many type of tables which support transactions but most popular one is InnoDB.
You can execute these SQL commands in PHP by using mysql_query() function.

  1. Begin transaction by issuing SQL command BEGIN WORK
  2. Issue one or more SQL commands like SELECT, INSERT, UPDATE or DELETE
  3. Check if there is no error and everything is according to your requirement.
  4. If there is any error then issue ROLLBACK command otherwise issue a COMMIT command.
Those who have no idea about the MySQL Transactions can take a look at the below code.
It will help you to get an overall idea about how a transaction works in MySQL.
 
mysql_query("START TRANSACTION");

$a = mysql_query("INSERT INTO table_name (amount) VALUES('100')");
$b = mysql_query("INSERT INTO table_name (amount) VALUES('200')");
if ($a and $b) {
    mysql_query("COMMIT");
} else {        
    mysql_query("ROLLBACK");
}


Fixing Skype Overwriting Phone Numbers in Web Pages

If you have Skype on your computer you may have noticed that sometimes Skype highlights phone numbers automatically when you visit a website. By the developers point of view this can be very frustrating. Not only can it make your site look bad, but it can mess up the layout as well. In fact, just recently we had a client whose page kept breaking because Skype was highlighting his phone number. Fixing this problem is not very hard. All you have to do is add some code to the head of your HTML document and it will prevent Skype from highlighting numbers in your theme no matter what browser it is being displayed on. This is the code you should paste:

"SKYPE_TOOLBAR" content="SKYPE_TOOLBAR_PARSER_COMPATIBLE" />   

Make sure it is between the and tags.

Monday, September 26, 2011

iOS 4.3.2 Restore IPSW for iPhone/iPad/iPod - Download Links

iOS 4.3.3 8J2 has been released by Apple for iPhone 4, iPhone 3GS, iPad 2, iPad and iPod touch and you can direct download from links below. Simply connect your device to the computer via USB and update to iOS 4.3.3 with iTunes 10.2.2

Download iPhone 4 (GSM) 4.3.3_8j2_Restore.ipsw
Download iPhone 3GS 4.3.3_8j2_Restore.ipsw
Download iPad 2 WiFi 4.3.3_8j2_Restore.ipsw
Download iPad 2 GSM 4.3.3_8j2_Restore.ipsw
Download iPad 2 CDMA 4.3.3_8j2_Restore.ipsw
Download iPad 4.3.3_8j2_Restore.ipsw
Download iPod touch 3G 4.3.3_8j2_Restore.ipsw
Download iPod touch 4G 4.3.3_8j2_Restore.ipsw

Thursday, August 4, 2011

jQuery Validator Plugin - File upload validation issue : Solved

Hi folks, have you had an issue in validating file upload with jQuery Validatior Plugin.
Sample:
$("#check").validate({
        rules: {
            myfile: {required: true,
                        accept: "png|jpg|gif|jpeg"
                      },
            },
        messages: {myfile: "ERROR"    }
    });

here it checks for file having jpg,png,gif,jpeg extension and it works. But the problem is the if we make a file with name 'foo_bar.1jpg', the validator will take this as a valid file also. Here their plug-in fails....

So i have modified the plug-in code so that it will take only having valid image extension.

Just replace the accept function in the jquery.validate.js to the below code,


accept: function(value, element, param) {
            var truncate = value.split(".");
            value = truncate[1];
            param = typeof param == "string" ? param.replace(/,/g, '|') : "png|jpe?g|gif";
            return this.optional(element) || value.match(new RegExp("^(" + param + ")$", "i"));
        },

Thursday, July 21, 2011

IE7 - JS library to make Microsoft IE behave like a standards-compliant browser

About

IE7.js is a JavaScript library to make Microsoft Internet Explorer behave like a standards-compliant browser. It fixes many HTML and CSS issues and makes transparent PNG work correctly under IE5 and IE6.

Usage

IE7.js

Upgrade MSIE5.5-6 to be compatible with MSIE7.

IE8.js

Upgrade MSIE5.5-7 to be compatible with MSIE8.
You do not need to include IE7.js if you are using IE8.js

IE9.js

Upgrade MSIE5.5-8 to be compatible with modern browsers.
You do not need to include IE7/IE8.js if you are using IE9.js

PNG

The script only fixes images named: *-trans.png
If you want the fix to apply to all PNG images then set a global variable as follows:
var IE7_PNG_SUFFIX = ".png";
You must set this variable before including the IE7.js script. Alternatively, you can set the variable inside the IE7.js script element:
 src="IE8.js">IE7_PNG_SUFFIX=".png";
The suffix will ignore query string parameters. For more fine-grained control you can also set IE7_PNG_SUFFIX to a RegExp object. If you want to use an alternative PNG solution then set the suffix to something that cannot possibly match:
var IE7_PNG_SUFFIX = ":";
By default, the PNG will be stretched (this simulates tiling). If you want to turn this off then set the no-repeat property as follows:
div.example {
  background: url(my-trans.png) no-repeat;
}
Unfortunately, the transparent background image cannot be tiled (repeated) using background-repeat. Nor can it be positioned using background-position.

Download

You may link directly to these files if you wish:
http://ie7-js.googlecode.com/svn/version/
Or go to the downloads section to download the current version.

Getting Started

Here is a nice introduction:
http://www.charlescooke.me.uk/web/lab_notes/ie7_script.html

Demo

http://ie7-js.googlecode.com/svn/test/index.html

Wednesday, July 6, 2011

Block adult Web content with easiest way, to keep your kids safe online

Are you having problems with seeing adult contents websites or Do you want to block access to improper websites to your children. Block adult Web content with the single easiest way, to keep your kids safe online — and away from adult websites — on your home Internet for free. No software to install.
Then this is what you have to do.

You must have 2 user accounts in your system, which one will be admin and other will be a user account which is for the rest of the users including children.

Here are the steps,
  1. Click the Start Orb, then select Control Panel.
  2. Click on Network and Sharing Center.
  3. Click on Local Area Connection under 'Active Networks.'
  4. Click the Properties button.
  5. Highlight 'Internet Protocol Version 4' and click Properties.
  6. Click the radio button 'Use the following DNS server addresses:' and type in 
    1. 208.67.222.123 in the Preferred DNS server and
    2. 208.67.220.123 in Alternate DNS server fields.
  7. Click OK button, then the Close button, then Close again. Finally, close the Network and Sharing Center window.  
  8. You are done !!!
  9. Make sure you are giving the limited account to children and not admin account. ;-)

1. Click the Start Orb, then select Control Panel.

2. Click on Network and Sharing Center.

3. Click on Local Area Connection under 'Active Networks.'

4. Click the Properties button.

Windows 7 may prompt you for permission to make network setting changes.

5. Highlight 'Internet Protocol Version 4' and click Properties.

6. Click the radio button 'Use the following DNS server addresses:' and type in OpenDNS' addresses in the Preferred DNS server and Alternate DNS server fields.

7. Click OK button, then the Close button, then Close again. Finally, close the Network and Sharing Center window.

At this point, we recommend that you flush your DNS resolver cache and web browser caches to ensure that your new DNS configuration settings take immediate effect.

Popular Posts