Friday, July 17, 2015

How to Add a Facebook Share Button to Blogger Posts


Allowing others to easily share your content on social media is something that is always important. Thankfully, many of the services we use for our online promotion have social sharing buttons that we can implement into our websites. Adding a Facebook Share button to Blogger is a little different than some other sites because we want the button to automatically insert the URL of the page the visitor is currently on, or the post they want to share, without having to update this link manually.
Adding a Share button to your blog’s template will ensure that it stays in place at the bottom of every post, and with the code below, the link will be automatically inserted into the button.

Let’s get started

Login to your Blogger account and backup your template in case something goes wrong. You can do this by clicking the Backup/Restore button in the top corner and saving the file to your computer.
Go to Template > Edit HTML.
Click inside the editor text area and press CTRL + F (or CMD + F if you’re on a Mac) to open up the “find” search box in the top right corner.
In the search box, paste this code and press enter:
<div class='post-footer-line post-footer-line-1'> 
It should find one instance of it, but that will be for mobile view. Press enter again to skip to the second instance of it instead. This is your normal blog view.
Directly above that line of code, paste this code:
<div class="facebook-share">
<a expr:share_url='data:post.url' name='fb_share' rel='nofollow' type='BUTTON-TYPE'/>
<script src='http://static.ak.fbcdn.net/connect.php/js/FB.Share' type='text/javascript'/>
</div>
If you want it to appear at the top of your post instead, jump back to the top of the editor and search for the SECOND instance of:
<data:post.body/>
Insert the code above that.

Choosing the button type

Facebook has 6 types of buttons that you can choose from. You can see them here in the “Layout” dropdown. In the “BUTTON-TYPE” part of the code above, enter one of the following as shown:
  • box_count
  • button_count
  • button
  • icon_link
  • icon
  • link

Save your template

The script will not appear in Preview mode, so save your template and check your live blog for your new Share button!

Share/Bookmark

Tuesday, July 7, 2015

How do I get a YouTube video thumbnail from the YouTube API?

Each YouTube video has 4 generated images. They are predictably formatted as follows:
http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg
The first one in the list is a full size image and others are thumbnail images. The default thumbnail image (ie. one of 1.jpg, 2.jpg, 3.jpg) is:
http://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg
For the high quality version of the thumbnail use a url similar to this:
http://img.youtube.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg
There is also a medium quality version of the thumbnail, using a url similar to the HQ:
http://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg
For the standard definition version of the thumbnail, use a url similar to this:
http://img.youtube.com/vi/<insert-youtube-video-id-here>/sddefault.jpg
For the maximum resolution version of the thumbnail use a url similar to this:
http://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg
All of the above urls are available over https too. Just change http to https in any of the above urls. Additionally, the slightly shorter hostname i3.ytimg.com works in place of img.youtube.com in the example urls above.

Share/Bookmark

Saturday, July 4, 2015

Test Credit Card Account Numbers

While testing, use only the credit card numbers listed here. Other numbers produce an error.
Expiration Date must be a valid date in the future (use the mmyy format).

Test Credit Card Account Numbers

Credit Card Type
Credit Card Number
American Express
378282246310005
American Express
371449635398431
American Express Corporate
378734493671000
Australian BankCard
5610591081018250
Diners Club
30569309025904
Diners Club
38520000023237
Discover
6011111111111117
Discover
6011000990139424
JCB
3530111333300000
JCB
3566002020360505
MasterCard
5555555555554444
MasterCard
5105105105105100
Visa
4111111111111111
Visa
4012888888881881
Visa
4222222222222
Note : Even though this number has a different character count than the other test numbers, it is the correct and functional number.
Processor-specific Cards
Dankort (PBS)
76009244561
Dankort (PBS)
5019717010103742
Switch/Solo (Paymentech)
6331101999990016

Share/Bookmark

The Easiest Way to Install APC on Amazon Linux EC2 Servers

APC or Alternative PHP Cache, is a free open-sourced "opcode cache" for PHP. It caches commonly run PHP processes into memory so that they don't have to be compiled every time. If you are running a Drupal or Wordpress site, this can really improve the performance of your website and server.
Installing the PHP APC module on Amazon Linux is this simple:
sudo yum install -y php-pecl-apc
Then go to /etc/php.d/apc.ini and make sure the process is enabled. Once you've got APC installed, you can check to see if it is running by copying the apc.php script to the webroot and navigating to it in your browser. This control panel will also give you some very useful statistics. From the PHP.net manual on APC:
Once the server is running, the apc.php script that is bundled with the extension should be copied somewhere into the docroot and viewed with a browser as it provides a detailed analysis of the internal workings of APC. If GD is enabled in PHP, it will even display some interesting graphs. The first thing to ensure, of course, is that it is actually caching files.
If APC is working, the Cache full count number (on the left) will display the number of times the cache has reached maximum capacity and has had to forcefully clean any entries that haven't been accessed in the last apc.ttl seconds. This number is minimized in a well-configured cache. If the cache is constantly being filled, and thusly forcefully freed, the resulting churning will have disparaging effects on script performance. The easiest way to minimize this number is to allocate more memory for APC.

