Book meme

The blog of Mariano Iglesias pointed me to a little game that is interesting. The rules:

  1. Grab the nearest book.
  2. Open it to page 56.
  3. Find the fifth sentence.
  4. Post the text of the sentence in your journal along with these instructions.
  5. Don’t dig for your favorite book, the cool book, or the intellectual one: pick the CLOSEST.

Here is my meme:

“You must make it very clear that this code is disposable, incomplete, and unable to be completed.”
The Pragmatic Programmer, Andrew Hunt & David Thomas

A couple of people did it already and it is fun to see what they picked and what sentence it is become when you remove it out of its context.

Checking out the CakeBot

I had a spare moment which is very rare and immediately took the opportunity to do what I wanted to do for ages… Check out the CakeBot!

With a couple of friends we have our own IRC server and I wanted more flexibility then the modules they use now.
CakeBot is an IRC bot written in cake and you can check it out at https://svn.cakefoundation.org/irc/branches/cakebot_1.0.x.x. I think achew22 and kabturek wrote the cakeBot but not sure.

The most of you people who has been on IRC channel of CakePHP knows what it is but here are some of the features when checked out on your own server:

  • It has a web interface to add users, channels and tells.
  • Web interface for the logs for each channel and can be searched
  • Adding commands (= hooks) is as easy as writing simple shell tasks
  • Adding simple commands by everyone to the database (~tell)

Some disadvantages I’ve encountered:

  • ~help, ~seen and ~forget commands are not Tasks but are in the Bot Task.
  • Passing the channel name and other params from the Bot to the commands is not very easy. Only the params you passed from the client are now available.
  • Missed the users_controllers.php for the web interface

Hacked all that bit still not satisfied abouth passing other parameters that are only available in the bot Task.

Checking query string with mod rewrite

The latest project I had to rewrite old URLs to new URLs. These URLs have been on the internet since 1994 so for the search engines and ranking on those pages it was very important.
Many URLs had to be detected through there query string, their GET arguments. Here is an example:
(more…)

Sending url parameter through _GET and Cake convention

Yesterday I tried to pass an ‘url’ GET parameter to cake but I got a ‘Http controller missing‘ error. Here is the url:
http://www.example.com/images/notify?myid=456&time=782638762863&url=http%3A%2F%2Fwww.cakephp.org
After a while I remembered that CakePHP uses the ‘url’ parameter when using mod_rewrite:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

This means that every request after the domain name is added to the url parameter. F.e.:
http://www.example.com/items/view/1234 will be transformed to http://www.example.com/index.php?url=items/view/1234. This means we cannot use the ‘url’ parameter ourselfs. (more…)

Search in CakePHP.org TextMate command

I’ve setup a Google custom search engine that will search in the cakephp.org domain. So this will include API, Tests, Trac and of course The Book.

When you search you have refinements at the top of the search results that gives you easy access to the subparts of cakephp.org

And because TextMate is my favorite Editor I added a command in there that will search any selected word in that custom search engine. Now I have all the sources for that keyword at my hand.

Download the command, unzip it and double-click to install. I added ctrl-shift-s to that command as a shortkey.

Cheers!

Update: As there was already a custom search for CakePHP related sites I added another command to search in there. So two commands: One to search only in the cakephp.org domain (with refinements) and one to search also in other cakephp sites. Download!

Set the session cookie to the top level domain

I have an app that uses multiple sub domains besides the www.domain.com like computer.domain.com and books.domain.com, etc.

What I wanted is to set the session cookie to the higher level domain ‘domain.com’ so the session cookie will be valid through all sub domains.
In the CakeSession class (which is the parent of the SessionComponent) you can set the path but not the domain.

After talking with ADmad, Jurian and kabturek on IRC we found out that the session.cookie.domain is never set by the CakeSession handler so you can set it yourself!

ini_set('session.cookie_domain', '.domain.com');

So set the top domain through ini set in your APP/config/bootstrap.php and all will be set but not without settings the Session.security level to ‘low’ otherwise the referer_check will be set to the current HTTP_HOST in the CakeSession object line 441.

So in the APP/config/core.php:

Configure::write('Security.level', 'low');

Now the session cookie will be valid for all your subdomains and the top level domain.

Cheers!
p.s. Sharing the same session between multiple APPs? http://teknoid.wordpress.com/2008/10/05/sharing-cakephp-session-with-another-app/

Language detection and appropriate redirects

The first two medium cake applications I wrote was immediately multilingual. To check whether there is a language in the url, cookie set and/or AJAX request is a matter of priorities. What will be the steps to set the current language?

(more…)