iPhone Flight Control Review

June 30th, 2009

If you’ve taken a look at the AppStore recently, you may have noticed that the top paid app is a little game from Ozzy developers Firemint. Yes, Flight Control is a top title, and with hoards of people heading abroad for summer sun, it seems quite appropriate to take a look if you haven’t already done so.

The idea of the game is very simple – you must guide aeroplanes and helicopters to safety on your airport’s two runways and helipad. To guide the planes, you select one and create a flight path by moving your finger on the touch-screen. It starts of quite sedately, but soon gets hectic, requiring a good measure of tactics and reactions.

The number 1 game is a great little time waster, and at only 59p, it’s an absolute steal.

Adobe Flex Gravatar Control

May 31st, 2009

Flex Gravatar Control

I have recently been getting to grips with Adobe Flex for a project that I’ve been working on, and thought a fun little bit of work would be to write a Flex Gravatar Control. I’d done the equivalent for ASP.NET, so why not have another go?

Incidentally, I don’t know whether there’s much call for a Flex Gravatar control – if you’re reading this and find a use for it – great, but I hope that there may be something in this post that helps a budding Flex developer too.

The general idea of component development is to package up a reusable bit of code for use in applications. Since a Gravatar is just an image, it seems natural that the Gravatar component extends (otherwise known as inheriting) the Flex mx.controls.Image class. The benefit of inheritance here is that we get a bunch of functionality for free that we can use as a basis for our control. We’ll be adding our specific Gravatar code so that the image shown is a particular user’s Gravatar.

Let’s take a look at the Flex Navigator for the Gravatar Project.

Flex Navigator for the Gravatar Project

Flex Navigator for the Gravatar Project

Aside from the standard stuff, as3corelib.swc is referenced in the libs folder. If you’re not aware of it, as3corelib is described as follows over at the project page hosted on Google Code.

The corelib project is an ActionScript 3 Library that contains a number of classes and utilities for working with ActionScript 3. These include classes for MD5 and SHA 1 hashing, Image encoders, and JSON serialization as well as general String, Number and Date APIs.

Since Gravatars use hashing for their URLs, we’ll be using the MD5 aspect of corelib.

The components directory contains a single file, GravatarImage.as, which contains the code for the Gravatar component, and Gravatar.mxml is the demo application’s MXML that uses the Gravatar component.

Let’s dive straight in and take a look at the component code:

package components
{
	// import the MD5 hashing code:
	import com.adobe.crypto.MD5;

	import mx.controls.Image;

	public class GravatarImage extends Image
	{
		public function GravatarImage()
		{
			super();
		}

		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
		{
			super.updateDisplayList(unscaledWidth, unscaledHeight);

			this.width = _size;
			this.height = _size;

			this.source = "http://www.gravatar.com/avatar/" +
							MD5.hash(_email).toString() + "?" +
							"size=" + _size +
							"&rating=" + _rating +
							"&d=" + _defaultImage;
		}

		private var _validRatings:Array = new Array('g', 'pg', 'r', 'x');
		private var _validDefaultImageTypes:Array = new Array('default', 'identicon', 'monsterid', 'wavatar');

		[Bindable]
		private var _email:String = new String();

		[Bindable]
		private var _size:Number = 80;		// default size of 80 pixels

		[Bindable]
		private var _rating:String = "G";	// default rating of G

		[Bindable]
		private var _defaultImage:String = "default"; // default to the blue 'G'				

		public function set email(value:String):void
		{
			// if the email is invalid, a default image will be returned:
			_email = value;
		}

		public function set size(value:Number):void
		{
			// sanity check on incoming value, must be between 1 and 512:
			if( value >= 1 && value &lt 512)
				_size = value;
			else
				_size = 80;
		}

		public function set rating(value:String):void
		{
			// do a sanity check on the rating, allowing values
			// only in the _validRatings array (defined above):
			if( _validRatings.indexOf( value.toLowerCase()) != -1)
				_rating = value;
		}

		public function set defaultImage(value:String):void
		{
			_defaultImage = value;
		}
	}
}

The code is pretty simple. The main function, updateDisplayList is called when the image should draw itself. It simply constructs a URL based on the properties that have been set, and makes a request to the gravatar service for the image. Note that the corelib’s MD5 hash is used to obfuscate the email address passed in.

The properties relate to those of the URL generated and are as follows:

email

The email address associated with the gravatar image.

size

The size property of the control can be in the range 1 to 512. If it is outside this range, a default of 80 will be used.

rating

The ‘highest’ allowed rating of image.

  • A G rated gravatar is suitable for display on all websites with any audience type.
  • PG rated gravatars contain may contain rude gestures, provocatively dressed individuals, the lesser swear words, or mild violence.
  • R rated gravatars may contain such things as harsh profanity, intense violence, nudity, or hard drug use.
  • X rated gravatars may contain hardcore sexual imagery or extremely disturbing violence.

