Archive

Posts Tagged ‘Tips’

Memo: fast grep of the word in the directory

November 2nd, 2009
 find ./ | xargs grep -i search_string

Linux, Memo , ,

Memo, 10 rules of User Interface

October 28th, 2009
  1. Visibility of System status
  2. Match between system and the real world
  3. User control and freedom
  4. Consistency and Standards
  5. Error prevention
  6. Recognition rather then recall
  7. Flexibility and efficiency of use
  8. Aesthetic and Minimalistic design
  9. Help users recognize, diagnose, and recover the errors
  10. Help and documentation

Main reasons and explanations are in the article from Jakob Nielsen: 10 Heuristics of User Interface.

Links , ,

Cakephp 1.2.x: Distinct Select

September 24th, 2009

Just a reminder for myself:

$foo = $this->$model->find('all', array('fields'=>array("DISTINCT {$model}.dnid")));

CakePHP 1.1.x style used to be:

$this->$model->findAll(null, "DISTINCT {$model}.city");

PHP , ,

Learning C++ as new language

January 7th, 2009

Quite interesting article from Stroustrup (unfortunately dated by 1999), however still topical. Here is a small list of concepts a person should be considered. The the approach to a new language, which:

– proceeds from the concrete to the abstract,
– presents language features in the context of the programming and design techniques that they exist
to support,
– presents code relying on relatively high-level libraries before going into the lower-level details (nec-
essary to build those libraries),
– avoids techniques that do not scale to real-world applications,
– presents common and useful techniques and features before details, and
– focus on concepts and techniques (rather than language features).

As well, as some interesting comparisons of C and C++ languages in his article.

Heap , ,

Fixing fonts in gVim under Windows

December 23rd, 2008

Nowadays, I was forced to work at the office doing Web Dev using Windows machine. It caused real headaches to setup some of the things from scratch to make in work like on my old Linux machine.

I haven’t thought that vim’ll look so weird from the Windows side, however gVim alternative seemed more adecvate, but the problem got me googling at the point of setting up correct fonts for the themes.

An old fonts vim plugin cause lots of errors, so I had to use SVN to get latest fixes for the Fonts.vim plugin. You can check it in the trunk of the repository; it worked perfectly for me, just copy-paste it to your \plugins\ directory, and play around the font-size.

Links, Linux , , , ,

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 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;
?>
prev('<< '.__('Previous Page', true),
array(), null, array('class'=>'disabled'));?>
| numbers();?>
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. ;)

Heap, Linux , , ,