Oct 192015
 

Was trying to connect to a PostgreSQL database running through VirtualBox locally, but is only exposed though SSH. In order to do that, I have to connect through an SSH tunnel. I found the following article here http://www.heidisql.com/forum.php?t=15472 that says:

SSH tunnel is built into HeidiSQL for MySQL only. For using a tunnel to a PostgreSQL server, you will need to start a plink.exe command line seperately, and then let HeidiSQL connect to 127.0.0.1 on the port you specified in the command line.

But I had no idea how to do that!

Did some research, and here’s what I ended up running that worked for me:

Make sure you have Putty installed (which included plink.exe). Open up a windows command prompt and navigate to the folder you have the Putty executables:

cd "C:\Program Files (x86)\PuTTY"

From there, run the following:

plink -L 5432:localhost:5432 "my local ssh profile"

where “my local ssh profile” is the name of the session config you have saved in PUTTY.

What this does it route all requests from localhost port 5432 to the connection it created through PUTTY and forwards them to the same port (hence the second 5432)

Now you just need to change the config for HeidiSQL to connect to ‘localhost’, port 5432. Then provide the user and password for the postgres database user you want to connect with.

Hope that helps!

Dec 082011
 

Here’s how to calculate the days until Christmas using PHP:

$daysuntilxmas = ceil((mktime(0,0,0,12,25,date('Y')) - time()) / 86400);
echo "There are $daysuntilxmas days to Xmas!";

You can combine this with my End of the day countdown javascript to have a realtime countdown with hours, minutes, and seconds. If you do that, decrement the $daysuntilxmas by 1 since you will already be counting partial days.

Hope that helps!

Dec 022011
 

Since posting Simple Mobile Browser Detection in PHP I have received feedback indicating that an iPad is not considered a mobile device. It ultimately depends on your definition of ‘mobile’, but I see their point in that tablets are very different from cell phones. Screen size and browser capability are pretty different between mobile phones and tablet/pads, so I can understand why you’d want to distinguish between them.

So I updated my code to detect just mobile phones:

function is_mobile_phone()
{
	$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
	$mobiles = array("iphone", "ipod", "blackberry", "nokia", "phone",
		"mobile safari", "iemobile");
	foreach($mobiles as $mobile)
	{
		if(strpos($ua,$mobile)) return true;
	}
	return false;
}

I removed ipad and kindle since those are easy to detect. I removed android, palm, and mini since some of those can be tablets. I added IEMobile for Windows phones. But the most significant change is replacing ‘mobile’ with ‘mobile safari’ and ‘iemobile’. Google had pointed out that it’s best to look for android AND mobile, but it’s just as easy to search for ‘mobile safari’. Most cell phones have a string similar to:

“Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; T-Mobile G2 Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1″

Whereas most tablets have a string resembling:

“Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10″

I came across a couple user agent strings that don’t follow these rules, but weren’t very popular devices. This should cover 95% of the cases.

May 142008
 

I recently did a lot of research concerning the effects of your driving speed on your car’s fuel efficiency. I was very shocked by all the info and results I found. I was also shocked that there wasn’t 1 site that explained it all together. So, I created one:

http://www.mpgforspeed.com/

The site gives you the detailed numbers and facts, and explains why it is. As always, comments are welcome…