Friday, 25 December 2009

Lolcat viewer

Hi Readers,

What a peaceful Christmas day, isn't it? In the morning I wrote a small AIR application brings lolcats into your desktop. Basically it's a dummy RSS reader for ICanHasCheezburger shows the latest kittens. Here you are:

Let's take a look at the code:

I used Flex with Flex SDK 3.0.
First we need a couple of display objects:
  • Image container: the main lolcat image
  • Secondary image container: the same lolcat image with delay. It makes transitions seamless.
  • Indicator: an external SWF animation indicates network loading
  • Control bar: previous / next / refresh buttons

 <mx:Image id="image_backup"/>
<mx:Image id="image" updateComplete="imageUpdateComplete(event);" click="nextImage();"/>

<mx:SWFLoader source="{indicator}" width="40" height="40" id="indicator_swf" alpha="0.6"/>

<mx:Canvas backgroundColor="0x000000" backgroundAlpha="0.5" bottom="0" left="0" right="0" height="40"
mouseOver="control_bar.alpha = 1"
mouseOut="control_bar.alpha = 0.3"
<mx:LinkButton label="Previous" bottom="10" left="10" color="#CCCCCC" click="{previousImage()}"/>
<mx:LinkButton bottom="10" right="10" label="Next" color="#CCCCCC" click="{nextImage()}"/>
<mx:LinkButton label="Refresh" horizontalCenter="0" bottom="10" color="#CCCCCC" click="{refreshLolcatXML()}"/>

For the SWF animation it's highly suggested to embed the SWF movie itself:
public var indicator:Class;

Loading RSS feed is stupid simple. The feed's address:
   public static const LOLCAT_RSS:String = '';

