Archive for April, 2008
April 24, 2008 at 11:35 am
· Filed under ajax, cakephp, php, programming ·Tagged ajax, cakephp, cake_security, observeField, php, programming, session
Finally even me landed on the AjaxHelper for give a bit of coolnes (;)) to an application of mine. I’m still using 1.1.18 version of CakePHP.
The problem finally was that when I did an ajax request call the session was restored. Asking in the Mailing List the problems seems to be that when an ajax call has been made the browser doesn’t send a correct User-Agent.
Starting from the hint gave me in the answer to my post, I found the solution that was setting the CAKE_SECURITY in app core.php to a level of medium or lower.
Permalink
April 18, 2008 at 10:53 am
· Filed under cakephp, php, programming ·Tagged alias, cakephp, controller, mvc, php, programming, url
The task was to have “aliases” for url. For example let’s think about a ProjectsController; each project is characterized by a unique id, a unique name and some other attributes. With the cake way you can refer to the projects with /projects/add, /projects/edit/$id, /projects/delete/$id and /projects/view/$id.
I would like to have an alias for the view: call each project even with a url like /projects/$name (friendlier url).
I achieved the task extending the ErrorHandler::missingAction(). Here is the code I used (pdf).
I don’t know if this is the proper way to do this but it’s working.
Permalink
April 15, 2008 at 4:47 pm
· Filed under cakephp, php, programming ·Tagged programming, php, cakephp, model, cache, queries
Again a simple tip. CakePHP by default, in order to optimize performance, has a query caching system. This is a very cool feature but sometimes it may be self-defeating. For example when you do queries for Unit Testing.
In order to disable query caching, it’s enough to set the model cacheQueries variable to false. Setting it to true will re-enable queries caching.
You can disable it for the whole model “life-time” setting it during “design time”
<?php
class Project extends AppModel {
var $name = "Project";
var $customValidate = array("name");
var $cacheQueries = false;
...
?>
or you can temporarily disable it by calling the $this->Model->cacheQueries=false (use your model instead of “Model”
)
Here is some extract of code (pdf).
Permalink
April 11, 2008 at 3:04 pm
· Filed under gimp, scheme, script-fu ·Tagged dpi, gimp, grayscale, resize, scale, scheme, script-fu, web
Finally I entered also the Script-Fu world. For the photography school I’m attempting I had to deliver to my teacher about 350 photos. posting them i JPG full resolution would have been raving. So I though to my self, why don’t learn a bit of script-fu and do a script for Gimp that will convert a directory of JPG into others JPG of smalles size?
I know I could have searched for something already done but I wouldn’t have learned Script-Fu/scheme.
This is my first script. I surely have not followed conventions and surely it could have been done better. Maybe there will be a time when I will improve it. For now it’s it and it’s working for my tasks.
The script will take a single JPG or all JPGs in a Directory, resize it to a custom size (by long image side), default 800px, convert it to 72dpi and save it with a different name. Leave a color version or a quick conversion to grayscale. This last one is useful in order to have a look for an entire set if it looks better in color or B&W.
However here is the source code (pdf) to copy and paste into an scm file.
Permalink
April 11, 2008 at 1:40 pm
· Filed under emacs ·Tagged emacs, lines, macro, sort, sort-lines, sorting
I will never stop saying how much I love emacs. I have to admit that it’s very difficult to learn how to use it and even after you have learned enough to use it, you will always find something that you didn’t know.
The task for today is simple: sorting the lines in a region. There’s an already existent macro: sort-lines. So first you will have to select the region and the call the macro. In the following example we will sort the lines of the whole document.
C-x h <RET> M-x sort-lines
Again: easy easy and easy 
Permalink