Friday, December 3, 2010

Protovis: Placing the Visualizations

If you want to place the visualization inside a div or any other container, there are two ways to do it(or at least I know two ways), but only one always work.

The first is to place the script tags where you build and render the visualization inside the div
tags, something like this:

<div>
    <script>
        ...
        vis.render();
    </script>
</div>

The other way, an this always work is to specify where it will be shown, something like this:

<script>
    ...
    var vis = new pv.Panel()
        .canvas($("vocabulary_chart"))
    ....
</script>

So It will be shown inside the div you specified.

Hope this helps you.

Wednesday, August 4, 2010

An useful shell script to use diff in a directory

Hi I just made this script to use diff in two directories, it fetch the files in the directories and diff them, if it finds a subdirectory it goes in and diff the files inside, I hope you use it and make it better.

You have to name the file recursive_diff.sh and place it in your home, sorry this is my first script and I dont know how to use paths, there are 3 parameters.

To call the script there are 3 parameters:

sh recursive_diff.sh original_directory copy_directory diff_files_firecory

example:

sh recursive_diff.sh my_project my_copy different_files


#!/bin/bash



for i in $(ls $1)
do
    if [ -f "$1/$i" ];then
 filename="$3/$i.diff"
 diff $1/$i $2/$i > $filename
 filesize=$(wc -c < $filename)
        if [ $filesize = 0 ];then
            rm $filename
        fi 
    else
 mkdir $3/$i
 sh $HOME/recursive_diff.sh $1/$i $2/$i $3/$i
    fi
done

Tuesday, June 1, 2010

Using ajax or another layout

Sometimes we want to render a view with the ajax layout, but only when it is been showed because an ajax request. I used to make two different views, and some times two different actions. But I realized that there is a component that help us tell when the call comes from an ajax request.

The component is the RequestHandler, to use it you have to set it on the controller, like this:
class ExamplesController extends AppController{
   var $components = array('RequestHandler');
and in the action we want to tell if it is an ajax call we have to set:
function myaction(){
   $this->layout = $this->RequestHandler->isAjax()?'ajax':'default';
so if it is an AJAX call the layaout that will be used is the ajax layout. By the way, this is a layout that comes with CakePHP, you don't need to create it. And you also can use any other layout you create.

Thursday, May 27, 2010

Internationalizating CakePHP Sites

Making an app easy to translate and could show it in different languages is a simple task in CakePHP, CakePHP brings a tool and a set of functions that help the developer on this job

The first that has to be done is to use the function __() when writing strings that we want to be translate. this function has the next params:

        __($stringToTransalte, $boolean);
        $stringToTranslate: is the string we want to be translated
        $boolean: indicate whether the string is only returned or also echo, false to echo the string

Thursday, May 20, 2010

Hello World

On this blog I will post all the solutions I found when dealing with CakePHP, Javascrit, PHP, Prototype and any other stuff on my daily programming.

I work making websites for different purposes, usually I use CakePHP, but some times I have to use Drupal, Moodle or pure PHP. An in a next project I'll have to use Flash and Flex, so I will deal with them soon.

I hope you find this blog useful.