Archive for the 'Tools and Utilities' Category

Winning at the shell game: iPython on Google App Engine

iPython is an awesome extended Python shell that gives you goodies like tab completion for instances, history tracing (so you can easily copy interactive sessions as doctests), etc. And, if you install it, your Django project on Google App Engine will automatically start using it instead of the regular python shell when you use ./manage.py shell.

To install iPython on OS X Tiger (yes, my Leopard discs are still safely in their box since I downgraded and I don't see any reason to bring them back out yet), I followed the following steps:

  1. Download the latest iPython from the iPython distributions page (ipython-0.8.4.tar.gz)
  2. Untar it, cd into the folder
  3. As per the instructions on the iPython download page:
    python setup.py build
    sudo python setup.py install
  4. To test it out on my Google App Engine/Django project, from my project folder: ./manage.py shell

(Note: The docs mention that you need to have readline installed on Mac OS X in order to use some of the features like tab completion and syntax highlighting. It just worked out of the box for me on OS X Tiger 10.4.11 -- I'm not sure if I had installed readline at some point or whether it was just there. Check out these instructions if you're having trouble.)

Once you have it installed, try out the cool code completion:

from my_app import models
models.

Press ⇥, and you'll see a list of all your models. models.my_model. ⇥ will show you the properties for that model and so on.

To create doctests, simply enter your test instructions in the shell and then type hist -n to get a dump of your history without line numbers that you can copy and paste into your doctest.

You can press ⌃ P and ⌃ ⇧ P to interactively bring up the previous and next commands in the history. If you've typed a bit of the command before doing this, it will filter to show you only those commands from your history that match the text you've entered.

You can also access the system shell without leaving iPython by preceding system calls with an exclamation mark. !ls, for example, will show you a listing of the current working directory.

And there's much more you can do that you can read about on the iPython documentation (or just type ? in the iPython shell itself and browse the docs interactively).

Check out iPython, it's yummy!

I found out about iPython from an excellent blog post by AkH on useful tips and good practices for Django projects. Thanks, dude!

Verifying SHA1 checksums on downloads

If you download development tools you will probably have come across SHA1 or MD5 signatures for downloads in the past.

It's very easy to test the download to make sure that the checksum is valid. For MD5 signatures, you simply type:

md5 name_of_file

And for SHA1 signatures:

openssl sha1 name_of_file

However, both those methods require you to manually verify that the signatures match. Which is a pain.

I was downloading the latest Google App Engine SDK release (version 1.0.2, which was released two days ago apparently) when I decided to whip up a very simple Bash script that verifies SHA1 checksums for you. I'm not sure if there's existing functionality that does this for you but it was simple enough to write.

Save the following script as sha1 and set it as executable to use it (chmod +x sha1)

#! /bin/bash

hash=$(openssl sha1 $1)
if [ "SHA1(${1})= $2" = "${hash}" ]; then echo "Key is valid."; else echo "Key is _not_ valid!!!"; fi

The script is very simple and doesn't do error checking for arguments, etc.

To use it, simply type:

./sha1 name_of_file SHA1_KEY_FROM_WEBSITE

So, for the latest Google App Engine SDK release, you'd type:

./sha1 GoogleAppEngine_1.0.2.dmg 105506c6c75badfaecfe912929ffb724b5d349b1

And it should respond with Key is valid.

FlashBrighton Big Day Out Schedule in Flash Lite

Yahoo! Hackday Schedule for mobile.

I have no idea why I made a Flash Lite schedule for FlashBrighton's Big Day Out when I should be working but here it is! (It updates the current session based on the actual time so you should see the highlights once it's past 12.30pm.)

Download it and transfer it to your Flash Lite 2.0 or 2.1 capable phone (15kb).

Coming up: Mock data support and better default argument handling in the SWX Service Explorer

I'm currently working on a stealthy little pet project of mine that involves creating a PayPal Website Payments Pro API in SWX. A couple of the methods in the API require quite a few arguments (all the billing-related fields for processing a credit card transaction, for example) and I quickly got sick of having to enter mock data manually in the SWX Service Explorer to test and debug methods calls. (This is one scenario where Transfer Object support would be helpful but adding that right now would complicate things too much.) So, to make things easier for myself (and hopefully some of you as well), I've added mock data support (both static and dynamic) to SWX PHP and the SWX Service Explorer.

Using mock data

In the SWX Service Explorer, methods that have mock data will have a "Use mock data" button enabled.

Clicking the button will fill the arguments with the mock data, as the following screenshot demonstrates.

Creating static mock data

The first way to create mock data is to include it in the JavaDoc-style comments in your service classes. Place mock data at the end of the comment and surround it in square brackets.

