Category Archives: Google

Advantages: Let Google Host jQuery For Your Website

Most of us (Web Developer) use JQuery during the development, if you are not aware about the jQuery or interested in any other JavaScript Library then below is just a very quick overview about the jQuery.

 

jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript.”

 

Well, how you include that in your file, generally as below.

<script type="text/javascript" src="/js/jQuery.1.8.x.min.js"></script>

 

We all know that the load of JavaScript directly affect the site page load time and Obviously on SEO. Then how to get rid by jQuery?
No worries, you know as usual Google always help us so let Google host jQuery for your website.

 

You can let Google AJAX Libraries CDN (content delivery network) serve jQuery directly from Google’s network as below.
There are three main benefits of doing this is Decreased latency, Increased parallelism and Better caching that directory affect you site page load.

 

You should use/include JQuery as below

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>

 

Benefits of Google CDN Networks(Google hosted JavaScript Libraries)

 

Decreased Latency
A Content Delivery Network (CDN) distributes static content across various servers, diverse physical locations worldwide. When a user visits a page serving files from a CDN, their download will automatically target the closest available server in the network which can reduce download times.

 

Increased Parallelism
All browsers limit the number of connections that can be made simultaneously. Depending on which browser, this limit may be as low as two connections per hostname.
Using the Google AJAX Libraries CDN eliminates one request to your site, allowing more of your local content to be downloaded in parallel.

 

Better Caching
When a user visits a site, their browser will download static files so that when the user visits that page the files will not have to be downloaded again, saving bandwidth usage, server load.
Google AJAX Libraries CDN is that your users may not need to download jQuery at all.

 

If you’re curious why the <script> reference is missing the leading http:, It’s a trick which allows you to use a single reference that works on both HTTP and HTTPS pages.

 

“Protocol-less” URL is the best way to reference third party content that’s available via both HTTP and HTTPS.

 

Share your WordPress page URL on social networking website by using a simple function

Share your WordPress post on facebook & other social networking website.

 

If you want to share your WordPress page URL on social networking website, it’s very simple to do.

Just place this function in your functions.php file, and call the function where do you want it to show.

 

<?php

function GetShareLinks() {
 
/* Your current page URL */
 $URI = get_permalink();
 
/* The js script used for goolge plus share button */
 $sharestring ='<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>';
 
$sharestring .='<a href="https://pinterest.com/scriptarticle/" target="_blank"><img width="16" height="16" alt="Follow Me on Pinterest" src="http://passets-lt.pinterest.com/images/about/buttons/small-p-button.png"></a>
 <a href="http://www.facebook.com/sharer.php?u='.$URI.'"><img src="'.get_bloginfo('template_url').'/images/facebook.jpg" alt="" /></a>
 <a href="http://twitter.com/intent/tweet?text='.$URI.'"><img src="'.get_bloginfo('template_url').'/images/twitter.jpg" alt="" /></a>
 <a href="http://www.linkedin.com/shareArticle?mini=true&url='.$URI.'"><img src="'.get_bloginfo('template_url').'/images/in.jpg" alt="" /></a>
 <g:plusone count="false" size="small"></g:plusone>';
 
return $sharestring;
 
}

?>

 

You can also use this function in other website (non WordPress) site, you have to just replace the get_permalink() function by current page URL and update the social icons images path.

 

If you face any issue to use this, put your comment, I’ll help you 🙂

 

Use of Environment variables

Environment variables windows

 

Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer.

 

You can say, It is a dynamic “object” that stores a value, which in turn can be referenced by one or more software programs in Windows (OS). Environment variables help programs know what directory to install files in, where to store temporary files, where to find user profile settings, and many other things.

 

Variable names are NOT case sensitive in Windows OS.

 

Environment variables are dynamic because they can change. The values stored can be changed to match the current system’s setup and design (environment). They can also differ between computer systems because each computer can have a different setup.

 

There are a number of environment variables that get referenced by programs and can come in handy for a computer user to find needed information about their computer environment.

Below is the list of some common and important environment variables.

 

%appdata%
%commonprogramfiles%
%local%
%localappdata%
%programfiles%
%temp%
%userprofile%
%windir%

 

You can get some common information using environment variable quickly.

 

You can quickly access any of the above folders by entering the environment variable in the Windows Run box or Windows Search Box.
e.g: To get into the Application Data folder type %appdata% and then press Enter in the Run box.

 

%appdata%
The %appdata% environment variable contains the directory path to the Application Data folder for your user profile. This folder stores settings and logs, among other things, for various software programs. The settings and logs stored there are specific to your user profile.

 

%commonprogramfiles%
The %commonprogramfiles% environment variable contains the directory path to the Common Files folder, within the main Program Files folder. This folder contains various files for common programs and utilities on a computer, mostly system and services related. The default directory path this variable points to is c:\Program Files\Common Files.

 

