RSS
 

Posts Tagged ‘Tips’

UIF to ISO files in Linux

19 Jun

Thanks to freshmeat resource:

yum install -y zlib zlib-devel
wget http://freshmeat.net/urls/a179e50646095ae06963e5db6b134c5b
unzip uif2iso.zip
make -C src PREFIX=/usr/local all install
uif2iso foo.uif bar.iso
 

Memo: fast grep of the word in the directory

02 Nov
 find ./ | xargs grep -i search_string
 

Memo, 10 rules of User Interface

28 Oct
  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.

 

Cakephp 1.2.x: Distinct Select

24 Sep

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");
 

Learning C++ as new language

07 Jan

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.

 

Fixing fonts in gVim under Windows

23 Dec

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.

 

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

 

CakePHP: Dynamic select boxes with AJAX

07 Aug

Working with CakePHP1.2 I had to implement some AJAX techniques in the framework, mainly dealing with onChange behavior of the form components, here is a small example of how we can use multiple selectboxes.

Note: For simplicity reasons, I didn’t include queries, and just used option-arrays:

//inside controller
<?php
       class FooController extends AppController{
                var $name = 'Fooes';
                var $components = array('RequestHandler');
                var $helpers = array('Html','Form','Javascript','Ajax');
 
              function beforeRender(){
                          if($this->RequestHandler->isAjax()){
                                   Configure::write('debug',0);       
                                  //prevent useless warnings for Ajax
 
                          }
                          $this->set('foobar',null); 
                         // initiate an array of options (otherwise, you'll get a warning)
 
             }
             function updateDistricts(){
                                   $this->layout = 'ajax';
                                   $this->beforeRender();
                                   $this->render('updateDistricts/','ajax');
            }
 
      }
?>

This is just a simple layout for calling AJAX methods, without database, sofisticated layout handling, routes etc (for these reasons we got CakePHP API, and CakePHP GoogleGroup)

//inside viewer (test-data): <em>foo/update_districts.ctp</em>
<option>Limassol</option>
<option>Nicosia</option>
<option>Larnaca</option>
<option>Famagusta</option>

The actual form would look like:

//this code was used as an element from /view/elements/*.ctp
 
<ul id="navlinks">
                 <li><?php echo $form->create('foo');?></li>
                 <li>
                         <?php
         print $form->input('Districts.name', 
                                     array('type'=>'select',
                                      'options'=>array('Limassol','Nicosia','Larnaka'),
                                       'id'=>'district_name',
                                       'empty'=>'Choose District',
                                       'label'=>'District'));
       print '<span class="ajax_update" id="ajax_indicator" tyle="display:none;">'.$html->image('ajax-loader.gif').'</span>';
            ?>
                 </li>
                 <li>
                   <?php
       print $form->input('Towns.name',
                                   array('type'=>'select',
                                   'options'=> $foobar,
                                   'style'=>'display:none',
                                    'showEmpty'=>true,
                                  'empty'=>'City',
                                   'id'=>'city_name'));
 
        print $ajax->observeField('district_name', 
                                   array(  'url'=>'updateTowns/',
                                   'update'=>'city_name', 
                                  'loading'=>"Element.show('city_name');           
                                  Element.show('ajax_indicator')",
                                  'complete'=>"Element.hide('ajax_indicator');
                                 Effect.Appear('city_name')",
                                 'onChange'=>true));  
         ?>                                         
         </li>           
         <li><?php echo $form->end('Search');?></li>
</ul>

As the result, once you change the default value of the first select box, the second one automatically calls the controller’s method, which renders the values (gets the option list from the view file) and renders it in AJAX manner

.

Related article: CakePHP Droppable helper with Dynamic select box