cakebaker moves to a new kitchen

After some thoughts I decided to leave the wordpress.com kitchen and to move to my own kitchen where I will have more freedom. What does that mean for you? Well, for you the urls change. The new urls are http://cakebaker.42dh.com respectively http://cakebaker.42dh.com/feed/ for the RSS feed. I am sorry for the inconveniences…

This is the last post here, all future posts will appear in my new kitchen. So I hope to see you there soon :)

pic2color

As I got an invitation to test the pic2color service, here a short review.

The goal of pic2color is to extract a color scheme from an image. It is an interesting idea, but the service is not really practical yet. You can select or upload an existing image, and it creates a WordPress theme with the color scheme from the image. If you don’t want to use that theme you have to manually extract the color values from the CSS file…

To test it yourself use the following credentials (I don’t know how long they will be valid):

Login Name: alpha_sZbX3mkr
Password: pic2color

Getting Things Read

As a blog reader you probably know the “problem” of the daily information flood from the blogosphere. If you have subscribed dozens of feeds you usually get dozens of new posts a day. In this post I will show you how I deal with that “problem”.

My strategy consists of two elements: scanning phases and reading phases.

The goal of a scanning phase is to bring down the “new posts” counter to zero. During such a phase, which takes around 5 minutes, I open each feed that contains new posts (in Bloglines that action resets the “new posts” counter for that feed). There are three options of what I can do with every post:

  • ignore it
  • read it
  • save it

If there are keywords in the title I am not interested in I ignore the post. There are probably other factors involved in this decision, but I am not really aware of them as the decision is made very fast. If a post overcomes this check, I look for the length of the post. If a post is short (that means I can read it in about 20 seconds), I read the post, otherwise I “save” it with checking the “mark as new” checkbox in Bloglines. That increases the “marked as new” counter, but has no effect on the “new posts” counter. If I have done this process for each new post of the feed, I move on to the next feed.

My day usually starts with such a scanning phase to see what interesting posts await me later. During the day I do a scanning phase before each reading phase.

The goal of a reading phase is to decrease the “marked as new” counter. It is obvious what happens in such a phase: reading the posts marked during the scanning phases. The number of posts I read during such a phase depends on the length of the posts and the time available (a side note: as it is not possible to estimate the reading time for posts of short feeds I usually do not subscribe to such feeds).

I switch to reading phases when my productivity is very low, e.g. after lunch. So my day usually contains three such phases.

Ok, that’s it. I hope I could give you some inputs for your own Getting Things Read approach.

Don’t forget to exit after a redirect

Last weekend I discovered something I was not aware that it works that way: that code defined after a redirect is executed. A simple example:

class UsersController extends AppController
{
    function beforeFilter()
    {
        // not logged in, so redirect to the login page
        $this->redirect('/login');
    }

    function delete($id)
    {
        $this->User->delete($id);
    }
}

This example redirects _and_ removes the specified user even if you are not logged in (you just have to know the url to delete users). To fix that potential security hole you have to add an exit() after the redirect:

function beforeFilter()
{
    // not logged in, so redirect to the login page
    $this->redirect('/login');
    exit();
}

findABaker job board started

This week there was a discussion in the IRC channel about a missing job board for cake related jobs. VoilĂ , here it is: findABaker. Feedback is as always welcome :)

Btw: I switched to a minimalist blog theme which should fix the issues with displaying code snippets in some browsers (and it is a good fit to my minimalist writing style *g*).

Selecting data in a specific date range

Sometimes, you have to return all objects created in a specific date range, e.g. you want to return all posts created in the last thirty days. Thanks to the nice functions for date operations provided by MySQL this task is simple:

$this->Post->findAll(
    'WHERE Post.created >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)');

CSSplay

An interesting site: CSSplay provides a lot of examples of what can be done with CSS. It is impressive what can be done with CSS (especially for someone like me who often struggles with CSS *g*).

YAML in a cake? No, thank you!

While implementing fixture support in the testsuite the question arised which format should be used for the fixtures? The first answer was: YAML, of course. It is used in Ruby on Rails, so it cannot be bad ;-) Hm. Let’s have a look at a simple YAML example:

// urls.yml
cakephp:
  id: 1
  name: CakePHP website
  url: http://www.cakephp.org

manual:
  id: 2
  name: CakePHP manual
  url: http://manual.cakephp.org

It looks nice. But there is one “problem”. It violates the DRY (Don’t repeat yourself) principle: the column names are repeated in each record.

So I decided to use a different approach: plain PHP. It is simple: each fixture is a class, and each record is a function. The YAML example from above rewritten as a class looks like:

class Urls
{
    function cakephp()
    {
        return array(1, 'CakePHP website', 'http://www.cakephp.org');
    }

    function manual()
    {
        return array(2, 'CakePHP manual', 'http://manual.cakephp.org');
    }
}

Simple, isn’t it?

Updating multiple divs with Ajax. Without crashing Firefox

In an earlier post I showed you how you can update multiple divs with Ajax. But there was one problem: it crashed Firefox on my machine, and other people reported the same problem, whereas it worked for others…

In a comment, Josh Southern, pointed me to the cause of the problem: the “latest” version, 1.4, of prototype, the Javascript framework used by CakePHP, caused the problem. After replacing the prototype library with the latest version (1.5.0_rc final) provided with script.aculo.us, the example worked fine with Firefox. Thanks to Josh for the hint!

Take over the “control” of some urls from CakePHP

By default, CakePHP takes full “control” of all URLs at the point where it is installed. Sometimes that behaviour is not desired. For example, my hoster defines an url like mydomain.com/stats where the statistics are available. If I install CakePHP in the root, this url no longer works resp. causes an error in CakePHP. The solution is to modify the .htaccess file in app/webroot. The original .htaccess file:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

And after the modification:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} ^/stats/(.*)$
    RewriteRule ^.*$ - [L]
</IfModule>
# Begin CakePHP
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

The added rule is rather simple: if the url starts with /stats stop the interpretation of the .htaccess file. That’s it.

Follow

Get every new post delivered to your Inbox.