Archive | August, 2008

Why Aptana is Quickly Becoming the Killer Stack

26 Aug

Anyone who knows me knows that I am a huge fan of Aptana.  (The recent acquisition of the pyDev plugin and its eventual incorporation into the IDE only solidifies that position.)  Their suite of services are quickly turning into the killer app stack for a large majority of web developers including myself and if you’re a developer who hasn’t given Aptana a try, I highly recommend you do – it’s free.

Yes, everything they’re doing has been done before.  And yes bigger and badder players have offerings in the IDE, cloud hosting, and developer community sectors, but it’s all about consolidation baby, and Aptana wins hands down in that arena.

The IDE Is Key

The foundation of any good development stack is not the test or deployment servers.  It’s not the language,  documentation, or even the community.  It’s the IDE, damnit.  Because, really – what connects all the other layers?  It should be the IDE, and that’s exactly what the Aptana IDE does.

The Aptana devs have done an excellent job in providing much more than just a text editor with syntax highlighting.  With the soon to be released Aptana IDE 1.2, you get project management, remote asset management with FTP, SVN and their new aptanacloud interface, database management, code tutorials and assistance for popular libraries and frameworks.

No, Aptana will probably never be as good a PHP editor as Zend Studio.  And it’ll probably never be a replacement for Cyberduck or Filezilla for file management, or Amazon’s web services for cloud computing.  And you’ll probably still try to ping the jQuery docs only to realize they are still slow as hell (good alternative here, btw).  But, in the Get Stuff Done web development world, having a working solution for all these built in to your IDE is invaluable.

The Future is in The Cloud

As a relatively new entrant into the web technology world, I would venture to say that the biggest and most exciting development during my short tenure is Cloud Computing.  But, I’ve said it before, and I’ll say it again – managing Amazon Web Services and EC2 instances is hard work.  Google App Engine fixes the hard work problem, but you’re forced into Google’s narrow framework and constraints.

Aptana’s new Cloud service is right smack-dab in the middle.  You’re given a sliding scale of server size, a couple of customization options, and bam! you’ve got a web server.  There’s no 50 step, command line based, get-one-step-wrong-and-you’re-hosed process to build and deploy a machine instance.  But, you also don’t have the fine-grained control of exactly what software your server runs.

That’s an easy trade-off for the web application developer, because execution on the core functionality of your app is what matters.  No one really cares how you’ve squeezed every last ounce of optimization into your server cluster (though there’s nothing wrong with that pursuit).

Oh, by the way, did I mention that Aptana Cloud is integrated with the Aptana IDE on every level – database management, source control, resource management, deployment, etc. etc?  Yeah, it is and it kicks ass.  Go sign up for the early access program and see for yourself.

Javascript is the New Cranberry

You know how you can walk down the juice aisle at your local grocery store and see 50 different juices and cranberry just seems to be involved with every damn one of them?  That’s javascript in the web world.  More often than not, JSON is the platform of choice for APIs and web services.  AJAX pervades just about every Web 2.0 application.  Hell, it’s even made it into our databases with CouchDB.

Hey, there’s nothing wrong with that – Jeff Attwood may hate working with javascript – but I kinda sorta almost maybe like it!  Especially when working with frameworks like jQuery, javascript can be a fun experience when it adds interactivity and wow-factor to your web application.

Enter Aptana’s end-to-end Javascript solution – Jaxer.  Damn, they thought of everything!  If web developers are spending so much time in their code interfacing with javascript APIs and writing Javascript UI interactivity, why not put javascript on the server side and use it as your middleware?  I like it.

Hell, I can see in the near future a scenario where Javascript is the only scripting language in an entire application.  Front end javascript, with Jaxer on the server, and CouchDB as the data-store.

Oh, and did I mention that Jaxer is integrated into the Aptana IDE with a debug console, profiler, etc? Ok, you get the point.

So Why Did I Write This?

