Tag archives for utility

Adminer for CakePHP

adminer

Managing your database should be a problem.

cPanel, phpMyAdmin are very difficult to install and you need to remember configurations or access you database.php file to read from.

Adminer is a one file db manager for MySQL and I wrote a simple webroot package to automatize loggin-in action reading from your App/Config/datavase.php file.

Continue reading »

Posted in CakePHP, Script | Leave a comment

PowerSet::def() API

Often my functions accepts an array of options to drive its behavior:

function foo( $data, $options = array() ) {
  if ( $options['filter'] = 'int' ) return intval($data);
  return $data;
}

The plus of accepting an array of options is your method can grow up without change it’s params API.

I often allow to accepts more than array type for my $options param:

function foo( $data, $options = array() ) {
  if ( is_string($options) ) $options = array( 'filter'=>$options );
  ...
}

This way my method API should be something like:

// full api
echo foo( $data, array('filter'=>'int'));

// compact api
echo foo( $data, 'int' );

I like DRY code so much!

Make it easy!

What PowerSet::def() does is to simplify the logic that convert different $options types into specific property names:

function foo( $data, $options = array() ) {
  $options = PowerSet::def($options, null, array(
    'string'=>'filter', 
    'integer'=>'length'
  ));
  ...
}

This code should be translated into:

"if $options type is -string- then put it value into -filter- key"
"if $options type is -integer- then put it value into -length- key"

In every cake $options will be converted into an array.

PowerSet::def('aaa', null, 'class');
-> array( 'class'=>'aaa' );

PowerSet::def(24, null, 'length');
-> array( 'length'=> (int) 24 );

PowerSet::def('aaa', null, array( 'string'=>'class', 'integer'=>'length'));
-> array( 'class'=>'aaa' );

PowerSet::def(24, null, array( 'string'=>'class', 'integer'=>'length'));
-> array( 'length'=> (int) 24 );

Why “null” as second param?

You can set up a default array to be extended with given values:

// useful to apply default values to an array
PowerSet::def('container', array(
  'id => '',
  'class => '',
  'style => '',
), 'class');
Posted in CakePOWER, Script | Leave a comment

Backbone Boilerplate on JsFiddle!

While learning and discovering Backbone it is useful to write down some trivial code but it is often too expensive to configure a local project.

To solve this problem I created a jsFiddle project with some resource packet into and ready to be forked out!

Try Backbone Boilerplate on jsFiddle!

Continue reading »

Posted in Tips & Tricks | 1 Comment

sqlDB.js – Access Webkit SQL databases

Today I’m pleased to share a little piece of code I wrote to access and query a webkit local sql database.

It allow you to:

  • open a connection
  • throw queries
  • handling callbacks (with context)
  • execute batch queries with a global callback when all queries are done

>>> Go Quickly to the GitHub Repo! <<<

… but i’d like to tell you WHY I wrote this code …

Continue reading »

Posted in Script | Leave a comment

Cache Manifest Generator (PHP utility)

Today I played with jQueryMobile to create a simple and quick webapp composed by multiple pages linked together using standard jQueryMobile API.

 

>>> Go Quickly to the GitHub Repo! <<<

Continue reading »

Posted in MovableApp.com | Leave a comment

Swedish Greys - a WordPress theme from Nordic Themepark.