Talking about dead projects…

Today I was watching some of the pictures from the last Flex 360 meeting in Milan ( on 7/9 April ) which someone posted on Flickr you can’t imagine my surprise when I saw this photo.

Unfortunately I dont know what they were talking about in the meantime, but for me just watching that picture gave me a sense of melancholy!

But… I don’t think the only advantage of SEPY was the “easy to use”, for what I remember it had tons of useful features..

By the way, are you sure that is a dead project?  🙂

Top Down or Bottom Up for Expression Evaluation ?

Last time I wrote about Top Down parsing, a technique for parsing that can be easilly implemented manually using function recursion.

Today it is time to talk about one of the other ways of parsing, called Bottom Up parsing. This technique try to find the most important units first and then, based on a language grammar and a set of rules, try to infer higher order structures starting from them. Bottom Up parsers are the common output of Parser Generators (you can find a good comparison of parser generators here) as they are easier to generate automatically then recursive parser because they can be implemented using sets of tables and simple state based machines.

Writing down manually a bottom up parser is quite a tedious task and require quite a lot of time; moreover, this kind of parsers are difficult to maintain and are usually not really expandable or portable. This is why for my tests I decided to port bYacc (a parser generator that usually generates C code) and edit it so it generates ActionScript code starting from Yacc-compatible input grammars. Having this kind of tool makes things a lot easier, because maintaining a grammar (that usually is composed by a few lines) is less time expensive than working with the generated code (that usually is many lines long).
I will not release today the port because actually I had not time to make sure it is bugfree and I’ve only a working version for Mac, but I plan to release it shortly if you will ever need it for your own tasks. My goal for today was to compare the speed of the parser I wrote with an automatically generated bottom up parser, to see which is the faster approach.

I created a bottom up parser which is able to execute the same expressions accepted by the expression evaluator I wrote last time. There are anyways some differences that – as you will probably and hopefully understand in the future – that make those parsers really different. Some will be disussed shortly here.

To do that I created a Yacc grammar and some support classes.
The parser grammar is really simple and really readable:
%{
%}
%token NUMBER SYMBOL
%left '+' '-'
%left '*' '/'
%left NEG
%%
program
: expr { Vars.result = $1; }
;
expr
: expr '+' expr { $$ = $1 + $3; }
| expr '-' expr { $$ = $1 - $3; }
| expr '*' expr { $$ = $1 * $3; }
| expr '/' expr { $$ = $1 / $3; }
| '-' expr %prec NEG { $$ = -$2; }
| '(' expr ')' { $$ = $2; }
| SYMBOL '(' expr ')' {
if( Vars.SYMBOL_TABLE[ $1 ] )
{
$$ = Vars.SYMBOL_TABLE[ $1 ]( $3 );
} else
{
trace( "can't find function" );
}
}
| SYMBOL {
if( Vars.SYMBOL_TABLE[ $1 ] )
{
$$ = Vars.SYMBOL_TABLE[ $1 ];
} else
{
trace( "can't find symbol" );
}
}
| NUMBER { $$ = yyval; }
;
%%

Continue reading the extended entry to see the results. Continue reading

Flash Switcher for Windows, OSX and Linux

With the upcoming release of Firefox 3 I thought I had to verify my extensions to see if they work with the new Firefox version too.
For the first version of flash switcher I did two different extensions for Windows and Mac. That was a problem for maintenance.

This time I wrote the extension from scratch and I decided to make it as much as cross platform as possible. Moreover I wanted to make the installation of new plugins easier than in the previous version of flash switcher extension ( where you had to copy manually the plugin file into the extension’s directory.. ).

Thus now this extension works ( at least with my tests and people who tested it ) with Windows, OSX and Linux. Specifically it has been tested on:

  • Windows XP
  • Ubuntu linux 8.04
  • OSX Leopard and Tiger

Also the installation of new plugins now it’s easy. Just click on the installed flash plugin and click “save”. Well, I think it’s quite easy 🙂

The only issue with the new extension is that it’s quite big because it comes with 2 flash versions for every OS platform. So it’s about 14Mb.

I also did a couple of video to show how it currently works on different platforms. Currently there are 2 videos (ubuntu and osx usage).

Flash switcher Ubuntu

In order to use this extension ( if you want to try it ) you need Firefox 3.
P.S. If you want to add more flash players to the extension, download and install the version you want from the flash player archive page.
Once a new flashplayer has been installed onto your system you can save it into your flash switcher archive using the “save as” menu item of the flash switcher.