Sounds like I’m a pretty hardcore Aptana fanboy, doesn’t it?  Well I can assure you the Aptana team hasn’t paid me should be paying me to say all this, damnit.  Oh well, I’ll throw in a diss just for good measure.  For some ungodly reason, the Aptana IDE only just recently added a word wrap feature.  Yes, you read that right – word wrap.  Word.  Wrap.

Ok, they maybe might have had some sort of plausible excuse, but damn – Word. Wrap.  That’s sort of like a television not having volume control, or a keyboard without the tilde – you don’t miss it until you don’t have it.

GeoCouch in CakePHP

26 Aug

I released a small php script for easily handling geodata in couchdb via php a while ago, check it out here.  I also put together a short tutorial on how to integrate this script in your CakePHP application.  The article is available here on the CakePHP Bakery.

Integrating CakePHP with bbPress – Part 2

25 Aug

This is the second of a 3 part tutorial on how to integrate bbPress with CakePHP 1.2.x. When complete, these 3 tutorials will accomplish:

  1. Integrating bbPress in a sub-folder (not a subdomain) of your cake install (part 1 here)
  2. Integrating user registration – when a user registers through your cake application they are automatically registered in bbPress.
  3. Integrating the login – when a user is logged in via the cake application they are automatically logged in in bbPress.

Part 2 – Integrating User Registration

This part is a little more tricky, but not unmanageable.   The challenge here is that your Cake application probably uses the Auth component, or a custom user setup.  So you probably have a prebuilt users table and chances are it does not conform to what bbPress is looking for in it’s users table.  Also, the encryption scheme between the two is probably different.

With that in mind, I’ve made the following design decisions

  1. My Cake users schema will remain intact AND the bbPress users schema will remain intact.
  2. Users must register through my Cake application only
  3. CakePHP is using the built-in Auth component.
  4. When a user registers through my Cake application – I run the necessary logic from the Cake User model to update the bbPress users table.
  5. The bbPress tables are in the same database as my CakePHP tables
  6. I change the encryption scheme of bbPress to conform to my Cake app.

Step 1: changing the bbPress password encryption.

If you’ve followed Part 1 of this tutorial, you’ve successfully installed and ran bbPress in a subfolder of your cakephp install.  Navigate to that subfolder, then open following file: bb-includes/backpress/code.wp-pass.php

Notice two functions, hash_password(...) and check_password(...).  We will overwrite these two functions to match the hashing that takes place in our CakePHP install.  If, as I denoted above, you are using the built-in CakePHP Auth component, this is very simple – just comment out the existing functions and replace them with the following:

	function hash_password($string) {
		$string = 'YOUR CONFIGURE::SALT VALUE'.$string;
		return sha1($string);
	}

	function check_password($password, $hash, $user_id = '') {
		$string = 'YOUR CONFIGURE::SALT VALUE'.$password;
		if(sha1($string) != $hash) {
			return false;
		} else {
			return true;
		}
	}

Replace the YOUR CONFIGURE::SALT VALUE with the appropriate value from your CakePHP application. This can be found in app/config/core.php.

With these two functions in place, your bbPress user system should be hashing and checking the passwords the same way.

Step 2: Saving a bbPress user from the CakePHP install.

Fortunately, CakePHP provides an easy hook into the ORM saving process with the afterSave() model callback.

To get your User model to save a new bbPress user when a new Cake user is created, add the following functions to your User model script:

	function afterSave($created)
	{
		if($created)
		{
			$sql = "INSERT INTO `bb_users`
			(`user_login`, `user_pass`, `user_nicename`,
			`user_email`, `user_url`, `user_registered`,
			`user_status`, `display_name`)
			VALUES(
			'".$this->data['User']['username']."',
			'".$this->data['User']['password']."',
			'".$this->data['User']['username']."',
			'".$this->data['User']['email']."',
			'',
			NOW(),
			0, '".$user['User']['username']."')";
			$this->query($sql);
		}
	}