defaultImage

URL encoded URL, protocol included, of a GIF, JPEG, or PNG image that should be returned if either the requested email address has no associated gravatar, or that gravatar has a rating higher than is allowed by the ‘MaxAllowedRating’ property. The default image type also supports ‘default’, ‘identicon’, ‘monsterid’, and ‘wavatar’ strings for alternative Gravatar default images.

So, how do we use the control? Again, it’s pretty simple. Let’s have a look at the application MXML:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
	xmlns:components="components.*">

	<mx:Script>
		<![CDATA[

			[Bindable]
			private var postComments:XML =
                <comments>
                    <comment name="Shane Porter" email="anemail@somedomain" />
					<comment name="Kate" email="someotheremail@somedomain" />
					<comment name="Mr Unknown" email="xxx@xxxyyy.com" />
                </comments>;

		]]>
	</mx:Script>

	<mx:DataGrid id="myDataGrid" dataProvider="{postComments.comment}" rowHeight="88" rowCount="3">
		<mx:columns>
            <mx:DataGridColumn dataField="@name" headerText="Name"/>
            <mx:DataGridColumn dataField="@email" headerText="Gravatar">
              	<mx:itemRenderer>
              		<mx:Component>
              			<components:GravatarImage email="{data.@email}" size="80" rating="G" defaultImage="monsterid" />
              		</mx:Component>
              	</mx:itemRenderer>
            </mx:DataGridColumn>
        </mx:columns>
    </mx:DataGrid>
</mx:Application>

There’s a component namespace reference on the outer Application element, and for illustrative purposes, some XML defined that is used as the data provider for a Data Grid control. The GravatarImage component is used as an item renderer for the ‘Gravatar’ column. The email property is set to the value of the email XML attribute, and the size, rating and defaultImage is also set.

Application in Design View

Application in Design View

When the app is run, the datagrid uses the XML as its data provider, and the Gravatars are rendered. Note that in this screenshot, I provided known email addresses associated with Gravatars. The bottom row is the same as the code shown previously, and since it is not associated with a Gravatar, the specified ‘monsterid’ default image is used.

The page shown in the browser

The page shown in the browser

Opera Face Gestures to revolutionise browsing

April 1st, 2009

The last few months has seen the release of Google browser Chrome, IE8 on the horizon, and new releases for Safari and Firefox. Opera isn’t taking it easy however, and have released a video of their new ‘face gestures’ software, that allows users to control their browser through the power of their face.

Check out the YouTube video!

5 things you may not know about ASP.NET

March 31st, 2009

Since its release in early 2002, Microsoft’s ASP.NET platform has gone from strength to strength. Despite its strong uptake from Microsoft-centric software houses, there may be a few people who have hesitated in adopting ASP.NET for their web development platform. Here I present some things you might not know about ASP.NET. Perhaps it’ll encourage you to take a look at it.

Cost

There once was a time when the standard IDE for developing ASP.NET apps, Visual Studio, was prohibitively expensive for the average Joe. In late 2007, Microsoft released its first versions of ‘Express’ software, aimed at students and hobbyists. Though Express incarnations have fewer features than their full version cousins, they do offer the possibility of exploring ASP.NET. The Microsoft website offers a download page for Visual Web Developer 2008 Express Edition. An express version of SQL Server is also available, and can be downloaded from the SQL Server 2008 download page.

MVC Support

The MVC pattern is an established and well-recognised way of building web applications, and is familiar to RoR, Java and PHP developers. For many years, MVC was not available as a standard approach to developing ASP.NET websites, but Microsoft has recognised the deficiency and have (at the time of writing) released version 1.0 Release Candidate of ASP.NET MVC. The release has had a mixed response from the ASP.NET community, many of whom are used to the traditional code-behind model. Despite the inevitable squabbles as to which way is best, many have welcomed the MVC approach for its separation of concerns and finer control over JavaScript and markup. To find out more about the release candidate, head over to Scott Guthrie’s blog post.

Learning Resources

A big advantage for anybody learning a new technology is the wealth of learning material that is available. Although you can rely on a large number of books, the ASP.NET learn website contains many videos on both traditional and MVC ASP.NET as well as data access.

Intrinsic jQuery Support

The lightweight open source JavaScript library that’s taken the web by storm is now fully supported by Microsoft. As well as full intellisense support in Visual Studio, Microsoft will be using the library as-is, without forking or changing the code from the main jQuery branch. What’s more, Microsoft will be using jQuery as a basis for future ASP.NET and ASP.NET AJAX features. I feel this counters the argument of Microsoft not supporting open-source software.