/**
   * Do a direct credit card payment.
   *
   * @param (str) A unique order id [12345-12345]
   * @param (str) Credit card number [5105105105105100]
   * @param (str) Card type (Visa, American Express, Mastercard, etc.) [Mastercard]
   * @param (str) 3 or 4 character Credit Security Code [123]
   * @param (number, 4 digits MMYY) Expiry date [1209]
   * @param (number) Amount to charge [2.50]

This is a quick and easy way of adding mock data to a method. The recommended practice here, when possible, is to place enough mock data in a method to allow the user to make a successful call via the SWX Service Explorer. This is in keeping with the SWX philosophy of making things Just Work and Show, Don't Tell.

Generating mock data

The new mock data feature does not limit you to static mock data. You can also generate dynamic mock data with a little bit of PHP.

To generate mock data for a method called doDirectPayment(), for example, you can include a private method called _doDirectPaymentMock() in your service class. This method gets called (and passed an array of any static mock data for the method, which you can either add to or ignore) by the service explorer. It expects an array of mock data (one for each argument) to be returned as per the following example.

function _doDirectPaymentMock($mockData)
{
    // Generate a random order number
    $orderNum = '"'.date('ymd-H').rand(1000,9999).'"';
    $mockData[0] = $orderNum;
 
    return $mockData;
}

In the above example, the order number needs to be unique so it's generated by code but all the other default values are statically obtained from the comments.

Update: In the latest version of the SWX Service Explorer in SVN, the dynamic mock data now updates every time you press the Use mock data button.

Default values for optional arguments

I've also modified how default parameters are handled in the SWX Service Explorer. Previously, they were handled Really Badly (tm). i.e., they were basically ignored. Now, if your method has a default value defined, it is displayed in the SWX Service Explorer by default. This is true even if you define the default value as a constant (in PHP4, you must stick to the CONSTANT_NAMING_CONVENTIONS for constant resolution to work correctly.)

(Note that in PHP5, you must place all optional arguments at the end of your method signature. This is a best practice to follow in any case.)

The following screenshot shows how default values for arguments are handled in the new service explorer:

Currently, the changes outlined in this post are only available from the trunk of the SWX Subversion repository. I'd appreciate it if you guys can test it out. After further testing, it will be included in the next SWX PHP release.

Visor now works on Leopard

Visor gets a Leopard upgrade!

Things are beginning to get back to normal on Leopard for me now that my beloved Visor has a Leopard version.

Visor is a SIMBL plugin that gives you access to a Terminal window as a Quake-style console that drops down from the top of your screen. And the Leopard version supports tabs! Woot!

A big thank-you to Tim Robles for alerting me to the Leopard release in the comments of my previous Visor-related post.

A YSlow tip for speeding up Viddler embeds

YSlow is a wonderful Firebug plugin from Yahoo! that helps you optimize your web sites by analyzing them according to 13 rules for high performance web sites as written by the Yahoo! Exceptional Performance team.

I just started playing with it on my site and one of the things it pointed out was that the default Viddler embed URL for the SWX screencast was redirecting to a different URL. Removing that redirection should speed things up according to Rule 11: Avoid Redirects and you should be able to apply this to all embedded Viddler videos.

Simply change the URL that is given to you by Viddler from the form

http://www.viddler.com/player/ad098fea/

to

http://www.viddler.com/flash/publisher.swf?key=ad098fea

and you'll remove the redirect and speed up the loading of the video.

I do hope that Viddler modifies the code that their Embed feature creates to use this direct URL and, also, to provide the option of embedding the video at its original size without your having to calculate it yourself.

Changing your password in the TextMate Blogging Bundle

I love the TextMate Blogging Bundle and write nearly all my blog posts using it. If you haven't seen it, check out this screencast (if that doesn't convert you, nothing will!) :)

One thing to note is that if you change the password on your blog, you'll need to update the password that the blogging bundle uses. I spent a few minutes wondering how to do this (going to "Setup Blogs", etc.) until I realized, *doh*, that I needed to update the password in Keychain (/Applications/Utilities/Keychain Access.app). It's actually nice to have all those passwords in one place and I think it's the first time I've had to use it to change something. Hey, it's just coming up to a year that I've had my Mac (and yes, I still love it on a daily basis!) :)

Hope this saves someone else some head scratching.

The best Mac SVN client

Seb just asked for Mac SVN client recommendations on Twitter and I realized that I hadn't blogged about Syncro SVN. It's the only SVN client I've found that is actually usable on OS X.

PC users are spoiled with the excellent TortoiseSVN but the few clients that exist on the Mac, well, how should I put it, umm, suck. Badly. Except for Syncro.

Check out Syncro SVN. Personally, though, I still prefer the command line! :)

How to get older versions of MAMP

MAMP stands for Macintosh, Apache, Mysql and PHP. It also happens to be my development server of choice and what I'm using to test SWX on. The great thing about it is that it has a very simple installation process (just drag the app to your Applications folder) and that it is entirely self-contained. It doesn't mess with anything on your system and if you want to, you can just erase the MAMP app and it's gone. (This is how all apps should work.)

Anyway, since I want SWX to work on as many versions of PHP as possible, today, I tried to track down a version of MAMP that contained a version of PHP that I know is causing problems (5.1.2). I found it difficult to track down older versions of MAMP so I thought I'd outline the process here for anyone else who might want to test their apps with different versions of PHP, Apache, etc.

Downloading an older MAMP release is a three-step process:

  1. Go to the MAMP releases page and find the release that you want. Note down its version number.
  2. Go to this search page on SourceForge and enter the version number of MAMP that you want.
  3. On the results page, click the appropriate link to download that version of MAMP.

If you are going to test with multiple versions of MAMP, it would make sense to move your htdocs folder somewhere outside the MAMP app and set your MAMP Document Root (under Preferences -> Apache) on your various MAMP installs to point to this one place.

There you go: Now you have a simple way to test with multiple versions of PHP, etc.

AsProject: rails-like toolset for ActionScript

AsProject Video Demo Screenshot

Luke Bayes and Ali Mills of asunit fame just released AsProject, an open source ActionScript development toolset that streamlines the open source development process by giving you a rails-like experience.

Check out the AsProject demo video.

This is very cool. I must set aside time to see how Arp can be integrated into this.






Bad Behavior has blocked 0 access attempts in the last 7 days.