Notice that we are just creating an SQL statement with all the necessary fields required to successfully insert the user into the bbPress system, and then executing that SQL. Also, if you are using the default functionality of the Auth component, $this->data['User']['password']; should automatically be hashed with the same scheme as Step 1.

Step 3 – Preventing registration from bbPress

This is the easy part. Simply add the following line to the top of your register.php script in you bbPress install and replace the path with the correct path to your cake registration page.

die(header('Location: /path/to/your/cake/registration/page'));

So, that’s it! Now, when you register a user through your Cake application, they should also appear in the bbPress users table, and you should be able to successfully log into both with the exact same credentials.

But, the plot thickens – we don’t want our users to have to log in to both the cake app and bbpress. We want them to be logged into both automatigically. Stay tuned for part 3 of this tutorial and I’ll attempt to tackle this very conundrum.

Integrating CakePHP with bbPress – Part 1

23 Aug

I’ve been working on StatForge.com for the past few days and one of the community features I want to integrate is a forum.  Rather than go for something bloated like phpbb or vanilla, I decided to go with bbPress from the makers of Wordpress.

This is the first of a 3 part tutorial on how to integrate bbPress with CakePHP 1.2.x.  When complete, these 3 tutorials will accomplish:

  1. Integrating bbPress in a sub-folder (not a subdomain) of your cake install
  2. Integrating user registration – when a user registers through your cake application they are automatically registered in bbPress. (UPDATE: part 2 here)
  3. Integrating the login – when a user is logged in via the cake application they are automatically logged in in bbPress.

Part 1 – Integrating bbPress in a sub-folder (not a subdomain)

It may be personal preference, but I’m not a big fan of subdomaining parts of an application.  There are definitely legitamite technical reasons to do so, but when I can get away with it, I try to use subfolders, i.e. http://statforge.com and http://statforge.com/forum/.

There’s a small hurdle here since CakePHP wants to ReWrite all your paths (if you’ve installed it in your domain root), but it’s easy to overcome.  Find the .htaccess file in the root of your cake install.  It should look like this:

   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]

This is rewriting all of your requests to the webroot folder. Assuming you want to install bbPress into a subfolder called forum (i.e. http://statforge.com/forum/) the change this .htaccess file to the following:

   RewriteEngine on

   RewriteCond %{REQUEST_URI} ^/forum/(.*)$
   RewriteRule ^.*$ - [L]

   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]

This simply reads – if the Request starts with /forum/ pass it through normally. If not, let Cake handle it. The only limitation here is that you cannot have a controller named ‘forum’ in your cake application.

That’s it – you should be able to drop a fresh bbPress install into the /forum subfolder and access it normally without Cake interfering.

I’ve already integrated the user registration between my CakePHP install and my bbPress install, but I’ve gotta run for the time being. Hopefully tomorrow I’ll throw up part 2 – it’s a bit more complicated. (UPDATE: part 2 here)

Fixing the Keyboard Issue on the Current Version of PhoneGap

23 Aug

PhoneGap currently has an issue with the keyboard not appearing whenever a form input is selected on a web site.  The key here is that the keyboard IS actually showing up, but it is being drawn behind the UIWebView used to render the webpage.

Here’s the solution I came up with.  I don’t understand enough about the rendering heirarchy to explain the why, but here’s the how:

In the GlassAppDelegate.m source file you should see a block of code that looks like the following:

 // Set up the image picker controller and add it to the view
	imagePickerController = [[UIImagePickerController alloc] init];

	// Im not sure why the next line was giving me a warning... any ideas?
	// when this is commented out, the cancel button no longer works.
	imagePickerController.delegate = self;
	imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
	[window addSubview:imagePickerController.view];

Simply move this block of code BELOW the following line. This renders the imagePicker object after the web view.

webView.delegate = self;