%local%
The %local% environment variable points to where the security policies & rules are located for the user’s account, Windows in general, Windows Firewall, Network, and various software programs on the computer. This environment variable is native to Windows 7.

 

%localappdata%
The %localappdata% environment variable contains the directory path to where programs store their temporary files. Common temporary files to be stored here are Desktop Themes, Windows Error Reporting, program caching and Internet browser profiles. This environment variable is native to Windows Vista & Windows 7.

 

%programfiles%
The %programfiles% environment variable contains the directory path to where programs are installed. This directory contains sub-directories for each program, which contain the primary files needed by each program in order to run on a computer. The default directory path this variable points to is c:\Program Files.

 

%temp%
The %temp% environment variable contains the directory path to where temporary files stored. These temp files are often Internet temporary files and other user application temporary files (Microsoft Word, Excel, Outlook, etc.).

 

%userprofile%
The %userprofile% environment variable points to the current logged in user’s profile and the directory where user profile data is stored. It is in this directory that a user can find the following folders: My Documents, My Music, My Pictures, Desktop, and Favorites (Internet Explorer bookmarks).

 

%windir%
The %windir% environment variable points to the Windows directory, where Windows system files are located.The default directory path for most versions of Windows is c:\Windows (for Windows NT 4 and 2000, it is c:\WinNT).

 

Get live currency rates in PHP and currency conversion using APIs

Get live currency rates in PHP & conversion using APIs

In the below method, we get live currency rates from Google.
This function uses CURL so make sure you have enabled curl extension in php.

 

Google has an inbuilt calculator which can also be used for converting a currency into another.Doing so is really simple, you just type “AMOUNT”, “CURRENCY_CONVERTING_FROM” in “CURRENCY_CONVERTING_TO” and search, the inbuilt calculator will give you the result.

Try this
http://www.google.com/finance/converter?a=1&from=USD&to=INR

 

