5 1/2 old site source

Posted on Monday 23 April 2007

As I’m retiring I’m doing a little cleanup of some old projects and putting them on a backup drive. I’m starting to realize that there’s a lot of stuff I’ve been meaning to open source but never got around to or got distracted. So I’ve decided to post it all here so everyone can enjoy it. Expect a barrage of random files over the next few days/weeks. Everything is under an MIT license.

You might remember the old 5etdemi.com homepage. The source is pretty messy, but there’s some neat ideas in there I think, like the history manager, click tracker that links to amfphp and some of the formulas for the transitions. Here’s the source.

You may have noticed that there’s a link on the right for donations. Use it. I’m going to get poor before I get rich with this neuroscience thing. Seriously, I am expecting my revenue to drop by about 2/3 for the next year, so if you can give a little love back in the form of cold hard cash, it’d be appreciated.

Filed under: News
I’m retiring

Posted on Friday 6 April 2007

The short: I got myself a summer job at the Montreal Neurological Institute, which I am hoping is the start of a brilliant career in neuroscience. Then I’m finishing my undergrad and hopefully doing a PhD in the field, and with the amount of work I have coming up, I don’t think I’m going to be able to keep up with the changing world of Flash, and besides, I’m ready for a new challenge. I will be finishing the 2 chapters in the Open Source Flash Development book, and releasing amfphp 2 (you can thank Apress for that one!), and that’s going to be the end of it. I might keep one client so I don’t get too much into debt, but I won’t be updating the blog anymore, and I will step down from the head developer position for amfphp. If anybody wants to take care of amfphp, then please drop a comment or send an email on the list. Also if anyone wants to buy the 5etdemi domain or keep up the blog, let me know, as I’m thinking of bringing the the site down.

The long: Just six months ago, I was ready to fill in John Grden’s rather large shoes as interactive director at Blitz. What the heck happened in 6 months? A lot of things. I don’t want to get into a self-apologetic rant as to why I’m so awesome, but I think the path I took is entertaining and instructive enough to merit being told, so here we go. When I was a teen, I picked up a copy of Gamepro that had a guide on HTML in it. I didn’t have a computer back then, so I just learned the thing by heart until I got access to one when I first got into Cegep. Then I learned JavaScript, Perl, and got my hand on a cracked copy of Flash 4. Those were the days of Flashkit, I didn’t have much of a social life back then, so I flashed for fun, never for money. Then college came, the booze, the women, Nietzsche, so I had a lot of other things on my mind then Flash, and stopped programming. A couple years later, somebody contacted me regarding one of my old movies on Flashkit, and offered money so I could modify it, so I did. The person in question was a member of Juvenal Habyarimana’s family, who you might remember as the guy who got shot in Rwanda right before the genocide started. I wasn’t exactly fond of working on a brutal dictator’s apologetic biography site, but back then I was dirt poor, and it was good money, so I accepted after consulting friends who I would as unscrupulous. Some of the work I did I posted on actionscript.org as open source, and that got me some contracts, and a few months later I started a one-man business now known as 5 1/2. I didn’t do that well until I stumbled upon an almost dead project called amfphp. I offered a patch for it on the mailing list, and a week later I was basically handed the keys to the project. That got me on the map, and I got to work on tons of interesting projects.

So Flash gave me financial independence, I got to bike around Europe, hitch-hike around BC, and live all sorts of crazy adventures without ever worrying about money. After coming back from Europe, I was not sure I wanted to get back into school, and I flew to LA for a job offer at Blitz, John Grden’s old job as Interactive Director. The job was great, but LA wasn’t for me, I got tired of freelancing, so I settled on a job in Montreal. I quit the job after three weeks and then sat at home for about a month, feeling depressed. I had always had ups and downs, but I figured it must have had to do with stress, or pressure, but it happened to me in Europe, in BC, and now in Montreal when I was basically on vacation, had no stress, and had money, so I had nothing to worry about. I suspected that I might suffer from manic depression, based on my experiences and my family’s pretty bad mental health history. My sister, who’s 7 years older than me, became an IV cocaine abuser, a prostitute, and ended up having an aneurysm in the right parietal lobe, about the only thing that could have slowed her down. So while I saw doctors and got diagnosed I had to stay in Montreal, so I took another semester at McGill, as I figured it’d be better than staying at home doing nothing. It worked out quite well, and I decided to quit fucking around, finish my degree and eventually do a PhD in computational neuroscience. In the end, I got diagnosed with type I bipolar disorder, and I’ll start the medication in a couple weeks, which is I guess a good thing if I want to keep focusing instead of bifurcating and making random stupid decisions while I’m high or low. I wish I had known earlier, as I really screwed some clients over when I was either high (agressive, impulsive) or low (couldn’t set my fingers on the keyboard), and dropped projects without warning or came up with all sorts of excuses for being late.