Share/Bookmark

Thursday, July 2, 2015

Create Virtual Hosts in a WAMP Server

The Windows Apache MySQL PHP (WAMP) server is incredibly powerful. Not only does it allow you to host a website using the world's most flexible web server, it also allows you to do so on your Windows host.
But don't think because you're on a Windows host that you lose much of the flexibility found on the Linux equivalent. In fact, much of the feature set translates — this includes virtual hosts. Using virtual hosts allows you to, effectively, host more than one site on a single machine.
For example, say you want to host:
  • localhost
  • mysite.localhost
I'll show you how to easily do both with a single WAMP server (I assume the WAMP server is up and running, and you have administrative access to the files and folders on that machine). We'll focus on one configuration file at a time.

hosts

First, you need to edit your hosts file on the server. This will map the virtual host name to an IP address. To keep this simple, we'll map 127.0.0.1 to mysite. Here's how:
  1. Open Notepad as the administrator.
  2. Open the file C:\Windows\system32\drivers\etc\hosts.
  3. Add the line: 127.0.0.1 mysite.
  4. Save the host file (making sure to not save it as a .txt file).

httpd.conf

The fastest way to access this file is to right-click the WAMP icon in the system tray and select Apache | httpd.conf (Figure A).
Figure A
wamp_virt_1_110513.png
The WAMP user menu
When you select the httpd.conf entry, Notepad will open with the contents of the httpd.conf file. Within this file, you need to uncomment out the entry for virtual hosts configuration file location. Search for these two lines:
# Virtual hosts
# Include conf/extra/httpd-vhosts.conf
Remove the "#" in the second line above and save and close the httpd.conf file.

httpd-vhosts.conf

The next file to edit cannot be accessed through the WAMP user interface; you should find this file in C:\wamp\bin\apache\Apache-XXX\conf\extra\ (XXX is the release number). Open that file in Notepad and add the following section (we're sticking with our current example of "mysite").
<VirtualHost *:80>
    ServerAdmin emailaddress@domain.com
    DocumentRoot "c:\MYSITE"
    ServerName mysite.local
    ErrorLog "logs/mysite.log"
    CustomLog "logs/mysite-access.log" common
</VirtualHost>
Notes about the code: You must add a <VirtualHost *:80> directive for every virtual host you create. The site administrator is emailaddress@domain.com. Also, if you need to serve the virtual host on a non-standard port, change it in the VirtualHost directive line. The reference to c:\MYSITE is the directory created to host the files and folders for the new virtual host; you'll need to create that folder (you can place it wherever you need in the folder hierarchy as long as it is accessible by Apache).
After you add the above code to the correct file, save it and restart your WAMP services. Now you should be able to see both localhost and mysite from your browser. You'll want to change those addresses to match your needs.

Share/Bookmark

PHP/Mysql Zip Code Proximity Search

Here is the best way I have found. Of course it will require that you have all of your zipcodes lat/lon encoded in the database.
// get all the zipcodes within the specified radius - default 20
function zipcodeRadius($lat, $lon, $radius)
{
    $radius = $radius ? $radius : 20;
    $sql = 'SELECT distinct(ZipCode) FROM zipcode  WHERE (3958*3.1415926*sqrt((Latitude-'.$lat.')*(Latitude-'.$lat.') + cos(Latitude/57.29578)*cos('.$lat.'/57.29578)*(Longitude-'.$lon.')*(Longitude-'.$lon.'))/180) <= '.$radius.';';
    $result = $this->db->query($sql);
    // get each result
    $zipcodeList = array();
    while($row = $this->db->fetch_array($result))
    {
        array_push($zipcodeList, $row['ZipCode']);
    }
    return $zipcodeList;
}
You should be able to just drop in this function. Pass it the $lat and $lon of the zipcode you want the radius for, include the optional radius, and get a list of zipcodes back.
You could very easily modify this to get all users where zipcode IN (radius_sql) and get your list users back.
Happy Coding!

Share/Bookmark