Category Archives: General

All uncategorized stuff

New hosting for this blog

Hi guys,

if someone tell you that it’s easy to start writing in your blog after looong break – it’s a lie πŸ™‚

Just wanted to say that this blog was moved to a new host. It was long time planned, but I’ve always delayed. The reason for movement according to the hosting provider was, that it exceeds the limit of the CPU time. For me a blog with less than 100 posts should not be such BIG problem…

Here is the stats of CPU usage from my account.

2009-02-18:      27.45
2009-02-19:      26.60
2009-02-20:      24.21
2009-02-21:      20.22
2009-02-22:      23.40
2009-02-23:      28.73

For me is really strange, and because the current host is really my server where I have control over all resources I will check what caused this load.

Anyway, the guys from the hosting company where really kind and supportive, and even proposed to pay me some compensation about this inconvenience, so it was (and still is) pleasure to work with them.

That’s it.

Strange issue with captcha field

Captcha caseWell, it’s more an observation than a real problem.

For my current CakePHP project I had to set a captcha field to a user registration form. I decided to be “creative” and I set the captcha image as background of the input field. In fact the graphical representation wasn’t bad at all. Unfortunately when it’s used, the captcha word shows wrong image and of course the result was wrong. To be correct the first attempt was always ok, but the second one (let’s say if the user decided to register again) the captcha was always wrong.

I checked everything especially after the image in Javascript library case and I couldn’t find anything suspicious.

The solution came when I removed the image from the background of the field and call it with an <img> tag. This time everything went just fine. This make me think that it’s a cache problem. I didn’t dig it deeply, because for now it’s working and as you can see it’s looking better.

So, an advise from me – never put your captcha image as background of your field, or call through css. Just use good old <img> tag instead.

Book review: CakePHP Application Development

CakePHP Application Development

In the beginning of December I’ve been asked to write a review of a book called CakePHP Application Development. The interesting thing was that I received a copy of the book exactly on my birthday – 29-th of December (probably consequence, but it was really nice). In this article I will write about what this book covers and my opinion of the content. Hope it will be a good guide for these of you who will decide to buy a copy of it from Amazon.com.

What this book covers

First two chapters start with some theoretical explanations about concepts and patterns which are used in the Framework as well as the process of installation of the framework.

The next chapter explain how to build a really simple application. The readers could use to with the framework way of coding, everything in this chapter is hand crafted, so people could actually see how it’s works.

After this there are 4 chapters which explain in details how the Models, Controllers and Views are working in details.

There is one chapter which explain how to build an scaffolded application with the Bake console script. There is an explanation how to create Models, Controllers and Views.

The next chapters explain how to build a real world example with CakePHP called Quickwall (Questions and Answers), which is different from standard blog creation example. In these chapters the authors upgrade and optimize the app and expand it’s functionality, so at the end it could be used in the real world.

The good things

  • Even though it’s really difficult to write for a framework which still is in development, where some coding conventions could be changed, this book cover almost everything which is currently used in CakePHP1.2
  • The book is build with example driven approach which is really helpful for understanding from the developers
  • Each article is separated in sensible 3 sub-sections: introduction, or theoretical part, Time for action and What Just Happened. This approach is really useful, because first, explained what will be done in the current chapter, the second part display the actual code snippets and the third one explain step by step the code presented in the previous part. For me it’s really good approach of writing a technical book
  • Using non trivial building a blog is also a plus, I personally don’t think that anyone will write a new blog platform, just because for fun. The Quickwall application could be used in real world without any problems.

What I didn’t like

  • It’s opposite of the first thing in the previous list – just because the framework in still in motion the book is jist a little bit outdated. There are few code snippets where I found that for example condition word is in the right part, while at this moment it’s moved to the left. The code in the book was:
    'conditions' => array('ModelName.field_name' => 'LIKE value')

    while it should be

    'conditions' => array('ModelName.field_name LIKE' => 'value')
  • There are some things which are missing although they are well known – the behaviors. The same as the authors explained about the components and helpers, they should take a moment and explain the behaviors as well. In fact this is totally missing in this book.
  • Although the validations are well explained in the book, I miss the list of methods provided from the core.
  • There isn’t any information about the internationalization, which for me as developer working with many people and different languages is essential.

