Friday 17 May 2013

How to replace plain URLs with links in JavaScript or PHP?

Hello Friends

If you want to convert plain text in to URLs in JavaScript or PHP. This is good solution for you.
In PHP :

[sourcecode language="php"]
public function makeLinks($str)
{
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
$urls = array();
$urlsToReplace = array();
if(preg_match_all($reg_exUrl, $str, $urls)) {
$numOfMatches = count($urls[0]);
$numOfUrlsToReplace = 0;
for($i=0; $i<$numOfMatches; $i++) {
$alreadyAdded = false;
$numOfUrlsToReplace = count($urlsToReplace);
for($j=0; $j<$numOfUrlsToReplace; $j++) {
if($urlsToReplace[$j] == $urls[0][$i]) {
$alreadyAdded = true;
}
}
if(!$alreadyAdded) {
array_push($urlsToReplace, $urls[0][$i]);
}
}
$numOfUrlsToReplace = count($urlsToReplace);
for($i=0; $i<$numOfUrlsToReplace; $i++) {
$str = str_replace($urlsToReplace[$i], "<a target='_balnk' href=\"".$urlsToReplace[$i]."\">".$urlsToReplace[$i]."</a> ", $str);
}
return $str;
} else {
return $str;
}
}
[/sourcecode]
In JavaScript

[sourcecode language="javascript"]
function makeLinks(text) {
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
return text.replace(exp,"<a target='_blank' href='$1'>$1</a>");
}
[/sourcecode]

Hope it helps.

Wednesday 15 May 2013

8 Things Productive People Do During the Workday

Forget about your job title or profession – everyone is looking for ways to be more productive at work. It’s time to set down your gallon-sized container of coffee, toss out your three-page to-do list, and put an end to those ridiculously long emails you’ve been sending.

8 Things Productive People Do During the WorkdayExperiencing a highly productive workday can feel euphoric. But contrary to popular belief, simply checking tasks off your to-do list isn’t really an indication of productivity. Truly productive people aren’t focused on doing more things; this is actually the opposite of productivity. If you really want to be productive, you’ve got to make a point to do fewer things.

Harness your productivity by taking note of these eight things:

1. Create a smaller to-do list. Getting things accomplished during your workday shouldn’t be about doing as much as possible in the sanctioned eight hours. It may be hard to swallow, but there’s nothing productive about piling together a slew of tasks in the form of a checklist. Take a less-is-more approach to your to-do list by only focusing on accomplishing things that matter.

2. Take breaks. You know that ache that fills your brain when you’ve been powering through tasks for several hours? This is due to your brain using up glucose. Too many people mistake this for a good feeling, rather than a signal to take a break. Go take a walk, grab something to eat, workout, or meditate – give your brain some resting time. Achieve more productivity during your workday by making a point to regularly clear your head. You’ll come back recharged and ready to achieve greater efficiency.

3. Follow the 80/20 rule. Did you know that only 20 percent of what you do each day produces 80 percent of your results? Eliminate the things that don’t matter during your workday: they have a minimal effect on your overall productivity. For example, on a project, systematically remove tasks until you end up with the 20 percent that gets the 80 percent of results.

4. Start your day by focusing on yourself. If you begin your morning by checking your email, it allows others to dictate what you accomplish. Set yourself in the right direction by ignoring your emails and taking the morning to focus on yourself, eat a good breakfast, meditate, or read the news.

5. Take on harder tasks earlier in the day. Knock out your most challenging work when your brain is most fresh. Save your busy work – if you have any – for when your afternoon slump rolls in.

6. Pick up the phone. The digital world has created poor communication habits. Email is a productivity killer and usually a distraction from tasks that actually matter. For example, people often copy multiple people on emails to get it off their plate – don't be a victim of this action. This distracts everyone else by creating noise against the tasks they’re trying to accomplish and is a sign of laziness. If you receive an email where many people are CC'd, do everyone a favor by BCCing them on your reply. If your email chain goes beyond two replies, it’s time to pick up the phone. Increase your productivity by scheduling a call.

7. Create a system. If you know certain things are ruining your daily productivity, create a system for managing them. Do you check your emails throughout the day? Plan a morning, afternoon, and evening time slot for managing your email. Otherwise, you’ll get distracted from accomplishing more important goals throughout the day.

8. Don’t confuse productivity with laziness. While no one likes admitting it, sheer laziness is the No. 1 contributor to lost productivity. In fact, a number of time-saving methods – take meetings and emails for example – are actually just ways to get out of doing real work. Place your focus on doing the things that matter most as efficiently and effectively as possible.

Remember, less is more when it comes to being productive during the workday.

What’s your secret to productive workdays?

Tuesday 12 February 2013

Set php.ini Values Using .htaccess

Did you know that you can set php.ini values right inside the .htaccess file? It's actually very easy.

The .htaccess Code


#format
php_value setting_name setting_value#example
php_value upload_max_filesize 10M

Of course you could simply place these in the .htaccess file, but .htaccess is a viable alternative if your host doesn't allow you to touch the php.ini file.

Resource :

http://davidwalsh.name/php-values-htaccess

Prevent Your CSS and JavaScript Files From Being Cached

Some websites use highly volatile, oft-changing CSS and JavaScript files. In the case of these files, it's important that the developer prevent browsers from caching them. How do we do that? By using a phantom querystring, of course. We'll use PHP to tack the current time onto the file reference.

The PHP


[sourcecode language="php"]
<link href="/stylesheet.css?<?php echo time(); ?>" rel="stylesheet" type="text/css" >
<-- RENDERS -->
<link href="/stylesheet.css?1234567890" rel="stylesheet" type="text/css">

