Mac Terminal Shortcuts For Repetitive Commands

If you’ve always wondered if it would be cool to be able to type your own custom command into mac terminal and have it do whatever wonderful command thing, you can conjure up in your wonderfully creative head.

Then i’m afraid to say it’s just not possible…ha…only kidding…keep reading if you want to find out how, it’s actually really quite simple.

So to setup these ultra cool, simple shortcut commands for your mac terminal you need to locate or create a .profile file.

If you have one already you’ll be able to find it using the following commands.

cd ~/
ls -f

This either will or won’t reveal a .profile file. If it doesn’t, no sweat, we’ll just go ahead and create it.

mate ~/.profile

(note i’m using Textmate here, you could use vim / nano or whatever gui takes your fancy.)

Once you’ve got this file open we’re going to use alias to define our shortcuts.

Here’s an example.

alias davetest="cd /Applications/MAMP/htdocs/davetestsite/"

Save the file, relaunch terminal and type “davetest” or whatever your shortcut is and wollah you’ll have created your very own customised mac terminal shortcut command.

Good work.

PHP Curl URL which has redirects to obtain the final URL

Been doing some toying around lately with various ways of scraping hidden URL’s from a website that deliberately tries to hide them.

I have been using PHP and the CURL library ascertain the final URL after redirects whilst also picking up on javascript redirects etc.

This is what i’ve come up with so far, and it’s working a dream.

function get_final_url( $url, $timeout = 5 ){
    $url = str_replace( "&", "&", urldecode(trim($url)) );

   	$cookie = tempnam ("/tmp", "CURLCOOKIE");
	$ch = curl_init();
	curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" );
	curl_setopt( $ch, CURLOPT_URL, $url );
	curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie );
	curl_setopt( $ch, CURLOPT_HEADER, true);
	curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
	curl_setopt( $ch, CURLOPT_ENCODING, "" );
	curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
	curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
	curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
	curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout );
	curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );
	$content = curl_exec( $ch );
	$response = curl_getinfo( $ch );
	curl_close ( $ch );
	if ($response['http_code'] == 301 || $response['http_code'] == 302):
	    ini_set("user_agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1");
	    $headers = get_headers($response['url']);
	    $location = "";
	    foreach( $headers as $value ):
	        if ( substr( strtolower($value), 0, 9 ) == "location:" )
	            return get_final_url( trim( substr( $value, 9, strlen($value) ) ) );

	if (preg_match("/window.location.replace('(.*)')/i", $content, $value) ||
	        preg_match("/window.location="(.*)"/i", $content, $value) || 
	        preg_match("/location.href="(.*)"/i", $content, $value) ):
	    	return get_final_url ( $value[1] );
	    return $response['url'];


// Simply called like so

$my_final_url = get_final_url('',10);

Rsync folder from one server to another

Incredibly useful function that i’ve been using alot today to help move clients sites into a new server setup quickly using rysnc.

rsync is a software application and network protocol for Unix-like and Windows systems that synchronizes files and directories from one location to another while minimizing data transfer using delta encoding when appropriate (thanks Wikipedia).

rsync -avz -e ssh username@yourotherserver:/pathto/domain/html/wp-content/plugins .

In this case I rsync the plugins folder into the current working directory (make sure if your copying and pasting this command to CD into the right folder first before running).

Trust me this will save you time!

I released Topmmorpg100 an MMORPG Topsite

Over the last few months as a bit of a side project I have been developing and building – an online MMORPG, MMO & Browser based gaming topsite voting site.

Game developers and game owners can list their games on for free and encourage their users to vote for them on it. They can make use of our industry leading API’s which provide developers with everything they need to make a successful job of incentivising voting for their players. Our API’s will do such things as callback your API URL when a vote is successfully processed with the playerID you pass to us in the voting process.

It’ll even allow you to verify a userID or IP Address has voted for your game. is looking for some more game owners to join, currently they are offering 100 free votes and 1 month free Gold membership to the next 5 sites that join up.

It’s certainly a very good MMORPG & Gaming voting site and is feature rich and well coded.

Come check out my hard work here if you like it, be sure to drop me a comment or buy me a beer sometime. Also if you have any improvements you’d like to see drop them here as well.