Archive

Posts Tagged ‘IT’

CakePHP: complex SELECT queries

September 3rd, 2008

As the project grows I had to work on some more complex queries to provide users with better searching facilities.

In this case, you might use two options:

  • Straightforward find() function from App::Model (where you’ll have to handle the outpu of data yourself, and trying to fit the search results in your websites layout)
  • Use Pagination functionality (which is designed for handling big chunks of data for you)

A simple example: from a small search menu, I need to get the data about item’s price, its type etc, so at this point, find() solution would look like:

$condition = array(‘OR’ => array(
                   ‘Item.type’   => $this->data[‘Item’][‘type’],
                   ‘Item.qty’     => $this->data[‘Item’][‘qty’],
                              ),
  array(‘Item.price BETWEEN ? AND ?’ => array($start_price,$end_price))
);
$this->(‘results’, $this->Item->find(‘all’, $condition));

Once you set results array in the view template, it will cause you few hours on how to rearrange data presentation, meanwhile you can use :

/*
* I’m going to use the same $condition
*  the difference will be at the view level and the way of setting the data "results"
*/

$this->set(‘results’, $this->paginate(‘Item’, $condition);

And in the view you might add some code like:

<?
echo $paginator->counter(array(
‘format’ => __(‘%page% of %pages%, showing %current%
records out of %count% total, starting on record %start%, ending on %end%’
, true)
));

foreach($results as $i => $item):
/*
* Items output
*/

endforeach;
?>
<?php echo $paginator->prev(‘<< ‘.__(‘Previous Page’, true),
array(), null, array(‘class’=>‘disabled’));?>
 |     <?php echo $paginator->numbers();?>
    <?php echo $paginator->next(__(‘Next Page’, true).‘ >>’,
 array(), null, array(‘class’=>‘disabled’));?>

Last lines of the code would manage the results listing for you, which has to be defined in your Controller:

var $paginate = array(
                         ‘Item’ => array(
                           ‘limit’ => 5,
                           ‘order’=> array(‘Item.added’ => ‘ASC’)
                           )
            )

Done, now you can easily handle your search outputs. ;)

Linux, etc , , ,

Licenses, patents and ideas

October 17th, 2007

I’ll try to make things short by quoting Richard Stallman:

Control over the use of one’s ideas really constitutes control over other people’s lives; and is usually used to make their lives more difficult.

Watching these patent wars between Novell, Red Hat versus IP Innovation just makes me wondering: how hard will be to distribute ideas in the world where everything is patented?

Links , ,

Robotics - toys for Bachelor students

October 11th, 2007

Due to the faculty specifics, most of the forth course classmates took & Automation course this semester.

For catching up the idea of automation procedures, the teacher gave us a small NXT Robot to play around. I couldn’t remember when was the last time I did these stuff, however this amazed me a lot.

This small “toy” is equipped with:

  • Light Sensor (black and white spectrum)
  • Ultrasound Sensor
  • Bump Sensor
  • Sound Sensor

Lots of things to play around, especially taking in account the programmatic aspects of generation and Open Source C compiler for these robots: RobotC project.

Gadgets , , , , , , ,

Evince vs Adobe Reader 8 on Ubuntu

October 7th, 2007

Evince:

  • Problems with pdf rendering after .chm to .pdf convertion
  • 80 Mb RAM usage

Adobe Reader 8:

  • Correct font rendering in non-native pdf formats
  • Correct pdf output with original .pdf’s.
  • 40 Mb RAM usage

Links , ,

Apple pages history

July 22nd, 2007

The appearance of new front page of usually bring new vibes of on the . Mac fans collected everything from 1997 year up to now.

Links , , ,

Video Editing with Ubuntu

July 18th, 2007

I haven’t thought that ’s going to be such a headache to find some good for and Audio Editing on platform! At this type of fields, you realize how much work should be done in future for Unices to reach Mac/Win multimedia platforms.

Win/Mac haters can take a deep breath, because there are no good alternatives for:

  • Abode Premier
  • Sony Vegas
  • Sound Forge

However, I’ve managed to find the combination of Kinovd and Cinelerra. The last one appeared to be a nice editor, even though some minor bugs arise (which were solved right away with Cinelerra helper). Here are some repositories for Cinelerra editor.

Enjoy editing! ;)

Design, Gadgets , , , , ,