domingo, 16 de março de 2014

EmbedForm with new relation

To insert new attributes to a Product in the default form we just need those few steps:

In the productForm class create the relation with the attribute form.

public function configure() {
    /* Create embedForm with an empty attribute */
    $new_attribute = new ProductAttribute();
    $new_attribute->setProduct($this->object);
    $this->embedForm('new_attribute', new ProductAttributeForm($new_attribute));
    $this->embedRelation('Attributes', new ProductAttributeForm());
}

...and we rewrite the saveEmbeddedForms methods
public function saveEmbeddedForms($con = null, $forms = null) {
    try {
        $new_attribute_form = $this->getEmbeddedForm('new_attribute');
        $values             = $this->getValue('new_attribute');

        /* Validations Rules to save the relation */
        if (empty($values['attribute_id'])) {
            unset($this['new_attribute']);
        }
    } catch (InvalidArgumentException $e) {
        error_log($e->getTraceAsString());
    }
    return parent::saveEmbeddedForms($con, $forms);
}

quarta-feira, 12 de março de 2014

Oracle extension oci8 in PHP5


Install OCI8 on PHP

Needs:
pecl    - sudo apt-get install php-pear
phpize  - sudo apt-get install php5-dev


1. Download "Oracle Instant Client Basic and SDK" from http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
2. Extract the content of both archives to /etc/opt/oci8/
3. Go to /etc/opt/oci8/ and find the file called libclntsh.so.*.* (e.g. libclntsh.so.12.1) and create a symbolic link called libclntsh.so
    . sudo ln -s libclntsh.so.12.1 libclntsh.so
4. Install the package libaio-dev
    . sudo apt-get install libaio-dev
5. Install now the oci extension:
    . sudo pecl install oci8
        . when prompt insert the path to the path to instantclient: instantclient,/etc/opt/oci8/
    Build process completed successfully
    Installing '/usr/lib/php5/20121212/oci8.so'
    install ok: channel://pecl.php.net/oci8-2.0.7
    configuration option "php_ini" is not set to php.ini location
    You should add "extension=oci8.so" to php.ini
6. Locate your php.ini and add the line "extension=oci8.so"

terça-feira, 4 de março de 2014

Git color

Edit your ~/.gitconfig and add the followind lines:

[color "status"]
added = green
changed = red bold
untracked = magenta bold
[color "branch"]
remote = yellow
[color]
diff = auto
status = auto
branch = auto
interactive = auto
ui = true
pager = true

domingo, 20 de outubro de 2013

Criar pen USB bootable linux em Macosx

Depois de ter a imagem da distro de Linux que pretendemos (no meu caso, Ubuntu), abrimos um terminal e navegamos até ao directório onde está a imagem.

jimmy@machine:~$ cd Downloads/

Executamos agora o comando que converte a imagem de iso para img:
jimmy@machine:~/Downloads$ hdiutil convert -format UDRW -o ubuntu-12.04.3-desktop-i386.img ubuntu-12.04.3-desktop-i386.iso
Reading Master Boot Record (MBR : 0)…
Reading Ubuntu 12.04.3 LTS i386 (Apple_ISO : 1)…
Reading (Windows_NTFS_Hidden : 2)…
................................................................................................................................................................................................................
Elapsed Time: 21.860s
Speed: 32.3Mbytes/sec
Savings: 0.0%
created: /Users/jimmy/Downloads/ubuntu-12.04.3-desktop-i386.img.dmg

Por omissão, o macosx cria as imagens com .dmg no final, para resolver o problema basta trocar o nome do ficheiro.
jimmy@machine:~/Downloads$ mv ubuntu-12.04.3-desktop-i386.img.dmg ubuntu-12.04.3-desktop-i386.img

Inserimos a drive USB e executamos o seguinte comando para saber onde está a nossa pen, neste caso em (/dev/disk1)
jimmy@machine:~/Downloads$ diskutil list
/dev/disk0
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *320.1 GB disk0
1: EFI 209.7 MB disk0s1
2: Apple_HFS brain 319.7 GB disk0s2
/dev/disk1
#: TYPE NAME SIZE IDENTIFIER
0: FDisk_partition_scheme *8.0 GB disk1
1: DOS_FAT_32 8.0 GB disk1s1

ATENÇÃO: memorize o numero da drive USB, neste caso é 1 (/dev/disk1)

"Desmontamos" a pen com o comando seguinte:
jimmy@machine:~/Downloads$ diskutil unmountDisk /dev/disk1
Unmount of all volumes on disk1 was successful

E corremos o comando que irá preparar a pen com o SO, troque o 1 (/dev/rdisk1) pelo número identificado no passo anterior:
jimmy@machine:~/Downloads$ dd if=ubuntu-12.04.3-desktop-i386.img of=/dev/rdisk1 bs=1m
707+0 records in
707+0 records out
741343232 bytes transferred in 77.944528 secs (9511165 bytes/sec)

quinta-feira, 26 de setembro de 2013

terça-feira, 10 de setembro de 2013

PHP5 Unable to load dynamic library

Problema

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/mysqli.so' - /usr/lib/php5/20090626/mysqli.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/mysql.so' - /usr/lib/php5/20090626/mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/apc.so' - /usr/lib/php5/20090626/apc.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/curl.so' - /usr/lib/php5/20090626/curl.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/gd.so' - /usr/lib/php5/20090626/gd.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/intl.so' - /usr/lib/php5/20090626/intl.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/mysql.so' - /usr/lib/php5/20090626/mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/mysqli.so' - /usr/lib/php5/20090626/mysqli.so: cannot open shared object file: No such file or directory in Unknown on line 0

Solução:

sudo apt-get install php5-mcrypt
sudo apt-get install php5-mysql
sudo apt-get install php5-intl
sudo apt-get install php5-curl
sudo apt-get install php5-gd
sudo apt-get install php-apc

terça-feira, 7 de maio de 2013

Alterar monitor principal no ubuntu

Para alterar o monitor principal do Ubuntu, Mint, etc... (O monitor com a barra)

#!/bin/bash
# Author: Andrew Martin
# Credit: http://ubuntuforums.org/showthread.php?t=1309247
echo "Enter the primary display from the following:" # prompt for the display
xrandr --prop | grep "[^dis]connected" | cut --delimiter=" " -f1 # query connected monitors

read choice # read the users's choice of monitor

xrandr --output $choice --primary