Pages

Sunday, July 8, 2012

cross domain request using jquery

Unfortunatly cross domin access is not available to functions placed in other domain in a json file that return data.

One way out is to show the same in a .php file or an .asmx page but what if we want the interface to be platform independent...



The way out is to host JSON services using jsonp or "JSON with padding"



http://en.wikipedia.org/wiki/JSONP



To make a cross domain Json request use the following Jquery function



http://api.jquery.com/jQuery.ajax/

Javascript code to get a string sliced till last occurance of a charcter

Javascript code to get a string sliced till last occurrence of a character function
 //javascript
getStringTillLastCharcter(str,chr)
{
    var flag=0;
    var lastpos;
    //alert(str.length);
    for(i=0;i < str.length; i++ )  {
        if(str.charAt(i)==chr)
            {
                lastpos=i+1;
            }
    }
    //alert(lastpos);
    return str.slice(0,lastpos);
}


Here is a code to get the string till the last occurance of a charcter.....

Javascript to automatically add wpmode behind your video url

//javascript
$(document).ready(function()
{
    $('#id_of_iframe').each(function()
    {
        var url = $(this).attr("src"winking smiley
        $(this).attr("src",url+"?wmode=transparent"winking smiley
    }
    );
}
;

HTML5 Placeholder crack

Placeholder does not works  with IE's since its HTML 5 property...here is the crack
//javascript
function defaultval(ele,e)
{
    if(e.type==="blur"winking smiley
    {
        if(ele.value===""winking smiley
        ele.value=ele.title;
    }
    else if(e.type==="focus"winking smiley
    {
        if(ele.value==ele.title)
        ele.value="";
    }
}

//HTML
input id="right_block_name" onfocus="defaultval(this,event)" onblur="defaultval(this,event)" class="right_block_form_name" type="text" name="full_name" title="Enter your name" value="Enter your name"

Complete Countries dump database

-- phpMyAdmin SQL Dump
-- version 2.10.3
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: May 04, 2012 at 05:25 AM
-- Server version: 5.0.51
-- PHP Version: 5.2.6

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `demo`
--

-- --------------------------------------------------------

--
-- Table structure for table `wp_countries`
--

CREATE TABLE `wp_countries` (
  `iso` char(2) NOT NULL,
  `name` varchar(80) NOT NULL,
  `printable_name` varchar(80) NOT NULL,
  `iso3` char(3) default NULL,
  `numcode` smallint(6) default NULL,
  PRIMARY KEY  (`iso`)
ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table `wp_countries`
--

INSERT INTO `wp_countries` VALUES ('AF', 'AFGHANISTAN', 'Afghanistan', 'AFG', 4);
INSERT INTO `wp_countries` VALUES ('AL', 'ALBANIA', 'Albania', 'ALB', 8);
INSERT INTO `wp_countries` VALUES ('DZ', 'ALGERIA', 'Algeria', 'DZA', 12);
INSERT INTO `wp_countries` VALUES ('AS', 'AMERICAN SAMOA', 'American Samoa', 'ASM', 16);
INSERT INTO `wp_countries` VALUES ('AD', 'ANDORRA', 'Andorra', 'AND', 20);
INSERT INTO `wp_countries` VALUES ('AO', 'ANGOLA', 'Angola', 'AGO', 24);
INSERT INTO `wp_countries` VALUES ('AI', 'ANGUILLA', 'Anguilla', 'AIA', 660);
INSERT INTO `wp_countries` VALUES ('AQ', 'ANTARCTICA', 'Antarctica', NULL, NULL);
INSERT INTO `wp_countries` VALUES ('AG', 'ANTIGUA AND BARBUDA', 'Antigua and Barbuda', 'ATG', 28);
INSERT INTO `wp_countries` VALUES ('AR', 'ARGENTINA', 'Argentina', 'ARG', 32);
INSERT INTO `wp_countries` VALUES ('AM', 'ARMENIA', 'Armenia', 'ARM', 51);
INSERT INTO `wp_countries` VALUES ('AW', 'ARUBA', 'Aruba', 'ABW', 533);
INSERT INTO `wp_countries` VALUES ('AU', 'AUSTRALIA', 'Australia', 'AUS', 36);
INSERT INTO `wp_countries` VALUES ('AT', 'AUSTRIA', 'Austria', 'AUT', 40);
INSERT INTO `wp_countries` VALUES ('AZ', 'AZERBAIJAN', 'Azerbaijan', 'AZE', 31);
INSERT INTO `wp_countries` VALUES ('BS', 'BAHAMAS', 'Bahamas', 'BHS', 44);
INSERT INTO `wp_countries` VALUES ('BH', 'BAHRAIN', 'Bahrain', 'BHR', 48);
INSERT INTO `wp_countries` VALUES ('BD', 'BANGLADESH', 'Bangladesh', 'BGD', 50);
INSERT INTO `wp_countries` VALUES ('BB', 'BARBADOS', 'Barbados', 'BRB', 52);
INSERT INTO `wp_countries` VALUES ('BY', 'BELARUS', 'Belarus', 'BLR', 112);
INSERT INTO `wp_countries` VALUES ('BE', 'BELGIUM', 'Belgium', 'BEL', 56);
INSERT INTO `wp_countries` VALUES ('BZ', 'BELIZE', 'Belize', 'BLZ', 84);
INSERT INTO `wp_countries` VALUES ('BJ', 'BENIN', 'Benin', 'BEN', 204);
INSERT INTO `wp_countries` VALUES ('BM', 'BERMUDA', 'Bermuda', 'BMU', 60);
INSERT INTO `wp_countries` VALUES ('BT', 'BHUTAN', 'Bhutan', 'BTN', 64);
INSERT INTO `wp_countries` VALUES ('BO', 'BOLIVIA', 'Bolivia', 'BOL', 68);
INSERT INTO `wp_countries` VALUES ('BA', 'BOSNIA AND HERZEGOVINA', 'Bosnia and Herzegovina', 'BIH', 70);
INSERT INTO `wp_countries` VALUES ('BW', 'BOTSWANA', 'Botswana', 'BWA', 72);
INSERT INTO `wp_countries` VALUES ('BV', 'BOUVET ISLAND', 'Bouvet Island', NULL, NULL);
INSERT INTO `wp_countries` VALUES ('BR', 'BRAZIL', 'Brazil', 'BRA', 76);
INSERT INTO `wp_countries` VALUES ('IO', 'BRITISH INDIAN OCEAN TERRITORY', 'British Indian Ocean Territory', NULL, NULL);
INSERT INTO `wp_countries` VALUES ('BN', 'BRUNEI DARUSSALAM', 'Brunei Darussalam', 'BRN', 96);
INSERT INTO `wp_countries` VALUES ('BG', 'BULGARIA', 'Bulgaria', 'BGR', 100);
INSERT INTO `wp_countries` VALUES ('BF', 'BURKINA FASO', 'Burkina Faso', 'BFA', 854);
INSERT INTO `wp_countries` VALUES ('BI', 'BURUNDI', 'Burundi', 'BDI', 108);
INSERT INTO `wp_countries` VALUES ('KH', 'CAMBODIA', 'Cambodia', 'KHM', 116);
INSERT INTO `wp_countries` VALUES ('CM', 'CAMEROON', 'Cameroon', 'CMR', 120);
INSERT INTO `wp_countries` VALUES ('CA', 'CANADA', 'Canada', 'CAN', 124);
INSERT INTO `wp_countries` VALUES ('CV', 'CAPE VERDE', 'Cape Verde', 'CPV', 132);
INSERT INTO `wp_countries` VALUES ('KY', 'CAYMAN ISLANDS', 'Cayman Islands', 'CYM', 136);
INSERT INTO `wp_countries` VALUES ('CF', 'CENTRAL AFRICAN REPUBLIC', 'Central African Republic', 'CAF', 140);
INSERT INTO `wp_countries` VALUES ('TD', 'CHAD', 'Chad', 'TCD', 148);
INSERT INTO `wp_countries` VALUES ('CL', 'CHILE', 'Chile', 'CHL', 152);
INSERT INTO `wp_countries` VALUES ('CN', 'CHINA', 'China', 'CHN', 156);
INSERT INTO `wp_countries` VALUES ('CX', 'CHRISTMAS ISLAND', 'Christmas Island', NULL, NULL);
INSERT INTO `wp_countries` VALUES ('CC', 'COCOS (KEELING) ISLANDS', 'Cocos (Keeling) Islands', NULL, NULL);
INSERT INTO `wp_countries` VALUES ('CO', 'COLOMBIA', 'Colombia', 'COL', 170);
INSERT INTO `wp_countries` VALUES ('KM', 'COMOROS', 'Comoros', 'COM', 174);
INSERT INTO `wp_countries` VALUES ('CG', 'CONGO', 'Congo', 'COG', 178);
INSERT INTO `wp_countries` VALUES ('CD', 'CONGO, THE DEMOCRATIC REPUBLIC OF THE', 'Congo, the Democratic Republic of the', 'COD', 180);
INSERT INTO `wp_countries` VALUES ('CK', 'COOK ISLANDS', 'Cook Islands', 'COK', 184);
INSERT INTO `wp_countries` VALUES ('CR', 'COSTA RICA', 'Costa Rica', 'CRI', 188);
INSERT INTO `wp_countries` VALUES ('CI', 'COTE D''IVOIRE', 'Cote D''Ivoire', 'CIV', 384);
INSERT INTO `wp_countries` VALUES ('HR', 'CROATIA', 'Croatia', 'HRV', 191);
INSERT INTO `wp_countries` VALUES ('CU', 'CUBA', 'Cuba', 'CUB', 192);
INSERT INTO `wp_countries` VALUES ('CY', 'CYPRUS', 'Cyprus', 'CYP', 196);
INSERT INTO `wp_countries` VALUES ('CZ', 'CZECH REPUBLIC', 'Czech Republic', 'CZE', 203);
INSERT INTO `wp_countries` VALUES ('DK', 'DENMARK', 'Denmark', 'DNK', 208);
INSERT INTO `wp_countries` VALUES ('DJ', 'DJIBOUTI', 'Djibouti', 'DJI', 262);
INSERT INTO `wp_countries` VALUES ('DM', 'DOMINICA', 'Dominica', 'DMA', 212);
INSERT INTO `wp_countries` VALUES ('DO', 'DOMINICAN REPUBLIC', 'Dominican Republic', 'DOM', 214);
INSERT INTO `wp_countries` VALUES ('EC', 'ECUADOR', 'Ecuador', 'ECU', 218);
INSERT INTO `wp_countries` VALUES ('EG', 'EGYPT', 'Egypt', 'EGY', 818);
INSERT INTO `wp_countries` VALUES ('SV', 'EL SALVADOR', 'El Salvador', 'SLV', 222);
INSERT INTO `wp_countries` VALUES ('GQ', 'EQUATORIAL GUINEA', 'Equatorial Guinea', 'GNQ', 226);
INSERT INTO `wp_countries` VALUES ('ER', 'ERITREA', 'Eritrea', 'ERI', 232);
INSERT INTO `wp_countries` VALUES ('EE', 'ESTONIA', 'Estonia', 'EST', 233);
INSERT INTO `wp_countries` VALUES ('ET', 'ETHIOPIA', 'Ethiopia', 'ETH', 231);
INSERT INTO `wp_countries` VALUES ('FK', 'FALKLAND ISLANDS (MALVINAS)', 'Falkland Islands (Malvinas)', 'FLK', 238);
INSERT INTO `wp_countries` VALUES ('FO', 'FAROE ISLANDS', 'Faroe Islands', 'FRO', 234);
INSERT INTO `wp_countries` VALUES ('FJ', 'FIJI', 'Fiji', 'FJI', 242);
INSERT INTO `wp_countries` VALUES ('FI', 'FINLAND', 'Finland', 'FIN', 246);
INSERT INTO `wp_countries` VALUES ('FR', 'FRANCE', 'France', 'FRA', 250);
INSERT INTO `wp_countries` VALUES ('GF', 'FRENCH GUIANA', 'French Guiana', 'GUF', 254);
INSERT INTO `wp_countries` VALUES ('PF', 'FRENCH POLYNESIA', 'French Polynesia', 'PYF', 258);
INSERT INTO `wp_countries` VALUES ('TF', 'FRENCH SOUTHERN TERRITORIES', 'French Southern Territories', NULL, NULL);
INSERT INTO `wp_countries` VALUES ('GA', 'GABON', 'Gabon', 'GAB', 266);
INSERT INTO `wp_countries` VALUES ('GM', 'GAMBIA', 'Gambia', 'GMB', 270);
INSERT INTO `wp_countries` VALUES ('GE', 'GEORGIA', 'Georgia', 'GEO', 268);
INSERT INTO `wp_countries` VALUES ('DE', 'GERMANY', 'Germany', 'DEU', 276);
INSERT INTO `wp_countries` VALUES ('GH', 'GHANA', 'Ghana', 'GHA', 288);
INSERT INTO `wp_countries` VALUES ('GI', 'GIBRALTAR', 'Gibraltar', 'GIB', 292);
INSERT INTO `wp_countries` VALUES ('GR', 'GREECE', 'Greece', 'GRC', 300);
INSERT INTO `wp_countries` VALUES ('GL', 'GREENLAND', 'Greenland', 'GRL', 304);
INSERT INTO `wp_countries` VALUES ('GD', 'GRENADA', 'Grenada', 'GRD', 308);
INSERT INTO `wp_countries` VALUES ('GP', 'GUADELOUPE', 'Guadeloupe', 'GLP', 312);
INSERT INTO `wp_countries` VALUES ('GU', 'GUAM', 'Guam', 'GUM', 316);
INSERT INTO `wp_countries` VALUES ('GT', 'GUATEMALA', 'Guatemala', 'GTM', 320);
INSERT INTO `wp_countries` VALUES ('GN', 'GUINEA', 'Guinea', 'GIN', 324);
INSERT INTO `wp_countries` VALUES ('GW', 'GUINEA-BISSAU', 'Guinea-Bissau', 'GNB', 624);
INSERT INTO `wp_countries` VALUES ('GY', 'GUYANA', 'Guyana', 'GUY', 328);
INSERT INTO `wp_countries` VALUES ('HT', 'HAITI', 'Haiti', 'HTI', 332);
INSERT INTO `wp_countries` VALUES ('HM', 'HEARD ISLAND AND MCDONALD ISLANDS', 'Heard Island and Mcdonald Islands', NULL, NULL);
INSERT INTO `wp_countries` VALUES ('VA', 'HOLY SEE (VATICAN CITY STATE)', 'Holy See (Vatican City State)', 'VAT', 336);
INSERT INTO `wp_countries` VALUES ('HN', 'HONDURAS', 'Honduras', 'HND', 340);
INSERT INTO `wp_countries` VALUES ('HK', 'HONG KONG', 'Hong Kong', 'HKG', 344);
INSERT INTO `wp_countries` VALUES ('HU', 'HUNGARY', 'Hungary', 'HUN', 348);
INSERT INTO `wp_countries` VALUES ('IS', 'ICELAND', 'Iceland', 'ISL', 352);
INSERT INTO `wp_countries` VALUES ('IN', 'INDIA', 'India', 'IND', 356);
INSERT INTO `wp_countries` VALUES ('ID', 'INDONESIA', 'Indonesia', 'IDN', 360);
INSERT INTO `wp_countries` VALUES ('IR', 'IRAN, ISLAMIC REPUBLIC OF', 'Iran, Islamic Republic of', 'IRN', 364);
INSERT INTO `wp_countries` VALUES ('IQ', 'IRAQ', 'Iraq', 'IRQ', 368);
INSERT INTO `wp_countries` VALUES ('IE', 'IRELAND', 'Ireland', 'IRL', 372);
INSERT INTO `wp_countries` VALUES ('IL', 'ISRAEL', 'Israel', 'ISR', 376);
INSERT INTO `wp_countries` VALUES ('IT', 'ITALY', 'Italy', 'ITA', 380);
INSERT INTO `wp_countries` VALUES ('JM', 'JAMAICA', 'Jamaica', 'JAM', 388);
INSERT INTO `wp_countries` VALUES ('JP', 'JAPAN', 'Japan', 'JPN', 392);
INSERT INTO `wp_countries` VALUES ('JO', 'JORDAN', 'Jordan', 'JOR', 400);
INSERT INTO `wp_countries` VALUES ('KZ', 'KAZAKHSTAN', 'Kazakhstan', 'KAZ', 398);
INSERT INTO `wp_countries` VALUES ('KE', 'KENYA', 'Kenya', 'KEN', 404);
INSERT INTO `wp_countries` VALUES ('KI', 'KIRIBATI', 'Kiribati', 'KIR', 296);
INSERT INTO `wp_countries` VALUES ('KP', 'KOREA, DEMOCRATIC PEOPLE''S REPUBLIC OF', 'Korea, Democratic People''s Republic of', 'PRK', 408);
INSERT INTO `wp_countries` VALUES ('KR', 'KOREA, REPUBLIC OF', 'Korea, Republic of', 'KOR', 410);
INSERT INTO `wp_countries` VALUES ('KW', 'KUWAIT', 'Kuwait', 'KWT', 414);
INSERT INTO `wp_countries` VALUES ('KG', 'KYRGYZSTAN', 'Kyrgyzstan', 'KGZ', 417);
INSERT INTO `wp_countries` VALUES ('LA', 'LAO PEOPLE''S DEMOCRATIC REPUBLIC', 'Lao People''s Democratic Republic', 'LAO', 418);
INSERT INTO `wp_countries` VALUES ('LV', 'LATVIA', 'Latvia', 'LVA', 428);
INSERT INTO `wp_countries` VALUES ('LB', 'LEBANON', 'Lebanon', 'LBN', 422);
INSERT INTO `wp_countries` VALUES ('LS', 'LESOTHO', 'Lesotho', 'LSO', 426);
INSERT INTO `wp_countries` VALUES ('LR', 'LIBERIA', 'Liberia', 'LBR', 430);
INSERT INTO `wp_countries` VALUES ('LY', 'LIBYAN ARAB JAMAHIRIYA', 'Libyan Arab Jamahiriya', 'LBY', 434);
INSERT INTO `wp_countries` VALUES ('LI', 'LIECHTENSTEIN', 'Liechtenstein', 'LIE', 438);
INSERT INTO `wp_countries` VALUES ('LT', 'LITHUANIA', 'Lithuania', 'LTU', 440);
INSERT INTO `wp_countries` VALUES ('LU', 'LUXEMBOURG', 'Luxembourg', 'LUX', 442);
INSERT INTO `wp_countries` VALUES ('MO', 'MACAO', 'Macao', 'MAC', 446);
INSERT INTO `wp_countries` VALUES ('MK', 'MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF', 'Macedonia, the Former Yugoslav Republic of', 'MKD', 807);
INSERT INTO `wp_countries` VALUES ('MG', 'MADAGASCAR', 'Madagascar', 'MDG', 450);
INSERT INTO `wp_countries` VALUES ('MW', 'MALAWI', 'Malawi', 'MWI', 454);
INSERT INTO `wp_countries` VALUES ('MY', 'MALAYSIA', 'Malaysia', 'MYS', 458);
INSERT INTO `wp_countries` VALUES ('MV', 'MALDIVES', 'Maldives', 'MDV', 462);
INSERT INTO `wp_countries` VALUES ('ML', 'MALI', 'Mali', 'MLI', 466);
INSERT INTO `wp_countries` VALUES ('MT', 'MALTA', 'Malta', 'MLT', 470);
INSERT INTO `wp_countries` VALUES ('MH', 'MARSHALL ISLANDS', 'Marshall Islands', 'MHL', 584);
INSERT INTO `wp_countries` VALUES ('MQ', 'MARTINIQUE', 'Martinique', 'MTQ', 474);
INSERT INTO `wp_countries` VALUES ('MR', 'MAURITANIA', 'Mauritania', 'MRT', 478);
INSERT INTO `wp_countries` VALUES ('MU', 'MAURITIUS', 'Mauritius', 'MUS', 480);
INSERT INTO `wp_countries` VALUES ('YT', 'MAYOTTE', 'Mayotte', NULL, NULL);
INSERT INTO `wp_countries` VALUES ('MX', 'MEXICO', 'Mexico', 'MEX', 484);
INSERT INTO `wp_countries` VALUES ('FM', 'MICRONESIA, FEDERATED STATES OF', 'Micronesia, Federated States of', 'FSM', 583);
INSERT INTO `wp_countries` VALUES ('MD', 'MOLDOVA, REPUBLIC OF', 'Moldova, Republic of', 'MDA', 498);
INSERT INTO `wp_countries` VALUES ('MC', 'MONACO', 'Monaco', 'MCO', 492);
INSERT INTO `wp_countries` VALUES ('MN', 'MONGOLIA', 'Mongolia', 'MNG', 496);
INSERT INTO `wp_countries` VALUES ('MS', 'MONTSERRAT', 'Montserrat', 'MSR', 500);
INSERT INTO `wp_countries` VALUES ('MA', 'MOROCCO', 'Morocco', 'MAR', 504);
INSERT INTO `wp_countries` VALUES ('MZ', 'MOZAMBIQUE', 'Mozambique', 'MOZ', 508);
INSERT INTO `wp_countries` VALUES ('MM', 'MYANMAR', 'Myanmar', 'MMR', 104);
INSERT INTO `wp_countries` VALUES ('NA', 'NAMIBIA', 'Namibia', 'NAM', 516);
INSERT INTO `wp_countries` VALUES ('NR', 'NAURU', 'Nauru', 'NRU', 520);
INSERT INTO `wp_countries` VALUES ('NP', 'NEPAL', 'Nepal', 'NPL', 524);
INSERT INTO `wp_countries` VALUES ('NL', 'NETHERLANDS', 'Netherlands', 'NLD', 528);
INSERT INTO `wp_countries` VALUES ('AN', 'NETHERLANDS ANTILLES', 'Netherlands Antilles', 'ANT', 530);
INSERT INTO `wp_countries` VALUES ('NC', 'NEW CALEDONIA', 'New Caledonia', 'NCL', 540);
INSERT INTO `wp_countries` VALUES ('NZ', 'NEW ZEALAND', 'New Zealand', 'NZL', 554);
INSERT INTO `wp_countries` VALUES ('NI', 'NICARAGUA', 'Nicaragua', 'NIC', 558);
INSERT INTO `wp_countries` VALUES ('NE', 'NIGER', 'Niger', 'NER', 562);
INSERT INTO `wp_countries` VALUES ('NG', 'NIGERIA', 'Nigeria', 'NGA', 566);
INSERT INTO `wp_countries` VALUES ('NU', 'NIUE', 'Niue', 'NIU', 570);
INSERT INTO `wp_countries` VALUES ('NF', 'NORFOLK ISLAND', 'Norfolk Island', 'NFK', 574);
INSERT INTO `wp_countries` VALUES ('MP', 'NORTHERN MARIANA ISLANDS', 'Northern Mariana Islands', 'MNP', 580);
INSERT INTO `wp_countries` VALUES ('NO', 'NORWAY', 'Norway', 'NOR', 578);
INSERT INTO `wp_countries` VALUES ('OM', 'OMAN', 'Oman', 'OMN', 512);
INSERT INTO `wp_countries` VALUES ('PK', 'PAKISTAN', 'Pakistan', 'PAK', 586);
INSERT INTO `wp_countries` VALUES ('PW', 'PALAU', 'Palau', 'PLW', 585);
INSERT INTO `wp_countries` VALUES ('PS', 'PALESTINIAN TERRITORY, OCCUPIED', 'Palestinian Territory, Occupied', NULL, NULL);
INSERT INTO `wp_countries` VALUES ('PA', 'PANAMA', 'Panama', 'PAN', 591);
INSERT INTO `wp_countries` VALUES ('PG', 'PAPUA NEW GUINEA', 'Papua New Guinea', 'PNG', 598);
INSERT INTO `wp_countries` VALUES ('PY', 'PARAGUAY', 'Paraguay', 'PRY', 600);
INSERT INTO `wp_countries` VALUES ('PE', 'PERU', 'Peru', 'PER', 604);
INSERT INTO `wp_countries` VALUES ('PH', 'PHILIPPINES', 'Philippines', 'PHL', 608);
INSERT INTO `wp_countries` VALUES ('PN', 'PITCAIRN', 'Pitcairn', 'PCN', 612);
INSERT INTO `wp_countries` VALUES ('PL', 'POLAND', 'Poland', 'POL', 616);
INSERT INTO `wp_countries` VALUES ('PT', 'PORTUGAL', 'Portugal', 'PRT', 620);
INSERT INTO `wp_countries` VALUES ('PR', 'PUERTO RICO', 'Puerto Rico', 'PRI', 630);
INSERT INTO `wp_countries` VALUES ('QA', 'QATAR', 'Qatar', 'QAT', 634);
INSERT INTO `wp_countries` VALUES ('RE', 'REUNION', 'Reunion', 'REU', 638);
INSERT INTO `wp_countries` VALUES ('RO', 'ROMANIA', 'Romania', 'ROM', 642);
INSERT INTO `wp_countries` VALUES ('RU', 'RUSSIAN FEDERATION', 'Russian Federation', 'RUS', 643);
INSERT INTO `wp_countries` VALUES ('RW', 'RWANDA', 'Rwanda', 'RWA', 646);
INSERT INTO `wp_countries` VALUES ('SH', 'SAINT HELENA', 'Saint Helena', 'SHN', 654);
INSERT INTO `wp_countries` VALUES ('KN', 'SAINT KITTS AND NEVIS', 'Saint Kitts and Nevis', 'KNA', 659);
INSERT INTO `wp_countries` VALUES ('LC', 'SAINT LUCIA', 'Saint Lucia', 'LCA', 662);
INSERT INTO `wp_countries` VALUES ('PM', 'SAINT PIERRE AND MIQUELON', 'Saint Pierre and Miquelon', 'SPM', 666);
INSERT INTO `wp_countries` VALUES ('VC', 'SAINT VINCENT AND THE GRENADINES', 'Saint Vincent and the Grenadines', 'VCT', 670);
INSERT INTO `wp_countries` VALUES ('WS', 'SAMOA', 'Samoa', 'WSM', 882);
INSERT INTO `wp_countries` VALUES ('SM', 'SAN MARINO', 'San Marino', 'SMR', 674);
INSERT INTO `wp_countries` VALUES ('ST', 'SAO TOME AND PRINCIPE', 'Sao Tome and Principe', 'STP', 678);
INSERT INTO `wp_countries` VALUES ('SA', 'SAUDI ARABIA', 'Saudi Arabia', 'SAU', 682);
INSERT INTO `wp_countries` VALUES ('SN', 'SENEGAL', 'Senegal', 'SEN', 686);
INSERT INTO `wp_countries` VALUES ('CS', 'SERBIA AND MONTENEGRO', 'Serbia and Montenegro', NULL, NULL);
INSERT INTO `wp_countries` VALUES ('SC', 'SEYCHELLES', 'Seychelles', 'SYC', 690);
INSERT INTO `wp_countries` VALUES ('SL', 'SIERRA LEONE', 'Sierra Leone', 'SLE', 694);
INSERT INTO `wp_countries` VALUES ('SG', 'SINGAPORE', 'Singapore', 'SGP', 702);
INSERT INTO `wp_countries` VALUES ('SK', 'SLOVAKIA', 'Slovakia', 'SVK', 703);
INSERT INTO `wp_countries` VALUES ('SI', 'SLOVENIA', 'Slovenia', 'SVN', 705);
INSERT INTO `wp_countries` VALUES ('SB', 'SOLOMON ISLANDS', 'Solomon Islands', 'SLB', 90);
INSERT INTO `wp_countries` VALUES ('SO', 'SOMALIA', 'Somalia', 'SOM', 706);
INSERT INTO `wp_countries` VALUES ('ZA', 'SOUTH AFRICA', 'South Africa', 'ZAF', 710);
INSERT INTO `wp_countries` VALUES ('GS', 'SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS', 'South Georgia and the South Sandwich Islands', NULL, NULL);
INSERT INTO `wp_countries` VALUES ('ES', 'SPAIN', 'Spain', 'ESP', 724);
INSERT INTO `wp_countries` VALUES ('LK', 'SRI LANKA', 'Sri Lanka', 'LKA', 144);
INSERT INTO `wp_countries` VALUES ('SD', 'SUDAN', 'Sudan', 'SDN', 736);
INSERT INTO `wp_countries` VALUES ('SR', 'SURINAME', 'Suriname', 'SUR', 740);
INSERT INTO `wp_countries` VALUES ('SJ', 'SVALBARD AND JAN MAYEN', 'Svalbard and Jan Mayen', 'SJM', 744);
INSERT INTO `wp_countries` VALUES ('SZ', 'SWAZILAND', 'Swaziland', 'SWZ', 748);
INSERT INTO `wp_countries` VALUES ('SE', 'SWEDEN', 'Sweden', 'SWE', 752);
INSERT INTO `wp_countries` VALUES ('CH', 'SWITZERLAND', 'Switzerland', 'CHE', 756);
INSERT INTO `wp_countries` VALUES ('SY', 'SYRIAN ARAB REPUBLIC', 'Syrian Arab Republic', 'SYR', 760);
INSERT INTO `wp_countries` VALUES ('TW', 'TAIWAN, PROVINCE OF CHINA', 'Taiwan, Province of China', 'TWN', 158);
INSERT INTO `wp_countries` VALUES ('TJ', 'TAJIKISTAN', 'Tajikistan', 'TJK', 762);
INSERT INTO `wp_countries` VALUES ('TZ', 'TANZANIA, UNITED REPUBLIC OF', 'Tanzania, United Republic of', 'TZA', 834);
INSERT INTO `wp_countries` VALUES ('TH', 'THAILAND', 'Thailand', 'THA', 764);
INSERT INTO `wp_countries` VALUES ('TL', 'TIMOR-LESTE', 'Timor-Leste', NULL, NULL);
INSERT INTO `wp_countries` VALUES ('TG', 'TOGO', 'Togo', 'TGO', 768);
INSERT INTO `wp_countries` VALUES ('TK', 'TOKELAU', 'Tokelau', 'TKL', 772);
INSERT INTO `wp_countries` VALUES ('TO', 'TONGA', 'Tonga', 'TON', 776);
INSERT INTO `wp_countries` VALUES ('TT', 'TRINIDAD AND TOBAGO', 'Trinidad and Tobago', 'TTO', 780);
INSERT INTO `wp_countries` VALUES ('TN', 'TUNISIA', 'Tunisia', 'TUN', 788);
INSERT INTO `wp_countries` VALUES ('TR', 'TURKEY', 'Turkey', 'TUR', 792);
INSERT INTO `wp_countries` VALUES ('TM', 'TURKMENISTAN', 'Turkmenistan', 'TKM', 795);
INSERT INTO `wp_countries` VALUES ('TC', 'TURKS AND CAICOS ISLANDS', 'Turks and Caicos Islands', 'TCA', 796);
INSERT INTO `wp_countries` VALUES ('TV', 'TUVALU', 'Tuvalu', 'TUV', 798);
INSERT INTO `wp_countries` VALUES ('UG', 'UGANDA', 'Uganda', 'UGA', 800);
INSERT INTO `wp_countries` VALUES ('UA', 'UKRAINE', 'Ukraine', 'UKR', 804);
INSERT INTO `wp_countries` VALUES ('AE', 'UNITED ARAB EMIRATES', 'United Arab Emirates', 'ARE', 784);
INSERT INTO `wp_countries` VALUES ('GB', 'UNITED KINGDOM', 'United Kingdom', 'GBR', 826);
INSERT INTO `wp_countries` VALUES ('US', 'UNITED STATES', 'United States', 'USA', 840);
INSERT INTO `wp_countries` VALUES ('UM', 'UNITED STATES MINOR OUTLYING ISLANDS', 'United States Minor Outlying Islands', NULL, NULL);
INSERT INTO `wp_countries` VALUES ('UY', 'URUGUAY', 'Uruguay', 'URY', 858);
INSERT INTO `wp_countries` VALUES ('UZ', 'UZBEKISTAN', 'Uzbekistan', 'UZB', 860);
INSERT INTO `wp_countries` VALUES ('VU', 'VANUATU', 'Vanuatu', 'VUT', 548);
INSERT INTO `wp_countries` VALUES ('VE', 'VENEZUELA', 'Venezuela', 'VEN', 862);
INSERT INTO `wp_countries` VALUES ('VN', 'VIET NAM', 'Viet Nam', 'VNM', 704);
INSERT INTO `wp_countries` VALUES ('VG', 'VIRGIN ISLANDS, BRITISH', 'Virgin Islands, British', 'VGB', 92);
INSERT INTO `wp_countries` VALUES ('VI', 'VIRGIN ISLANDS, U.S.', 'Virgin Islands, U.s.', 'VIR', 850);
INSERT INTO `wp_countries` VALUES ('WF', 'WALLIS AND FUTUNA', 'Wallis and Futuna', 'WLF', 876);
INSERT INTO `wp_countries` VALUES ('EH', 'WESTERN SAHARA', 'Western Sahara', 'ESH', 732);
INSERT INTO `wp_countries` VALUES ('YE', 'YEMEN', 'Yemen', 'YEM', 887);
INSERT INTO `wp_countries` VALUES ('ZM', 'ZAMBIA', 'Zambia', 'ZMB', 894);
INSERT INTO `wp_countries` VALUES ('ZW', 'ZIMBABWE', 'Zimbabwe', 'ZWE', 716);

Writing .htaccess RewriteRules

RewriteRules

Rewriterules are the heart and sole of the mod rewrite, here is where you declare the file to be rewritten, where it is to be rewritten and tack on any special commands.

Rewrite rules are broken down into 4 simple blocks. I'll refer to these blocks as the Call to action, Pattern, Rewrite and Command Flag.

Example:
RewriteRule ^dir/([0-9]+)/?$ /index.php?id=$1 [L]

Call to action: RewriteRule
Pattern: ^dir/([0-9]+) /?$
Rewrite: /index.php?id=$1
Command Flag: [L]

Between each of these blocks of the rewrite rule there should be a space. With that being said let's go ahead and break down each of these 4 blocks and discuss what they do.


Call to action Block

The only way to screw this up is to spell RewriteRule incorrectly or leave out the space between this and the starting of the pattern block. If you do spell it incorrectly you'll trigger an error and the browser will out put a 500 error. Note if you ever see a 500 error on your site it mostlikely due to a bad line of code in your .htaccess file.

Pattern Block

This one little piece of the mod rewrite is where the power is. In the pattern block of the rewrite rule we use regular expressions to detect the requested file name or uri and from this we can extract key parts to pass to the rewrite block.

Pay attention because this is the hardest part of mod rewrite.


Regular expressions is just a method to detect letters, numbers and symbols using special characters. These special characters are called metacharacters.

Pattern Matching metacharacter Definitions

Char. Definition
\ Use before any of the following characters to escape or null the meaning or it. \* \. \$ \+ \[ \]
^ Start matching at this point
$ End point of the match
. Any character
[] Starts a class
| Starts alternative match this|that would mean match this or that
() starts a back reference point
? match 0 or 1 time Quantifier
+ match atleast 1 or more times Quantifier
* match 0 to infinite times Quantifier
{} match minimum to maximum Quantifier {0,3} match up to 3 times



Class Definitions []

Char. Definition
^ Negates the class. [^A-Z]+ means don't match any uppercases
\ Use before any of the following characters to escape or null the meaning or it. [\+]+
- Range for matching [0-9]+ [a-zA-Z]+

I'll show a few quick samples just so you understand how to use all of the above. Then we're going to move right on to the Rewrite Block since we'll be going over all of this in our basic section.

In this example we just need the numbers in the ulrs below to pass through the mod rewrite to make our query. First we have to ask ourselves, "What is the common pattern in these urls"?

In this example there are two common patterns that we can match against. The first one is they all start with category/. The second is they all end in .htm. This should be an easy match
    1. category/1.htm
    1. category/56.htm
    1. category/092340923.htm
    1. category/9334.htm
So to use regular expressions to match all of these urls below we need to set our starting point to ^category/.

Now we need to tell the rewrite rule to look for any number 1 or more times. We'll use a character class to do this [0-9]+. Since we need this number to complete our rewrite block we're going to tell the mod to reference this so we can use it later. We do this by surrounding the the
[0-9]+ with brachets like this ([0-9]+).

To finish the match we're going to negate the . (remember this means any 1 character) even though a . is considered 1 character we're going to go ahead and negate it to read as a dot and then finish the match with htm$.

Mouse over the characters for a definition:

RewriteRule ^category/([0-9]+)\.htm$ /category.php?cat_id=$1 [L]


Another Regular Expression I recently wrote for matching letters,numbers,spaces,underscores is as follows

/(^[A-Za-z][\w\s]*)$/

Source: http://www.webforgers.net/mod-rewrite/mod-rewrite-syntax.php#quantifiers

Check the status of ur local .htaccess and mod_rewrite

Check if mod_rewrite is enabled and your htaccess file is overriding

1) create a page phpinfo.php in your root call the phpinfo() function in the same

2) Now request this page from ur browser and look for a section called Loaded Modules.If it shows mod_rewrite....bingo its enabled from server

3) Next backup ur .htaccess default file and create a new one in that write

DirectoryIndex phpinfo.php

Now request ur website root from browser if you see phpinfo.php being called ur .htaccess is working in other words #allow override is enabled at httpconfig.

Using Array_Filter in a class

Array_Filter does not runs directly for arrays defined as class data members.


Use the below code to filter such an array.

$fltr_instance=array_filter($array,array('className', 'callBack function defined in class'));

A file upload helpful php code

if(isset($_POST['sendmail']))
{
    //echo "
";
    //print_r($_POST);
    //print_r($_FILES);
    //echo "
";

    //$attachment = chunk_split(base64_encode(file_get_contents($_POST['upload'])));

    //Get the uploaded file information
    $name_of_uploaded_file =
    basename($_FILES['upload']['name']);
    //echo $name_of_uploaded_file;
    //get the file extension of the file
    $type_of_uploaded_file =substr($name_of_uploaded_file,strrpos($name_of_uploaded_file, '.') + 1);
    //echo $type_of_uploaded_file;
    $size_of_uploaded_file =$_FILES["upload"]["size"]/1024;
    //echo $size_of_uploaded_file;
    $max_allowed_file_size = 100; // size in KB
    $allowed_extensions = array("doc", "pdf", "docx","txt"winking smiley;
    //Validations
    if($size_of_uploaded_file > $max_allowed_file_size )
    {
        $errors .= "\n Size of file should be less than $max_allowed_file_size";
    }
    //------ Validate the file extension -----
    $allowed_ext = false;
    for($i=0; $i    {
        if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0)
        {
            $allowed_ext = true;
        }
    }
    if(!$allowed_ext)
    {
        $errors .=
        " Only the following file types are supported: ".implode(',',$allowed_extensions);
    }

    if(!isset($errors))
    {
        move_uploaded_file($_FILES["upload"]["tmp_name"],WP_CONTENT_DIR.'/uploads/'.basename($_FILES['upload']['name']));
        $to=  get_option('ugmm_career_email');
        $subject=get_option('ugmm_career_upload_field');
        $message="File uploaded by".get_option('ugmm_career_upload_field');
        $headers = 'From:upload<'.$to.'>';
        $attachments = array(WP_CONTENT_DIR ."/uploads/".$_FILES["upload"]["name"]);
        wp_mail($to,$subject,$message,$headers,$attachments);
        $sentmail=true;
    }
    else
    $sentmail=false;
}
?>

CakeTime Utility class/TimeHelper in Cakephp 2.0

Use CakeTime Utility class as follows
App::import("CakeTime",'utility')
Time helper no more works in controller from cakephp 2.0 onwords.

Magento Session storage?Which and when to choose??

Magento stores sessions by 4 means file-storage,database, memcached and tmpfs-backed file-storage

The benefits of file-based sessions for Magento are simplicity, stability and durability. It’s simple because you don’t have to do anything to set it up. It’s stable because most modern filesystems use journaling to make sure that in the event of a system crash your session data is consistent. I also durable, because a system restart will not cause you to lose your session data.

Add below line in local.xml to start file based storage
<session_save>session_save>

Database session storage is the other storage type.With database session storage the session data is stored in the Magento MySQL database. The connection used is the same as the core connection.

One of the key benefits of using database sessions is the clustered environment support. In a filesystem based session storage scheme, if you have more than one Magento frontend node in a cluster, they will need to share session data (unless you use a loadbalancer with sticky sessions) and the database gives you that capability quite easily.

To use the database for session storage simply have this in your local.xml


<session_save>session_save>

Memcached session storage takes a bit more setup than either of the previous two options.For starters you need a Memcached server running.
Once you have it up and running, the memcached session storage offers a number of benefits. Firstly it is very cluster friendly. The session data can be shared by any number of webnodes, and to make things even better you can easily add more memcached server nodes so that even your session storage can be scaled to handle many 1000′s of concurrent sessions*. Secondly, it is (or can be) separate of the database and web node entirely, which offloads the work of storing sessions from busy nodes in a high-traffic environment.
The memcached server is not tolerant to failures, if your system crashes or dies the data in memory will be lost. Being a separate server does allow the session storage to be kept running during a web or database node restart though – something you cannot do with the tmpfs storage option below.

To use the database for Memcached storage simply have this in your local.xml
 
<session_save>session_save>
<session_save_path>session_save_path>
 
tmpfs-backed Filesystem Session storage
 
This is not really a good idea for storing sessions, it’s highly volatile and unstable two things you probably don’t want for ecommerce store sessions. It’s also not scalable either as it relies on the machine’s physical memory, and you can only stick so much of that in – you might need it for the web server too. It will also not help at all in a clustered environment as it is machine specific.
Despite all it’s limitations I really wanted to test tmpfs sessions more out of curiosity than anything, I have a hunch that it will make quite a performance boost. Let’s see how it does in the benchmark section below.
If you’re keen to try this, I’ll assume you know what you’re doing on the system side of things. Mount var (or var/sessions) as a tmpfs and set Magento to use file based session storage like in the first option above.


 

Tuesday, July 3, 2012

Check if java script is disabled

use
"noscript" html tag

check here

Jquery conflicts with Prototype

Use $$=jQuery.noConflict();

that's all

and then for all JQuery $ use $$

example

for $("#sdf")  use $$("#sdf")

Generate Excel Report with Php and Mysql using code

Step 1. Include phpexcel class file along with your config file and make its object with excel file name passed parameter in constructor. You can check for  error in next line as shown

1require_once("excelwriter.class.php");
2
3$excel=new ExcelWriter("report.xls");
4
5if($excel==false)
6echo $excel->error;


Step 2. Now time to fetch data from mysql database. Before fetch data, call excel header having columns as values of array.

01// this will create heading of each column in excel file
02
03$myArr=array("S.No.","Company Name","Email","City","Username","Reg. Date");
04$excel->writeLine($myArr);
05
06// now fetch data from database table, there is a new line create each time loop runs
07
08$qry=mysql_query("select * from customer");
09if($qry!=false)
10{
11 $i=1;
12 while($res=mysql_fetch_array($qry))
13 {
14 $myArr=array($i,$res['company_name'],$res['email'],...);
15 $excel->writeLine($myArr);
16 $i++;
17 }
18}


Step 3.  Create link to generate excel file.
1<a href="javascript:void(0);" onClick="download();">Download Excel Reporta>
and here download function pointing to excel file
1
 Download Code Here