So, anyways, it’s been a rocky road, I’m 24 and I still haven’t finished my degree, but I got a book deal, became head of a successful open source project, worked on awesome projects, traveled, read a ton of books, made a lot of friends and enemies and slept with an inordinate amount of women, so I guess I got a lot of life experience out of it, something that apparently doesn’t come from book learning. I’ll be working at the MNI this summer, hopefully we’ll be able to deflate some of the more fundamentalist views on Bayesian inference in motion processing in the primate visual cortex. I’m hopeful it’s the start of a brilliant research career, I started at the bottom in Flash only a few years ago and got reasonably close to the top, so I hope I’m not overly optimistic on this one.

I don’t want to get into a fight as to the future of Flash, but I will refer to Guy Watson’s post; Flash is just a tool, one that might get replaced in the near future, you shouldn’t base your life around it, and there’s a lot of things more important than technology and programming. I wish everyone would use the energy and time put into defending Adobe and Flash and invest it in something more useful, like helping out their fellow man, but I fear that’s wishful thinking. Finally, thanks to everyone who have supported or inspired me, who are too numerous to name, but I’ll try:

Andrew at K1 marketing who has my nicest guy in the world award for helping me out when I was stuck in Vancouver, Will who has been a steady victim of my mood swings, everyone who gave me a place to stay while I was in Europe, Micael, Tink, Thomas and Sonke, fellow bloggers Aral Balkan and Jesse Warden who I greatly admire despite our differences, anyone who’s been a victim of my sometimes not-so-subtle personal attacks, and Robert Penner and Keith Peters for inspiration.

Filed under: News
SWX: still a bad idea

Posted on Friday 30 March 2007

Some more comments on the SWX controversy, after Aral’s rebuttal of my previous post. First off, just to be absolutely clear, I am not bashing Aral, or anybody working on SWX itself. Aral and I have have collaborated on amfphp, and are coauthors (among several other very talented people) on a new open-source Flash book, and we get along quite well, thanks ;) I’m also not saying that SWX is a stupid idea; in fact the idea behind SWX is quite clever, but the implementation is not going to yield any net benefits for the community (more on this later). As for my statement that SWX is a hack, I stand by that, and I think other people agree. But of course, you could argue that once a hack is sufficiently abstracted away in classes, it doesn’t have the disadvantages normally associated with hacks, and that makes it a valid solution. Unless I am misunderstanding Aral’s argument, I think that’s his point.

But the main advantage with SWX, as outlined by Aral, is simplicity. The code on the homepage is indeed very simple and lightweight. However, once you start abstracting away this simplicity, you’re going to end up with what is more or less a library. For example, if you wanted to be able to use SWX as you would use Remoting, using callbacks, then the abstracted code would have to: create a movieclip to absorb the loaded data, poll that thing, fire events, do cleanup. If we include batching, then it would have to set up a timer to do the job automatically. If we include RecordSet support, then there would have to be a RecordSet class in the first place, which would probably be as large as the current Remoting RecordSet class. So in the end, once SWX is sufficiently abstracted away in a library, that library which does everything Remoting does is going to be as fat as the Remoting library. So the advantage of simplicity falls through. On the server-side, once SWX starts dealing with batched calls and serializing RecordSets and the like, it’s very likely it’s going to be as fat as amfphp. So we’re going to end up, with a lot of hard work, with something completely equivalent, in size, speed, and every other variable to Remoting. Now amfphp has only now started reaching full maturity, and it’s already 3 or 4 years old. If the past is any indication as to the future, then SWX will likely take just as much time to reach the level we’ve reached in amfphp.

