Say happy new year!!

Here we are, like every year, at the end.
Unfortunately this year I can’t be abroad for holidays like in the past (taking pictures of other countries’ beauties :)). I will be on holidays later, in February, in the United States for 2 weeks.
So, I hope everybody will have an unforgettable new year’s eve.

Ok, I finish this useless post with a video I just discovered on YouTube, a video of 1999 (when internet was still a mystery for me), and this is more a gift for me and for my friends who spent that night together with me 🙂

httpv://www.youtube.com/watch?v=MEru-Ux0OEU

Merry Christmas

Ok, everyone is sending all kind of wishes by mail in these days and now it’s my turn!
So, Merry Christmas to everyone!
I hope you will spend beautiful days during your holidays and come back extremely happy
Rõõmsaid Jõulupühi ja Head uut aastat
Wesolych Swiat i Szczesliwego Nowego Roku
Feliz Navidad y Próspero Año Nuevo
Joyeux Noël et Bonne Année!
Fröhliche Weihnachten und ein glückliches Neues Jahr!
 

P.S. I hope you like the new site style I’m still modifying (the header photo is a pic I’ve taken near Perugia, where I lived for 4 years…)

Flex Cookbook

It’s online the Flex cookbook beta in the Adobe Developer Center.
I’m a big fan of the cookbooks since I first bought the PHP cookbook and later Python cookbook. It’s probably the most simple way to learn with real examples of common problems.

As written in the Flex cookbok beta site, the in the Flex cookbook you can:
– Find solutions to your Flex-related problems.
– Publish solutions you have created for the greater Flex community.
– Comment on solutions created by others.
– Opt for a chance to have your solution published by O’Reilly.

I hope it will grow up with more and more contents!

AMFPHP 1.9 changes and future plans

Recently Patrick released a new testing version of AMFPHP which supports the Flex2 AMF3 object encoding.

Some changes:

$this->methodTable is DEAD. All methods in /services are now considered remotely accessible, unless you set them to protected or private (PHP5) or start the method name with an (_)
– Returning a mysql_query will now return either an Array or an ArrayCollection depending on the setting in gateway.php
– browser now brings up the brand spanking new Flex 2-based service browser

This is a testing version since it has still a lot of limitations and it has been tested only on PHP5. I see the post today and I haven’t tested yet…
You can read here for a detailed list of changes

Moreover Patrick plans to add to amfphp the Flex Data Services (read what they are). In this post he got a brief explanation about flash player/FDS communication and ask for developers to help him with the developement of FDS in amfphp (you might need a copy of charles).

ActionScript Parsing, the YACC revenge :)

After my first attempts with ANTLR scanners in python/java I decided to start back with Bison/Flex again to see the difference in performances.
So first I need to wrote from scratch the grammar/lexer files using only the ECMAScript 4 specifications and much patience (the elastic grammar file help me a lot too).

After finishing a first version of the parser I tested it on the same file (75Kb actionscript file) which both java and python parsed in more than 1 second.
The result was unbelievable: 0.02 seconds for that file!

Then I tested it on multiple files, and for about 320 files of the whole adobe corelib library it took 220ms

Ok, the parser it’s not yet complete and doesn’t care about regexp and xml syntax, but its performance convinced me enough…
Now, the next step is to finish and test the parser and finally create a python library using pyrex, then a benchmark test again.

If someone is interested in testing the parser, download it (use “parser –help” form the command line for usage help), but remember this is only a first test.. not really helpful right now (I just wanted to share my text/parsing experiences).

An experience with antlr, java and python

I just wanted to share a little experience with generating an AS3 parser using antlr and python.
I was trying first to create the parser using GNU Flex and Bison in C, probably the best way for a very performancing parser.
Yeah, that’s right.. but looking at the antlr syntax I realized that’s easier and easier.
Moreover I start using this very useful eclipse plugin for antlr debugging which made my life easier!