Career Prospects

Microsoft’s ubiquity means that learning ASP.NET and supporting technologies will do no harm to your career prospects. .NET skills are ranked as some of the most in-demand in the UK.

Email help for Recruitment Consultants

February 10th, 2009

Having registered with various job boards and spoken to various recruitment consultants in the past, it’s no surprise that I get a few ‘job’ emails from time to time.

The vast majority of these emails are essentially spam. Despite me entering details about preferred location, experience and daily rate requirements on job websites, I often get mails that are for the wrong end of the country, junior jobs and low rates.

I just got a mail from a recruiter that contained the following text:

Dear Shane

PUT PARAGRAPH ONE HERE

PUT PARAGRAPH TWO HERE (Or delete if unneccessary)

Put PARAGRAPH THREE HERE (Or delete if unneccessary)

{Name of person removed}
Microsoft .net Consultant
{Name of agency removed}

I didn’t feel the urge to deal with somebody who needed reminding that an email can be separated into separate paragraphs, and that if it contained less than 3 paragraphs, the unneccessary (sic) paragraph helper text should be removed.

Unbelievable. Still, at least they got my name right.

Super Mario Kart – for real

January 27th, 2009

I have to admit to playing Super Mario Kart a great deal on the SNES, but this is something else.

Apple says Goodbye to the Keyboard with new Laptop

January 9th, 2009

Let’s be honest, the recent Macworld show was a disappointment – no iPhone nano, no update to the ancient Mac Mini.

But then, I found this baby – this is the future!

Professional CodeIgniter Book Review

December 30th, 2008

With all the furore surrounding Ruby on Rails, you’d be forgiven for forgetting that any other web application framework ever existed. The fact is, of course, that there are many to choose from, and one leading PHP-based framework is MVC-based CodeIgniter.

The CodeIgniter website is a great place to start for newcomers and more experienced developers alike, but I still like a good book, that I can hold in my hand and digest. Wrox’s Professional CodeIgniter is such a book, and presents a good overview of the framework that’s getting deserved attention in the web development community.

The book weighs in at a fairly lightweight 336 pages, but covers various aspects of CodeIgniter development, together with a history of the Model View Controller Pattern and an examination of Agile Development that is often employed by modern web-centric development teams. Whilst these discussions are not completely necessary to experienced programmers looking at getting to grips with CodeIgniter, they may benefit others who are looking for a more rounded introduction to web development. Being familiar with MVC and agile-development, I skipped these sections and headed for some CodeIgniter code.

Chapter 3 satisfies my code craving, where an overview of CodeIgniter is presented, covering such topics as the default installation, configuration, CodeIgniter libraries, helpers, and models, views and controllers, the foundation of any CodeIgniter site.

Chapters 4-8 walks through the development of an e-commerce style website with a shopping cart, categories and products, and a dashboard for managing details of the site. Chapter 9 covers some security issues, and although the information is presented, it is not intended as an exhaustive coverage of PHP Security. There is never a one book fits all situation, and for PHP security, you’re likely to find Essential PHP Security of great use.

The book concludes with an brief examination of the site launch, though this adds little of any significant importance.

It’s good to see a CodeIgniter book, and the quality of the writing is generally high, with easy to follow code examples. The book is very thin on AJAX coverage, which is quite a negative. Used in conjunction with the excellent CodeIgniter forums and website, it’s likely to prove a great resource for learning the framework.

The book’s list of Chapters is as follows:

  1. Welcome to the MVC World
  2. Agile Methodologies and Approaches
  3. A 10,000-Foot View of CodeIgniter
  4. Creating the Main Website
  5. Building a Shopping Cart
  6. Creating a Dashboard
  7. Improving the Dashboard
  8. Last-minute Upgrades
  9. Security and Performance
  10. Launch

Programmatic impersonation in C#

November 27th, 2008

Impersonation

I recently deployed a WPF app on a server that allowed the user to stop and start some application-related services. The purpose of the app was to allow users with administrative rights an easy way to manage the services that they needed to manage. Granted, they could manage the services through the services MMC, but the little WPF app was a requirement, and it’s our job as developers to make things easier for our clients – right?

All went well until a change of requirements meant that a user without administrative rights needed to use the program to stop and start the required services. When I tried to use the app, I got an exception – quite rightly, stopping and starting the services required admin rights. We needed the restricted user to be able to log on and use the app, but still needed to restrict their permissions.

So – step in programmatic impersonation in C# – a way to give restricted users the power that that’s required, all within the confines of your application.

The first thing to point out is that I got quite a bit of this code from a google search, but I had to do a bit of work to get things in a state that I found really useful.

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Runtime.InteropServices;
using System.Linq;
using System.Security.Principal;
using System.Text;