The conclusion

I would recommend this book for PHP developers who are new to the framework and they are willing to understand the core functionality of it. With the good approach of introduction-code-explanation, it will be really easy to learn how to use the CakePHP. This book could build a base, but it cannot create from you an advanced CakePHP developer (well I think it’s not the main purpose of it anyway). The learning is ongoing process and people which are willing to learn could start with this book, but after this, they need to continue reading other materials, as well as start with real development tasks, because the practice is the best teacher invented ever.

Here is a sample chapter from the book kindly provided from Pakt Publishing

Reviews by others:

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!

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.

My first WordPress plugin

Hey,

I am very proud to present you, my first plugin for WordPress platform – Autocompleter.

The plugin adding autocomplete functionality for the search input field of your blog. The values are the tags and categories existing in the blog and this way you will help your visitors to find easily the proper information in your blog.

My first implementation was with Prototype and Script.aculo.us, but because I like very much jQuery library and I found a wonderful plugin for autocomplete, I build it with jQuery.

You can check the demo in this blog – top right – search box πŸ™‚

Hope you will like it and you will vote for it πŸ™‚ Thanks

The official page is: wordpress.org/extend/plugins/autocompleter

bInspiration.com – a small and funny application

binspiration.com Hey guys,

I am really proud to present my last project written in CakePHP – bInspiration.com.

What is all about?
bInspiration.com is a web 2.0 service which aims at helping people to get inspired. Visitors are challenged to write a sentence including 2 already given words. The application is funny way to get creative, because “filling the gaps” in a text could give unpredictable and interesting results and that’s why I thought it’s really inspiring. More you can learn from about section of the site.

How long does it take to create this
Well, I’ve decided to create this application somewhere about mid of June and in fact the time for development and design was really short, about week and a half, but due to some hardware and admin problems with my hosting, I’ve delayed the start up.

Later on, I decided to show it to some friends and the responses were not very optimistic. Most of the people didn’t get the idea of the site, so definitely there was something wrong. Apart from this I received some very good ideas for improvements and I decided to add them before going live.

The features

  • Ajax interface – the whole interface is ajaxed and it’s really easy to use it.
  • Multilingual – thanks to CakePHP i18n class, the application automatically detect the browser language preferences and translate whole site. According to this, all user’s created content will be filtered by the selected language, so users can read and write in their preferred /or at least available in the site/ language.
  • No administration – yes that’s true, and it’s feature. As a real Web2.0 application, visitors of the site are the real administrators. They can vote for each sentence in the database and from their decision the content will be promoted or completely removed from the database /two spam votes will remove the sentence from the database/.
  • Follow an author – there is possibility to browse through all authors in a specific language. It’s also possible to follow them by subscribing to their rss feed.
  • View the archive – it’s possible to browse through all sentences in the specific language.
  • Changing the given words on the fly – this was an idea from Daniel – to give possibility to switch the current fixed pair, if the visitor is not inspired by the current one.

Future plans
Well, the plans really depends from the activity of the users. πŸ™‚ But at least I have idea to make some statistical reports such as

  • Most active language
  • Most and worst sentence by language
  • Most active author
  • Most used words
  • Probably a contest πŸ™‚

and many other.

I would love to hear any comments about it.

Adding autocomplete field for search in WordPress

Added a nice Autocomplete field of the search box in that blog /top right/. It’s really nice to have and I really enjoyed doing it.

I followed that article: How to: Create an Ajax-based Auto-completing Search Field for your WordPress Theme, but instead of using suggested js code, I’ve used Script.aculo.us Autocomplete way.

I really enjoyed and I hope you will like it too.

Update: I’ve wrote a plugin for this: nik.chankov.net/autocompleter/. Enjoy!