So my question is: if SWX will eventually do all that Remoting does in an equivalent fashion, is it worth spending all that time to do it? We’re talking about creating an AS2 abstraction layer (easy), AS3/mxml abstraction layer (harder), recordset support on the server side (simple but a pain to test), do all the testing, then there’s a discovery interface (service browser), documentation, support, and so on and so forth. It’s been a recent goal of mine to create the Universal Remoting group, which is aimed at reducing duplication of code and documentation across Remoting projects to get less bugs and better products that work equivalently on every platform. One of the main goals is to create a Flex 2 based service browser that will work across (so far) amfphp, SabreAMF, AMFRUBY and Fluorine. The Flash community has traditionally been balkanized into various equivalent projects where some die off, some survive, and a lot of time and effort is wasted in between. I think Aral has done a great job of letting projects talk to each other and get themselves known with OSFlash. But I don’t want to see the community fragment and duplicate effort over several equivalent projects.

Aral has done some very nice work with the Flex SWX call inspector (or whatever it’s called), and I’d definitely like to see that work with Remoting to replace the old NetConnection debugger. Similarly, having a simpler abstraction layer for Remoting in AS2 for smaller apps would be great; if someone wants to take a stab at that, please do. But duplicating efforts is going to get us nowhere. As Lorenz in the wonderful book On Agression argued, while competition between different animal species yields positive evolution, intra-species competition yields net negative evolution, at the cost of survival for everyone.

Filed under: News
SWX: a bad idea

Posted on Thursday 29 March 2007

My fellow flasher Aral Balkan sent me an email today about his new project, SWX. Basically SWX is a way of sending and receiving data from and to PHP that is very similar in principle to, say, amfphp. Instead of using the native NetConnection object, however, SWX relies on loadMovie, and its ability to send and receive data on a remote server. Instead of sending the data as AMF, the data is sent as PHON, which is very similar in essence to JSON. Instead of receive an AMF packet, you receive a swf which contains variables. As much as I love and respect Aral, I must say, I find SWX a bad idea.

Now my first point is that SWX reinvents the wheel, and for no good reason. Let's list out the various ways to do asynchronous data communication in Flash. We have LoadVars, XML, Remoting, JSON, SOAP, XML-RPC, and PHPObject. One solution seems more than enough for this very simple tasks; adding another one to these 7 seems like a complete waste of time. Of course, it wouldn't be if in fact SWX gave some mighty good advantages over all the other solutions. To my knowledge, however, the only positive advantage to using SWX is the ability to use getBytesLoaded and getBytesTotal, which isn't available, in, say, Remoting.

The second point is that this approach, while clever, is a hack at best. If you look at the sample code on the webpage, which I will reprint here:


org.swxformat.PHP.init();
 
// dataHolder is a movie clip on Stage.
dataHolder.className = "Simple";
dataHolder.method = "echoData";
dataHolder.data = [ 'data', 'to', 'send' ];
 
dataHolder.loadMovie("http://localhost:8888/swx/trunk/php/swx.php", "POST");
 
// A very simple check for returned data
function onEnterFrame()
{
        debug_txt.text = "Data: " + dataHolder.data;
}
 

The first thing you'll notice is that dataHolder is a movie clip on Stage. That means that either you must place this empty movie clip on stage manually, or you have to use createEmptyMovieClip first. Of course, if you do the latter, you have to think about depths and whatnot. The second thing you'll notice is that there is an onEnterFrame. I thought the whole reason we dropped the use of onEnterFrame for polling a movie clip is that we had all sorts of crazy issues with that, including the difference between 0 and 4 loaded bytes. There's a reason why MovieClipLoader appeared in Flash 7. To my knowledge, MovieClipLoader doesn't allow you to send POST variables, so using that is a no go. The third point is that the PHON serialization that is used relies on a prototype hack, which I will show here:


        // Extend the prototypes of the Object, Array and String
        // classes to add automatic PHON serialization functionality.
        Object.prototype.toString = function()
        {
                var str:String = "array(";

                for (var i:String in this)
                {
                        str += "'" + i + "' => " + this[i].toString() + ", ";
                }

                str = str.substr(0, str.length-2);
                str += ")";

                return str;
        }
       
        Array.prototype.toString = function()
        {
                var str:String = "array(";

                var len:Number = this.length;
                for (var i = 0; i < len; i++)
                {
                        str += this[i].toString();
                        if ( i != len-1 ) str += ", ";
                }

                str += ")";
                return str;
        }

        String.prototype.toString = function()
        {
                // From JSON.as by Trannie Carter <tranniec@designvox.com>
                // http://json.org/json.as
                var l:Number = this.length;
                var s:String = "'";
                for (var i:Number = 0; i < l; i += 1)
                {
                        var c = this.charAt(i);

                        if (c >= ' ')
                        {
                                if (c == '\\' || c == '"' || c == "'")
                                {
                                        s += '\\';
                                }
                                s += c;
                        }
                        else
                        {
                                switch (c)
                                {
                                        case '\b':
                                                s += '\\b';
                                                break;

                                        case '\f':
                                                s += '\\f';
                                                break;

                                        case '\n':
                                                s += '\\n';
                                                break;

                                        case '\r':
                                                s += '\\r';
                                                break;

                                        case '\t':
                                                s += '\\t';
                                                break;

                                        default:
                                                c = c.charCodeAt();
                                                s += '\\u00' + Math.floor(c / 16).toString(16) +
                                                    (c % 16).toString(16);
                                }
                        }
                }
                return s+"'";
        }
                               
}        // end of if
 

