Beautify JavaScript for TextMate

November 23rd, 2007

Via Choan, I discovered Beautify JavaScript.

Of course, I couldn’t help porting it to TextMate (specially after Choan asked me about it on Twitter :)

So, here’s the command:

Download Beautify JavaScript for TextMate

It’s bound to ⌃ + ⇧ + Q, and uses the current selection or the current document if there’s no selection.

The code is taken straight from the Beautify JavaScript site. It’s written in PHP, so it’s quite fast. It could probably be made faster by using shell scripting, but it’s a quick hack written in 1 minute while attending a conference :)

Hope you like it.

rake + growlnotify

September 16th, 2007

Here’s a quick tip for those of you using Rakefiles on a Mac.

If you have long-running tasks, and would like to be notified when they finish (to keep on working while they run, or have a quick glance at email) you can use growlnotify. Here’s a code fragment from one of my rake tasks:

desc "Compile App"
task :compile do
  @start = Time.now
  %x(mtasc -swf #{SWF} -main -mx -version #{PLAYER} #{APP}.as #{trace})
  %x(mtasc -swf MiniVideo.swf -header 320:240:31 -main -mx -version #{PLAYER} MiniVideo.as #{trace})
  %x(mtasc -swf #{SWF} -main -mx -version #{PLAYER} #{APP}.as -trace no)
  %x(cp *.swf swf)
  @end = Time.now
  msg = "Finished compiling in #{@end - @start}s."
  if @nodebug
    msg += "\ntrace() disabled"
  end
  %x(growlnotify --name Rake -m '#{msg}' 'Rake')
end

Check the syntax for the command by running

$ growlnotify -?

Hope you like it : )

How to use Console.app for Flash debugging

March 14th, 2007

Following a thread on the TextMate mailing list. I have commited some changes to the ActionScript bundle.

I was using XTrace for debugging, but some people on the list either couldn’t get it working or didn’t like it very much.

An article linked on the thread, “Debugging Flex Applications on OS X” made me think that we already have a nice logging app in OS X: Console.app.

Some googling around turned up more information. This article: “trace() outside the Flash IDE with tail” had all the information I needed (the first one isn’t very clear about where the log file is stored by default, so at first I thought it wasn’t working)

Some coffees later, here is the result:

Flash debugging with Console.app

So… if you update your bundles, you’ll find I have removed the default behaviour for trace (that is, to open XTrace) and now it is optional. If you add

trace: xtrace

to your mtasc.yaml file, XTrace will work as before.

Or, you can add a custom trace function:

trace: com.namespace.for.your.custom.trace

If you want to use a different logger (i.e: LuminicBox, Zeroi…) you should play with ‘trace:’ and the (also new) ‘params:’ option in mtasc.yaml

The ‘params’ option in mtasc.yaml is usefull if you want to send extra arguments to MTASC on compilation:

params: -strict -keep

(’-keep’ has been removed from the defaults, so you’ll have to add it manually to ‘params’)

Special thanks to Aaron Clinger and Rui Carmo for the ideas, links, inspiration and buggering on the list :)

TextMate and Growl

December 16th, 2006

Coming soon to your nearest ActionScript bundle:

TextMate with Growl

Technorati tags: , ,

TextMate and the “Build With MTASC” command

December 2nd, 2006

If you use TextMate to develop ActionScript, and keep the bundles up to date with the SVN repository or the GetBundle plugin, you may have noticed a new command in the ActionScript bundle: “Build With MTASC”.

Following Allan’s suggestion of getting TextMate to compile ActionScript out of the box (i.e: you don’t need to install anything apart from TextMate), I’ve been making some changes to the bundle, and it now includes some tools that make Flash development easier (and faster!)

When used with single files, “Build With MTASC” will compile the current file to something called “yourCurrentFile.swf” and will try to open it with SAFlashPlayer (that is the standalone Flash player).

When used inside a project, the command will search for a ‘mtasc.yaml’ file in your project root, and use it to compile your project.

If you don’t have a ‘mtasc.yaml’ file, the command will work as if you were compiling a single file.

However, if you want to compile a project you can trigger the command “Install MTASC Support Files”. It will copy a default ‘mtasc.yaml’ file to your project root.

The file is self-commented, but some documentation is on the way.

You can always check the “MTASC Help” command, and it will display the latest info about the bundle.

I hope you like the command, and it makes your long compiles a little bit shorter!

Update: If you don’t feel like using Subversion, here’s the updated ActionScript bundle in zip format.

TextMate + ActionScript

November 27th, 2006

I’ve been appointed as the “official” maintainer for the ActionScript Bundle in TextMate.

The bundle has been sitting idle for too long, and was in need of a deep revision. I’m currently cleaning it up, and bringing it up to par with more active bundles, by using new TextMate functionality (the new “TextMate Web Preview” comes to mind)

I’ve also updated it with some new commands. I’ll keep you updated on them in the blog :)