Install flash switcher

Runtime expression evaluation in ActionScript

Finally I have a bit of free time to write down this post.
Some days ago a guy on the forum asked about how to evaluate at runtime simple mathematical expressions with support for symbols and function calls.

Now that the eval function have been removed from the language for reasons I’ve not enought time to talk about, we need to parse and execute those expressions manually.

I built a simple Actionscript library that can be used to parse mathematical expressions: it has support for function calls, for variables and it is able to convert the expression into a postfix rappresentation if you may need it. The expression parser is quite simple and have been built manually following some concepts related to programming language compilers; it includes a Scanner (or lexer – however you want to call it) to tokenize the expression, a Parser that convert the expression into an Abstract Syntax Tree and a simple routine that evaluates that AST using a Symbol Table as evaluation context.

There are no comments inside the code right now; I hope to find a little bit of time to write an in depth discussion about this topic. In the mean time you can continue reading the entry for a general explanation about how does the code works and for some examples that may be useful.

Here is a simple example that shows how does the code works:

import it.sephiroth.expr.CompiledExpression;
import it.sephiroth.expr.Parser;
import it.sephiroth.expr.Scanner;
public class Example
{
public static function run(): void
{
var expression: String = "sin( x / ( 8 / 2 + (-0.12 + 2.3) * x / x ) ) * 100";
var scanner: Scanner = new Scanner( expression );
var parser: Parser = new Parser( scanner );
var compiled: CompiledExpression = parser.parse();
var context: Object = {
x: 100,
sin: Math.sin,
cos: Math.cos
};
trace( 'Postfix:', compiled.toString() );
trace( 'Result:', compiled.execute( context ) );
}
}

Before I forgot, you can download the source code here with a simple example included.

Continue reading

Finally a code coverage tool for AS3!

Today is really a good day.

I was waiting for this kind of tool since a lot of time, and thanks to Joe we can finally do Code Coverage of our Actionscript code.

The project is hosted on Google Code, and can be obviously downloaded for free; the project is born after some tests of the author, that edited the Flex compiler to include additional informations that are used to generate a code coverage log that then can be read by softwares that display the output in a more user friendly and fashion way.

For anyone who doesn’t know, Code Coverage is a good practice used most in software testing, that is applied to understand how much source code is touched by our tests. This way a developer knows if a test covers all the source code (or the required portions) and can tune his tests if they don’t.

This project is probably one of the first born after the public release of the Flex SDK source code, and we are pretty sure that there are much more projects coming in the near future.

Finally we can do a little bit of Code Coverage in Aviary 🙂

cacheAsBitmap hell

Last week I spent a whole day trying to solve an issue in Phoenix due to a strange problem which comes up suddenly after some code changes.
The problem was that now using the transformation tool the bounds of the selected bitmap were not detected correctly and the tool itself didn’t work.
So I spent a lot of time in checking out all the recent code changes ( and they were a lot! ) to find out the possible cause…
Anyway, I was lucky to figure out the problem by accident and the problem was cacheAsBitmap!

The problem with the tool is because in order to find the correct bounds of any element on the stage it use the .concatenatedMatrix property of the element itself ( which represents the combined transformation matrixes of the display object and all of its parent objects, back to the root level ).
BUT if any of its parent display object ( not the root itself ) has the cacheAsBitmap property set to true then the concatenatedMatrix returns a wrong value!

I put a real simple flash example of what I mean. Just click on any of the 2 colored objects to activate the transform tool, then click on the “cache” button and click again on those objects to see the difference.