Google also has a secret calculator API (http://www.google.com/ig/calculator) that is usually used for iGoogle gadgets, but its free and open, anyone can use it.
So if you want to convert a currency into another using the API, you can grab the below code.


<?php

function get_currency($from_Currency, $to_Currency, $amount) {

$amount = urlencode($amount);
$from_Currency = urlencode($from_Currency);
$to_Currency = urlencode($to_Currency);

$url = "http://www.google.com/finance/converter?a=$amount&from=$from_Currency&to=$to_Currency";

$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$rawdata = curl_exec($ch);
curl_close($ch);
$data = explode('bld>', $rawdata);
$data = explode($to_Currency, $data[1]);
return round($data[0], 2);
}

// Call the function to get the currency converted
echo get_currency('USD', 'INR', 1);

?>

 

You can also do same by using live currency Value from yahoo finance (http://finance.yahoo.com/)

Here is an example to get the value of US Dollar in Indian Rupees.


<?php

$from   = 'USD'; /*change it to your required currencies */
$to     = 'INR';
$url    = 'http://download.finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='. $from . $to .'=X';

$handle = @fopen($url, 'r');
if ($handle) {
$result = fgets($handle, 4096);
fclose($handle);
}
$allData = explode(', ', $result); /* Get all the contents to an array */
$dollarValue = $allData[1];
echo 'Value of $1 in Indian Rupees is &#8377; '.$dollarValue;

?>

Advanced .htaccess security and block access using .htaccess file

Block access to files using htaccess

1. Block access to .htaccess file
Add the following code block to your htaccess file to add an extra layer of security.Any attempts to access the htaccess file will result in a 403 error message.Your first layer of security to protect htaccess files involves permissions via CHMOD to 644.

# secure your htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>

2. Block access to a Specific File
To restrict access to a specific file, add the following code block and edit the file name, “secure_file.jpg”, with the name of the file that you wish to protect.

# prevent viewing of a specific file
<files secure_file.jpg>
order allow,deny
deny from all
</files>

3. Block access to multiple file types
To restrict access to a variety of file types, add the following code block and update the file types within parentheses to match the extensions of any files that you wish to protect.

<FilesMatch “\.(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$”>
Order Allow,Deny
Deny from all
</FilesMatch>

4. Block unauthorized Directory Browsing
Prevent unauthorized directory browsing by instructing the server to serve a “xxx Forbidden – Authorization Required” message for any request to view a directory. For example, if your site is missing it’s default index page, everything within the root of your site will be accessible to all visitors. To prevent this, include the following htaccess rule.

# disables directory browsing
Options All -Indexes

To enable directory browsing, use the following directive.

# enables directory browsing
Options All +Indexes

Likewise, this rule will prevent the server from listing directory contents.

# prevent folder listing
IndexIgnore *

And, finally, the IndexIgnore directive may be used to prevent the display of select file types.

# prevent display of select file types
IndexIgnore *.wmv *.avi *.mp4 *.etc

Definition of .htaccess Regex Characters

Definition of .htaccess Regex Characters & htaccess regular expression special characters

 

#
The # instructs the server to ignore the line. It is used for including comments. Each line of comments requires its own #. When including comments, it is good practice to use only letters, numbers, dashes, and underscores. This will help eliminate/avoid potential server parsing errors.

 

[F]
Forbidden: Instructs the server to return a 403 Forbidden to the client or browser.

 

[L]
Last rule: Instructs the server to stop rewriting after the preceding directive is processed.

 

[N]
Next: Instructs Apache to rerun the rewrite rule until all rewriting directives have been achieved.

 

[G]
Gone: Instructs the server to deliver Gone (no longer exists) status message.

 

[P]
Proxy: Instructs server to handle requests by mod_proxy

 

[C]
Chain: Instructs server to chain the current rule with the previous rule.

 

[R]
Redirect: Instructs Apache to issue a redirect, causing the browser to request the rewritten/modified URL.

 

[NC]
No Case: Defines any associated argument as case-insensitive.

 

[PT]
Pass Through: Instructs mod_rewrite to pass the rewritten URL back to Apache for further processing.

 

[OR]
Or: Specifies a logical “or” that ties two expressions together such that either one proving true will cause the associated rule to be applied.

 

[NE]
No Escape: Instructs the server to parse output without escaping characters.

 

[NS]
No Sub request: Instructs the server to skip the directive if internal sub-request.

 

[QSA]
Append Query String: Directs server to add the query string to the end of the expression (URL).

 

[S=x]
Skip: Instructs the server to skip the next “x” number of rules if a match is detected.

 

[E=variable: value]
Environmental Variable: Instructs the server to set the environmental variable “variable” to “value”.

 

[T=MIME-type]
Mime Type: Declares the mime type of the target resource.

 

[]
Specifies a character class, in which any character within the brackets will be a match. e.g., [xyz] will match either an x, y, or z.

 

[]+
Character class in which any combination of items within the brackets will be a match. e.g., [xyz]+ will match any number of x’s, y’s, z’s, or any combination of these characters.

 

[^]
Specifies not within a character class. e.g., [^xyz] will match any character that is neither x, y, nor z.

 

[a-z]
A dash (-) between two characters within a character class ([]) denotes the range of characters between them. e.g., [a-zA-Z] matches all lowercase and uppercase letters from a to z.

 

a{n}
Specifies an exact number, n, of the preceding character. e.g., x{3} matches exactly three x’s.

 

a{n,}
Specifies n or more of the preceding character. e.g., x{3,} matches three or more x’s.

 

a{n,m}
Specifies a range of numbers, between n and m, of the preceding character. e.g., x{3,7} matches three, four, five, six, or seven x’s.

 

()
Used to group characters together, thereby considering them as a single unit. e.g., (perishable)?press will match press, with or without the perishable prefix.

 

^
Denotes the beginning of a regex (regex = regular expression) test string. i.e., begin argument with the proceeding character.

 

$
Denotes the end of a regex (regex = regular expression) test string. i.e., end argument with the previous character.

 

?
declares as optional the preceding character. e.g., monzas? will match monza or monzas, while mon(za)? will match either mon or monza. i.e., x? matches zero or one of x.

 

!
Declares negation. e.g., “!string” matches everything except “string”.

 

.
A dot (or period) indicates any single arbitrary character.

 


Instructs “not to” rewrite the URL, as in “…domain.com.* – [F]”.

 

+
Matches one or more of the preceding character. e.g., G+ matches one or more G’s, while “+” will match one or more characters of any kind.

 

*
Matches zero or more of the preceding character. e.g., use “.*” as a wildcard.

 

|
Declares a logical “or” operator. for example, (x|y) matches x or y.

 

\
Escapes special characters ( ^ $ ! . * | ). e.g., use “\.” to indicate/escape a literal dot.

 

\.
Indicates a literal dot (escaped).

 

/*
zero or more slashes.

 

.*
Zero or more arbitrary characters.

 

^$
Defines an empty string.

 

^.*$
The standard pattern for matching everything.

 

[^/.]
Defines one character that is neither a slash nor a dot.

 

[^/.]+
Defines any number of characters which contains neither slash nor dot.

 

http://
This is a literal statement — in this case, the literal character string, “http://”.

 

^domain.*
Defines a string that begins with the term “domain”, which then may be proceeded by any number of any characters.

 

^domain\.com$
Defines the exact string “domain.com”.

 

-d
Tests if string is an existing directory

 

-f
Tests if string is an existing file

 

-s
Tests if file in test string has a non-zero value

 

Hope the above will help you a lot, if you have any issue in htaccess rules…post your valuable comment below.