Archive

Archive for April, 2010

Never celebrate too early.

April 28th, 2010 1 comment

Why you should never celebrate too early.

Damn! That is whack!

{lang: 'en-GB'}
Share

FIX: WordPress Older Posts not working in IIS with Permalinks

April 28th, 2010 2 comments

I spent some time tweaking my blog today after moving it to some fresh hardware. You may find that everything is loading much faster now which can be attributed to two plugins in addition to the hardware upgrade – wp-super-cache and wp-widget-cache.

I’ve also fixed a long standing bug with my particular configuration of WordPress that runs on IIS which causes the “Older posts” link at the bottom does not function for the second page. The WordPress generated URL for this is

http://www.thushanfernando.com/index.php/Index.php/page/2

Which is a bit problematic, this ofcourse can be reproduced only on IIS from my musings (serves me right eh?). There are a couple of suggestions by people on the forums already, but I wasn’t too keen on them as they seemed too high-level fixes.

I’ve enabled Permalinks with this format:

http://www.thushanfernando.com/index.php/2010/04/28/sample-post/

So I looked through the sources to see why this was happening. After a bit of snooping about I got to the get_pagenum_link function in wp-includes/link-template.php file.

Heres a bit of source for reference – this is with WordPress 2.9.2:

function get_pagenum_link($pagenum = 1) {
	global $wp_rewrite;

	$pagenum = (int) $pagenum;

	$request = remove_query_arg( 'paged' );

	$home_root = parse_url(get_option('home'));
	$home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
	$home_root = preg_quote( trailingslashit( $home_root ), '|' );

	$request = preg_replace('|^'. $home_root . '|', '', $request);
	$request = preg_replace('|^/+|', '', $request);

	if ( !$wp_rewrite->using_permalinks() || is_admin() ) {
		$base = trailingslashit( get_bloginfo( 'home' ) );

		if ( $pagenum > 1 ) {
			$result = add_query_arg( 'paged', $pagenum, $base . $request );
		} else {
			$result = $base . $request;
		}
	} else {
		$qs_regex = '|\?.*?$|';
		preg_match( $qs_regex, $request, $qs_match );

		if ( !empty( $qs_match[0] ) ) {
			$query_string = $qs_match[0];
			$request = preg_replace( $qs_regex, '', $request );
		} else {
			$query_string = '';
		}

		$request = preg_replace( '|page/\d+/?$|', '', $request);
		$request = preg_replace( '|^index\.php|', '', $request);
		$request = ltrim($request, '/');

		$base = trailingslashit( get_bloginfo( 'url' ) );

	if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) )
		$base .= 'index.php/';

		if ( $pagenum > 1 ) {
			$request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( 'page/' . $pagenum, 'paged' );
		}

		$result = $base . $request . $query_string;
	}

	$result = apply_filters('get_pagenum_link', $result);

	return $result;
}

This function (from reading through) essentially generates the links for the page numbers & page navigation taking into account Permalinks if configured. This is all fine and dandy for Unix hosts but for Windows, unfortunately this bit of code fails us.

...
$request = preg_replace( '|page/\d+/?$|', '', $request);
$request = preg_replace( '|^index\.php|', '', $request);
$request = ltrim($request, '/');
...

As the preg_replace is case sensitive, it will not replace the invalid Index.php that is seen on IIS. So the easiest fix is to tweak the regex pattern a little bit and tell it be case insensitive.

...
$request = preg_replace( '|page/\d+/?$|', '', $request);
$request = preg_replace( '/|^index\.php|/i', '', $request);
$request = ltrim($request, '/');
...

This will then generate the (invalid) urls and the preg_replace will remove any additional Index.php’s from the request URL as its already mentioned in the $base variable a few lines below:

...
if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) )
$base .= 'index.php/';
...

Once you make the change and upload the files, your “Older posts” will start working again. I’ll submit a patch to WordPress I’ve submitted a patch to WordPress Trac, now its just a wait and see what they say, in the meantime here’s a patch file if you don’t want to modify sources manually. If there any issues, post a comment :-)

{lang: 'en-GB'}
Share

The move to Android from WinMo and Android 2.2 (aka Froyo) coming soon!

April 26th, 2010 1 comment