The grammar file I created is a compromise between the asdt grammar file and the ECMA-262 grammar specification.

Once finished working on my eclipse project I’ve managed to parse succesfully all the adobe corelibs files using this java test file:
package org.sepy.core.parsers.as3;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import antlr.CommonAST;
import antlr.RecognitionException;
import antlr.TokenStreamException;
public class Application {
public static void main(String argv[])
{
if(argv.length > 0)
{
File file = new File(argv[0]);
if(file.exists())
{
FileInputStream is = null;
try {
is = new FileInputStream(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
AS3Lexer L = new AS3Lexer(is);
AS3Parser P = new AS3Parser(L);
try {
P.compilationUnit();
} catch (RecognitionException e) {
// TODO Auto-generated catch block
System.out.println(" line=" + e.line + ", column="+ e.column);
System.out.println(e.getMessage());
e.printStackTrace(System.err);
} catch (TokenStreamException e) {
// TODO Auto-generated catch block
System.out.println(" line=" + L.getLine() + ", column="+ L.getColumn());
System.out.println(L.getGuessInfo());
System.out.println(e.getMessage());
e.printStackTrace(System.err);
}
CommonAST.setVerboseStringConversion(false, P.getTokenNames());
CommonAST ast = (CommonAST) P.getAST();
System.out.println("Tree:");
System.out.println(ast.toStringTree());
}
}
}
}

Ok, done that I decided to export the grammar file for python (thanks to antrl python export feature).
Everything works fine also for python, but I realized that the python script were so much slower than the java one!
import sys
import antlr
import AS3Parser
import AS3Lexer
L = AS3Lexer.Lexer(filename);
P = AS3Parser.Parser(L);
P.setFilename(filename)
try:
P.compilationUnit();
ast = P.getAST();
except:
pass

On a 75Kb actionscript file the python script took about 7 seconds to run, while the java application only 2 seconds. I know python interpreter caould be slower than many other languages, but I never thought so much slower.
So I run the python hotshot profiler to see which could be the bottleneck in the python script and I found most of the problems were due to unuseless antlr (the python module) method’s calls.
After making corrections to the antlr.py file the same script took exactly half of the time. Now 3 seconds. Wow 🙂
But not fast enough.
So I enabled for the antlr python script psyco module and this time the same script took only 1.6 seconds.
Now the python script is fast enough, even if I’m sure I can make more optimizations in the antlr module…

Apollo tour continues…

Apollo & Flash9 (codename Blaze) tour continues, next time will be in Rome, Italy on 1st of December.
Mike Chambers and Mike Downey will be the speakers for this event organized by actionscript.it community.
During this event will be also explained Flex Data Services and AS3.
for more info about this event see the original entry @actionscript.it, also for informations about the event location.

Red5, first thoughts

As I promised myself, I started to spend some of the time in testing red5 since I’ve read the about the 0.6RC1 release.
Unfortunately I wasn’t able to run it on my Windows Vista so I try it on an older Windows XP. Once unpacked the installer I first tested some of the example applications boundled, everything worked fine.. cool, nice, great project indeed!

But then I wanted to migrate one of my FCS2 projects to Red5 in order to test “the real world”.
Ok, I need to write in Java? (there’s Python support, but it’s Jython) Cool.. I never seen Java, I thought it was a monster with eight heads 🙂
Got the first Java editor I found on the net, IntelliJIdea (what a wonderful editor indeed! much expensive, but really cool), and started with headache..
But at least, for a newbie like me, it seems to me like editing ActionScript3 files, so it wasn’t so difficult to make things running.
I’m still “trying” to re-write the application (with minor changes also in the flash files) but I managed to make remote sharedobjects, streams and remote calls running like in the FCS2 original application and I’m so happy 🙂

I just encounter a couple of time a Windows blue screen error while getting webcam streams (I need to make a snapshot next time) and some human unreadable java exceptions (It’s indeed a my fault) but I think it was a positive beginning after all.
Great great compliments to red5 developers!