2011/12/20

Alternativa a PuTTY en windows

Para conectarme mediante ssh/telnet en windows hasta ahora utilizaba el mítico Putty. Cumplía bastante bien su función aunque era incómodo y se volvía un poco loco si trabajaba con editores. Hoy he probado TeraTerm y me encuentro más cómodo. Recomendado! :)
       
   

2011/11/24

Escapar espacios en blanco en variables en Bash

Hoy me he sentido un poco estúpido... la típica chorrada que no te acuerdas ni se te ocurre como solucionar. Lo pongo aquí etiquetado como "humor". :D

En un script para la línea de comandos, tenía que entrar en un directorio con espacios en su nombre.

Pues no era capaz...
> foo="/tmp/foo bar/" 
> cd $foo 
bash: cd: /tmp/foo: No such file or directory 

Intenté todas las combinaciones posible para escapar el espacio y mil trucos.

Solución:
> foo="/tmp/foo bar/" 
> cd "$foo" 


Las comillas!!!!
       
   

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.