Saturday, September 3, 2011

How To add a HTTPS address to your etc/hosts File

First Open your hosts file on   /etc/hosts on Linux  OR  C:\Windows\System32\drivers\etc on Windows systems

As known, the default port for web browsing is port 80, so every record inserted in the hosts file as default use port 80.

In order to add an "https" address just specify the ssl port for the desired record like so:

127.0.0.1:443    mysite.com

Now https://mysite.com will be handled by your localhost

Friday, September 2, 2011

How To Add Social Like and Share buttons to your site or blog

The internet is going social and if there's a free easy way to get more publicity and attract more people then why not?!

To get a good coverage of social sharing you'll need three most important buttons
provided by Google, Facebook and Twitter social networks
So, to get a social buttons stripe just like that:



 You'll need the following code:



Google plusone


Code:

<script type="text/javascript">
      (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
      })();
    </script>
    <g:plusone size="medium"></g:plusone>


for more info and more versions of the Google plusone button see: http://www.google.com/webmasters/+1/button/


Twitter Tweet Button


Code:
<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" >Tweet</a>
<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>



for more info and more versions of the Tweet Button see: http://twitter.com/about/resources/tweetbutton


Facebook Like Button


Code:
<div id="fb-root">
</div>
<script src="http://connect.facebook.net/en_US/all.js#appId=155577994527327&amp;xfbml=1">
</script>
<fb:like layout="button_count" send="true" show_faces="false"></fb:like>


for more info and more versions of the Facebook Like button see: http://developers.facebook.com/docs/reference/plugins/like/


The Complete Code:


<div class="social_buttons">

<!-- Facebook -->
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js#appId=155577994527327&amp;xfbml=1"></script>

<span><fb:like layout="button_count" send="true" show_faces="false"></fb:like></span>


<!-- Twitter -->
<span><a class="twitter-share-button" data-count="horizontal" href="http://twitter.com/share">Tweet</a></span>
<script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script>


<!-- Google -->
<script type="text/javascript">
(function() {var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;po.src = 'https://apis.google.com/js/plusone.js';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })();
</script>

<span><g:plusone size="medium"></g:plusone></span>

</div>

Friday, July 29, 2011

Calculate time-diff and calculate age from birth date

On my searches I've found many many different, complicated functions for time difference and many different functions calculate age, But for such a simple task I thought there should be a simpler solution.
so here are a few good simple ways to calculate time differences and age

good and simple function that because of the versatility of strtotime function can support many different date formats:

function dateDiff($from, $to = "now")
{
return round((strtotime($to) - strtotime($from))/60/60/24);
}

and if age calculation is what you desire,
a simple function to calculate age by birth date

/**
* Calc age from MySQL date format
* @param string $date YY-mm-dd (MySQL Date Format)
*/
function calcAge($date)
{
//Break the date into an array
list($Y,$m,$d) = explode("-",$date);
//Calculate Year Diff
$age = date("Y")-$Y;
//Subtract a year if exact birth date hasn't passed yet
if(date("md") < $m.$d) $age--;
//And finally return the age
return $age;
}