My Twitter

URL Shortening Function

January 8th, 2010

Here is a function I use from time to time in my code which I thought I should share. It allows you to quickly shorten URL’s via 6 popular URL shortening websites.

function shorten_url($url, $service=NULL){
		if($service== 'tinyurl'){return get_link('http://tinyurl.com/api-create.php?url='.urlencode($url));}
		elseif($service == 'urly'){return get_link('http://ur.ly/new.txt?href='.urlencode($url));}
		elseif($service == 'isgd'){return get_link('http://is.gd/api.php?longurl='.urlencode($url));}
		elseif($service == 'klam'){return get_link('http://kl.am/api/shorten/?format=text&url='.urlencode($url));}
		elseif($service == 'unu'){return get_link('http://u.nu/unu-api-simple?url='.urlencode($url));}
		else{return get_link('http://api.tr.im/v1/trim_simple?url='.urlencode($url));}
		return $url;
	}

	function get_link($url){
		if(function_exists('curl_init')){
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_VERBOSE, 1);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			//curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
			//curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_URL, $url);
			$result = curl_exec($ch);
			$resultArray = curl_getinfo($ch);
			if ($resultArray['http_code'] == 200){
				return $result;
			} else {
				return FALSE;
			}
			curl_close($ch);
		}elseif(ini_get('allow_url_fopen') == 1){
			return fopen($url, 'r');
		}
		return FALSE;
	}

/* Usage */
echo shorten_url('http://www.fullondesign.co.uk/');
// returns: http://tr.im/JPCz

PHP Function: realpath()

December 19th, 2009

One functions I wish I had known about when i start learned PHP is the realpath() function. Pretty much what it does is take symbolic link (such as ‘../’ or ‘/’) and returns a canonicalized absolute link (like ‘/home/public_html/folder’). Here is an example of it in action:

<?php
echo realpath('../');
// Would return: /home/mike/www/blogposts
?>

Video: Stop Sign Designed by Committee

December 17th, 2009

My motto is “Clients are idiots”, though if you let them know this odds are you will not be paid. I tend to find this motto is true 90% of the time in the Design/Development field, mostly because clients see you as someone who is paid to make something the way they want to, not in a way that will look good & be functional. Here is a video which pretty much sums up why clients suck.

Click here to go to the original source of the video.

5 changes I would like to see in 2010

December 16th, 2009

2009 has been a somewhat interesting year for the internet; it’s become more mobile & more user friendly. However here are a few ideas I have had over the year, which I would like to see arrive in 2010.

Video Stream Caching

One of the big annoyances I have with streaming video files (normally on websites such as YouTube & Megavideo) is whenever I go to jump to another section of the video I lose what I currently have already loaded. It would be really useful if I could quickly go back to the section I’ve previously loaded.

video_stream_caching
This is a mock up I done, the video I used is from RayWilliamJohnson

I’m quite sure this would need to be implemented by the software, but I can’t see how it would be difficult to add.

Read the rest of this entry »

Programmers are…

November 18th, 2009

Programmers are…

Programmers Are...

Big thanks to Dan for showing me this ^^