I switched from using Windows Mobile Phone devices to the Android platform a couple of months back with the Google Nexus One. With Microsoft following the lead of Apple in closing everything they’ve kept open for so long, there wasn’t much to look forward to with Windows Phone 7 (I was almost going to work on that team had I moved to the US a couple of years ago). Though, I’ve started writing for the new WP7 series via work, I’ve felt it was time to move on. Android is a breath of fresh air, I’ve toyed around with the G1 but the Nexus (whilst still a HTC device) is a joy to use as is the operating system. I actually have two Nexus’s these days, one is kept stock as my primary phone, whilst the other is using the Cyanogen mod.

Windows Mobile was never touch friendly – and rightfully so, as the operating system was written for stylus usage as a primary goal,  then later HTC (via TouchFlo3D) bolted on a new UI to bring touch friendly UI candy for Windows Mobile. Though Windows Phone 7 brings this to the table (with touch being a primary design goal), I’m ashamed to say they’ve taken what WinMo was good for – being easy to customise and cook ROMs for and turned it to the Apple-esque closed ecosystem and Jobs likes being in control of his herd.

The great thing about the Android is that its got potential and its constant source of updates are very welcome (probably the fastest growth for a platform thus far!), the AppStore has increased exponentially the past few months (which is good and bad – useless app count increases) as users begin to crawl out of the rotting Apples and the stained Windows phones. Another key is that all your Google services are integrated nicely. I’ve given up most of my daily things to Google – email, calendar, contacts… They’re all “in the cloud” and (for now) synchronisable and safe (not that you couldn’t do this with the iPhone or Windows Mobile).

The next release of Android (2.2) is dubbed Froyo and brings some very funky new updates.

JIT Compiler

Probably the biggest addition in this release but first and foremost, the design and architecture of the Android platform is a bit different to others. Forgetting the native development paradigm for Android, you write applications utilising the Java language.

From the Android Developer Guide:

Android applications are written in the Java programming language. The compiled Java code — along with any data and resource files required by the application — is bundled by the aapt tool into an Android package, an archive file marked by an .apk suffix. This file is the vehicle for distributing the application and installing it on mobile devices; it’s the file users download to their devices. All the code in a single .apk file is considered to be one application.

In many ways, each Android application lives in its own world:

  • By default, every application runs in its own Linux process. Android starts the process when any of the application’s code needs to be executed, and shuts down the process when it’s no longer needed and system resources are required by other applications.
  • Each process has its own virtual machine (VM), so application code runs in isolation from the code of all other applications.
  • By default, each application is assigned a unique Linux user ID. Permissions are set so that the application’s files are visible only that user, only to the application itself — although there are ways to export them to other applications as well.

It’s possible to arrange for two applications to share the same user ID, in which case they will be able to see each other’s files. To conserve system resources, applications with the same ID can also arrange to run in the same Linux process, sharing the same VM.

In order to achieve this, the Android platform uses the Dalvik Virtual Machine (which is register based as opposed to the more common stack based machines) suited for embedded devices – low memory footprint, run multiple VMs by offloading the process isolation, memory, threading and IO management to the operating system (Android).

The caveat with the Dalvik VM is that the performance is not ideal (it has no JIT compiler) and (by the looks of it) needs to improve garbage collection process (fragmentation is a concern currently). If you’re keen on understanding more about the Dalvik VM, checkout a talk from 2008′s Google I/O about Davik VM Internals (1:01:34). They also realise the performance implications of the runtime.

However, back in November 2009, Bill Buzbee commited the Dalvik JIT code to the Android platform bringing JIT compilation which (if you’ve been using any of the CyanogenMod’s lately) makes a very noticeable and welcome performance boost to all applications.

The (trace-based JIT) compiler detects frequently executed traces (hot paths & loops) and emits optimised code for the platform as necessary, ensuring that minimal heap memory is utilised without the use of any persistence storage – which is what you want in an mobile device!  Trace based JIT compilers are very common today, the TraceMonkey engine in Firefox is an example where dynamic languages (like Javascript) have had a boost through their use. Take a look at SPUR which is a Microsoft research project to bring trace-based JIT Compiler for CIL.

Whilst included in Android 2 it was never enabled, and by the looks of it, Android 2.2 will see this being enabled and stable :-)

Linux Kernel update 2.6.32

The upgrade from 2.6.29 to 2.6.32 should bring a trimmed memory foot print and some performance tweaks as well as 802.11n support on devices such as the Google Nexus (yay!)

Flash 10.1 Support

There’s lots of hoo-haa about Flash support on iP*’s and other devices, I’m not too concerned about having it on my phone (less annoying ads browsing the interwebs) but it seems Google will bring Adobe Flash 10.1 support to Android. For some, it was a deal breaker when it came for choosing a phone. I guess now its a matter of ooh-ah!

