RSS
 

Posts Tagged ‘IT’

CakePHP: complex SELECT queries

03 Sep

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 Pagination:

/*
* 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. ;)

 

Licenses, patents and ideas

17 Oct

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 it 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 it be to distribute ideas in the world where everything is patented?

 

Robotics – toys for Bachelor students

11 Oct

Due to the faculty specifics, most of the forth course classmates took Robotics & 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 Lego stuff, however this NXT 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 NXT generation and Open Source C compiler for these robots: RobotC project.

 

Evince vs Adobe Reader 8 on Ubuntu

07 Oct

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
 

Apple pages history

22 Jul

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

 

Video Editing with Ubuntu

18 Jul

I haven’t thought that it’s going to be such a headache to find some good software for Video and Audio Editing on Linux platform! At this type of software 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 video editor, even though some minor bugs arise (which were solved right away with Cinelerra helper). Here are some Ubuntu repositories for Cinelerra editor.

Enjoy editing! ;)

 

Totem with Beryl in Ubuntu

07 Jul

Fast and easy solution:

~$gstreamer-properties

And set your video default output as “X Window System (No Xv)”. Seems to be working fine…

 

Safari vs IE vs Netscape vs Firefox

01 Jul

[video]http://www.youtube.com/watch?v=TdEQh83nqjU[/video]
Just GetFirefox video ad