Tuesday, August 28, 2012

Xubuntu: Monitor dual con VGA primario

Gracias a este post pude dar con la solución al problema que tenía casi desde que utilizo Ubunutu:

Usar dos monitores y elegir cuál es el primario

Pero el post no me daba con la solución. Seguí indagando en la configuración y realicé algunos cambios y al fin pude dejar Mi monitor VGA como primario y el de mi Notebook como secundario:
  1. Ir a Configuración > Editor de configuración
  2. Fijarse que se esté en el canal 'Displays'
  3. Desplegar propiedad 'Default
    1. Debiesen aparecer 2 sub-propiedades. Mi caso: LVDS1 (Notebook) y VGA1 (Monitor externo)
  4. Tomar el valor de X del monitor que dejarás como principal (VGA1)
    1. VGA1 > Resolution. Mi caso: 1920x1080
  5. Cambiar las propiedades en en monitor secundario (LVDS1)
    1. LVDS1 > Position > X: 1920 (Tomamos el valor X del punto 4.1)
  6. Cerra sesión y entrar nuevamente
Así tendrás tu monitor VGA como primario y el de tu Notebook como secundario. Esto también sirve para PC's con 2 monitores.

Acá un screenshot:




Tuesday, August 14, 2012

Browser-Update.org - Infórma a tus visitantes de actualizaciones a los navegadores

Browser-Update.org - Infórma a tus visitantes de actualizaciones a los navegadores

Tuesday, May 22, 2012

Get new and modified files from n days ago

This is another way to get new and modified files from your project.

If you use cvs system, you need to export files first

(using svn)*
svn export files/path export/path

* Maybe you need to use before
svn add * --force

Go to export/path and get the last new/modified files you want
cd export/path
find . -mtime -N -ctime -N | cpio -vdump ../final_files


N are the days that you want to get, so if you need to get files from 7 days ago then you write:
find . -mtime -7 -ctime -7 | cpio -vdump ../final_files

Monday, May 07, 2012

Codeigniter: multifile_array upload helper

If you need to use multiple files for upload in a form, but using array names (like files[]) with Codeigniter is not possible. Besides, $_FILES schema is not compatible with $this->upload->do_upload().
With this helper you can use this kind of names for make it possible. Only use array name for all files in a form and use the helper:

In view
<form...
<input type="file" name="f_file[]">
<input type="file" name="f_file[]">
...
</form>

In controller
$this->load->helper('upload');
multifile_array();
foreach ($_FILES as $file => $file_data)
  $this->upload->do_upload($file);

Download multifile_array upload helper

Wednesday, March 28, 2012

Codeigniter + HMVC + Namespaces (part 2)

Now I'm going to continue with CI+NAMESPACES+HMVC transformation. (See part 1)

Codeigniter + Namespaces + HMVC

Working with namespaces in hmvc is same that part 1. The diference is how we load a namespaced module:

namespace controllers\blog;

class user extends \MX_Controller {
  public function get_comments($id_user){
     /* Code */

     //[1]
     $module = $this->load->module('namespace\modulename/classname');
     //[2]
     $module->method($x, $y);

     // OR [3]
     \Modules::run('namespace\modulename/classname/method', $x, $y);
  }
}
$_ns = __NAMESPACE__;

How to load a module
  1. Load module into a variable. The format is namespace\[backslash]modulename/[slash]classname
  2. Call the module method
  3. Run module method statically
Download HMVC extension patch

Download HMVC module example

Tuesday, March 06, 2012

Codeigniter + HMVC + Namespaces (part 1)

Codeigniter 2.1.0 is PHP4 compatible, so it can't work with namespaces.

I work with HMVC extension, and I see that working with it and without namespaces it's a little clumsy (for example class collisions) so, I decided to modify Codeigniter and hmvc extension to work with namespaces for controllers.

Both solutions are independents. First I'm going to explain how to make it possible in Codeigniter only.

Codeigniter + Namespaces

namespace controllers\blog //[1]

class user extends \CI_Controller { //[3]
  public function get_comments($id_user){
     // Code  
  }
}
$_ns = __NAMESPACE__; //[2]

What is new here?
  1. You can see namespaces declaration, obviously [1]
  2. The new (required) variable. It is used by patch [2]
  3. As Codeigniter doesn't work with namespaces we must use a global namespace [3]
Anything else?

No! How easy!

Well, one more thing is required. Replace the system/core/Codeigniter.php file with the patch.
If you are afraid to do it, I have modified 2 lines only.

Saturday, February 18, 2012

Codeigniter: Working with template views

Codeigniter doesn't provide a template engine, and it makes that each views has all html code.
Including files is a good idea, but I'm not happy adding every time de include code, is not DRY.

Well the best way to work with templates is the Decorator Design Pattern, and for make it possible in Codeigniter I was used the Most Simple Template Library for CodeIgniter until that discovered the next: Using another view like template.

Using it is very easy, is not neccesary use other library and you can add any functionality.

How to make it.

Simple use

Controller
public function action(){
   $data = array(
     'view' => 'view_name',
     'title' => 'Hello World'
   );
   $this->load->view('template_tpl', $data);
}

View
php  + view html

Template view
php + general html
$this->load->view($view);
php + general html

File system
/application/views/template_tpl.php
/application/views/view_name.php


Advanced use

If you use different sections in your site/application the simple use is not ver helpful. Following the same philosophy you can make possible it.

Controller
public function action(){
   $data = array(
     'section1' => 'section1',
     'section2' => 'section2',
     'view' => 'view_name',
     'title' => 'Hello World'
   );
   $this->load->view('template_tpl', $data);
}

View
php  + view html

Section
php  + section html

Template view
php + general html
section($section1);
php + general html
$this->load->view($view);
section($section2);
php + general html

File system
/application/views/template_tpl.php
/application/views/view_name.php
/application/views/section_name.php


Solve a little problem

To work with sections, we need to solve a little problem: If you don't send a section name to template, codeigniter show the next error:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: variable_nameFilename: views/file.php
Line Number: x
To solve it we need to add this function to our template:
function section(&$name){
    $CI = & get_instance();
    isset($name) ? $CI->load->view($name) : null;
}




Tuesday, February 07, 2012

Codeigniter: Language lines into javascript


I’ve extend language_helper and I’ve added a langJs function.

For use it you only call it with an array including lines for pass to javascript.

Example

In the controller
$this->load->helper('language');
$this->lang->load('calendar', 'spanish');

In the view
[php]

echo langJs(array('cal_wednesday', 'cal_january'));

[javascript]
alert(_msg.cal_wednesday);

Load all lines
If you need load all lines, you can do something like this:

In the Controller

$this->load->helper('language');
$this->lang->load('calendar', 'spanish');
$data['lang_keys'] = array_keys($this->lang->language);

In the View
echo langJs($lang_keys);

As you can see, is very easy passing messages to javascript.
Download Language Helper