namespace ServiceControllerApp.Security
{
    public class Impersonator : IDisposable
    {
        private WindowsImpersonationContext _impersonatedUser = null;
        private IntPtr _userHandle;

        public Impersonator()
        {
            _userHandle = new IntPtr(0);

            string user = "servicecontroller";
            string userDomain = ConfigurationManager.AppSettings["MachineDomain"];
            string password = "yourpassword";

            bool returnValue = LogonUser(user, userDomain, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref _userHandle);

            if (!returnValue)
                throw new ApplicationException("Could not impersonate user");

            WindowsIdentity newId = new WindowsIdentity(_userHandle);
            _impersonatedUser = newId.Impersonate();
        }

        #region IDisposable Members

        public void Dispose()
        {
            if (_impersonatedUser != null)
            {
                _impersonatedUser.Undo();
                CloseHandle(_userHandle);
            }
        }

        #endregion

        #region Interop imports/constants
        public const int LOGON32_LOGON_INTERACTIVE = 2;
        public const int LOGON32_LOGON_SERVICE = 3;
        public const int LOGON32_PROVIDER_DEFAULT = 0;

        [DllImport("advapi32.dll", CharSet = CharSet.Auto)]
        public static extern bool LogonUser(String lpszUserName, String lpszDomain, String lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);

        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
        public extern static bool CloseHandle(IntPtr handle);
        #endregion
    }
}

Impersonator is a simple class that uses interop to call Win32 LogonUser and CloseHandle functions. We have to use interop because .NET doesn’t provide the equivalent methods.

The code shown above has a user, domain and password actually in the code – for some situations this is a security risk, so the credentials should be obtained in another manner, but for my needs, it was satisfactory, and their direct inclusion simplifies this example.

The class has a WindowsImpersonationContext to manage the impersonation, and the constructor sets up the required logon rights using the LogonUser interop.

Crucially, the impersonation must end, with an equivalent Log Off – and the class implements IDisposable to call the required log off code. Using the class is easy.

using (Impersonator impersonator = new Impersonator())
{
    // code in here
}

The good thing is that because the class implements IDisposable, you don’t have to pepper your code with the log off code equivalent. I hope it’s of use to somebody wishing to implement impersonation.

Fieldrunners iPhone Game Review

November 20th, 2008

Fieldrunners Review

I greeted the launch of the AppStore with great excitement and expectation, especially since a version of Monkey Ball was to be released that very same day. I was however disappointed with the iPhone incarnationl, and outlined my reasons in my review. Despite pretty graphics, over-sensitive controls made the gameplay non-existent. In addition, other games that grabbed my interest also disappointed with poor controls and use of the iPhone’s accelerometer.

Spore Origins was better than I thought, with finer control over movement, but I found the gameplay rather shallow. Disappointment once again.

A couple of weeks ago, I found a gem of a game, and refreshingly, it didn’t use the accelerometer, and the touch screen interface was implemented perfectly. Not only this, but it was fun to play, addictive, and graphically reminiscent of SNES games from an era of games that I loved. That game is Fieldrunners, currently standing at Number 12 in the top paid apps in the App Store. With an average score of 5 stars from 199 reviewers, it’s obviously got it’s followers, and I’m one of them.

Fieldrunners at number 12 in the paid apps chart.

Fieldrunners at number 12 in the paid apps chart.

Developed by Subatomic Studios, the game is a Tower Defence derivative where you have to construct a series of defence towers to protect yourself against wave after wave of air and land combatants.

Version 1.0 of the game was released on October 15, and was a cracking game in its own right, but lacked a sound and music, and had just the one map. A free upgrade, version 1.1, was launched yesterday and features excellent sound and music, and an additional map that extends the lifespan of the game. The game offers three levels of difficulty, and comprises of 100 waves of attack that must be resisted. For each enemy unit that makes it across the field, one of 20 lives is lost. The game ends when either all lives have been lost or 100 waves have passed. The new version also offers an ‘endless’ mode where the number of waves is endless and the game ends only when the player loses their 20 lives. 20 lives may sound a lot, but the waves are relentless and things can get quite hectic. The animation is fantastic and makes the game a pleasure to watch as much as actually play.

A good overview of the game in play is available over at YouTube:

The game is simple to learn, and the following help screens perfectly describe what the game is all about:

Building towers for defence

Building towers for defence

Upgrading defences

Upgrading defences


Building strategic routes

Building strategic routes


Tower types

Tower types

For anybody who hasn’t yet got the update, here is a screenshot of the new ‘Crossroads’ level:

New level Crossroads

New level 'Crossroads'

At only £2.99, the game is an absolute steal, and my faith in iPhone gaming has been restored!