Problem – the imagePicker is obscuring the web view! Simply add the statment imagePickerController.view.hidden = YES; to the above block of code so that the entire block looks like:

 // Set up the image picker controller and add it to the view
	imagePickerController = [[UIImagePickerController alloc] init];

	// Im not sure why the next line was giving me a warning... any ideas?
	// when this is commented out, the cancel button no longer works.
	imagePickerController.delegate = self;
	imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        imagePickerController.view.hidden = YES;
	[window addSubview:imagePickerController.view];

As it sounds like, we are just hiding the imagePickerController’s view – we don’t need it when the application starts anyways. But, we do need it when we access the images API through javascript, so find the block:

else if([(NSString *)[parts objectAtIndex:1] isEqualToString:@"getphoto"]){
				NSLog(@"Photo request!");
				NSLog([parts objectAtIndex:2]);

				webView.hidden = YES;
        [window bringSubviewToFront:imagePickerController.view];
				NSLog(@"photo dialog open now!");
}

and add the line imagePickerController.view.hidden = NO; above webView.hidden = YES; so that the entire block looks like:

else if([(NSString *)[parts objectAtIndex:1] isEqualToString:@"getphoto"]){
				NSLog(@"Photo request!");
				NSLog([parts objectAtIndex:2]);
        imagePickerController.view.hidden = NO;
				webView.hidden = YES;
        [window bringSubviewToFront:imagePickerController.view];
				NSLog(@"photo dialog open now!");
}

Voila! Compile and run the app and the keyboard should now appear when a form input is pressed on your iphone.

Extending PhoneGap to Return the iPhone’s Unique Identifier

22 Aug

Yesterday I wrote about the nascent project, PhoneGap, that acts as a Cocoa Touch-native wrapper to your web-based application.  I’ve been playing with it non-stop since I stumbled accross it and it works like a charm!

When phonegap initializes, it loads a few parameters from the client iPhone into your javascript environment.  By default these include the phone model, version, and gap version.  For my specific application, I wanted to load the iPhone’s unique identifier.

To add this uniqueIdentifier parameter is simple – looking in the phonegap sources, Find the GlassAppDelegate.m script in the Classes folder. Using Xcode’s method-finder bar, navigate to the (void)webViewDidStartLoad:(UIWebView *) method and replace it with the following:

- (void)webViewDidStartLoad:(UIWebView *)webViewLocal {
	NSLog(@"Page loaded");
	NSString *jsCallBack = nil;
	jsCallBack = [[NSString alloc] initWithFormat:@"\
				  __gap = true; \
				  __gap_version='0.1'; \
				  __gap_device_model='%s'; \
				  __gap_device_version='%s'; \
				  __gap_device_uniqueid='%s';",
				  [[[UIDevice currentDevice] model] UTF8String],
				  [[[UIDevice currentDevice] systemVersion] UTF8String],
				  [[[UIDevice currentDevice] uniqueIdentifier] UTF8String]
				  ];
	//NSLog(jsCallBack);
	[webViewLocal stringByEvaluatingJavaScriptFromString:jsCallBack];
	[jsCallBack release];

}

I’m simply access the uniqueIdentifier property of Cocoa’s UIDevice class.

To be able to access this paramter in your javascript, jump into the gap.js that you should be loading in your iphone web app, find the Device.init function, and replace with:

    init: function(model, version) {
        try {
            Device.available = __gap;
            Device.model = __gap_device_model;
            Device.version = __gap_device_version;
            Device.gapVersion = __gap_version;
			Device.uniqueIdentifier = __gap_device_uniqueid;
        } catch(e) {
            alert("GAP is not supported!")
        }
    },

Voila! You can now access the client iphone’s unique identifier via Device.uniqueIdentifier in your javascript.

Next up – figuring out how to access the keyboard through the UIWebView :X

PhoneGap – Native iPhone Apps Running your HTML, CSS, JavaScript Code

21 Aug

Stumbled across phonegap – a project that allows you to publish a native iPhone app that simply acts as a pass-through to your web application of choice.  The best part is, you can tap into some of the core frameworks of the iphone SDK via javascript, i.e. you can tap into the Core Location framework, Acceleration, etc, etc! Hats off to the developers of this project. It’ll make my life a whole lot easier.

Step 1: Develop a website on the stack of your choice. Better yet, use the iUI library to develop a website that looks and feels like a native iphone app.

Step 2: Download phonegap from github and open the project in Xcode.  Simply edit the file called url.txt in the Resources folder to point to the URL of your iphone app. Compile and run and you should see your website appear.

Step 3: To access the SDK libs, simply use their function calls:

     getLocation();

     // automatically calls this callback
     gotLocation(lat,lon) {
          // do awesome stuff with google maps, etc, etc.
     }

Check out more information on their google group.

Interviewed in the MIT Technology Review

19 Aug

Figaro Interactive was recently Interviewed by the MIT Technology Review for our Google App Engine site, Brave New Fiction.   It’s a nice article on App Engine and what it means for web development in the coming times.

Web App Writers: Rejoice, Beware

Software developer Brit Gardner, cofounder of Dallas-based Figaro Interactive, tested App Engine’s capabilities by beginning work on a demo application soon after the service came out. Though he didn’t know Python, the programming language App Engine requires, he says he was able to build his application in the space of a few days. Gardner says that he sees App Engine as significantly different from Amazon Web Services, in that it’s a framework for application development, rather than merely a place to rent processing and storage ­capacity. He says that his site isn’t close to hitting Google’s page-view and storage limits, and he doubts that many other sites will be, either, since there are a lot of sites out there and only so many users.

A Review of Mint.com 3 Months In

18 Aug

Let me preface by saying that most of my friends and family think I’m crazy.  Partly because I spend almost every waking moment with my fingers on, or in close proximity to, the home-row keys; partly because I quit a nice job about a year ago to start a web technology company (did I mention my degree is in Mechanical Engineering?); and partly because I sign up for and use all these new-fangled, never-heard-of, web-based services that sometimes I even have a hard time explaining what they are or why they are useful.

With that frame of reference, it’s easy to understand why some of my friends think I’m crazy for using Mint.com.  It’s a web-based personal finance company that leverages a slurry of leading edge web technologies to deliver a rich and more convenient money management experience.

To take advantage of this convenience, you must trust Mint.com enough to give them your account information for every financial service you want them to track.  And, if you want the complete, unfiltered experience, this means you give them the lock and key to your entire financial kingdom.

Scary, huh?  Well, a lot of my friends and family think so.  But, that’s why there’s people like me – risking life and limb to try out these new services, getting our hands dirty, getting stung so you don’t have to, jumping through… well, you get the point.

A lot of these services I use I don’t speak very highly of to people that ask me about them, or worse I don’t care enough to talk about them at all.  After a few months of using Mint.com, I felt compelled enough about the service to say: use it.

If you’re worried about reputability, here’s a couple of items that might or might not help:

  1. They won the TechCrunch 50 last year.
  2. Some schmucks thought enough of them to give them $17 mil in financing.
  3. They have a partnership with the Motley Fool.
  4. They can connect to a bajillion banks – you don’t get that kind of access for long if you’re shady or insecure.

If you can get past the giving-out-your-information part, here’s why the service is great:

  1. All your finances in one place.  This is huge for me.  I don’t want to spend 30 minutes logging into different online bank accounts, opening different tabs, remembering passwords, doing math to calculate net worth.  Your Mint.com account has all this information behind one account log-in and it’s presented clearly and succinctly, which brings me to…
  2. 99.9% of online bank user interfaces suck. Either because they muck up the interface trying to hawk you their fee-based services, or they just don’t understand usability, most online bank interfaces suck.  They are slow, repetitious, and useful information is usually deeply nested in the slowness and repetitiousness!  Mint’s UI takes advantage of a lot of newer web technologies.  AJAX for live updates to the account, healthy use of javascript for sortable tables and tabbed panels, Flex/Flash for interactive graphing, etc.
  3. The better interface translates to a better understanding of your situation. In my opinion, this makes a big difference in your financial responsibility.  A lot of people I know don’t know what their complete financial situation just because they are too lazy to put all the pieces together!  I know I’ve started checking and understanding my finances more often just because it’s so damn easy.  Previously, I would log into my different accounts and update this amazingly crafted spreadsheet that would crunch numbers and spit out graphs.  It worked great except for the whole me-having-to-update-it part.  I did it maybe once a week?  When it’s all done for you like on Mint you just plain use it more – it’s that simple.
  4. They can connect to so many damn banks.  And it’s all done behind the scenes.  A couple of other services I used relied on these browser plugins that were clunky, recorded your actions, and didn’t work half the time.  I don’t know enough about Mint to understand how they are tapping into all these banks – do they have deals cut with some of them?  Do they have pre-recorded scripts for all these banks?  I don’t know and honestly I don’t care that much – it just works.
  5. Not just banks, investments and loans too.  I’ve set up my IRA and Car loans on Mint as well.  Great way to track something daily that I usually only tracked once a month if I was lucky.  It’s also great to have these long-term finances available because they go into calculting your net worth.  Do most people really know their net worth, not just what’s in their checking account?  I submit that most people don’t but they probably should.
  6. Categorizing transactions is a breeze.  This also goes a long way towards increasing a person’s financial responsibility.  If you can put your transactions into accurate buckets, it’s dead simple to identify where you’re spending too much or where you can trim the fat.  Now, actually taking action is the hard part.

There are some things that can be improved:

  1. When you log into your account, Mint begins the fetching of data.  While much more streamlined than other services, it’s still a pain to sit there and wait while a rotating ‘wait please’ graphic  bores into your soul, scraping an almost unnoticable chunk of your sanity from your psyche every second.  Or is that just me?  Most people I know check their finances at the same times every day.  If there were a way to tell Mint to fetch the data at a given time during the day so it’s immediately available, that would be great.  If this already exists, it needs to be more prominent!
  2. One of the primary graphs on the account page is your ‘budget’ bar graph.  Mint presents a bar for each of about 5 or 6 categories of transactions for the current month.  These represent what percentage of your budget for those categories you’ve spent so far this month.  There’s also a ‘total budget’ bar at the bottom that’s just the sum of all the categories. This is a nice feature and somewhat useful, but some of the categories don’t fit into this model very well and throw off the usefulness of the total.  For instance, most of my Utilities come all at once – at the end of the month.  So, until the last day of the month my ‘total budget’ is in the green – I’m doing great!  Then, when the utilities hit, my total expenses jump up sometimes well over the budget for that month.  This negates some of the usefulness of the chart as a steady gauge of expenses.  I don’t know the solution to this problem.
  3. Also, Mint.com makes money by giving you ‘Ways to Save’.  These are simply offers from financial institutions that pay Mint to present these to you.  I have no problem with this business model, and more power to it.  But, they definitely need to work on the content of the ‘Ways to Save’.  Most of these extend reality by saying that because I’ll get double the rewards points for every milk purchase if I switch to X service that I’ll save Y amount of dollars.  Oh, and by the way the new interest rate on X service is a lot more than your current one, but we’ll just forget to use that in our calculation.  Come on.  Give me something real to work with.  This may improve over time as more financial institutions start presenting real offers.

Bottom line though, if you’re looking to give yourself a kick in the ass in the financial responsibilty department, definitely check out Mint.com.  It’s a well thought out, well implemented, and well polished service.

Braid Sountrack

17 Aug

Found this via joystiq, via mudron’s comic.  I love the music in Braid, and it has the rare quality of being nice to listen to outside of the game context, unlike other game soundtracks I really love.

Braid Soundtrack on iTunes