Monday, 27 July 2009


Hi Readers,

Today I found a bit unusual usage of switch. What if you have different N options and you have to invoke M common commands and N different commands? How you can save some extra typing job for yourself? (Or how to avoid code repetition.)

switch (var) {
case n1:
case nN:
case n1:
case nN:

Got it? The trick is using the same case terms multiple times. If you like it check the DRY approach. And of course don't forget about KISS.

Good day,

Friday, 24 July 2009

Drupal Flash interaction example

Hi Readers,

I had to make a presentation about a theoretical workaround describes an approach Drupal and Flash can work together. Basically there are two concepts. One Flash for all - means one big flash object is the whole site, and the other one, lots of flash objects in html. In the first concept the flash object handles everything. In the Drupal era it requires the Services and AMFPHP module. I would say it is rather a communicaton heavy way. On the other side the lots-of-flash way needs large numbers of interactions between the underground html layer. Lets see this approach in the slides:

Sunday, 19 July 2009

Flex/AIR PHP evaluator

Hi Readers,

OS X hasn't got [readline] for PHP. That is why you can't use [php -a] in command line for testing PHP codes. Sad. If you want one, you can get a similar from: by Stefan Fischerländer and David Phillips. It's an easy replacement, however, I wanted to use one that can keep my command history. If you use macports, you maybe win but I don't want to use that. (I heard it is kinda evil sometimes.) Recently I have found a bestof documentation of Flex at (Have I mentioned it is free? :) Oh yeah.) So I made a really simple AIR php -a replacement.

Concept is stupid easy. An AIR app sends a POST request for a PHP script lies on my localhost. This script evaluate the text I want to check and sends back. See? K, check the code:
The AIR part:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="" layout="absolute">

public function eval():void {
var url:String = "http://localhost/flex_eval.php";
var ur:URLRequest = new URLRequest(url);
var ul:URLLoader = new URLLoader(ur);
var uv:URLVariables = new URLVariables();

uv.phpsnippet = php_snippet.text; = uv;

ur.method = URLRequestMethod.POST;

ul.addEventListener(Event.COMPLETE, evalComplete);
ul.addEventListener(IOErrorEvent.IO_ERROR, ioError);


public function ioError(event:IOErrorEvent):void {
php_result.text = "Missing PHP file from:\n" +
"http://localhost/flex_eval.php\n\n" +
"Create one with the following code:\n\n" +
"<?php\n" +
"echo 'Flex PHP Snippet results ('.date('H:i.s').')'.\"\\n\\n\";\n" +

public function evalComplete(event:Event):void {
php_result.htmlText =;

<mx:TextArea left="10" right="279" top="10" bottom="40" id="php_snippet" backgroundColor="#2E2E2E" fontFamily="Courier New" color="#FFFFFF" fontWeight="normal" fontSize="12"/>
<mx:TextArea width="261" right="10" top="10" bottom="10" id="php_result"/>
<mx:Button label="Eval" bottom="10" left="10" right="279" click="eval();"/>

And the PHP part:
echo 'Flex PHP Snippet results ('.date('H:i.s').')'."\n\n";

You can compile the mxml stuff in Flex Builder 3.0 (and I guess also with the free Flex sdk). And here you are a quick downloadable version:

Guddai readers,