So we hack toString in Array, Object and even (gasp!) String. I am not even to bother to expand as to the myriad ways in which I think this is a bad approach, but you can imagine the argument. The fourth issue with this hack approach is that it is not going to work in AS3, either in Flex or in Flash 9. For one thing because you can't hack prototype, for another because the AS3 bytecode is different from the AS2 bytecode.

SWX also had the disadvantage of being impossible to debug in Charles or ServiceCapture. Aral did a nice job with his Flex debugger, but why bother when you have native tools in your hands that do the job really really well. I could go on: SWX doesn't have anything for batched calls, or for typed objects, and I can hardly see how it could be put to use on a serious RIA. You might argue that SWX is not meant to be used in RIAs, it's better for smaller projects, but that's why we have LoadVars and XML. Honestly I really don't see the point.

Now I'm not saying that Aral's code is useless. In fact, having a non-native way to write swfs in PHP is great. But I think that as it stands, SWX doesn't do anything Remoting, or SOAP, or XML-RPC, or JSON doesn't already do, and do very well at that. If this were 2001, I'd be jumping in the air in excitement over this new approach. But this is 2007, and we have better, proven, and standardized tools to do asynchronous data exchange in Flash. Again, why reinvent the wheel?

Filed under: News
amfphp chapter in osflash book - project ideas

Posted on Wednesday 28 February 2007

I'm currently writing a chapter on amfphp in an upcoming book on Open Source Flash to be published at Friends of Ed. Much of the chapter is going to be geared towards mini-projects as I feel amfphp really isn't that complicated and people learn much better with an actual live example than with abstract discussions on architecture and security.

Now the key thing is that I have only about 20 pages left for projects, and I'd like to cover Flash and Flex, so it's going to be tight. There are many aspects I want to make sure these projects talk about: sending mail, saving bitmaps, doing CRUD, authentication, etc. Some ideas that come to mind include:

  • CRUD scenario: something simple, like an address book, simple message board, guestbook, mini-blog, etc.
  • Email form including inline spell check (perhaps using the above address book)
  • "Fun" scenario: perhaps something involving flickr, webcams, drawing or whatever, preferably something that doesn't use AS2 components, and perhaps using ImageMagick or GD...
  • PhpMyAdmin-like app (in Flex)
  • Something involving Treemaps or linked resources, maybe a webpage links analyzer with a graph view or something, in Flex

I could probably write a whole book on just the above ideas, but right now I only have a single chapter ;) So I've narrowed it down to a single "visual shout" scenario with three self-contained projects:

  • Add shout page (in Flash): essentially, a form with name, email and message, in addition to a webcam viewer. There will be a snapshot button for the webcam. Clicking "send" sends the data and the webcam image to the server to be saved in a database, in addition to sending a notification email.
  • View shouts page (in Flash): A series of tiles, with the webcam image, the name and the message underneath it. Includes a paging mechanism.
  • Admin shouts (in Flex): A datagrid with filtering and delete, edit mechanisms. Authenticated.

What do you think? Can you come up with a better scenario given all the constraints? Am I not going over some key aspect of amfphp that you want covered? Can you write the chapter for me while I do my general relativity paper :D ? Comments appreciated.

Filed under: News