[kml_flashembed publishmethod=”static” fversion=”10.0.22″ movie=”http://blog.sephiroth.it/wp-content/uploads/2008/03/cacheasbitmap_hell.swf” width=”450″ height=”450″ targetclass=”flashmovie” bgColor=”#ffffcc”]

Get Adobe Flash player

[/kml_flashembed]

P.S. I’ve reported the bug in the flash player bugbase, if anyone is interested in watch or vote for it.

iPhone & Ubuntu notes…

No Flash stuff this time 🙂
During my last trip to New York city I finally decided to buy an iPhone for me too (I think I have everything from Apple right now.. except a mac 🙂 ).
The most annoying thing for a linux user like me is obviously the fact that the iPhone syncronization should pass from iTunes, which is not available for linux…
Ok, there are some ways indeed to copy music like this: http://help.ubuntu.com/community/PortableDevices/iPhone, but as you can see is not so smart.

Sync your address book isn’t easy too. The AddressBook sqlite can be easily browse using an SQLite browser such as SQLite Database Browser http://sqlitebrowser.sourceforge.net/, just get the AddressBook.sqlitedb (it’s into  /private/var/mobile/Library/AddressBook/)  from the iphone via sftp (just remember to install BSD Subsystem and OpenSSH) and call a simple query like this:
SELECT t1.First, t1.Last, t2.value from ABPerson as t1, ABMultiValue as t2 WHERE t2.record_id = t1.ROWID
For a full AddressBook sync you can read more here: http://www.estamos.de/blog/…the-making-of/

Another tip I just discovered is how to upload into the iPhone my own Ringtones.
First convert the mp3 file into an M4R file using this command line script:
mplayer -ao pcm input_file.mp3 -ao pcm:file="~temp.wav"
faac ~temp.wav -o output_file.m4r -w
rm ~temp.wav

then using sftp put the output_file.m4r into /Library/Ringtones directory. A sample workflow can be this one:
~/iphone/Ringtones$ mplayer -ao pcm The_Spell.mp3 -ao pcm:file="~temp.wav"
MPlayer 1.0rc2-4.2.3 (C) 2000-2007 MPlayer Team
CPU: Intel(R) Core(TM)2 CPU T7600 @ 2.33GHz (Family: 6, Model: 15, Stepping: 6)
CPUflags: MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled with runtime CPU detection.
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
Playing The_Spell.mp3.
Audio file file format detected.
Clip info:
Title: The Spell
Artist: Lunatica
Album: Fables & Dreams
Year: 2004
Comment: 00001A75 000016D0 00004374
Track: 6
Genre: Other
==========================================================================
Forced audio codec: mad
Opening audio decoder: [libmad] libmad mpeg audio decoder
AUDIO: 44100 Hz, 2 ch, s16le, 128.0 kbit/9.07% (ratio: 16000->176400)
Selected audio codec: [mad] afm: libmad (libMAD MPEG layer 1-2-3)
==========================================================================
[AO PCM] File: ~temp.wav (WAVE)
PCM: Samplerate: 44100Hz Channels: Stereo Format s16le
[AO PCM] Info: Faster dumping is achieved with -vc null -vo null -ao pcm:fast
[AO PCM] Info: To write WAVE files use -ao pcm:waveheader (default).
AO: [pcm] 44100Hz 2ch s16le (2 bytes per sample)
Video: no video
Starting playback...
Cannot sync MAD frame 538.0 (08:58.0) 0.8%
Cannot sync MAD frame
Cannot sync MAD frame
Cannot sync MAD frame 538.0 (08:58.0) 0.8%
A: 288.3 (04:48.2) of 538.0 (08:58.0) 0.8%
Exiting... (End of file)
alessandro@alessandro-u-laptop:~/iphone/Ringtones$ faac ~temp.wav -o The_Spell.m4r
Freeware Advanced Audio Coder
FAAC 1.26.1 (Jan 22 2008) UNSTABLE
Quantization quality: 100
Bandwidth: 16000 Hz
Object type: Low Complexity(MPEG-2) + M/S
Container format: Transport Stream (ADTS)
Encoding ~temp.wav to The_Spell.m4r
frame | bitrate | elapsed/estim | play/CPU | ETA
12388/12388 (100%)| 137.8 | 12.5/12.5 | 22.95x | 0.0
alessandro@alessandro-u-laptop:~/iphone/Ringtones$ sftp root@192.168.1.203
Connecting to 192.168.1.203...
root@192.168.1.203's password:
sftp> cd /Library/Ringtones
sftp> put The_Spell.m4r

Get your Aviary invitation!

One of the most ambitious projects I’ve ever worked on is finally coming out. It’s really gratifying when looking at what people is able to do using our software, for example meowza, one of my favourite artists.. Damn, I wrote the software but I just can draw a couple of circles and place a text on the canvas, nothing else 🙂 I would never have imagined that someone could do so awesome images.

Now Aviary finally opens to beta user using invitations. So, if you want to participate to the beta and try out Phoenix or Peacock ( the tool created by Mario ) just send me an email, I can give out some invitations.
We’re also planning to add some new cool features to Phoenix in the next days!
Recently Mario has also posted on his site a nice video on both Peacock and Phoenix in action, watch it here.

P.S. We’re hiring! If you’re a talented developer write me an email!