<canvas> rocks, <video> sucks

When in news.yc I find posts like “iPhone 5 website teardown: How Apple compresses video using JPEG, JSON, and <canvas>” I really fall in love.

Seriously. So much in love that I need to try it by myself. Hence, VideoCanvas.
VideoCanvas is a mix of PHP, ffmpeg and ImageMagik.

Starting from a video, it creates an images with all the tiles and an HTML page with hard-coded JSON containing frames info and some JavaScript to start the video.

It relies on ffmpeg to extract video frames in separate images. Then with the ImageMagik extension of PHP it creates a minimum set of tiles to recreate the video in the <canvas>.

Have a look at the final result of version 0.1. Here you can find the source video made with Kazam Screencaster.

(Edit: the JS code has been updated to use requestAnimationFrame when available)

Posted in Image processing, PHP | Leave a comment

Experimenting PHPADD on Doctrine2

Today I tried to unleash PHPADD over Doctrine2 sources.

Of course, it couldn’t even start: it didn’t support namespaces. So I had to improve the analysis of tokenized PHP source and now it works.

By the way, the report was not satisfying as I expected. With a big project such Doctrine you understand how much it is important to have a concise report. So now:

  • the parameters are internally indexed by name. This means that it is easy to detect a changed type, but names changes are still seen as “added param $newName” + “removed param $oldName”.
  • @inheritdoc is supported.
  • multiple types (integer|bool $param) are supported.

This leads to an almost accurate analysis of Doctrine2 ORM classes:

Scanned 261 files with 1672 methods in their classes. 919 methods (55.0%) are regular, 388 methods (23.2%) have no docblock, 365 methods (21.8%) have an outdated docblock.

Since these changes are not in the pear channel yet, if you are lazy&curious the report is here.

Posted in PHPADD | Leave a comment

5.3.7 is the best PHP release ever

Before release 5.3.7, PHP was fantastic. It had everything the web needed, built-in.
But starting from 5.3.7 something in the interpreter changed:
- a stupid regression on crypt()
- the knowledge it has only 70% of code covered by tests
- the knowledge it has almost 200 failing tests
- the knowledge that no one runs tests on it before release

So, now PHP is evil. Personally, I agree with Anna Filina:

This is an insult to all people who work hard at it. The words that you use to describe things are simply baffling. “You” and “them” are the community, and it’s your responsibility as much as theirs.

People can improve. The crypt() function can be fixed (ooops, already done). The failing tests can be analized and fixed. The release team can learn to avoid to be embarrassed again. If you understand something that can be improved, you can improve.

For this reason I think PHP 5.3.7 is a great release for self-improvement.
One point for PHP, zero points for stupidity.

Posted in Uncategorized | Leave a comment

PHPADD 1.3.0

I just uploaded to the PEAR repository the latest version of PHPADD, which is labeled 1.3.0.

From this release I can consider it useful, since it includes the ability of exclude whatever you do not want to scan. In fact, you can exclude from scanning any path, class name or method name.

In Allbus, the company where I work, we have several types of classes that are not so much interesting, like implementations of Factory or View Model patterns.  A Factory creates instances of Services with all the needed collaborator injected, with method names like getVehicleService() – which is self-explanatory. A View Model selects some fields from the Sacred Domain Model and always has just a method, setUp(). Nothing more!

As you can see, in such cases the use of docblocks is tautological. While analyzing what classes need a visit to their docblocks, it is important to have no noise around. Simply leave behind classes that do not introduce logic:

phpadd --exclude-paths application/*/view/model/* ...
phpadd --exclude-classes Factory$ ...
phpadd --exclude-methods ^setUp$ ...

If you have already installed an older version of PHPADD, you can just run pear upgrade-all. Otherwise, install it via the repository.

Posted in PHPADD | Leave a comment

PHPADD: abandoned docblocks detector

Docblocks may become as evil as comments when they’re not treated as first-class citizens (see: Meaningless docblocks).

PHPADD can analyze a directory with PHP source code and detect (for each file, for each class, for each method) if the parameters in the function declaration are compatible with the parameters found in the docblock, reporting the outdated ones.

This can be easily integrated in your build script and the result can be published in build result. Using Hudson, you just need HTML Publisher plugin.

Install it
With PEAR it is very simple. On Linux, you may need to prefix each command with sudo.

pear channel-discover pear.webmatters.it
pear install webmatters/phpadd

Try it
Once installed it responds to phpadd from your console.

phpadd --publish-html /tmp/output.html directory/to/analyze

This command will produce an output like this.

Please note, phpadd has to be improved. For example, it needs to ignore warning on files/classes/methods matching a given regular expression (controller classes, for example).
Or the difference between docblock params and function params: it is not so smart.
If you want to help, fork it on GitHub!

Posted in PHPADD | 14 Comments

BannedComboItems: ComboBox with disabled items

Combos are beasts. Beasts for developers (400 lines of ugly configuration) and beasts for customers.
For some business logic, you may not select some elements. What to do in these cases?

If you do not put unselectable items in the combo, your customers will say you: “Why can’t I see raspberries in the list? I’m sure I added them to the system“.
And if you put everything in the combo, they will say you “Oh, that’s too much, why do I see all this useless stuff?“.

But wait for a moment, we already solved this problem 20 years ago in menus!
Continue reading

Posted in ExtJS extensions, User experience | 1 Comment

Git tips and tricks

Display the active branch in the terminal prompt
Add this line to ~/.bashrc
PS1='\u@\h:\w$(__git_ps1 " (%s)")\$ '

Automatic add during commit
git commit -am "message"
It automatically adds already versioned files to the index before commit. This will automatically remove file disappeared from the filesystem. Untracked files will not be added.

Add to the index just some part of a file
git add --patch
For each chunk, you can type: y (stage it), n (do not stage it), q (do not stage & quit)

Interactive index add
git add --interactive
This UI has Super Cow Powers. Go in update mode with update. Now type:

1     to add the first file to the index
1-3 to add files 1, 2 and 3 to the index
-1   to unstage first file

To go back into “what now” mode, press Enter. With revert mode you can restore a file as it is in HEAD. For other modes, type help.

Undo a commit
To go back to the previous state
git reset --soft HEAD^
Fix what was wrong and commit from the discarded commit (ORIG_HEAD)
git commit -c ORIG_HEAD

Posted in Git | Leave a comment

Ext.Ajax on steroids [AuthorizedAjax]

In the company I work for we use ExtTop, the Windows-like desktop environment which provides icons, taskbar and start menu. It is a single page web application. You can open all the windows you want, but you will never reload the page.

We want to log users off after one hour of inactivity. If your user session is destroyed and you try to open a form, you should be warned that you cannot continue and you will be invited to log in again.

That’s very simple. For each Ext.Ajax request, you should check that you are still in, if not, open a login form and if the server accepts your credentials, continue. For each request. For each request. For each request. [...]

That repetition sucks. What could we do?

  • copy and paste all the code, in every Ext.Ajax.request()
  • create a detectIfLoggedOf() function and call it in every success() callback of Ext.Ajax.request()
  • define a new Ext.Ajax that do everything.

Since you should spend your time writing a strong web application, let’s discard option 1 and 2. AuthorizedAjax is option 3.

Please keep in mind this is more a proof of concept rather than a real implementation. There is no documentation (yet?). See the example and read it’s configuration file.
Continue reading

Posted in Domain specific languages, ExtJS extensions | Leave a comment

Once upon a time…

This post is all about testing. If you are already testing your code, you can skip it.

Imagine PHP without the in_array() function: you need it, so you have to write it:

function inArray($needle, array $haystack)
{
	foreach (...) { ... }
	return $found;
}

Then you check if it works:

$array = array(4, 8, 15, 16, 23, 42);
var_dump(inArray(2, $array));
var_dump(inArray(16, $array));

You see that everything works as expected, you throw away the three lines above and commit your code. It works, afterall!

Continue reading

Posted in Things you must know | Leave a comment

ExtDiamond 1.1

This is a minor release, with a little but important functionality. Download it on GitHub!

What changed
ExtDiamond is shipped with some built-in widgets. Right now we have only GridPanel and Form.Field, but we hope to have something more in the future.
By the way, you application may use non-standard widgets (meaning: not provided with ExtJS) that you developed by yourself or bought from someone.

In these cases, you may need to define your own widget reference classes, especially if your component is complicated.
This release allows you to register a path where ExtDiamond will search your own widget classes, that will be loaded when you call handleAs() on your references.

Now that all the original functionalities are completed, I will concentrate my time on new features.
Finally, I want to notify you that ExtDiamond API is available.

Posted in ExtDiamond | Leave a comment