2011/11/05

Drivers en PDO de PHP

¿Cómo saber que driver tengo disponibles para acceder a bases de datos con PHP::PDO?
Ejecuta esto en un terminal:

echo "PDO avalable drivers: \n";
foreach(PDO::getAvailableDrivers() as $driver) {
echo '* '.$driver."\n";
}

Y obtendo como salida el siguiente resultado:

PDO avalable drivers:
* mysql
* pgsql
* sqlite
* sqlite2

UPDATE:

Más facil todavia php -m | grep pdo
       
   

2011/06/23

Indentar todo una sección de código python con emacs

Cuando has programado un trozo de código en python y luego es necesario meterlo en un bucle... Arrrgggg... ¿a indentar línea por línea?

Emacs tiene la solución. Marca la sección que quieres desplazar y teclea:

C-c >

Otros comandos (extraídos de python.about.com):

* C-j: Insert a new line with the same indentation level as the current line
* RET: Insert a new line with the same indentation level as the current line
* C-M-a: Go to the beginning of the current function or class
* C-M-e: Go to the end of the current function or class
* C-M-h: Mark the current function or class for copying, etc.
* C-M-x: Execute the current function or class
* C-c C-b: Submit a bug report
* C-c C-c: Execute the buffer (i.e., the file being displayed)
* C-c C-d: Trace the stack of the process being executed
* C-c C-h: Get context-based help
* C-c TAB: Indent a highlighted (or marked) region
* C-c C-k: Mark a block of text. Using this at the head of a class or function definition will mark the entire block.
* C-c C-l: Shift the region to the left. If the cursor is in the middle of a region, the lower half of the region will shift.
* C-c RET: Execute the current file, opening a new window to show the output.
* C-c C-n: Jump to the next statement.
* C-c C-p: Jump to the previous statement.
* C-c C-r: Shift the region to the right. If the cursor is in the middle of a region, the lower half of the region will shift.
* C-c C-s: Execute a Python command.
* C-c C-t: Toggle shells
* C-c C-u: Go up one block
* C-c C-v: List the version of the Python mode
* C-c C-w: Run PyChecker
* C-c !: Open the Python interactive shell
* C-c #: Comment the highlighted (marked) region
* C-c :: Check the indentation off-set
* C-c <: Shift the region to the left
* C-c >: Shift the region to the right
* C-c ?: Show Python mode documentation
* C-c |: Execute the highlighted (marked) part of the current program.

Note that Python mode for Emacs offers more functionality than this, but these are the basics. If you know Emacs from editing other languages, learning your way around the Python mode is a snap.
       
   

2010/12/29

Metrónomo en Ubuntu

Qué lejos queda mi época de técnico de sonido... y de mis estudio casero. Actualmente tengo problemas hasta para sacar sonido por la tarjeta del portatil. Dejando aparte los problemas con rosegarden, qsynth y jack, estuve atascado para poder ejecutar sin problemas GTick un métronomo simple y cómodo que usa GTK+ y OSS (compatible con ALSA).

Pues el caso es que tenía el siguiente error:
Couldn't start metronome.
Please check if specified sound device
and sample file are accessible.
Y "/dev/dsp" que era el dispositivo configurado no existía.

Finalmente encontré con la solución. Ejecutar con el comando:
$ aoss gtick
aoss es un script que permite la compatibilidad de las librerías OSS y ALSA.
       
   

2010/12/27

Máquina virtual en VirtualBox como servidor

Tengo un máquina virtual con Debian servida desde "Windows XP" con VirtualBox 3.2. Quiero tener accesibles servicios lanzados en la máquida huesped (el Debian) que sean sólo desde la máquina windows.

La solución es hacer Port Forwarding como explican aquí. En mi caso particular con jetty, para acceder a servicios en el puerto 8080 hice:

C:\...\Orable\VirtualBox> VBoxManage.exe setextradata "VM Name Here" \
"VBoxInternal/Devices/pcnet/0/LUN#0/Config/jetty/Protocol" TCP

C:\...\Orable\VirtualBox> VBoxManage.exe setextradata "VM Name Here" \
"VBoxInternal/Devices/pcnet/0/LUN#0/Config/jetty/GuestPort" 8080

C:\...\Orable\VirtualBox> VBoxManage.exe setextradata "VM Name Here” \
"VBoxInternal/Devices/pcnet/0/LUN#0/Config/jetty/HostPort" 9999


Todo esto con la máquina parada. Antes de iniciarla, en la configuración la red tuve que marcar "pcnet" porque sino daba un error relacionado con la obtención de la MAC.
       
   

2010/07/29

Usar editor externo en postgresql

Aunque pgAdmin es un programa bastante cómodo e intuitivo para administrar bases de datos postgres, el cliente en línea de comandos es realmente potente y ágil.

En algunas ocasiones es verdad que para programar sobre la base de datos, hacer consultas muy complejas o realizar otras operaciones trabajar en el terminal es algo engorroso. En el terminal no es tan sencillo editar y no tienen tantas ayudas como en un programa de edición de textos o un IDE.

Existe la posibilidad de usar un editor externo para editar una consulta concreta.

El comando
 \e 

permite abrir un editor con el "Query Buffer" actual. La primera vez que se ejecuta este comando '\e' te pregunta qué programa externo usar; emacs con su sql-mode puede que sea el mejor ;). Admite como parámetro un fichero también.
 \e [FILE]


Si quieres editar una función concreta, puedes utilizar:
 \ef [FUNCTION_NAME] 

que si ejecutas sin parámetros te genera una plantilla básica para empezar a programar.

En ocasiones puede pasar lo siguiente si queremos editar/ver una función:


#\ef dropgeometrycolumn
ERROR: more than one function named "dropgeometrycolumn"


Esta función es de PostGIS y existe un conflicto de nombres debido a que es posible aplicar "polimorfismo". Si miramos la firma de las funciones:


# \df dropgeometrycolumn

Schema | Name | Result data type | Argument data types | Type
--------+--------------------+------------------+---------------------+--------------
public | dropgeometrycolumn | text | character varying, character varying | normal
public | dropgeometrycolumn | text | character varying, character varying, character varying| normal
public | dropgeometrycolumn | text | character varying, character varying, character varying, character varying | normal
(3 rows)


Para poder editar una de esas funciones concretas habría que espedificar los argumentos:


# \ef addgeometrycolumn(character varying, character varying, integer, character varying, integer)
       
   

2010/07/06

Error con DBF en OpenOffice 3.2

Con Ubuntu 10.4 cuando intentaba abrir o guardar un fichero DBF en OpenOffice Calc me daba el siguiente mensaje de error:

General Error.
General Input/Output Error.

Pensé que podía ser, que como pasa en las nuevas versiones de Office de Microsoft, que han dejado de dar soporte a este formato "clásico". Pero no, buscando un poco encontré la solución que parece que dio la lata a más de uno.

Hay que instalar openoffice.org-base y todo arreglado.
       
   

2010/02/02

Baixar videos de agalega.info

Con GNU/Linux non son quen de ver os videos de agalega.info nin con Firefox nin cun video player usando mms.

A solución foi baixar o arquivo usando o seguinte comando:

 mplayer mms://url -dumpstream -dumpfile foo.wmv