Compiling MTASC and Swfmill for Intel Mac

June 7th, 2006

The problem

Lately, I’ve been revising mi workflow for ActionScript project.

One of the first options was using MTASC and Swfmill (along with a nice build system using rake in Ruby, but that’s a different story…)

The first compiling tests were pretty exciting, but then I got a little surprise:

My PowerBook 12″ 1.3Ghz compiles 50% faster than an iMac Dual Core 2Ghz!

I checked version numbers for MTASC and Swfmill in both systems. I found out that I was using an old MTASC version on the PowerBook.

When I updated it, the PowerBook was even faster…

Next check was checking if the latest MTASC version was optimized for Intel processors:

AleMac:~ ale$ file bin/mtasc 
bin/mtasc: Mach-O executable ppc

Darn…

What about Swfmill?

AleMac:~ ale$ file bin/swfmill 
bin/swfmill: Mach-O executable ppc

Cool…

The answer

Due to my freakiness, the first thing I thought about was recompiling MTASC and Swfmill (god bless Open Source :) for Intel Mac.

If you also thought it would be a breeze, you are wrong. Here’s the chronicle of how I compiled MTASC and Swfmill in Tiger for Intel and lived to tell the story…

Requirements

Installing DarwinPorts`+ dependencies

Install DarwinPorts, fix the PATH, and get ready for the journey…

First thing to do is to update DarwinPorts’ packages

sudo port -d selfupdate
Password:
DEBUG: Rebuilding the darwinports base system if needed.
Synchronizing from rsync://rsync.darwinports.org/dpupdate/dports
receiving file list ... done

Here’s what you’ll need to compile MTASC and Swfmill:

  • zLib
  • pkgconfig
  • libxml2
  • libxslt
  • freetype
  • libpng
  • gdbm

Let’s roll!

sudo port install zlib
sudo port install pkgconfig
sudo port install libxml2
sudo port install libxslt
sudo port install freetype
sudo port install libpng
sudo port install gdbm

This will take about 10 minutes (iMac Dual Core 2.0Ghz, 1Gb RAM)

We’ll also need OCaml and findlib.

OCaml is available in DarwinPorts, but findlib is not, so we’ll compile both using GODI

Installing OCaml and findlib with GODI

Download the source code for GODI and uncompress it wherever you like. I’m putting it on ~/src (that is, a folder called ’src’ in my home folder)

In order to compile GODI, we have to configure a couple things…

cd /Users/ale/src/godi-bootstrap-20060405/
./bootstrap --prefix $HOME/src/godi

Then we start compiling… Binaries will be place in ~/src/godi/bin and ~/src/godi/sbin, so you’ll have to add those folders to your PATH (if you don’t know how to do it, you may not be reading this, actually :)

Now the fun begins:

cd /Users/ale/src/godi-bootstrap-20060405/
./bootstrap_stage2

After a little while (6 minutes here…) we’ll have an Intel Mac native OCaml compiler, and GODI will be ready to install packages… Run ‘godi_console’ and install the folowing:

  • godi-findlib
  • conf-tcltk
  • conf-gdbm
  • godi-ocaml-dbm
  • godi-ocaml-all

Once you install them, you’re ready to compile MTASC (yes, this is only the begining…)

Compiling MTASC

Compared to what we’ve done by now, compiling MTASC is a child’s game…

Download the installation script for MTASC here: http://www.mtasc.org/doc/mtasc/install.ml

I’ve saved it in ~/src/mtasc

cd /Users/ale/src
mkdir mtasc
cd mtasc
curl http://tech.motion-twin.com/doc/mtasc/install.ml -o install.ml

You’ll have to patch ‘install.ml’ so it compiles in OSX. Just look for this line

let zlib = match Sys.os_type with "Win32" -> "zlib.lib" | _ -> "-lz"

and replace it by this:

let zlib = "/opt/local/lib/libz.a"

(that’s where DarwinPorts installs zLib by default…)

Now we compile MTASC:

ocaml install.ml

Hopefully, when lines stop flying up your screen, you’ll have to binaries in ‘mtasc/bin’: ‘mtasc’ and ‘mtasc-byte’

Time for testing…

AleMac:~/src/mtasc/bin ale$ file mtasc
mtasc: Mach-O executable i386
AleMac:~/src/mtasc/bin ale$ file mtasc-byte 
mtasc-byte: Mach-O executable i386

Woohoo! :D

Let’s try with Swfmill

Compiling Swfmill

Uncompress the Swfmill sources in ~/src

tar xvzf swfmill-0.2.11.tar.gz

I couldn’t make it work without some tweaking: do a folder-wide search for ‘-static’ and replace it with ” (it should work by using –disable-static when configuring, but somehow it didn’t)

Run the configure script:

./configure --prefix=$HOME

and compile…

make

When it’s done, we’ll have a nice binary in src/swfmill-0.2.11/src

Again, let’s make sure it worked:

AleMac:~/src/swfmill-0.2.11/src ale$ file swfmill
swfmill: Mach-O executable i386

The last step is moving the binaries to a folder on your $PATH (I’ve used ~/bin, my repository of all thing binary).

Is it worth it?

Well… here’s a little test I put together with MTASC + Swfmill + Ruby, comparing the latest downloadable MTASC with the “native” and “bytecode” versions we just compiled.

The test runs 4 compiles, measuring the time it takes with the ‘time’ command. Mi test uses the ‘-keep’ option, so after the first compilation it’s quite cheap. SWF files were deleted after each compilation batch.

MTASC PowerPC + Swfmill PowerPC

real    0m1.020s
user    0m0.649s
sys     0m0.352s

real    0m0.197s
user    0m0.073s
sys     0m0.026s

real    0m0.101s
user    0m0.073s
sys     0m0.025s

real    0m0.103s
user    0m0.073s
sys     0m0.024s

MTASC “native” Intel + Swfmill Intel

real    0m0.568s
user    0m0.150s
sys     0m0.072s

real    0m0.105s
user    0m0.073s
sys     0m0.025s

real    0m0.103s
user    0m0.073s
sys     0m0.026s

real    0m0.101s
user    0m0.073s
sys     0m0.025s

MTASC “bytecode” Intel + Swfmill Intel

real    0m0.227s
user    0m0.156s
sys     0m0.061s

real    0m0.102s
user    0m0.073s
sys     0m0.025s

real    0m0.102s
user    0m0.073s
sys     0m0.026s

real    0m0.101s
user    0m0.073s
sys     0m0.026s

Numbers speak for themselves… :D

So… ¡enjoy yourself!

Note: If you have a big project where you can run longer tests (mine is quite simple) it would be great if you posted your numbers, or you can send it to ale {at} bomberstudios {dot} com and I’ll post the test results…

Here are the binaries for your downloading pleasure:

The binaries are only for Intel Mac (not Universal) and have only been tested on 2 machines. If you get it working on yours, please post a comment…

Update: I’ve built Universal binaries. Please let me know if they work…