How to retrieve Google Backlinks count with PHP

Here's a simple script to retrieve the approximate number of backlinks Google has for a site. The function and how to call it follows:

function get_google_backlinks_count($url) {
	$url = "$url"

	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_REFERER, '');
	$response = curl_exec($ch);

	$json = json_decode($response);
	return $json ->; responseData ->; cursor -> estimatedResultCount;

echo get_google_backlinks_count('');

How to fix linux not sending mail problem: Sendmail stat=Deferred: Connection refused by []

I recently experienced a problem where my server was not sending mail from the PHP mail() function or the command line "mail" function. After looking through /var/log/maillog, I was able to see that the local mail server was refusing the connection. Some Google searching landed me at the following thread, where the third post did the trick:

Simple PHP script for unzip function

Here’s a simple PHP function to unzip a ZIP file and retain directory structure – great for use when you can’t use exec(). The function will return false on error and true on success. Call it with the following code:

if (unzip('../'))
	echo 'Cool, it worked!';
	echo 'Uh oh, something went wrong.';
function unzip($zipfile) {
	$zip = zip_open($zipfile);
	if ($zip) {
		while ($item = zip_read($zip)) {
			$name = zip_entry_name($item);
			if (substr($name, -1) == '/') {
				if (!file_exists($name)) {
					$dir = mkdir($name);
					if (!$dir) {
						return false;
			} else {
				if (zip_entry_open($zip, $item, "r")) {
					$f = file_put_contents($name, zip_entry_read($item, zip_entry_filesize($item)));
					if ($f === false) {
						return false;
				} else {
					return false;
		return true;
	return false;

How to Duplicate Database Rows in MySQL

If you're looking for a quick, easy way to duplicate a MySQL Row, try the following example:

		(Col2, Col3, ...)
		(Col2, Col3, ...)
	FROM Tbl1
		WHERE Col1 = 1;

This example assumes you want to duplicate the row where Col1 equals 1. You could change the where clause to anything for that matter. However, if there are more than one rows selected from the SELECT statement, it will INSERT each row, not just one.

Likewise, you could duplicate a whole MySQL table using the following:

		(Col2, Col3, ...)
		(Col2, Col3, ...)
	FROM Tbl1;

How To Convert Large XML Files to CSV

I usually struggle with converting very large XML files to other formats just because they are in a dynamic format and most programs you find run out of memory before properly parsing them.¬†Well, I’m happy to say, I found a FAST and EASY solution. Of course this will work for small files as well as big files.

You’ll want to grab a copy of the msxsl command line utility from Microsoft.

After you’ve got that, you’ll need to setup a XSL file to tell the program how to format your file. If you’re unfamiliar with XSL, you can familiarize yourself here.

After you’ve got your XSL file created, it’s a simple command line entry:

msxsl xml_file.xml xsl_file.xsl -o output_file.csv

The following is a sample XML and XSL file that I used.

XML File:

		Tue, 20 Jan 2009 16:28:08 CST
		Tue, 20 Jan 2009 16:51:01 CST

			The Hills Season 1

		Tue, 20 Jan 2009 16:28:08 CST
		Tue, 20 Jan 2009 16:53:54 CST

			Hogan Knows Best Season 2

		Thu, 22 Jan 2009 14:49:12 CST
		Thu, 22 Jan 2009 14:51:35 CST

			Carlos Mencia 2007

			Comedy Central

XSL File (Creates tab-delimited file)


How to mount Amazon EC2 EBS volume on an instance’s file system

The following assumes you have created a volume in AWS Management Console and attached it to your instance as /dev/sdh.
A brand new volume is unformatted block storage.  It shows up as another device, but doesn’t contain a filesystem.  (An EBS volume that previously had a filesystem created on it won’t be mounted either by the attachment process).
You can verify that your instance can see the EBS volume by running the following command on the instance:
cat /proc/partitions
You’ll see an entry for sdh.  At this point, you should create a filesystem and mount it manually.  You could create an EXT3 filesystem on the device and then mount it on ‘/mnt/ebs’ with the following commands, (run as root):
mke2fs -F -j /dev/sdh
mkdir /mnt/ebs

mount /dev/sdh /mnt/ebs 

Android 1.6 Version Update (Donut) adds new Power Control Widget

I’m a developer and have made a few apps for android, so I updated to the newest SDK today, Android 1.6, named "Donut". It’s supposed to roll out in October.

One of the first new things I noticed was a nifty power control widget, which gives you the ability to quickly toggle wifi, bluetooth, gps, data syncing, and brightness. Not a particularly big deal, because I’m currently using worthy widgets downloaded from the market, but it’s nice to have it natively for sure. Still waiting on a 3g toggle though…