Automatic application updates

Currently, updating Android applications is quite tedious – updating one application at a time, but it seems a newer update will automatically ensure that your applications are up to date – which is good and bad, I’d like to control when and where it decides to eat up my 3G data for updates (Eg. Update when on wireless)

Hopefully a rollback feature will also be implemented in case the newer versions break things.

Other updates

  • OpenGL ES 2.0 enhancements which game developers will find enticing.
  • The ability to control the color of the trackball (which currently flashes white)
  • Enabling of FM Radio
  • Fixes for resolution and “crazy screen” woes.

When will we be getting this? No-one knows, but suggestions are around the time for the Google I/O event on May 19th.

Next up, I’ll write about some of the applications that I’ve come to use daily, in the meantime you can see the apps running on my Android by checking my AppBrain account. Later some development articles on Android too :)

{lang: 'en-GB'}
Share

Office 2010 and SQL Server 2008 R2 (soon) available on MSDN!

April 26th, 2010 No comments

If you haven’t heard already, Microsoft have RTM’d both Office 2010 and SQL Server 2008 R2 and Office is already available for MSDN Subscribers with SQL Server 2008 R2 arriving soonishly – you can look at the download page for SQL Server 2008 R2 and download it from MSDN now (03/05/2010). There’s also a great ebook titled “Introducing SQL Server 2008 R2” available in XPS and PDF format :)

I’m one of those who love the ribbon UI, its made things easier for me (helps that I really wasn’t a heavy MSFT Office user back in the days). Now everyone’s getting on board the ribbon train, even the beloved WinZip!

Don’t forget the Office 2010 Movie from last year.

{lang: 'en-GB'}
Share

Visual Studio 2010 & Resharper 5 hit the interwebs.

April 13th, 2010 No comments

A little late on this one, but MSFT have released the long awaited Visual Studio 2010 release and JetBrains have also released ReSharper 5.

A full breakdown of Visual Studios are also available, not a huge fan of all these different SKUs to be honest. You can download a copy from your MSDN subscriptions now, or download the trial version (direct download), buy an upgrade from VS2008 or just download the .NET 4.0 runtime (48Mb).

I’ve spent the past 3 hours downloading from MSDN and its been crawling.

MUST.HAVE.PLINQ.FIX.

{lang: 'en-GB'}
Share

Disputing a parking fine, Melbournian style!

April 7th, 2010 2 comments

Back when I was at Uni, a close friend (who drove a Toyota Supra) and I used to attract parking inspectors like magnets (needless to say, our girlfriends were not impressed!). There was very little we could do too, some of the inspectors would “camp out” and await our batch of cars (we had a system!) as we swapped each others cars in the hopes we don’t get fined, then BAM! fined. Anyway, those days are long gone. Most of the areas we parked are now permit zoned but these days, inspectors seem to be far more aggressive with fines with very little leniency.

Here’s a letter sent to the City of Melbourne disputing a fine, thought this was hilarious – and encouraging.

Australian Parking Find Dispute

Source: NextRound.net

Anyway, that was win for you and me kiddo. For the helpless people that need hope and encouragement, we may not win the war, but we’ve won the battle.

Add that to the collection of Aussie funnies! I wonder if there’s a “Parking Inspectors” forum like the OzLiberty forums, they all get together and marvel at each others fines – time to troll!

{lang: 'en-GB'}
Share

Google shows the power of HTML 5, ports Quake II to run in browser!

April 3rd, 2010 No comments

The title says it all. Using the Jake2 port of Quake II (to Java) the bright sparks at Google have used GWT to bring Quake II to HTML 5.

We started with the existing Jake2 Java port of the Quake II engine, then used the Google Web Toolkit (along with WebGL, WebSockets, and a lot of refactoring) to cross-compile it into Javascript. You can see the results in the video above — we were honestly a bit surprised when we saw it pushing over 30 frames per second on our laptops (your mileage may vary)!

At first I thought it was an April fools joke, but as cruel as that may be, it wasn’t. Download the source and give it ago, I nearly fell of my chair.

At the moment you have to build from source and mess about a bit, but fear not, I followed the guide on OSNews by Kroc on our MacBook Pro and it worked quite well, yet to try it on Linux.

{lang: 'en-GB'}
Share

xkcd goes CLI!

April 2nd, 2010 No comments

This is cool, xkcd is now command line based! Try it!

{lang: 'en-GB'}
Share