30 Mar 2011, 11:24am

1 comment

Optimising your iOS Launch Images

iOS asks you to provide a PNG image that is displayed when loading. This was all very well and fine back in the pre-iOS4, pre-iPhone4, pre-iPad days… but now at a minimum you need to provide 4 Default.png launch images. Since it’s PNG, it can get a bit weighty. For a color-rich screen for my app OS Converter, the launch images along weighed in at 2.3MB

Here’s a review OS Grid Converter recieved recently:

This has to be the best app I have downloaded yet!!

Quick to download, did this in the middle of the forest! Easy to convert gps to os co-ordinates and ensured I found exactly where I was on the map!

Thanks for a great piece of software

The ability to download the App in the forest is a good one – so adding 2.3MB for basically no benefit seems like a total waste.

Unfortunately you can’t provide a JPEG file – the spec insists on PNG. However it doesn’t restrict you on the type of PNG images. So I’m now using PNG-8, with 16 colors (with ‘Perceptual’ selection, 8% dither). For the type of images I’m using this results in only about 5% quality, but the total file size is reduced to 496KB. Well worth it, when you consider the review above.

28 Mar 2011, 3:14pm

leave a comment

MinutesToAbbott.com

Created this little joke site last year after the 2010 election which delivered a hung parliament. Figured I should actually put it live sometime.

Wondering if the current time is accurate…

MinutesToAbbott.com

28 Mar 2011, 1:40pm

leave a comment

mod_rewrite for moving a phpBB Forum

Recently I split off 3 forums from an old site and created them fresh on the new site (pretty easy to do, just dupe the DB and nuke the ones you don’t need).

Here’s the mod_rewrite I used to redirect the links for *just* those 3 forums to the new site:

 

In the .htaccess file of the forum’s root directory:


RewriteEngine on

RewriteCond %{QUERY_STRING} f=(26|27|29)
RewriteRule ^viewforum\.php "http\:\/\/community.geospike.com\/viewforum.php" [R=301,L]

RewriteCond %{QUERY_STRING} f=(26|27|29)
RewriteRule ^viewtopic\.php "http\:\/\/community.geospike.com\/viewtopic.php" [R=301,L]

The RewriteCond ensures the redirection only applies to the 3 forum IDs that I wanted. The rewrite rule matchs the viewforum and viewtopic links to the new forum, with a “permanent” 301 redirect. As the RewriteRule regex is not terminated with “$”, all the parameters are sent to the new URL.

Easy.

23 Mar 2011, 1:09pm

7 comments

Custom Authentication with Drupal 7

Was looking into Drupal 7 yesterday. One of my requirements would be to use my own authentication system.

The problem with Drupal, which seems to be a great piece of software, with generally good documentation is all the damn different versions. Most of the sample code I found on this topic was for Drupal 6.x or 5.x, and it is slightly difficult to figure out what goes where.

In the end, I resorted to doing what I dislike and reading the code to learn how it works. Reminds me of Rails ;-)

Here’s how I did it, this is very rough code.

Create a folder in the module directory.  Create a file of the same name, with a .info extension, in my case geospike.info:

name = geospike
description = Authenticates with Geospike.com
package = Other
core = 7.x

Create another file with the same name, but .module, in my case geospike.module.

<?php

function geospike_form_user_login_block_alter(&$form, &$form_state) {
	_geospike_user_login_form_alter($form, $form_state);
}

function geospike_form_user_login_alter(&$form, &$form_state) {
	_geospike_user_login_form_alter($form, $form_state);
}

function _geospike_user_login_form_alter(&$form, &$form_state) {
	$saveForm = $form;

	$form = array();

	// overrides the default validator
	foreach( $saveForm as $key => $value ) {
		if( $key == '#validate' ) {

			$form[ $key ] = array();
			foreach( $value as $validator ) {
				if( $validator == 'user_login_authenticate_validate' ) {
					$validator = 'geospike_authenticate_validate';
				}
				$form[ $key ][] = $validator;
			}
		} else {
			$form[ $key ] = $value;
		}
	}
}

function geospike_authenticate_validate( $form, &$form_state ) {

	$name = $form_state[ 'values' ][ 'name' ];
	$pass = $form_state[ 'values' ][ 'pass' ];

	// use Drupal authentication for this user
	if ($name == 'your_admin_username')
	{
		return user_login_authenticate_validate($form, $form_state);
	}

	$authenticated = your_awesome_authentication_method($name, $pass)

	if ($authenticated)
	{
		// this sets up the external user with Drupal by creating a local entry. If they don't exist they are added
		user_external_login_register($name, "geospike");

		// we must set the 'uid' to pass back.  this looks up the logged in user and sets the Drupal UID
		$account = user_external_load($name);
	    $form_state['uid'] = $account->uid;
	}
	else
	{
		// do nothing, Drupal will handle the errors

	}
}

Obviously you need to implement your_awesome_authentication_method.

I boiled that code down from the tutorial found here p2 p3

With 7.0, you may get a PHP warning which you have to patch Drupal to fix.

 