<script type="text/javascript" src="/site-script.js?<?php echo time(); ?>"></script>
<-- RENDERS -->
<script type="text/javascript" src="/site-script.js?1234567890"></script>
[/sourcecode]

It's a very simple technique and doesn't affect your CSS or JavaScript code in any way.

Resource :

http://davidwalsh.name/prevent-cache

Android Detection with JavaScript or PHP

Hello Friends

You have a web application and you want to detect that if your Application is opened from android device than it will be redirect to any other URL that will be Android compatible.This is a good solution for you.

What's obvious is that Android development is a hot topic that will only grow. Here are a few methods by which you can detect iOS' main competitor: Android.

The JavaScript


Searching the user agent string for "Android" is the quickest method:

[sourcecode language="php"]
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if(isAndroid)
{
// Do something! // Redirect to Android-site? window.location = 'http://android.viralsolani.co';
}

[/sourcecode]

The PHP


Again, we'll use PHP's strstr function to search for Android in the user agent:

[sourcecode language="php"]
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
if(stripos($ua,'android') !== false){// && stripos($ua,'mobile') !== false) {
header('Location: http://android.viralsolani.co');
exit();
}
[/sourcecode]

Bonus! .htaccess Detection



We can even use .htaccess directives to detect and react to Android devices!

[sourcecode language="php"]
RewriteCond %{HTTP_USER_AGENT} ^.*Android.*$
RewriteRule ^(.*)$ http://android.viralsolani.co [R=301]
[/sourcecode]

And there you have it: three different Android device detection! Have fun with your mobile development!

Resource :

http://davidwalsh.name/detect-android

Thanks

 

Wednesday 6 February 2013

How to install SSL Certificates with Apache 2 on Ubuntu 12.04

Please note that commercial SSL certificates require a unique IP address each for SSL-enabled site, although multiple non-SSL sites may also share that IP address.

Step – 1 Create a Certificate Signing Request

A CSR is an encrypted body of text. Your CSR will contain encoded information specific to your company and domain name; this information is known as a Distinguished Name or DN.
In the DN for most servers are the following fields: Country, State (or Province), Locality (or City), Organization, Organizational Unit, and Common Name. Please note:
1. The Country is a two-digit code -- for the United States, it's 'US'. For countries outside of the United States,
2. State and Locality are full names, i.e. 'California', 'Los Angeles'.
3. The Organization Name is your Full Legal Company or Personal Name, as legally registered in your locality.
4. The Organizational Unit is whichever branch of your company is ordering the certificate such as accounting, marketing, etc.
5. The Common Name is the Fully Qualified Domain Name (FQDN) for which you are requesting the ssl certificate.
If you are generating a CSR for a Wildcard Certificate your common name must start with *. (for example: *.digicert.com). The wildcard character (*) will be able to assume any name that does not have a "dot" character in it.
To remain secure, certificates must use keys which are at least 2048 bits in length. If your server platform can't generate a CSR with a 2048-bit key

[sourcecode language="php"]
mkdir /etc/apache2/ssl
cd /etc/apache2/ssl
openssl req -new -newkey rsa:2048 -nodes -keyout yourdomain.key -out yourdomain.csr
[/sourcecode]

Replace yourdomain with the domain name you're securing. For example, if your domain name is viralsolani.co, you would type viralsolani.co.key and viralsolani.co.csr.

• This begins the process of generating two files: the Private-Key file for the decryption of your SSL Certificate, and a certificate signing request (CSR) file (used to apply for your SSL Certificate) with apache openssl.

• Open the CSR file with a text editor and copy and paste it (including the BEGIN and END tags) into the form from where you purchase your SSL certificate.

• Save (backup) the generated .key file as it will be required later for Certificate installation

Execute the following command to protect the key:
chmod 400 /etc/apache2/ssl/www.yourdomain.com.key

Execute the following command to protect the signed certificate:

[sourcecode language="php"]
chmod 400 /etc/apache2/ssl/www.mydomain.com.crt

[/sourcecode]

Step – 2 Get the Certificate Authority Root Certificate
In My case it is Go Daddy. So you need to go from wherever you purchase your SSL certificate and you need to submit the below generated CSR. And you can then download the certificate.
You will get two files. I’ve upload that two files in same folder where I’ve put my CSR and Private key that i.e /etc/apache2/ssl/
Step – 3 Configure Apache to use the Signed SSL Certificate.

This configuration vary depend upon OS and version of that OS. So I’ve installed Ubuntu 12.04 and to configure the certificate you need to do below steps.
You need to configuration in Apache virtual hosting file.
So now you need to go: /etc/apache2/sites-available/default-ssl

[sourcecode language="php"]
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin viral.solani@gmail.com

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

SSLCertificateFile /etc/apache2/ssl/yourdomain.com.crt
SSLCertificateKeyFile /etc/apache2/ssl/yourdomain.com.key
SSLCertificateChainFile /etc/apache2/ssl/gd_bundle.crt

</VirtualHost>
</IfModule>

[/sourcecode]

Basically you need to locate yourdomain.com.crt , yourdomain.com.key and gd_bundle.crt.
Now last thing you need to do is restart you apache with the following command

[sourcecode language="php"]
/etc/init.d/apache2 restart

[/sourcecode]

You should now be able to visit your site with SSL enabled. Congratulations, you've installed a commercial SSL certificate!

Monday 28 January 2013

2012 in review

The WordPress.com stats helper monkeys prepared a 2012 annual report for this blog.



Here's an excerpt:



4,329 films were submitted to the 2012 Cannes Film Festival. This blog had 14,000 views in 2012. If each view were a film, this blog would power 3 Film Festivals

Click here to see the complete report.