Monthly Archives: December 2008

The last post for 2008

Merry Christmas and Happy New Year to all readers of this blog!

This is my last post for this year and I could say I am pretty happy with the results achieved. There are 42 posts and 311 comments on them. Hopefully some of the posts helped someone, which is the main goal of this blog.
So, next year I hope they will be at least 1.5 times more. (at least I am thinking for stable growth) :).

Ok, the main reason for this post is completed, now it’s time to show you what brought me Santa Claus … a second monitor as well as good Video Card with 2 outputs, so now I am working on dual monitor machine. Here is the picture of my new work place:

Dual screen

Adding second screen on Ubuntu is really piece of cake – I was ready to go after 15 min including the HW mounting ๐Ÿ™‚ Hopefully this addition will increase my productivity ๐Ÿ™‚

That’s all folks. See ya next year! Happy New Year to everyone!

Autoload your javascript and css in CakePHP

Have you ever wanted to have all your css or javascripts files loaded automatically once they are on place under /webroot/js and webroot/css folders? Well this is the solution.

What is all about

I’ve build a quick helper which will include all files under the js/ and css/ directories. So once the javascripts and css are there, they will be loaded automatically.

How to use it?

Using it is really easy. It’s like a normal helper:
1. add the file autoload.php under your /app/views/helpers
2. add it in the $helpers var in the controller
3. add the following snippet in your layout file. It should be under /app/views/layouts:

<?php echo $autoload->javascript();?>

This will include all files under /webroot/js

<?php echo $autoload->css();?>

This will include all files under /webroot/css

<?php echo $autoload->all();?>

This will include all files under /webroot/js and /webroot/css

Key features:

1. The helper includes all files recursively.
2. The helper includes also files under /root/vendors/js and /root/app/vendors/js too (same apply to css). Vendors are loaded first. (Thanks to suggestion from Juan Basso)
3. The order of the files in one directory is based on the name, so now you can control the order as well. (Thanks to suggestion from Juan Basso)
4. Files starting with . (dot) are not included, files under directories starting with . are not included as well, so you can exclude some files
5. if you want to load some files after other use directories. For example if you want to include plugins after the main lib (jQuery), place them in plugins directory like:
the result will be:

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/plugins/plugin_one.js"></script>
<script type="text/javascript" src="js/plugins/plugin_another.js"></script>

(same apply to css as well)

Warning: I’ve noticed that this helper doesn’t work properly with scriptaculous, because the script tries to load the additional plugins and they fail, but for jQuery there is not a problem at all.

Finally here is the code of the helper:
Continue reading

Careful with JavaScript includes

Ok, this is not a code snippet article. It’s just an experience which you probably already met, but it was nightmare to find and it took me 1/2 a day to fix this “stupid” bug.

So what is the case?

Working on a project including some advanced JavaScript and Ajax techniques my coworker Milen noticed that the Session is not behaving as expected. In a simple function like:

 function test($id = false){
  if ($id != false) {
    echo $id;
    echo $k = $this->Session->read('some_var');
    $this->Session->write('some_var', $id);
  $this->set('tests', $this->paginate());

The result should be quite easy to be predicted: if you pass for example 5 on the second reload the $k should be with the same value as $id. Unfortunately instead of 5 the $k was ‘images’. Yep, quite strange, isn’t it?

if you put die() at the end of the function, the result is as expected.

What was the problem

In our current project we are using jQuery and some of it’s plugins. So the problems was in the ThickBox plugin. If you remove it from the header everything works.

Digging into unpacked version of the plugin we’ve noticed that the loading picture is not where it should be. there is an variable

 var tb_pathToImage = "images/loadingAnimation.gif"

and as you may notice the path is not compatible with Cake convention and obviously it’s not in the http://server/cakeapp/tests/test/images/.

In the example above we were writing id into the session. Yes but calling: http://server/cakeapp/tests/test/images/loadingAnimation.gif mean that $id take value of ‘images’.

It was quite tricky, because if you loading CSS or JavaScript and the file is not there, FireBug or even the html /if there is no correct CSS the styling will fail/ will warn the developer, but image loaded into the JS function is quite difficult to find.

Anyway, the conclusion is “Watch you JavaScript libs and what files they require”.

That’s my face

last week I found this site [That’s my face] and I decided to take a try.

The process of submission is very easy. You need 3 images (front, left side and right side), once submitted you need to specify some key points which will make these images to become 3D object. Once you finish this, your face went on queue and it will be ready after couple of ours and the site will send you notification mail.

Official description of the service:

How it Works : Take a frontal and profile photo of your face, upload it to our servers and within a few hours we’ll generate your facial profile which includes:

Site features:

  • Your face at 20, 40 and 60 years old
  • Your face as an African, Indian, Asian or Caucasian
  • Your face as man or woman
  • Your caricature
  • Identify your facial asymmetries
  • Attractiveness rating
  • Compare yourself to others and find you look-alikes
  • Buy your custom-made FaceStatue!

I really liked the ages simulation. ๐Ÿ™‚

Here is how I will look at 60 years:
That's my face

There is also analysis of your facial features:

  • 61 Shape Features
  • 26 Asymmetric Shape Features
  • 36 Skin Features

There is also “similar faces” comparison:

  • People with similar shape+skin
  • People with similar shape
  • People with similar skin
  • People with similar asymmetries

It’s a really big fun using it! I would recommend you to take a try.