Archive

Posts Tagged ‘Tips’

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

Programming , ,

Fixing fonts in gVim under Windows

December 23rd, 2008

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

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

An old fonts vim plugin cause lots of errors, so I had to use SVN to get latest fixes for the . plugin. You can check in the trunk of the repository; worked perfectly for me, just copy-paste 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, 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 , , ,

CakePHP: Dynamic select boxes with AJAX

August 7th, 2008

Working with CakePHP1.2 I had to implement some 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’,);

              function beforeRender(){
                          if($this->RequestHandler->isAjax()){
                                   Configure::write(‘debug’,0);       
                                  //prevent useless warnings for
                         
                          }
                          $this->set(‘foobar’,null);
                         // initiate an array of options (otherwise, you’ll get a warning)

             }
             function updateDistricts(){
                                   $this->layout = ;
                                   $this->beforeRender();
                                   $this->render(‘updateDistricts/’,);
            }

      }
?>

This is just a simple layout for calling methods, without database, sofisticated layout handling, routes etc (for these reasons we got API, and 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(-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 $->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 in manner

.

etc , , , , ,

Speed up your work in Vim

May 9th, 2008

If you don’t know what’s , then:

  1. You’re IDE’s fan
  2. You’ve never used

An option “you’re using Emacs” is not included - you would have definetely known . You’d hate for the sake of “holly wars”.

I’m not an Emacs lover, neither those huge IDE’s with bunch of boxes, bookmarks, you name . Most of these things are useless when you need to code something fast, so I just stuck with : simple, light, fast, and have a lot of functionality. Here are just few of speeding up process I’ve been using lately:

If you got some repetitive function calls or anything you’re not bothered to print just fire up:

Comments:
:ab #cb /********************************
:ab #ce /*******************************/

Printing

#cb

or

#ce

will paste initial comment pattern.

:ab #r require_once();
:ab #i  include_once();

Minus another dozen of lines to be typed.

Text search:

You can

:set incsearch

which will enable incremental search for you, or use regexp, like:

:/\<agent\>/

will find you “agent” in current file.

Using ftp:

cmap ,r :Nread ftp://ftpdomain/public_html/index.html
cmap ,w :Nwrite ftp://ftpdomain/public_html/index.html

These are just basics, Bram Moolenaar, the developer of , got a good article on how to optimize your work with Vim, and David Rayner with his page of Vim tips. Compulsory to learn for beginners!

Linux , ,

Add remove problem in Win XP

November 8th, 2007

Finally, I’ve got time to fix this bug.

After upgrading my Internet Explorer 6 up to the seventh version, Add/Remove window in Control Panel wasn’t loading. After a bit of googling the problem was solved:

1.win+r, load “regedit32″
2.Go to: HKEY_LOCAL_MACHINE
3.SOFTWARE -> Microsoft -> -> Uninstall
4.Find “ie7″ folder and in the right side menu look for for “Uninstall string” row
5.Follow the Uninstall string and extract .exe file which will handle uninstalling IE7.
6.Restart your PC.

After , everything loads fine now. The only disadvantage - you’ve got your Internet Explorer 6 back :)

Links, etc , , ,