Now… if you want to remove the registration and password recovery forms (as I did), one approach is to create a “sub-theme” to override these forms with whatever info you like.

From the docs (note that in that example, for Drupal 7, ‘user_register’ should be ‘user_register_form’, that’s a bug).

Creating a geospike folder in the themes directory with the file geospike.info:

name = Geospike
core = 7.x
engine = phptemplate
base theme = bartik
stylesheets[all][] = geospike.css

And in template.php, specifying the forms to override.

<?php
/**
* Registers overrides for various functions.
*
* In this case, overrides three user functions
*/
function geospike_theme() {
	// get these form value names user.module:user_menu

  return array(
    // 'user_login' => array(
    //   'template' => 'user-login',
    //   'arguments' => array('form' => NULL),
    // ),
    'user_register_form' => array(
      'template' => 'user-register',
      'arguments' => array('form' => NULL),
    ),
    'user_pass' => array(
      'template' => 'user-pass',
      'arguments' => array('form' => NULL),
    ),
  );
}

// function geospike_preprocess_user_login(&$variables) {
//   $variables['intro_text'] = t('This is my awesome login form');
//  // $variables['rendered'] = drupal_render($variables['form']);
// }

function geospike_preprocess_user_register(&$variables) {
  $variables['intro_text'] = t('This is my super awesome reg form');
  $variables['rendered'] = drupal_render($variables['form']);
}

function geospike_preprocess_user_pass(&$variables) {
  $variables['intro_text'] = t('This is my super awesome insane password form');
  //$variables['rendered'] = drupal_render($variables['form']);
}

?>

Finally, create files to match your ‘template’ specifications above, so user-register.tpl.php and user-pass.tpl.php. Put whatever you want there!

And vola! Custom authentication, and new users are redirected anywhere I like.

After all this, I’m not sure if I’m going to go with Drupal. Seems like a pretty amazing and extensible system. But the problem with being jack of all trades, is that you’re not generally the best at any of them.

9 Mar 2011, 2:36pm

5 comments

AdWhirl vs Mobclix: They both suck

I’ve been trying to improve my ad situation for 2 free utility apps I have written.

There are two solutions I’ve heard of to help you maximise clicks and reduce dependance on a particular ad network, they are AdWhirl and Mobclix, and offer different approaches. With AdWhirl, you sign up to as many ad networks as you want, and intergrate all their SDKs, but you use AdWhirl to mediate which ad network is shown. Requests go to its server, so you can adjust the network percentages, and API keys any time.  With Mobclix, you just integrate their API, and they farm out requests to multiple networks.

Why do they both suck then?

I read a lot of information about Mobclix, and it seems they are very very slow at paying.  This information was as recent as December 2010. From what I read, if you email one of the insiders (and complain publicly), they can fast track your payments. I don’t want to waste my time trying to chase up payments.  This is a non-starter. All the tech in the world is useless if you don’t get the money you have earn’t. I don’t really care for claims that “it’s better now” or “it’s improving”, this is something that should be right from day 1 (and like I said, I have read about very recent problems), otherwise it’s nothing more than a Ponzi scam.

AdWhirl is a great idea, but suffers from a few design defects that prevent me from using it.  Firstly, there is no iPad support.  Everything was wonderful back when there was just the iPhone and 320×50 ads, but now we have many different sizes, and it seems, at least for now, that they couldn’t work out a good way to mediate it all.

Another problem with AdWhirl is that you select percentages for your networks (including house ads), then it has a backfill list that it tries in order.  My problem with this, is that I *always* want it to go to iAd first.  iAds are just that much more profitable.  But when I do this (by setting iAds to 100%), I lose the mediation percentages feature, and it just goes down my backfill one by one.

The nail in the coffin for AdWhirl is that it was bought out by AdMob (which was bought out by Google). It’s open source, so there is a measure of trust that it is not favouring AdMob – but the problem here, is that AdMob have very little incentive to continue development, since it basically has the affect of reducing requests to their own network. So I get the impression the code base is languishing unmaintained.  Yes it’s open source – but no, I don’t want to spend my time working for AdMob unpaid…

So I implemented a custom solution. Actually in less time than I spent fooling around with AdWhirl, et. al.  Basically I request an iAd. If there isn’t one, I request an AdMob one [can sub in any other network here, if AdMob disappoints] (which internally will use house ads for unfilled requests), and if *that* fails, I show a static ad I bundled with the App.  It’s really not that hard to setup, and AdMob seem pretty decent.  This also works great for iPad.

AdMob however does not have the ability for iPad house ads.  This is very lame – the iPad is over a year old, and how hard can it be to simply offer a different size for house ads? Very disappointing, but for now, it’s not worth my time to worry about it.

AdMob have an interesting ad exchange idea. So if you can’t display any paid ads, it will display an add for someone else’s app – and someone will then display one for yours, free!

Well anyway:  grab OS Grid Converter and DMS Converter free on the App store, if you have a need for such tools.  In a week from now you will get iPad support, and AdMob ads…