Alexey Zakhlestin's Blog

Programming for Mac and Web

Lcache

Permalink

Does anyone know what this is going to be?

I was going to name my extension (soon to be published) to PHP “lcache”, when I suddenly noticed, that there is, already something named “lcache”. The most funny part that it is php-related too… :)

Mysql Bug

Permalink

MySQL is a very strange database. That’s why it has such strange bugs

It does support cross-database delete, but only if you do not specify aliases for tables. Unfortunately, there are situations, when aliases are vital :-(

Ini2yaml in PHP

Permalink

If you still use INI file for some of your PHP-projects configuration, I guess it is time for you to migrade to YAML which is more flexible and has way more expressiveness. Here is a little tool to help you in migration process

<?php
    require "<a href="http://spyc.sourceforge.net/">Spyc.php</a>";
    if ($argc != 3)
        die("I need 2 parameters: in_file.ini, out_file.yml\n");

    if (!is_readable($argv[1]))
        die("can't read from ".$argv[1]."\n");

    $ini = parse_ini_file($argv[1], true);
    file_put_contents($argv[2], Spyc::YAMLDump($ini));

MySQL Console and Utf-8

Permalink

MySQL console has a long history of not properly counting column-widths for multibyte data. This was fixed in 4.1.12/5.0.25

Although, with a little catch. You have to start mysql console with “–default-character-set=utf8” key or it will fall back to it’s “classical” behavior

Did You Know…

Permalink

Did you know, that while preg_match is faster than ereg, mb_ereg is even faster? Well, it is.

It’s all about libraries, actually.

  • “ereg” uses good-ol’ posix library, which is good, but… well… “old”.

  • “preg_match” uses PCRE

  • “mb_ereg” uses ultra-fast Oniguruma library

Haxe

Permalink

Ok, here is something interesting. I was browsing looking for something related to flash/actionscript programming and ways of client-server interaction (remoting). After an hour or so, I found something called ”haXe“…

haXe is a “web oriented universal language”, which means, that you can write all the front-end and back-end stuff in haXe, and compile it to the target platform afterwards. Currently, there are three target-platforms: flash, javascript and neko byte-code (you can learn more about NekoVM here). It is a high-level object-oriented strong-typed language with a strict syntax. It supports anonymous local-functions and anonymous objects. Another great thing about haXe: it has type inference, which means, that one rarely needs to specify the type manually. The program will just “know” which type should be there. haXe doesn’t have multiple inheritance, but has support for interfaces and “class parameters” (which are similar to C++’s templates).

If you are into that stuff, you can check all the language reference. Some pieces are really-really interesting. It seems like haXe tries to take the pieces of both object-oriented and functional languages and makes an interesting mixture.

Now, some more practical stuff. As I mentioned, I found haXe, while looking for stuff related to flash programming. Using haXe, it is possible to write code in a language, which is more powerful than ActionScript-3.0 and compile it to swf, targetted to any flash-player version you like. You will still be limited by APIs which are bundled with that version of player, but the language itself is no more a limit. By the way, as a bonus, you get a bunch of powerful haXe’s apis, which are not available for usual actionscript developers.

haXe supports different kinds of remoting. It is possible to use flash’s AMF remoting, if you need to be compatible with that or native haXe remoting. Synchronous and asynchronous modes are available, of course, and it is also possible to use flash-javascript interaction. And, yes, I know you want to ask: you can do AJAX stuff in haXe too :)

You can download haXe here. It is precompiled for several platforms. It is trivial to compile it yourself, if you have ocaml compiler anywhere around (which is the case, if you use some kind of unix).

The usage is simple. Start with creating the following Test.hx:

    class Test {
        static function main() {
            trace("Hello World !");
        }
    }

Now, just issue the following command in the console: haxe -swf test.swf -main Test. You will have a working swf file which says ‘Hello’ to all the world :)