Screen Shot 2013-01-17 at 10.46.49 AM

Installing and Configuring the Google TV Emulator

The Google TV developers released a GoogleTV add-on for the Android SDK that makes emulation possible on the Windows and Mac Operating Systems (Linux was already supported).

Assuming that you have the Android SDK already installed:

In order to use the emulator, you need to open the Android SDK Manager and make sure that you have the “Google TV Addon” [under Android 3.2 (API 13)] and the “Intel Atom x86 System Image” [under Android 2.3.3 (API 10)].

 

If you installed the “Intel Atom x86 System Image”, you need to install the “Intel Hardware Accelerated Execution Manager” which can be found in the <sdk>/extras/intel/Hardware_Accelerated_Execution_Manager/
directory.  
For Windows, install the IntelHAXM.exe file.  
For Mac, install the IntelHAXM.dmg file.
You can read the installation instructions here http://developer.android.com/tools/devices/emulator.html

Create a new “Device Definition” in the “Android Virtual Device Manager” using the configuration below.  
For 1080p use a resolution of 1920×1080 and a density of xhdpi.
For 720p use a resolution of 1080×720 with a density of tvdpi.

 

Then create a “Android Virtual Device” using the “Device Definition” that you just configured.

 

Share:
Google TV Logo

What is Google TV

What is Google TV?
Google TV is an Android based platform that brings live TV, web and android apps all together in one device. It is like having a computer, cell phone, and television all in one.

Why develop for Google TV?
Did you know that the average person watches 5 hours of television every day? Due to this large amount of TV watching about 20% of televisions sold in 2010 were internet ready. Having this Google TV platform gives you the ability to develop apps that will enhance the TV viewing experience for millions of viewers. For example an app focused on sports can bring the most up to date statistics, video content and game scores to each viewer on personal demand.

Does developing for Google TV intrigue you? Well if it does then my next post will take you through the steps of how to get your Google TV development experience started.

Share:

Adding a hook to the PHP output headers

With PHP 5.4 you can now easily add a callback function, using header_register_callback, to be called just before the headers are sent to the browser.

For example:

  header('Content-Type: text/plain');
  header('X-Test: test-header');

  header_register_callback( 'remove_XPoweredBy_header' );

  echo 'Testing';

This allows you to set a callback function, in this case, remove_XPoweredBy_header.

An example of something to do in this callback function:

  function remove_XPoweredBy_header()
  {
    header_remove('X-Test');
  }

This will prevent “X-Test” from showing up in the headers.

Share:

Getting and Setting HTTP Response codes in PHP 5.4

A new function were added to PHP 5.4 that make getting and setting HTTP response code easy.

To get the current HTTP code, all you have to do is call the http_response_code function

  echo http_response_code()  //If all is ok, this should echo 200

To set the HTTP response code, add a parameter to the http_response_code function

  http_response_code(404)
  echo http_response_code()  //This should echo 404 and return 404 in the header
Share:

Class Member Access on Instantiation with PHP 5.4

Class members can now be accessed on instantiation in PHP 5.4. This is a very handy addition.
Before PHP 5.4 you had to create an object into a variable, and then access the class member/function:

  //The old way
  $object = new SomeClass();
  $object->someFunction();

With PHP 5.4 you can access the class member directly on instantiation:

  //The new way
  (new SomeClass)->someFunction();
Share:

Function Array Dereferencing in PHP 5.4

PHP now supports array dereferencing directly from a function call. Before PHP 5.4 you had to store the returning value from a function into a variable, and then use the variable.
Eg:

  $cars = $explode(",", "ferrari,lamborghini,maserati,bugatti");
  echo $cars[3];  //bugatti

Now with PHP 5.4 you can do it like this:

  echo $explode(",", "ferrari,lamborghini,maserati,bugatti")[3];  //bugatti

Another example with your own function:

  function get_cars()
  {
    return ["ferrari","lamborghini","maserati","bugatti"];
  }
  echo get_cars()[3];  //bugatti
Share:

The Shorter Array Syntax in PHP 5.4