And the upadating function for getting the feed itself:
   public function refreshLolcatXML():void {
var ur:URLRequest = new URLRequest(LOLCAT_RSS);
var ul:URLLoader = new URLLoader(ur);
ul.addEventListener(Event.COMPLETE, rssReady);
ul.addEventListener(IOErrorEvent.IO_ERROR, networkError);

Let's see what we have got when the request comes back (this is the event I registered for Event.COMPLETE):
   public function rssReady(event:Event):void {
var xml:XML = new XML(;
var items:XMLList = xml.*..item;
currentImageNum = 0;
for each (var item:XML in xml.*..item) {
if (item..MEDIA_NS::content[1]) {

I really like the ActionScript 3 XML layer. XML is already a native ActionScript 3 item, and the XML and XMLList classes make processing XMLs so easy. Quickly the response string is converted to XML and traversed for the important lolcat URLs. On every RSS reload I save results in the imageList ArrayCollection variable. I used one defined namespace, because the URLs can be found under that namespace:
   public static const MEDIA_NS:Namespace = new Namespace('');

Right after getting the response the first image is displayed. These are the stepping functions:
   public function nextImage():void {
if (image.source != imageList[currentImageNum]) {
indicator_swf.visible = true;
image.source = imageList[currentImageNum];
currentImageNum = (currentImageNum + 1) % imageList.length;

public function previousImage():void {
currentImageNum = (currentImageNum - 2 + imageList.length) % imageList.length;

One last small trick. When the image container triggers an updateComplete event, the whole resized for the appropriate image's size:
   public function networkError(event:IOErrorEvent):void {trace('Network error: ' + event);}

public function imageUpdateComplete(event:FlexEvent):void {
trace('Image update. W: ' + image.measuredWidth + ' H: ' + image.measuredHeight);
if (image.measuredWidth > 0) {
var tw:Tween = new Tween(this, Application.application.width, image.measuredWidth, 400, -1, onResizeWidthUpdate, onResizeWidthEnd);
var th:Tween = new Tween(this, Application.application.height, image.measuredHeight + 18, 400, -1, onResizeHeightUpdate, onResizeHeightEnd);
image_backup.source = image.source;
indicator_swf.visible = false;

With the Tween class it's also easy. This is the full Flex source, if you are interested in:
Download Lolcat's source.

And one other cool thing. I've seen a lot that awesome AIR installer object on many sites. So, made a bit research and found this tool you can make your own AIR installer:
Adobe AIR intaller badge This is what you see above.

Happy holidays,

Thursday, 24 December 2009

Design Patterns

Hi Readers,

It was high time to publish this post. A long time ago I decided to implement all the design patterns are in the famous GOF book: Design Patterns: Elements of Reusable Object-Oriented Software
Why? Because doing it by yourself the most efficient learning method. At least, for me. When I read this book first, I thought, know everything. All patterns made sense. But after time I realized using those patterns in practice are _REALLY_ hard. If you don't see what are the scopes, what object has access to what other objects, etc ... means you won't use it efficiently. Although, I'm still not confident with a lot of pattern. And by the way, I think it's not the best book for introducing these patterns. I found Wiki pages more useful in a lot of cases.

Here you are the downloadable JAVA sources:

[Disclaimer: these are my interpretations. Don't take it for sure. My understanding sometimes like a 1 month old pig's ass.]

Download ChainOfResponsibility pattern (BehavioralPatterns)

Download Command pattern (BehavioralPatterns)

Download Interpreter pattern (BehavioralPatterns)

Download Iterator pattern (BehavioralPatterns)

Download Mediator pattern (BehavioralPatterns)

Download Memento pattern (BehavioralPatterns)

Download Observer pattern (BehavioralPatterns)

Download State pattern (BehavioralPatterns)

Download Strategy pattern (BehavioralPatterns)

Download Template pattern (BehavioralPatterns)

Download Visitor pattern (BehavioralPatterns)

Download Adapter pattern (StructuralPatterns)

Download Bridge pattern (StructuralPatterns)

Download Composite pattern (StructuralPatterns)

Download Decorator pattern (StructuralPatterns)

Download Facade pattern (StructuralPatterns)

Download Flyweight pattern (StructuralPatterns)

Download Proxy pattern (StructuralPatterns)

Download AbstractFactory pattern (CreationalPatterns)

Download Builder pattern (CreationalPatterns)

Download FactoryMethod pattern (CreationalPatterns)

Download Prototype pattern (CreationalPatterns)

Download Singleton pattern (CreationalPatterns)

If you find any mistake, please let me know. I want to fix them. Thanks.

Happy Holidays,

Ps.: And this is the small shell script I packed the source folders:
for dir in BehavioralPatterns StructuralPatterns CreationalPatterns
for pattern in `ls $dir`
tar -czf $pattern.tar.gz ./$dir/$pattern
echo "Download $pattern pattern ($dir)

Saturday, 19 December 2009

6th Hungarian Drupal Podcast

Hi Readers,

Our 6th podcast was about Drupal module development. We spoke about the first steps to make a project on, about maintaining, clean code, sustainability and a lot of other useful stuffs. Check this out:

Magyar Drupal Podcast - 6. rész from Peter Arato on Vimeo.

(Sadly this episode is very silent.)


5th Hungarian Drupal Podcast

Hi Readers,

With a bit late let me announce our 5th podcast. It was about Drupal myths. A lot of people who don't know Drupal has bad feelings around it. We wanted to break these walls and collected all the most famous myths. Here we are:

Magyar Drupal Podcast - 5. rész from Peter Arato on Vimeo.


Saturday, 21 November 2009

Drupal multisite

Hi Readers,

Let me show how I made a Drupal multisite on my localhost. Of course, I did it a bit different way (I'm sure). That's me. By the way, this is the NORMAL description about multisites:

1: Deploy a Drupal site
Download the newest Drupal and install it. I did it into a folder, under my web root folder: /PATHTOYOURWEBROOT/DRUPALMULTISITEDIR/

2: Add your first site name to /etc/hosts
sh# sudo echo " FIRSTMULTISITENAME" >> /etc/hosts

3: Also tell to Apache, where is your new domain points
Insert at the end of your httpd.conf this snippet:

4: Rename sites/default to your first multisite's name
sh# cd sites

5: Restart apache
After restart check this out: http://FIRSTMULTISITENAME/

Of course, it's just one site. Adding a new site (SECONDMULTISITENAME):
  • Create subdirectory in sites (SECONDMULTISITENAME)
  • Copy a brand new settings.php into it, and create a files folder
  • Add the /etc/hosts entry (2)
  • Add apache directive (3)
I think, it's not that hard.


Hungarian Drupal Podcast - Episode 4

Hi Readers,

We finished recording our 4th podcast. It was a bit calm, a bit non-informative, but still us:) We continued the development environment topic. The video:

Magyar Drupal Podcast - 4. rész from Peter Arato on Vimeo.

Next part will be - I hope so - a quite interesting episode: Drupal myths and legends.
We collect a lot of things ... wait for it ... in Google Wave. Yeah baby, we all have a Wave account. You can ask why I am so happy about it, and it's because a simple fact: concurrent editing. We have a single wave conversation with all the topics we would like to talk about, and we could edit it at the same time. It boosted the planning phase a lot.


Saturday, 14 November 2009


Hi Readers,

I would like to give you a quick description how to work with FMS (Flash Media Server) under OS-X. Unfortunately FMS server is only available for Windows and Unix. Almost. I tried to fire it up in Ubuntu 9.10, and got a bunch of error messages. I would have killed both of that bastard application. Nevermind. So these were my steps to a working environment:

1 - Install Virtualbox and Windows XP in it
This is an easy step, just make sure you use latest version of VBox.

2 - Run Windows XP, and install FMS
The development version of FMS is free: download Though, you have to have an Adobe account. (1 minutes registration) The installation is straight forward, you can't make a mistake. I suggest you using the built-in Apache if you don't use that guest os for other webserver functions.

3 - Port forward to the guest machine
I'm not a server guy, so maybe it's not the best, but it's working, and that is the point. By default, your guest OS is listening on your localhost ( But without port forward you can't access to it. We have an Apache (port 80) and the FMS (admin server port: 1111, fms server port: 1935) on our newly installed Windows XP. These 3 ports we have to bind. Open a terminal in OSX, and type these commands:

(change the YOURGUESTMACHINESNAME text to the name of your guest OS - which is the name in the vbox machine list)

VBoxManage setextradata "YOURGUESTMACHINESNAME" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/httpfwd/Protocol" TCP
VBoxManage setextradata "YOURGUESTMACHINESNAME" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/httpfwd/HostPort" 8888
VBoxManage setextradata "YOURGUESTMACHINESNAME" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/httpfwd/GuestPort" 80

VBoxManage setextradata "YOURGUESTMACHINESNAME" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/fmsadmin/Protocol" TCP
VBoxManage setextradata "YOURGUESTMACHINESNAME" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/fmsadmin/HostPort" 8889
VBoxManage setextradata "YOURGUESTMACHINESNAME" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/fmsadmin/GuestPort" 1111

VBoxManage setextradata "YOURGUESTMACHINESNAME" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/fms/Protocol" TCP
VBoxManage setextradata "YOURGUESTMACHINESNAME" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/fms/HostPort" 8890
VBoxManage setextradata "YOURGUESTMACHINESNAME" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/fms/GuestPort" 1935

(more about these settings in the virtualbox's UserManual.pdf)

Now you have to restart your guest OS. Settings above allows you to access to your guest OS, for example for port 80 type http://localhost:8888 into your browser in OS-X. You should see the FMS server start page with a video (train). If you don't see, there is something I missed or is wrong.
And one more step, you have to turn of the firewall in Windows. (Sorry but I haven't found a better way.)

4 - Create a sample Flash / Flex project on the client side (host OS)

It doesn't really matter which one you use. Here you are my working actionscript code:

public var nc:NetConnection = new NetConnection();

public function connect():void {
var r:Responder = new Responder(responderResult, responderStatus);

nc.connect('rtmp://localhost:8890/HelloWorld');'serverHelloMsg', r, "John Doe");

public function responderResult(result:Object):void {
trace('Result came: ' + result.toString());

public function responderStatus(status:Object):void {
trace('Status update');

5 - create the server side code (in the guest OS)

The server side parts has to be written in ActionScript 1.0. (Pretty weird.) I just pasted the sample from the tutorial:

application.onConnect = function(client) {

client.serverHelloMsg = function(text) {
return "Welcome: " + text;



Copy it into: C:\Program Files\Adobe\Flash Media Server 3.5\applications\HelloWorld\HelloWorld.asc.

6 - Start FMS server in the guest OS
In Start Menu you can find an icon that starts the FMS server.

7 - Test you application
And be patient if it won't work at the first try.

Of course, these stuffs are all available in the documentations.
Flash Media Server: get all the official documentations
Great FMS service tool for your host OS: FMS Feature Explorer

Best wishes,

Friday, 13 November 2009

Hungarian Drupal Podcast - Episode 3

Hi Readers,

This week we had out third podcast (about development environments). I have to say, I'm so f**king enthusiast about it. I wouldn't have imagined that kind of greatness of a podcast. It's not about us, it's about a channel to share information. And we have feedback. I wouldn't enjoy 100$ per episode as much a correct negative feedback. It means someone is watching you. Ok, enough hype. Let's see the 3rd part:

Magyar Drupal Podcast - 3. rész from Peter Arato on Vimeo.

I guess I forgot to mention, but check the URL we have: That was a huge win for sure.
In the following episode we will continue with the second part of development environments. We left a lot of interesting stuff. On: 19th of November, 18:00. If you follow me on twitter, you will get a notification about the start.

We are waiting for your feedback/questions: podcast {worm} pronovix {point} com

Best wishes,

Drupal life

Hi Readers,

This Friday me and my colleagues took some presentation at the university. I had a pretty cool and easy topic: contribution. For me, it means, how you can be a valuable member of the Drupal community. I always realize the Drupal is such an awesome thing. Of course, it's quite subjective, but have never seen other communities being so viral, enthusiastic. Here you are my slides:

I don't want to duplicate what is in there. I tried to cover the possibilities you can involve to Drupal. And yeah, it is vast, isn't it?:)

Honestly, there are no better slides the Dries's presentations. Those are absolutely awesome.


Monday, 9 November 2009

Drupal FormAPI Examples (with source)

Hi Readers,

We at Pronovix used to keep Drupal lessons at Universty of Szeged (SZTE). My last presentation was about Form API. I made an example module with the following parts:
  • Basic form building - validation - submission
  • System setting forms
  • AHAH form elements
  • Theming form elements
  • Custom Form API (FAPI) field
  • Remote form execution
  • Confirmation form.
You can download the source code from:
If you enable the module, you should see these links in the Navigation menu:

My slides was just a shame, sorry about that, but I like more practical explanations.


Sunday, 8 November 2009

Building a Druplash site - full Flash version

Hi Readers,

I've already spoke enough about Druplash, now let's see how to build quickly (~2 hours from scratch) one. Here is a short demo about the stuff have:

There is several ways to leverage Flash-Drupal, and one is when using a full-sized Flash object on the site.
The features we insist everytime:
Good news: for an initial release, we don't need to write any custom Drupal module. Some modules we have to download:
For the demo we need also:
Enable: Services, Services - Key Authentication, AMFPHP, Views Service, Node Service, System Service, Views, Views UI.
The downloaded Flash application assume you have a Views list of nodes with the name of: news. It also assumes you have a node with NID=1. (So you should create these two

Warning: because of the rush, the site url is hardcoded in the Flash movie. You can recompile the Flex project with the correct path pointing to your site's amfphp gateway, or you put the site under drupal_sx_druplash_full folder (and the site should be there: http://localhost/drupal_sx_druplash_full/).
Update: the compiled SWF is updated in the tar.gz file. Now it should work out of the box on every URL.

The source of the Flex application: (updated)
If we installed successfully a base Drupal 6 site and enabled these modules, let's copy the Flash object (DruplashFull.swf) into: sites/default/files/DruplashFull.swf
Visit the SWFAddress settings page at: /admin/settings/swfaddress
The following image shows my settings:

Now you should see the replaced content if you visit the front page:

I think that's it. You have to give permission to non-admin users if you want to the same content with Flash them. This is just a very quick and dirty demo, but in the Flex source code you can check what basic features you can start.

I worked with the latest module version, but some of them (ex: Services) are under heavy development. Just be aware, user experience may be vary:) If you need any other info, let me know, I'd glad to help you.

Flex source:
Live demo:

Best regards,

Saturday, 7 November 2009

Hungarian Drupal Podcast - Episode 2

Hi Readers,

Let me announce our new episode of the Hungarian Drupal Podcast. Topics:
  • Drupal meetings
  • Open Atrium
  • Search + Solr
As out listeners suggested, we made a topic list (above). This way you know what you can expect to. We set the lights a bit better, sat closer to the camera and tried to speak louder than in the first part. The first episode is watched by more than 170 people. I think it's a good start.
Here you are the video:

Pronovix podcast, episode 2 from Peter Arato on Vimeo.

Next time we will speak about how to build an efficient development environment. I think this is kinda topic can fill not just one full podcast. We'll see.
If you have any question, claim, or advice, please leave me a comment. Thanks in advance.

Best wishes,

Drupalcamp Prague (CZ)

I had the privilege to participate on Drupalcamp CZ Prague: It was an awesome Drupal meeting. I liked the city, I liked the people there. We arrived at the bus station, Prague just before midnight. We lost a bit, but the found the hostel. Both the 2 days there were plenty of good presentation. I also took one about Druplash, here you are my slides:

Although my English still horrible, it wasn't so bad. (I hope.) Though, I realized, when I take presentation, I'm half as smart as other times, at least. Maybe because of you don't want to waste the time with thinking of your words, just pushing the slides. There were some developer interested in the Flash - Drupal way of site building. I'm glad to it.
I really enjoyed the other presentations. Check the program:
At the nights we could taste some delicious Czech beers.
Yup, and the best non-drupal part: I were in KFC. OMG, I love that place. I ordered a big bucket (Kyblik) of chicken with fries and the mandatory unlimited drink.
Lot of good memories, thanks Prague. See you next time.

Best wishes,

Hungarian Drupal Podcast

Hi Readers,

I always had the passion to help and share things I know (or not know). In Hungary, there are so few podcast about technology. That was the moment I realized, let's do it. This is our very first, very low cost podcast:

Pronovix podcast, episode 1 from Peter Arato on Vimeo.

We were so lame, but it seemed we had an audience. Let's see, why it's so cool, even if you have so much to learn? Because it's free knowledge. We bought some beer, heated up the room, sat down the coach and just spoke what we are enthusiast about. We stream every our podcast at the time of recording on UStream, this makes listeners possible to take real-time questions. Later then we realized it's not the best practice to talk about everything. On the other side we got several advice and critics. Let's me say a big THANK YOU for all your help in improving the podcast. Second episode is coming soon. [It's already happened, but you know, I'm a big blog-procrastinator.]

Best Regards,

Saturday, 12 September 2009

Mindmap tool for Drupal

Hi Readers,

As always, long time no see. I intend to write a small wrap-up about my new development, GraphMind: - Flex source
Origin of the project is Kristof Van Tomme's, our CEO idea. If you know FreeMind, you have to admit how useful organizing your ideas, tasks and everything in a mindmap. A whole theory is built around that (ex: GTD).
This a quick demo about how the code worked a week ago:

If you check the project page on you'll get an overview about the features. You can try it also.
For me, the most interesting part was the inner structure of the code. I like to work with actionscript, especially in Flex Builder. Hardest challenge is to handle interaction in a way that doesn't require too much public variables and static classes. First I found a really useful approach: manager classes. For this project we need a small amount of managers for handling events between the different tiers. These magagers, of course, are singleton entities. There is one for the stage logic, one for the connection logic ...etc. Another new (for me) way to handle event driven flows are (as I called them) temporary transfer objects. For instance you need to load data through a connection, you work with the data itself, some state object (reflect the state of the flow) and some others. In an event driven flow you should pass all these items through numerous functions. That is where temporary transfer objects help a lot. When a new data load starts, a temporary object instantiated. During the connection stages (ex: connect, authentication, data load, data receive) the temporary object populates with new properties. At the end of the process you get the temp object with all the required data.
Other thing I'm not sure, if you have a display object represents data what classes you should use. For now I have a display class (subclass of UIComponent) with a property that a data-object class. It works fine, but it's possible there is a better way.
In flex you have a cool feature: view states. You can bind transition effect for state changes. One flaw this feature has is the lack of mixed states. But - now I realized you can do something similar if you group stage elements and use view states on groups (MXML components). Anyway:)
Ok, let's ruin that pink cloud, what about the annoying habits of flash?
I found key events and focus handling a bit messy. Why? Triggering key events you need a display object can receive focus (as far as I know). I use canvas for mindmap which seems incapable of receiving key events. You have to click on another element (textbox, datagrid..) if you want use keys. Ridiculous. Anybody has an idea how to solve it?
Next is onblur events for textinput fields. Onblur event triggered when it lose the focus. But if you click on a canvas element, onblur event on textfield don't triggered. WTF? And these things are quite important.
A small bug from yesterday was save() function for FileReference. It is in the reference but Flex Builder can't find it and so, can't compile. I updated to flex sdk 3.4 and still nothing. Any idea?
I have an education-version key for Flex Builder and it gave me right to get a Gumbo beta extension key (Flash Builder). I was really happy. Yesterday I downloaded and played with it. Importing my old project was seamless, however, Application.application is now deprecated, but the suggested class is not working for me. Needs searching. There is a bunch of new improvements I really want to try. First let's mention themes. And service builder. So cool stuffs. But still in beta. I'll try to upgrade GraphMind to the 4th version of the sdk.


Sunday, 16 August 2009

Augment reality sample

Hi Readers,

I am quite busy as always and have no idea what to post. Recently we've been working on an awesome project involves Flash and Drupal. I can speak about this a lot, but that needs a bit more preparing. Till then I show you something I made in the past. When this awesome flash-3d-augmented reality technology came into the IT world I wanted to try and created a small sample.
That is it:

Really simple. By the way this is my first hackish screencast (because of typing instead of speaking). This English is so hard. Houhh.


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,

Sunday, 28 June 2009

Twistable Flash object with ActionScript3

Hi Readers,

It came to my mind I've never made a twistable element in Flash. So I wrote one. The basics:
It needs an item (descendant of the DisplayObject class) to twist. Don't forget to position this element to the point you want to twist around. (Most cases it is the center point.) My idea is when you click on the object, you store the current angle relative to center of ui element and store the current angle of the object. Then if you move your cursor, you will know the difference between the initial angle and the current angle. And you add this difference to the stored angle of the object. [It is easy, however, my english makes it hard to understand.] The interesting thing is to get the angle from a cursor position. I thought that the good old trigonometrics functions give the shade between 0 and 360 but, it came to light, I was wrong. Some recall:
A triangle with a 90 degree angle has 3 side: adjacent, opposite, hypotenuse. You can calculate the tangent alpha by division of the oposite with adjacent. Arctangent gives the reverse of tangent, so atan(tan(alpha)) = aplha. But if you make some test you realize its not the whole 360 degree (or 2PI in rad) but 2 peaces of 180. Strange, but I have never been a math guy.

Anyway, here you are my quick source. Just paste to a Flash IDE as it is and run it.
var angle_onDown:Number;
var angle_potmeter:Number;
var is_turn:Boolean = false;

var potmeter = new Sprite();;, -100, 200, 200, 20, 20);;
potmeter.x = potmeter.y = 200;

potmeter.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
potmeter.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
potmeter.addEventListener(MouseEvent.MOUSE_UP, onUp);

function onDown(event:MouseEvent):void {
is_turn = true;
angle_onDown = getCurrentAngle(event.stageX - potmeter.x, event.stageY - potmeter.y);
angle_potmeter = potmeter.rotation;

function onMove(event:MouseEvent):void {
if (is_turn) {
potmeter.rotation = angle_potmeter - (angle_onDown - getCurrentAngle(event.stageX - potmeter.x, event.stageY - potmeter.y));

function onUp(event:MouseEvent):void {
is_turn = false;

function getCurrentAngle(relX:Number, relY:Number):Number {
var relDegree:Number = Math.atan(relY / relX) / Math.PI * 180;
return relX < 0 ? 180.0 + relDegree : relDegree;

You can grab the rectangle and twist.

I would be happy if anyone can explain why the formula in the getCurrentAngle() function gives 2 peaces of 180 interval? (That is why I added the ternary operator for the return command.)


Wednesday, 24 June 2009

PHP Beauty

Hi Readers,

Google announced this article collection recently: I thought 'What the heck, let's bechmark something.', and took a small experiment:

<div style="display:none;">

$sum = 0;

$count = 10000;
$iteration = 100;

for ($j = 0; $j < $iteration; $j++) {
$t1 = microtime(TRUE);
for ($i = 0; $i < $count; $i ++) {
//print "aaa"."bbb"."ccc"."ddd"."eee"."fff"."ggg"."hhh";
echo 'aaa','bbb','ccc','ddd','eee','fff','ggg','hhh';
$t2 = microtime(TRUE);
$sum += $t2 - $t1;

var_dump($sum / $iteration);

And the results were quite nice: 0.026 against 0.017. So that is why echo still rocks, because with echo you can use comma instead of period. Never heard of commas for echo before. This is a PHP magic:)


Monday, 22 June 2009

OS X + PHP Part 2

Hi Readers,

As I promised, this my second explanation about how to build a PHP web development environment in OS X (10.5).
As I mentioned a very basic configuration ships with the distro by default. But for me it was not enough. Going further from my last setup ( I noticed there isn't APC for PHP. No GD2 support (neither GD1). I depressed till found this miracle:
Marc Liyanage compiled a very good PHP 5.2.9 with a lot of modules. If you step through his description you can install it quite easily. At the end you get a new php.ini. You need to add your previous xdebug settings to it. For APC see this article: As it turned out, the pecl related APC is wrong on OS X, but the original APC compilation will work.
Lately my favorite high end IDE is the stable NetBeans (6.7 RC3 has a StackOverflow for me). For PHP it works out of the box but for any Java related project I had to change the default java classpath:

In a nutshell thats all about it. The MySQL and Apache server works as I wrote before. By the way just for play I tried the free MAMP application, but I found it a little bit old for my claims. It has a pretty cool minimalistoc control interface, works fine but doesn't contain some imprtant module. To be honest I was't bother with it so much. (My bad.)

One thing. Last week I began to use NetBeans for debugging PHP projects. The reason I didn't use it for debug I didn't know how I can examine pages other than index.php. But as a matter of fact if it starts and finish it's first debug run you can enter any subpage into the browser (the same has the xdebug session) and the debug cycle will start again. So its really cool. There is a big advantage against ViM+XDebug, I like more NetBeans's variable browser. In ViM you are restricted to the php xdebug config (ex maximum variable nested level) and the limited height of the editor. But sake of NB's tree visualizaton you can traverse arrays and objects quite convenient.
(Other tiny minus sign for osx - the default key bindings messes the F2..F6 key usages in vim.)

Thats it. Any webdev environment related question would be welcomed:)


Sunday, 14 June 2009

SQL dump with each database separately

Hi Readers,

This morning I missed my old MySQL tables from Windows XP, but for some reason I needed separate database dumps for each db. As far as I know I've 2 options to do that, dump each db in command line or to write a script in command line. No way. So I made a quick & dirty PHP script to generate the dump commands:

$usr = 'YOURUSER';
$pwd = 'YOURPASS';
$date = date('Ymd');

$conn = mysql_connect('localhost', $usr, $pwd);
$resource = mysql_list_dbs();

while ($row = mysql_fetch_object($resource)) {
echo 'mysqldump -u '.$usr.' --password='.$pwd.' '.$row->Database.' > mysqldump_'.$date.'_'.$row->Database.'.sql'."\n";

And then:
c:\php dumpscript.php > dumpcmd.bat

Thats it.


Saturday, 13 June 2009

First Macbook - webdeveloper enviroment

Hi Readers,

This week I've got my first Macbook. I don't want to say any advertisement for the machine. Apple already has a very ugly campaign, just check and watch some commercial. Anyway. I love it even if it's so hard to setup.
Some quick steps, how you can setup a minimal web developer environment if you've never seen OS X.
  1. OS - by default
  2. Apache (2.2) - Enable it in System preferences / Sharing (Web) []
  3. Apache rewrite - overwrite appropriate line in httpd.conf to: AllowOverride All
  4. PHP - by default
  5. MySQL - download the official 5.06 version package (install both two dmg-s), and link the /tmp/mysql.sock to /var/mysql/mysql.sock
  6. MySQL - if mysql doesn't allow to get in, you have to hack an account []
  7. XDebug : download macvim, xdebug plugin for vim and compile the xdebug extension []
Important paths / files:
  • /etc/php.ini
  • /etc/apache2/httpd.conf
  • /etc/apache2/users/youruser.conf
  • /private/etc/... [almost the same as in /etc]
  • apachectl restart/start/stop
  • /usr/local/mysql/bin/mysql
  • /Library/StartupItems/MySQLCOM/MySQLCOM start/stop/restart
It just an overview, it's highly suggested to read some external materials. My intention was giving a small insight what you should expect. For me (as a first-time macer) was kinda hard to setup the basic stuffs. Of course there are easier ways. If you want to find some seamless solution, just check out these projects: MAMP, Fink.

I want to write about my other experiences about the mac, but for now there are tons of works to do, so back to mac.


Monday, 1 June 2009

Tiny Hanoi solver C in a tweet

Hi Readers,

Recently I've started to re-learn C. (You know, always fun:) Unfortunately I've never know the language well. So, that is my smallest code that can resolve the so-called Tower of Hanoi problem:

Actually the code could fit in a tweet:) Check this out:

main(){h(1,4,3);}h(int f,int t,int c){if(c==1)printf("%d>%d\n",f,t);else{int b=7^(f|t);h(f,b,c-1);h(f,t,1);h(b,t,c-1);}}


Pattern recognision based Drupal trigger

Hi Readers,

Last week I contribute my second module on

I used the so popular technology came up recently: augmented reality with a small difference, not there isn't any 3D magic. (But I'm thinking on it.) You can find a detailed description on the link above.


Drupal sandbox creator shell script

Hi Readers,

I'm a really bad blogger. First, I never write. Secondly, I never write about new stuffs. I have my reason and to be honest, I've seen too many very good article so I had to realise, it's not going to be a tech blog. I'm really curious about how my coming MacBook affects to my reading habit. I've got a lot of hope in it. And another big news for me. I'll be a proud cat holder? Call me crazy but she will be my first child. (Besides that if her teacher says she is the smartest in the class - I won't believe it:) Anyway. To restart this stuff I intend to share a small Drupal site generator script with you.

What is the problem?
I'm a Drupal developer. I need to test modules before using it on production sites. I need to try out a lot of things. And the best for doing that is a Drupal sandbox. But it takes 1 or 2 minutes to create one. (At least for me.) ((It should be a Drupal install contest - yeah:))

Create a sandbox once and pre-populate it when needs a new one.

  1. Download the latest Drupal install:
  2. Install it in a directory called: drupal_sandbox
  3. Install all the modules you want by default (contrib ones as well)
  4. Use the database name of: drupal_sandbox in the settings.php
  5. Tar the drupal_sandbox directory: tar -cvzf drupal_sandbox.tar.gz drupal_sandbox
  6. Create an sql dump: mysqldump -u YOURUSER --password=YOURPASS drupal_sandbox > drupal_sandbox.sql

The script:

#!/usr/bin/env bash

# Directory where the tar.gz and sql file lies
# Base file name for the tar.gz and sql files
# Your web root
# Your MySQL user

cd $www_dir
tar -xvzf $package_dir/$package_name.tar.gz
mv $package_name $1
cd $1/sites/default
mv settings.php settings.php.bckup
sed "s/$package_name/$1/g" settings.php.bckup > settings.php

mysql -u $mysql_user --password=$mysql_pwd -e "create database $1"
mysql -u $mysql_user --password=$mysql_pwd $1 < $package_dir/$package_name.sql

Call the script with a parameter (the name of the new drupal site (directory & sql))
sh ./ drupal_site_for_testing

Thats it. I hope it works for you. On my environment its fine.

Good luck,

Saturday, 28 March 2009

HTML element related data storage

Hi Folks,

I'm working on a voting widget generator Drupal module. Arbitrary voting widgets can be defined through a hook, and my module renders them to the node page. At the final phase the forms are converted to an ajaxian style and this needs a lot of information related to elements. The good old (quick and dirty) way to do this is the custom attributes. For example:

<img src="" class="..." weight="..." type="..." key="..." nid="..." />

As far as I know, it works in most browser, however, I bet it fails on any xhtml validation. (And so ugly.) My idea is a common data storage. You create a new element with a unique ID that can be a key as well in a javascript object, which would contain data. Let's see an example:
<script type="text/javascript>
var data = {};
$('div.class').append('<img id="i1" src="pic1.png" />');
// save data
data['i1'] = {weight:__, type:__, key:__, nid:__, names:[__, __, __]};
// retrieve data
var necessary_name = data['i1'].names[2];

That's all. This example is just a schema. It can help if you generate lots of elements or you want to attach data elements in runtime.


Friday, 13 March 2009

Drupal module finder Flex - AIR application


Recently I began learning Flex. The idea was from my boss and a girl who linked an adobe site with a LOT flex video on it. (Thanks @SquirrelMaster) - check it

In the Drupal world there are two important buzzwords related to Flash: Druplash and Druplex. In a nutshell, these words cover the intelligent way that a Drupal application and a Flash application can communicate between each other. The basic idea behind this is the usage of Drupal as a back-end (information source) and the Flash as a better way to visualize the datas. To embed a flash game, video or a file/image uploader is not communication at all. As far as I know, it is very new field, however, there are quite a lot interesting idea there isn't any world changing way to implement it. If you interested in it, here you are some links to dig:

SWFObject provide a better way to add flash content to your HTML. It checks the client's flash player and browser capabilities. And if the environment unable to render your SWF appropriately, it displays an alternative content -> in the SEO side, makes your page readable for robots.

With SWFAddress your flash object can communicate with the JavaScript on the same page. Thus JavaScript can send a state (like the url) about the site (and from the url the flash can restore some action or timeline state - for example if the url is, it loads the shoes page). And of course vica-versa. Flash can send it's state to javascript and with that the javascript can modify the url for example. If its seems useless just think about sending a url for your friend. If the flash site can't handle the url, it always shows the home page.

Drupal has a module called Services. It defines a bunch of services (user services, node services, ...etc) and supports several layers to communicate (HTTP, RPC, XML-RPC, SOAP). The work-flow abstraction is quite simple. You send a request to the Drupal site, it does something (get data) and send back to the caller. The real power that you can create any custom services easily and with it you can retrieve any the information you want from Drupal.

AMF is a message format Flash use in transactions. It's binary, so mush more smaller than an XML message format. AMFPHP is a converter from AMF to PHP native format.

AMFPHP porting to Drupal.

There are some slides about Druplash and Druplex:

Anyway. I fell in love with Flex. The reason I'm writing this post I developed a small application that helps searching Drupal modules on your desktop. How? With AIR. Unfortunately you have to install the desktop flash interpreter tool: called AIR player. It's more or less the same as Flash Player with a minor difference, it have the flash ran on desktop. Another interesting development: Adobe put the SWF and FLV/F4L technology to free license and strives to ease running flash applications on different devices. You know, now it's not the best on a unix based distro. But, ... at least you have the option for it.

So, back to my Flex app. If you want to try, you can download from here:

Adobe AIR player is available at here:

I can imagine a lot Flex application which can help the Drupal development. Making this was't more than 2 hours. Well, I know, it doesn't do too much as well.

If you have a creative idea that would be great to implement with Flex, please tell me. I'd be pleased to hear any feedback.


Saturday, 21 February 2009

Drupal Timetracker Screencast

Hi All,

This week I made my first screencast. It's about my new Drupal module called Timetracker. I have never ever thought how hard to make a video introduction. As my colleagues said, I speak in Hunglish, some kind of mixing with English and Hungarian. I sware I'm working on to imporve it. But you know. I'm not a rocket scientist. Anyway. That video took me 2 days and a lot of struggling. The module the video about is a tool for tracking your personal activities in the Drupal sphere. You can find several similar pages on the net, like Actually it's a pretty useful application.
My module is still under developing, although it's working fine. But it has some performance and usability issue I want to make better. I sent my application for a CVS account to, I hope they'll answer me soon.
So, here is the brief introduction about Timetracker:

I used Camtasia Studio to record that stuff and to be honest, I amazed how cool is this tool. Unfortunately the free version is time limited but I suggest everybody to try it if thinking about screencasting.


Sunday, 15 February 2009

10 practice how to improve your productivity

I keep myself as a workaholic guy. In the last few years I strove to be more and more productive. There are a couple of practices which save time for you a day. I want to share some of them with you. (DANGER! If you do exactly what is written, you can easily become to antisocial.:)

1 - do your household works rarely
When you washing dishes or clean your room there is a huge overhead to prepare for the process and after that it takes time to work again. If you buy 7 dinner sets or 40 pair of socks your costs are cleared in a few weeks. Do you know the activity scattering theory? If you have N jobs and the i. job takes Ti time than:
T1 + T2 + ... + TN = SUM(Ti)i=1..N * SQRT(N) * 1.2
So it takes more than the total time because you can't change tasks in a moment.
win ~ 3.5 hours a week

2 - walk fast
Be quick whatever you have to do if its not your work. Walk fast to your work and home. An average human walks with 3-5 km/h. When you fast you reach even 10-13 km/h. Anyway, you don't have do window shopping or sightseeing. Products are expensive and the city is boring.
win ~ 2 hours a week

3 - use a mindmap
Thinking on things you don't remember eats time. Nobody can hold everything in his or her head. With a mindmap you can maintain all the things you are going to do. There are bunch of free mindmap applications on the internet. Freemind, MindMeister, MindOMO... If you don't know the GTD methodology, I suggest you to read about it.
win ~ 2.5 hours a week

4 - create the best desktop environment
You can save a lot of time with a well configured desktop. There are some of the best practices:
  • fast dial icons everywhere (frequently visited bookmarks, most used program icons...)
  • scripts for frequent processes (remote connection, generate things, version tracking practices...)
  • use online tools: email, rss reader, mindmap, storage, server works (thus you can work everywhere)
  • make a unix setup script with your custom configuration files, commands and installation profiles (reduce os installation time)
  • use 2 monitors instead of 1 large
win ~ 3 hours a week

5 - listen power metal a lot
If you are listening dynamic music (power metal, speed metal) you feel yourself to be forced to work faster. And it gives you energy as well.
win ~ 1 hour a week

6 - you have to deal with tiredness
Mature human needs about 6 hours of sleeping a day. But even if you sleep 6 hours, you could be tired. I know coffee is popular, but fruits and vegetables are important as well. And also you can organize your works. For example if you are tired, let's do some boring administration stuff. And thus you can do the hard work when you can concentrate.
win ~ 2 hours a week

7 - buy books instead of reading PDFs (but keep those too)
Books are cheap if you think how they can help your job. And you can read faster real pages than the screen. You can add comments and highlight parts easily as well. But PDF documents are really useful when you want to search on a certain keywords.
win ~ 1.5 hours a week

8 - don't have lunch at home
Making your own food takes a lot of time. Buying ingredients. Preparing. Cooking. Eating. Cleaning. And in this case you have to find out what do you want to eat. And to get healthy ingredients cost a lot. Restaurants are cheaper and more efficient.
win ~ 3 hours a week

9 - buy more RAM and use faster internet connection
Everybody hates waiting for programs to start or give feedbacks. Even if it takes a few minutes it happens a hundred or thousand times a day during your work, so let's multiply it: few seconds x 1000 = few 1000 seconds ~ 1 hour . Don't forget a major rule! If you can get things faster, you get things faster, thus you do get more of them. More = better.
win ~ 1 hour a week

10 - never try to guess how many tips you've got before you write a 'TOP X' article
I wasted about an hour with thinking about the 10th practice. But I haven't got any other really efficient idea. Don't waste your own time with useless things.
win ~ 1 hour

Total - you win ~20.5 hours a week! Not bad. If you get 40$ for an hour it is 820$ a week. So a new MacBook is 1299$ and you can buy one in 12 days:) OMG that's beautiful:)

Be agile, be enthusiastic, be efficient. That's it. Thanks for reading it.

Friday, 13 February 2009

I'm back to sum up the last three weeks


Long time no see. First, I'm happy that now I'm working on Pronovix. My new colleagues are awesome. They are really lifehackers:) This company works with Drupal and made several cool stuffs. Until a month ago I'd never participated in any Drupal project. When I began learning from Pro Drupal Development I felt myself strong and energetic and agile. But when I got my first mission, it changed a little bit:) Thinking in a Drupal way is REALLY hard at the first time. You know. Everybody can make a full fledged Ajax site with a strong PHP back-end. But when your hands are tight, it could be a huge pain. And the point. In English. Yeah. That's cool. But I love challenges. Learning is fun. Drupal fun. English fun. Working fun. Thats I guess equal to FUN^4. Not bad.
The other interesting happenings was the installing war. God knows how many times I sad malicious words. Anyway. Its all because my old Asus laptop. There are 4 types of Linux distributions:
1 - not well supported, pain (60%)
2 - deprecated kernel, softwares (10%)
3 - cant detect properly my SiS videocard (10%)
4 - cant detect my Broadcom wifi card (20%)
I know. Every geek is saying that you can always configure your unix based distro. Yes. But I can't. My favorite screenplay:
1 - I need network access
2 - To enable the network I had to fire up my wifi
3 - To fire up my wifi i had to download the firmwares and stuffs from the network
Yes, thats recursive. Maybe some parts of my brain still on running. That cause me a big headache. But I couldn't have a rest because on windows the web development really slow. I tried the follow distros:
Ubuntu (4 version), Mint, SuSE, Debian, Arch, PCLinuxOS, Fedora, Slackware, FreeBSD, PcBSD.
But 2 days ago miracle happened. Just browsed and stumbled upon of Mepis Linux. I've never heard about it. But found quite a lot update, so thought it worth a try. And then ... First it asked me what resolution I want during installation. WOW! Kick ass. Next, it discovered my wifi card and made enable networking. Crazy. Then it can connected to the Debian Lenny repository, so really up to date. Thanks God it uses KDE 3.5.10. Only one defect it has, cant render monochrome fonts. But the default way isn't so bad. I can handle it.
So, I suggest you trying it. At least once. Oh, I forgot the candy:) My webcam is working under Mepis. (Even XP is incapable to do this.) Run and download -
Last I want to share with you, I found a very delicious gummy candy:) And If I mentioned delicious, I registered on I don't know why I did't take that before. To be honest, I feel shame. You know my bookmarking site idea in my former post. You can follow me there:
And one thing at the end. I watched anime. This is a huge step to me. And I get used to drinking coffee in the weekends. Maybe once I'll become to a real geek:)
So. I'm hungry thus this post is over. I hope I could give you at least a small information (use Mepis).
Tomorrow I plan writing a blogpost about 'Top 10 thing which makes you more productive'. Because I'm always striving to be the most productive I can. Now is really bad.
And I wrote a small article about unit/functional testing (Selenium, PHPUnit...), but I need a little time to correct it. Maybe on Sunday.


Monday, 26 January 2009

Doctrine or own database layer

Good Evening fellows,

Last night I commit some changes to github (see at last post). To test that code works properly, I checked out it. (Or checkouted? Sorry for that.) And I realized, I had to modify an accessibility modifier in Doctrine's code. (One variable from private to public.) I had to take this change, because Doctrine has it's own autoloader support. But at the beginning of my development, I decided to use as well. And as we know, two autoloader don't work at the same code. So I built in Doctrine's autoloader in my one, but to work fine, I had to access to $_loadedModelFiles. That's the story. However, I'm wondering, which way I should continue my development. What do you think? The options:

1 - I keep Doctrine, because it is awesome, and create a subclass of Doctrine to populate it with an accessor
2 - Drop this idea and write a thin database layer/connector with a medium level of security features

To make a good decision, I list some pros and cons:

Why I should keep Doctrine?
- it's fully tested
- secure
- OO based
- use the hydrated technology
- use cache
- you can describe relationships between tables, and Doctrine will find out when you try to use something like this: $user->boss->company->ceo->hometown->postcode
- its done
- universal (mysql, postrgesql, oracle, sqlite...)

Why not?
- its huge, probably you don't need it in small sites (and with large sites you chose another framework:)
- its not mine
- you have to download separately
- mess up my autoloader
- not the best for optimizing database queries (I think so, but it could be a very stupid thought)
- its huge (again)

I guess, Doctrine should have to go. But I will break my head on it this week.
Anyway, If you could suggest me anything... please, I would be glad about it.


Saturday, 24 January 2009

PHP development


In this post I'm gonna write, what environment I'm working in. I'm always hesitating about what os should be used:
- linux (debian, ubuntu, slackware)
- solaris
- windows (xp, vista)
Making easy the choice, I'm usually forced using windows xp. (It must be some 'LOL' in your head.) I tell why. At first, Adobe Flash/Photoshop runs only under WinXP (and OS-X, but unfortunately I don't have enough money to buy a Mac, and iDeneb ( doesn't support audio). Next, in my humble opinion, that on TFT display only the plain old monochrome font rendering the best method to display texts. I hate when I can see the red and green/blue offset near the fonts face. And to be honest, some unix distributions have some problems in this field. Even if you managed to setup monochrome fonts in the base system, qt3 and qt4 applications, there are several place where ugly fonts left (eg. in browser). I think if you are a web developer, it matters. Anyway, from my side the main reason the adobe products. I hate to reboot systems every hour. That's, why I use XP. But, as you read before in my blog, I use VirtualBox as well (with Ubuntu on it):)
To code I usually use Eclipse PDT (now version 2.0, hurray!) or GVim. This morning I found a very exciting tool which for debugging PHP:
It wasted half of the day to setup, but totally worth it. To raise your curiosity, I tell only a little about it (more on the page I linked):
With this Vim + remote XDebug you can follow the code running at runtime, line by line, function by function. You can see the function stack, breakpoints ... kicking awesome. (and a cool magic for those you want to enchant)
For tracking my code I get used to using GIT. I'm glad to know GIT. If you know too, you know what I mean, If not, just visit and discover it. Unfortunately msysGit got across my system (some memory dump, even I uninstalled CygWin completely), so I use Git on CygWin. It's convenient, and can run gitk with graphical interface. I had a small pain pushing my repo to github (because of ssh keys), but at the and it succeeded. If you are enough brave, visit my github repo at:
I decided to maintain this framework more frequent. Working with Drupal gives me a lot idea how a good framework has to be work. But of course, I don't want to steel:) [Think about it, for a minute! What is stealing? Especially in the development world. Not an easy topic. It needs bears to discuss. A lot!] Anyway its free as Drupal. So, nothing to worry about.
To finish my dev. environment, its important to tell some about the background:
- MySQL 5.06
- Apache 2.2
- PHP 5.2.7 (with APC, PDO, XDebug...)

Thats all folks, If I forgot something, I strive to recover that.

Friday, 23 January 2009

JQuery minimal validation plugin

Hi All,

Tonight I am gonna spread a dummy JQuery plugin:) At first I want to fix that I love jQuery. It's logical, well structured and awesome (like Barney Stinson). One boring night I wanted to create a jquery plugin, just for fun and see how it works. I decided to write a validation plugin. The topmost features of a validation plugins are the follows:
- disable submission until all the fields are fill the requirements
- display some information about the error's cause
- sign somehow the parts of the form are false
- if an item became valid, warning message will disappear (toggling)
And of course, there are several criteria related to different kinds of form elements:
- not empty (required)
- only digits
- email
- min/max value/length
- ... etc

I made the basic features with checking 'required' criteria. This sample for those guys (ladies) who recently started to work with jquery or javascript. I tested it on newest browsers (FF3, O9, IE7, C1), and worked fine on each of them. If you curious about some other criteria implementation or anything, I will happy to help you.

And the stuff... oh yes. It needs a form, like:
<form action="" method="post" id="form1">
<label for="name">Name</label>
<br />
<input type="text" name="name" class="required"/>
<br />
<label for="email">Email</label>
<br />
<input type="text" name="email" class="required" />
<br />
<label for="description">Description</label>
<br />
<textarea class="required" name="description"></textarea>
<br />
<br />
<input type="submit" value="Submit" />

and needs a style:
.validation {
background: #f55;
padding: 4px;
border: 2px solid #fff;
color: #fdd;
font-size: 10px;
float: right;

and finally needs to bind to a form via jquery:
<script type="text/javascript">

That's it. If you want this working sample:
View it -
Download it -
[after download - don't forget to get jquery####.js and link in the html]

Sleep well

Tuesday, 20 January 2009

Firefox bookmark export

Hi Everyone,

Once happened this situation. I wanted to export my bookmarks from Firefox (3.0.5), but no one *.html files were created. Ok, I thought, JSON format is still appropriate, but an error message occured, and the exportation was failed.
I find this bug report about it:
So maybe Avast antivirus and PC-Tools Spyaware Doctor was guilty for that matter. But I didn't tend to close those applications, so, here is a tricky way to solve the problem:
Open Google Chrome -> Import Bookmarks and Settings -> Select Firefox and the bookmarks checkbox -> Import ... and now you are able to export the same from Google Chrome.

Sometimes I'm thinking about a site I should develop for saving personal bookmarks online. I can imagine some enchanted feature in it, for example, at first, it could load a speed dial page (like Opera). Or there would be a scored list. So, if you visit a page more times than others, it would be on a better place in the ordered list. I think its sounds logical, because some pages are used more frequent, so its likely to search these links more times.
On the other hand, its on the web. Pretend you need an important website you save before, but you saved it at home, and you are somewhere in the world (or at work). So annoying. Maybe, at default all the links could be private, but you can share any of them (like Google Reader feeds). But now, it is just an idea. And as always, probably there are several sites exists already in the internet ... please inform us if you know a good one:) Thanks!


Friday, 16 January 2009

Save Skype chat history


Tonight I want to present my first VBScript. Before having lunch, I had some free time, so I surfed the net, when bumped into the developer section at I remembered, my every OS-reinstall destroyed Skype chat history. But to be honest, the default format of the history filer is very messy, so it is difficult to read. I decided to delve into the SkypeAPI technology and it turned out that making simple scripts is so easy. You can use PHP, JavaSctipt, JScript, Java and VBScript. I choose the last one, because it seemed to be the most easy to run in Windows. You just put in a file with vbs extension, and run. So here is the code I wrote, I'll tell how it works soon:
' Define global variables
Dim oFSO, chat_file, folder_to_save
' Directory where You want to save history (you can modify it)
' Now it is relative, so it will be created where Your *.vbs script runs
folder_to_save = "SkypeChatHistory"
line_count = 0

' Create FSO
Set oFSO = CreateObject("Scripting.FileSystemObject")

' Connect to Skype API via COM
Set oSkype = WScript.CreateObject("Skype4COM.Skype", "Skype_")
' Open skype, if it is not running
If Not oSkype.Client.IsRunning Then
End If

WScript.Echo "Skype history will be saved. Found " & oSkype.Chats.Count & " chat group."

' Iterate chats
For Each oChat In oSkype.Chats
names = ""
' First name is You, so it is unnecessary to keep
no_1st_flag = TRUE
For Each oUser In oChat.Members
If no_1st_flag Then
no_1st_flag = FALSE
   names = names & "_" & oUser.FullName
End If
get_file("chat" & names & ".txt")
chat_file.WriteLine(vbNewLine & "==== CHAT HISTORY (" & Replace(names, "_", "") & ") ====" & vbNewLine)
line_count = line_count + oChat.Messages.Count
' Fix by an anonymous commenter
If oChat.Messages.Count > 0 Then
For Each oMsg In oChat.Messages
' Fix by Vadim Kravchenko
On Error Resume Next
chat_file.WriteLine(oMsg.FromDisplayName & " (" & oMsg.Timestamp & "): " & oMsg.Body)
End If

WScript.Echo "Backup was finished (" & line_count & " line saved). You can find your chats in: ./" & folder_to_save

' Garbage collection
SET chat_file = NOTHING
SET folder_to_save = NOTHING

' Access to a file given by name
Sub get_file(file_name)
' Parameter fix by: rommeech
Set chat_file = oFSO.OpenTextFile(folder_to_save & "/" & file_name, 8, True, -1)
End Sub

' Find an appropriate directory the logs to save, however, to avoid collision with former dirs
Sub set_next_free_dir()
If oFSO.FolderExists(folder_to_save) Then
ext = 1
While oFSO.FolderExists(folder_to_save & "_" & ext) And ext < 100
  ext = ext + 1
folder_to_save = folder_to_save & "_" & ext
End If
End Sub

Save it to your Desktop (*.vbs), and double click on it. At the first time, Skype will ask you, whether you are aware of the security issues, and really want to add permission to connect the SkypeAPI ... if you trust me, just click OK. It will creates a folder called SkypeChatHistory and some files in it. Every filename consists the other member of the chat sessions, so, if you talked 3 times with your friend, John Doe, there will be a 'chat_John Doe.txt' in SkypeChatHistory with 3 conversation in it. If you are keen-eyed, you will notice conversation lines are in reversed order. --homework-- :)
Now, I think, this code is quiet enough to save messages, and learn from it the way it works. If you can write a really small function to invert the collection (oChat.Messages), please comment it, and I will extend the code. Perhaps I make a gui for it with Visual Studio, I don't know. It must be dozen of good Skype backup applications already.

Update: eigenein did a fantastic job making a Windows application for the same purposes:

Sleep well!

Wednesday, 14 January 2009

Books from Amazon

Today finally I've got my books:

Code Complete (2nd edition)
Programming Ruby (2nd edition)
Pro Drupal Development (2nd edition)

Now I see, each one is second edition. Nice. I'd read before this books in pdf, but both of them consist over 700 pages ... and my eyes burn down if I read it on the screen.
I started to work with Drupal a month ago. It's really interesting, and a little complex at first sight. This book is the best I've heard. But I found some mistake in the sample code in the book:
  • page 23: the 'variable_del(...' line is unnecessary, the page wasn't load with it for me.
  • page 151: need an extra line: in 'function joke_load($node) {
    return db_fetch_object(...
  • page 216: after '} else if ($delta == 1 && user_access('administer nodes')) {' need an array definition:
    $items = array();

I suggest you to download the original source code from, it has the correct code.
If anybody found some typo, please report me and I will put that in the post. Or if I wrong, tell that as well:)


P.s.: And one thing for beginners like me with Drupal! My first Drupal sandbox was in WinXP with normal php module collection + APC. (PHP 5.2.8, MySQL 5.06, Apache 2.2) But when I called the modules page in the admin section, it took 17 seconds. Very long time. But I guessed its normal, because when Drupal loads admin module page, it reconfigures all of them, and crawl some new one, if it finds. But last night (just for fun) I tried it in Ubuntu (in VM), page loaded in 1-2 seconds. I was amazed. Even I didn't install apc in the unix environment. So, just count with it.
Anyway, there is a very good article, how to get Drupal to run faster:

Tuesday, 13 January 2009

Search PHP function from terminal


Last week I bought some unix books, beacuse I almost blowed up with the new Slackware. It is happened, that it didn't recognized my wifi network ... I am not aware of unix network layer. So I thought it is the right time to digg in the topic. By the way, my first issue is a shell script, which can find a php function with its phpdoc and exact location.
How it works?

# Usage: ./pfs <your dev. dir> <function name>, eg.:
./pfs ./project1 user_get

And the code itself (pfs):

# Check params
if [ $# -lt 2 ]
echo "Missing parameters.\nUsage: php_function_search [path] [function name]\n"
exit 1


for extension in php inc php3 html htpl
for file in `find $1 -type f -name "*$extension"`
if [ -f $file ]
# Find function line
function_line_array=`cat $file -n | grep "function $2" | awk '{print $1}'`
for function_line in $function_line_array
comment_end=`expr $function_line - 1`
# Find the 1st comment line
comment_start=`cat $file -n | sed -n "1,$function_line p" | sed -n '/\/\*\*/ p' | tail -n 1 | awk '{print $1}'`
non_comment_start=`cat $file -n | sed -n "1,$comment_end p" | grep "^[^*]*$" | tail -n 1 | awk '{print $1}'`
if [ $comment_start ]
# Print doc
echo -ne "\033[00;32;40m"
echo "Found in <$file> on line ($function_line)."
if [ $comment_start -gt $non_comment_start ]
echo -ne "\033[00;36;40m"
sed -n "$comment_start,$comment_end p" $file
echo -ne "\033[00;33;40m"
sed -n "$function_line p" $file
echo -e "\033[00;37;40m"

Some aspects. Function name covers the first part of the function name. For example 'pfs ./ user_get' will match to user_get, user_get_name, user_get_all ...etc. First, the directory given is walked recursively to find all files. Search in each file the function pattern. It gives the line numbers those are in. Then until! that line the script searches the last line starts with '/**' (phpdoc block start). And there is another barbarian hack. It searches the last noncomment line, because if the last noncomment line num is bigger than the last comment line till the function, that means the comment don't relate to the function. So we shouldn't list it. After all, all block displayed width different colors: echo -ne "\033[00;36;40m". Sometimes when you need to know, what parameters a specific function requires, or what is the functions exact name, or whether exists any alternative copies of the function... it seems useful.
Just try it, and if you find a bug, please report it, a fixed it immediately.