installing sublime text 2 on ubuntu

so, what is sublime text?

as it’s website says,

Sublime Text is a sophisticated text editor for code, markup and prose.
You’ll love the slick user interface, extraordinary features and amazing performance.

is it available in the ubuntu repo? yes, but not the latest version.

so, to install sublime text 2 do the following,

  • open up your console and type the following lines,
sudo add-apt-repository ppa:webupd8team/sublime-text-2
sudo apt-get update
sudo apt-get install sublime-text

btw, it’s free to evaluate and the licence costs about $49. if you’re a developer, i’m sure this money is well spent.

how to detect ipad using javascript

ipads are becoming one of the most used interface for the internet, here’s a simple snippet to detect if the user is on ipad.

var isiPad = navigator.userAgent.match(/iPad/i) != null; 
var ua = navigator.userAgent; 
var isiPad = /iPad/i.test(ua) || /iPhone OS 3_1_2/i.test(ua) || /iPhone OS 3_2_2/i.test(ua); 

[courtesy :]

How to sort objects in Javascript

Arrays can be sorted using the sort() method in javascript, however this method cannot be applied to javascript objects.

function sortObject(obj){
		var objArray = [];
		for(e in obj){
		objArray.sort(function(a, b) {return b[1] - a[1]});
		return objArray;

The function will return a 2 dimensional array sorted in descending order. So, how do you sort it in ascending order?

How to validate email address and phone numbers (UK)

Even the simplest of the websites found on the internet now support user registration and one of the hassles in creating a user registration system is validation the information

function is_valid_email($email){
   return preg_match("/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/i", $email)
function is_valid_phone($phone){
    return preg_match("/^(\s*\(?0\d{4}\)?(\s*|-)\d{3}(\s*|-)\d{3}\s*)|(\s*\(?0\d{3}\)?(\s*|-)\d{3}(\s*|-)\d{4}\s*)|(\s*(7|8)(\d{7}|\d{3}(\-|\s{1})\d{4})\s*)$/i",$phone);

More regular expressions can be found at

Make your links super cool with this fade effect snippet

Changing a link text colour on mouse hover is cool. But do you know, you can add some super cool fading effect to your link texts?

    -webkit-transition: color 300ms ease-in 200ms;
    -moz-transition: color 300ms ease-in 200ms;
    -o-transition: color 300ms ease-in 200ms;
    transition: color 300ms ease-in 200ms;
    color: #000;

The transition property has 3 parameters, “property duration effect delay”. It works on all recent browsers.

How to construct a tree from flat structure

This snippet comes in handy when you store a tree structure as a table database and want to convert it back to a tree structure.

function constructTree($data){
		$index = array();
		$tree  = array();
		foreach ($data as $key=>&$row) {
		  $index[$key] = &$row;
		  $row['children'] = array();
		  if ($row['parentid'] == 0) {
			$tree[$key] = &$row;
		foreach ($data as $key=>&$row) {
		  $index[$row['parentid']]['children'][$key] = &$row;
		  if(isset($row['parent']))$index[$row['parentid']]['parent'] = $row['parent']+1;
		return $tree;