Recursive Search in python
12 November 2009 at 4:19 PM | In Python | Leave a CommentTags: Python
I do this script to make recursive searches in a specified folder in Ubuntu Server.I shere it and hope will be usefull to someone:#! /usr/bin/env python import os def search(path,file_name): try: files = os.listdir(path) trunk = 0 except OSError: print “Access Denied: ” + path trunk = 1 if trunk == 0: for f in files: if os.path.isdir(path + f): search(path + f + ‘/’,file_name) else: if file_name == f: print ‘Found : ‘ + path + f if __name__ == ‘__main__’: path = raw_input(”Search Folder: “) file = raw_input(”File to Search: “) search(path,file)
PHP “short tags”: a bad practice
11 November 2009 at 3:42 PM | In PHP | Leave a CommentTags: clean code, PHP, php standars
The use of php “short tags”( example: <? echo “Hola Mundo!” ?>) is a bad and common practice that many PHP developers still use. The shortags format is only aviable using the function short_tags() in PHP3 or activating the short_open_tag in php.ini configuration file(it comes activated by default). I dont recommend to use it when you develop applications to redistribute or use in external servers because it can cause conflicts for user if short tags are not enabled. In the official PHP manual and the Zend Framework manual recommends not use “short tags” and it going to be deleted in version 6 of PHP. Remember that clearness is very important to a professional coder: use ever <?php echo “Hola Mundo!” ?>.
Join PDF files in linux
20 October 2009 at 1:00 PM | In GNU/Linux cli | Leave a CommentHello linux users: in this post i will show how to join two or more PDF files into one. You have to install the Ghostscript driver to do that, typing in a terminal(is for Debian and Ubuntu):
apt-get install gs
apt-get install pdftk
Now we join the PDFs with this command:
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=unidos.pdf file1.pdf file2.pdf
Here is the explanation of command:
gs: Call to the Ghostscript program.
-dBATCH: Close the Ghostscript when terminate the process.
-dNOPAUSE: Dont pause the program to aks for user interaction.
-q: Dont show messages during the process.
-sDEVICE=pdfwrite: Use Ghostscript PDF generator to do the process.
-sOutputFile=unidos.pdf: The name of the result file.
You can also join all PDF files in a directory typing *.pdf.
Looking for help to start a statistic project in linux
16 October 2009 at 1:06 PM | In Ideas | Leave a CommentHello to all the linux comunity, im looking forward to start a new project. It consist in a statistic application with a nice GUI like Statistic or StatGraph in Windows enviroment, i think there is not a good visual statistic program for linux and users that work with statistic programs in Windows have dificulties to migrate to Linux. GNU R is a powerfull statistic program, i will make my project based on R using python R(http://rpy.sourceforge.net/rpy2.html) and GTK2 toolkit. Please all the people interested in collaborate with code , artwork and ideas contact me please.
Linux:how to mount partitions at startup
16 October 2009 at 12:39 PM | In GNU/Linux cli | Leave a CommentIf you want to add a extra drive/partition and want it to automatically mount on start up then heres what i did, there is other ways.
- Firstly you need to get the information of the drive/partition you want to mount. To do it open a Terminal and type the following command:
blkid
and you will get something like this:
/dev/sda1: UUID=”FAF804CFF8048C57” LABEL=”Sistema” TYPE=”ntfs“
/dev/sda3: UUID=”87d8a036-4271-4063-81d0-fc8a78889bf6″ TYPE=”ext4″
/dev/sda5: UUID=”E884ED1284ECE3D2″ LABEL=”Work” TYPE=”ntfs”
/dev/sda6: UUID=”144A5E7CA87A5099″ LABEL=”Sof-CEAC” TYPE=”ntfs”
/dev/sda7: TYPE=”swap” UUID=”43a7e90c-7ad9-4790-a169-14ae9b8b1945″
If you want to mount the first drive sda1 named “Sistema” you need tu login as root typing su and follow this steps:
- Create a new directory in /media with drive name, in this case sda1.
mkdir /media/sda1 - Now you have to write your /etc/fstab file to mount the partition, you need to change the red parts with your drive information.Type that command:
echo “UUID=381046201045E60A /media/sda1 ntfs defaults 0 2″ >> /etc/fstab - Now restart your computer and the drive should appear mounted automatically.
Jquery Ctrl + Key function
9 October 2009 at 6:16 PM | In Jquery | Leave a CommentHello friends, in a recent PHP app im working i needed to make a Control+G key combination in a form to submit the data to a database. I create a Jquery function to make it easy and use with all Control + combinations, now i share it with the comunity, i hope it can be usefull to someone:
$.ctrl = function(key, callback, args) {
$(document).keydown(function(e) {
if(!args) args=[]; // IE barks when args is null
if(e.keyCode == key.charCodeAt(0) && e.ctrlKey) {
callback.apply(this, args);
return false;
}
});
};
The function can be called with 3 parameters, the first is the key you should press, second is the callback function to execute when you press the combination, and third is an additional array of arguments to pass to the callback funtion. Here is a function call example.
$.ctrl('G', function(s) {
alert(s);
}, ["No presiones D"]);
Crear pergamino en GIMP
30 September 2009 at 2:36 PM | In Design | 3 CommentsTags: Design, GIMP
Crea una imagen de 500×300
Ve a la pestaña de capas e inserta 4 capas transparentes como se muestra a continuación:

Sobre la capa “papel”, seleccionar la herramienta “Seleccióon Rectangular” R ![]()
Hacer una selección como se muestra:


Ahora vas al menú Seleccionar->Distorción y aparecerá una ventana, puedes modificar los parámetros para obtener diferentes distorciones y precionas Aceptar. El resultado será el siguiente:

Ahora en la ventana de herramientas seleccionamos el color #d0c1a2 y lo arrastramos a la selección. A continuación nos paramos sobre la capa oxido en la pestaña de capas y nos vamos a la pestaña Patrones y arrastrar el patron llamado slate
a la imagen.
Ahora selecciona la capa “luces” y con la herramienta pincel selecciona un pincel como este:
y escoge el color negro.
Ve al menú Editar-> Trazar Selección, en la ventana que sale seleccione la opción Trazar utilizando una herramienta de pintura y haga click en el botón Trazo. Para agregar más iluminaciones escoja diferentes pinceles y dibuje a su gusto sobre el lienzo, aquí mi resultado:
Ahora selecciona la capa llamada “polvo” y ve al menú Filtros->Renderizado->Nubes-> Plasma… y en la ventana que aparece ajusta los parámetros a tu gusto y presionas Aceptar. Luego ve al menú Colores->Desaturar…(Puedes cambiar las opciones a tu gusto para un mejor resultado) y presiona Aceptar.
Ahora nos vamos a la pestaña Capas y seleccionamos el modo de las 3 primeras capas(polvo, luces y oxido) a solapar y listo. Puedes agregar un texto y poner el modo en solapar o agregar una somba a la capa “papel”. Aquí está el resultado final:

Python:Notificaciones con DBus
28 July 2009 at 7:29 PM | In Programming, Python | Leave a CommentTags: Programming, Python
Hola es este post voy a mostrar como enviar notificaciones al escritorio Gnome mediante Python y DBus como se muestra en la imagen siguiente:

Notificación con dBus
#!/usr/bin/env python
import dbus
# Inicializando el bus de tipo session para comunicarse entre aplicaciones
bus = dbus.SessionBus()
# El objeto Notifications se encarga de enviar las notificaciones
noti = bus.get_object(‘org.freedesktop.Notifications’,'/org/freedesktop/Notifications’)
interface = dbus.Interface(noti,’org.freedesktop.Notifications’)
#Muestro la notificacion
#El tercer parametro es el icono a mostrar del stock de gtk y el ultimo es el tiempo de la notificacion
notificar = interface.Notify(“DBus Test”, 0, “gtk-about”, “Hola mundo”,’Hola que viva linux’, “”,{},50000)
Espero a alguien le pueda servir, saludos
Calcular el trimestre actual en PHP
7 May 2009 at 5:45 PM | In PHP, Programming | Leave a CommentHola amigos, ayer mientras trabajaba me vi en la necesidad de calcular el trimestre del año dado el número del mes y cree esta pequeña función en PHP que permite realizar este cálculo, si no se le pasa ningún mes ella tomará el mes actual por defecto. Aquí les dejo el código para quien pueda ser útil:
<?php
function trimestre($mes=null)
{
$mes = is_null($mes) ? date('m') : $mes;
$trim=floor(($mes-1) / 3)+1;
return $trim;
}
?>
Rotar videos con memcoder y mplayer en linux
7 May 2009 at 1:32 PM | In GNU/Linux cli | Leave a CommentTags: GNU/Linux cli, mplayer, video
A veces nos encontramos con vídeos que se encuentran rotados, como los copiados de una Ipod o reproductor MP4. En Linux existen soluciones para rotarlos.
Si desea rotar su vídeo y guardarlo ya en la posición que desea puede hacerlo con MENCODER de la siguiente forma:
Valla a Aplicaciones—>Terminal y teclee el siguiente comando:
mencoder -vf-add rotate=opción -oac mp3lame -ovc lavc /lugar/video_entrada.extensión -o /lugar/video_salida.extensión
Donde:
-oac es el codec de salida de audio(Output Audio Codec) pude utilizar otro si Mp3lame no está disponible
-ovc es el codec de salida de vídeo(Output Video Codec)
Si solo desea ver el vídeo rotado sin guardarlo puede usar Mplayer mediante el siguiente comando:
mplayer -vf-add rotate=opción /lugar/video_entrada.extensión
opción: es la rotación que se le dará al vídeo, se pueden usar las siguientes:
0 Rotar 90 grados en sentido horario y voltear.
1 Rotar 90 grados en sentido horario.
2 Rotar 90 grados a la izquierda.
3 Rotar 90 grados a la izquierda y voltear.
Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.