PHP 5.4 introduced a new shorter array syntax, similar to the syntax used in JavaScript.

The old, longer syntax:

  //The old way
  $cars = array("ferrari", "lamborghini", "maserati", "bugatti");

The new syntax is an alternative to the old syntax.

  //The short way
  $cars = ["ferrari", "lamborghini", "maserati", "bugatti"];
Share:

Check if PHP is using HTTPS (SSL)

I had to come up with a way to check if PHP is running in SSL mode today. This will work on both Apache, Nginx and IIS

function is_ssl()
{
    $secure_connection = false;

    if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'
        || $_SERVER['SERVER_PORT'] == 443) 
    {
        $secure_connection = true;
    }

    return $secure_connection;
}

I found this little nifty function on StackOverflow</a

Detecting a Multi-Dimensional Array in PHP

I recently had to find a quick way to check if an array is a multi-dimensional array, only to find that there are no PHP built-in function to do this. Here is a quick and easy way to do it:

function is_multi_array( array $arr )
{
    return is_array($arr[key($arr)]);
}

This can easily be used in the following context:

$a = array("dimension1" => array("dimension2" => "I like it") );
if( is_multi_array( $a ) )
{
    echo $a['dimension1']['dimension2'];
}
Share:

Making a Radio Group Tab-able Using jQuery

Recently I had to come up with a solution to make radio boxes tab-able. Mozilla Firefox allows you to tab over each radio box in a group, however, all other browsers do not. The solution is actually quite simple. First, in your HTML make sure to name your radio boxes with the same name, but also add a .1, .2, .3, and so on, to separate them. You will also need a hidden element. This is the one you want to do validation against. For example:

    
     Radio 1
     Radio 2
     Radio 3

Now add a little bit of code that will parse once the DOM is ready:

    
        $(document).ready( function() {
            rt = new RadioTabs();
            rt.init( "group1", ["group1.1", "group1.2", "group1.3"], ["click"] );
        });
     

All this does is tell the RadioTabs class (coming next) which tabs will be in the group. Finally, add this somewhere on you page. Preferably on a separate page.

	/* Create Tabable Radio Boxes */
	function RadioTabs() {
		/* Declare Private Members and Methods */
		var hidden = '';
		var group = [];
		var events = [];

		/* void Bind Events to each individual Radio Box */
		var bindEvents = function () {
			//Loop through Events
			for( var e = 0; e < events.length; e++ ) {
				//Loop through Radio Buttons
				for( var g = 0; g < group.length; g++ ) {
					//Add a Rel value to each group box - to be used in the bind
					$('input:radio[name="' + group[g] + '"]').attr('rel', g);
					//Bind actual events to each radio box
					$('input:radio[name="' + group[g] + '"]').bind(events[e], function( event ) {
						var n = $(this).attr('rel');
						$('[name="' + hidden + '"]').val( $('[name=' + group[n] + ']').val() );
						//Step through radio group and set to false
						for( var i = 0; i < group.length; i++ ) {
							if( group[i] != group[n] ) {
								$('input:radio[name="' + group[i] + '"]:checked').attr( 'checked', false );
							}
						};
					});
				}
			}
		};
	 
		/* Declare Public Members and Methods */
		return {
			/* string Set the Hidden Input Element */
			setHidden    : function ( value ) {
				hidden = value;
			},
			/* array Set the Radio Group Elements */
			setGroup    : function ( values ) {
				group = values;
			},
			/* array Set the Events to bind to */
			setEvents    : function ( values ) {
				events = values;
			},
			/* void Init the script */
			init            : function ( hid, grp, evt ) {
				this.setHidden( hid );
				this.setGroup( grp );
				this.setEvents( evt );
				bindEvents();
			}
		};
	};

All the above piece of code does is it will allow you to tab through the radio boxes, and then set the hidden elements value to that of the selected radio box. You might have to tweak a little bit with CSS in IE7 and 8 (I don’t support 6 anymore) to make it show that the box is selected. This should do the trick

    input[type=radio]:focus {
        outline:#000 dotted thin;
    }
Share: