>>> import datetime
>>> import time
>>> time.time()
1275242762.4052529
>>> int(time.time())
1275242769
>>> n=int(time.time())
>>> print datetime.datetime.fromtimestamp(n)
2010-05-30 20:06:20
Sunday, May 30, 2010
Python notes - Timestamp to Datetime
Syncing your music at home with Android
I was a bit tired to use always a cable for syncing music inside my home pc with my phone, even more to continue hearing the same music all the days on the tram or the bike because I forgot to plug the cable, mount and cp the files.
Using an Android G1/Dream phone, I've been able to synchronize music and other files on the fly while arriving home via wifi and an encrypted connection.
First I thought to try scp and control the access time of the files to synchronize, but then I thought that rsync would do a better job, so I went for installing CyanogenMod 5.0.7 that it is and Android 2.1 (Eclair) with our great rsync.
Once done the dirty job, I installed ASE scripting for Android, and from there I started my little one liner script.
We can also create dsa and rsa keys in our android device, for that just open a terminal and write:
$ su # dropbear-keygen
just in case we want to do password-less sync. If you want to show the rsa key from your phone do:
dropbearkey -y -f /data/dropbear/dropbear_rsa_host_keyMore information about ssh at
Finally create a new shell script for ASE scripting with something like: (note the non default ssh port if you use something different than 22)
su -c "rsync -av --partial --stats --progress --delete --rsh='ssh -p1234' dani@my_ip:/media/Music/android/ /sdcard/Music"
Add a new launcher on the phone's desktop and you're all set. If apart from wifi, you also use 3G and one gps locale application, the possibilities for sync your music are almost infinite.
Saturday, May 29, 2010
Add keyboard shortcut on Ubuntu to send user defined signal
Sometimes it is needed to do a task quick and effective on linux, here is when it comes into account keyboard shortcuts.
There is several ways to make this work, but the easiest one I found is just using the default tools provided by Ubuntu.
So, lets say we want to send a user defined signal to a Unix process in our machine to do some specific task asynchronously, that is, when we press the keyboard shortcut. In Windows systems probably we would need to trap events to do something similar.
To do that just go to System - Preferences - keyboard shortcuts and add your command.
In this particular case we want to add:
bash -c -i "kill -USR1 $(pgrep -f your_proccess_name.py)"
Take into account that first we specify the Unix interpreter to be used and then the command.
Kill is sending our user defined signal to our python script, and from that python script we will capture and handle the signal.
Tuesday, May 04, 2010
Using someone else to read for you

Time is limited and that makes me try to optimize it as much as possible. There is quite a lot of blogs that I'm subscribed to and that I would like to have the time to read, even more all of those blogs or webpages contains valuable references or hyper links that I'd love to read as well.
What I really hate is have to go through all of them looking for the topics that I like, really I don't have the time, and posts and more posts goes into the cruel destiny of never-read land. Because of that reason, since some time ago I keep some "readers" on my machine, they're basically some processes that examine my preferred webs, starting the search with my Reader subscriptions and then sneaking into the first level links from them.
So basically the parent process is looking for new information in my social circle that talk about my interests.
As an example the first version of the script was doing something like:
for i in $(cat google-reader-subscriptions.xml | grep xmlUrl | sed 's/^.*xmlUrl="//g' | sed 's/".*$//g'); do echo "Checking website: " $i; curl -s $i | grep "Alicante" ; done
Then the future version include a handy mail notification as soon as my preferred news appear, or any link from my web social circle talk about it.
Oops dinner is ready, lets keep my readers doing the job, I'll see later what they have to say... ;-)
Image from: http://www.rdpl.org
Saturday, May 01, 2010
Installing Ubuntu Lucid Lynx with no CD and encrypted home
Follow steps here to setup dhcp server and tftp server:
https://wiki.koeln.ccc.de/index.php/Ubuntu_PXE_Install
Download the netboot image and place it inside the proper directory:
/var/lib/tftpboot
Use a crossover cable to connect one pc to the other, or disable home router dhcp so there is no conflicts.
Dowload iso alternate disk from Ubuntu (important must be alternate) and place it inside your local web server /var/www/ubuntu/
sudo mkdir /var/www/ubuntu/ sudo mount -o loop /path/to/.iso /mnt sudo cp -a /mnt/* /var/www/ubuntu/
Then boot from network card on your client, the pc where you want to do the installation, and instead selecting a remote repository over the internet (they could fail, your local server not :-) ) Just select your local server repository as a ubuntu mirror something like:
http://yourserver/ubuntu
Finish the installation and boot in your new system. If you have encrypted your home directory as I usually do, you may notice some issues regarding access to it, a message like "Could not update ICEauthority", you should be happy to notice it and observe that your home dir is not mounting, this is preventing that any other can read it even if they install another operating system.
So to fix it, just install the package ecryptfs-utils and run under terminal the nexts lines, so you can type your personal passphrase. First type your passphrase and then type your system password.
cd $HOME/.ecryptfs/
ecryptfs-wrap-passphrase wrapped-passphrase
tip from http://angelverde.info/tag/ubuntu/
Then reboot to go to a new login screen and log in normally, all your home settings will be there.
https://wiki.koeln.ccc.de/index.php/Ubuntu_PXE_Install
Download the netboot image and place it inside the proper directory:
/var/lib/tftpboot
Use a crossover cable to connect one pc to the other, or disable home router dhcp so there is no conflicts.
Dowload iso alternate disk from Ubuntu (important must be alternate) and place it inside your local web server /var/www/ubuntu/
sudo mkdir /var/www/ubuntu/ sudo mount -o loop /path/to/.iso /mnt sudo cp -a /mnt/* /var/www/ubuntu/
Then boot from network card on your client, the pc where you want to do the installation, and instead selecting a remote repository over the internet (they could fail, your local server not :-) ) Just select your local server repository as a ubuntu mirror something like:
http://yourserver/ubuntu
Finish the installation and boot in your new system. If you have encrypted your home directory as I usually do, you may notice some issues regarding access to it, a message like "Could not update ICEauthority", you should be happy to notice it and observe that your home dir is not mounting, this is preventing that any other can read it even if they install another operating system.
So to fix it, just install the package ecryptfs-utils and run under terminal the nexts lines, so you can type your personal passphrase. First type your passphrase and then type your system password.
cd $HOME/.ecryptfs/
ecryptfs-wrap-passphrase wrapped-passphrase
tip from http://angelverde.info/tag/ubuntu/
Then reboot to go to a new login screen and log in normally, all your home settings will be there.
Wednesday, April 21, 2010
Sunday, April 18, 2010
Image conversions / JPG to PDF and TIFF to PDF
With ImageMagick use command
$ convert img1.jpg img2.jpg img3.jpg all_images.pdf
With libtiff-tools create multipage tiff and than convert to pdf
$ tiffcp 1.tif 2.tif ... N.tif multi.tif
$ tiff2pdf -o out.pdf multi.tif
$ convert img1.jpg img2.jpg img3.jpg all_images.pdf
With libtiff-tools create multipage tiff and than convert to pdf
$ tiffcp 1.tif 2.tif ... N.tif multi.tif
$ tiff2pdf -o out.pdf multi.tif
Saturday, April 10, 2010
looping through files with spaces in the filenames in bash
I sometimes have to transfer files with spaces in the names, I like using a for loop, but the usual way doesn’t work. Usual way:
for file in `find . -type f|grep .ext$`
do
/do/something/to $file
done
To get around this I use a while loop with a read instead. Using the read will read to the end of the line, enclosing within quotes escapes the spaces. Unusual way:
find . -type f|grep .ext$ |while read file
do
/do/something/to "$file"
doneWednesday, April 07, 2010
Vulnerabilidad Sockstress del protocolo TCP
Muy interesante la vulnerabilidad, y también la historia de cómo se desarrollaron los acontecimientos.
http://www.kriptopolis.org/sockstress
http://www.kriptopolis.org/sockstress
http://gabriel.verdejo.alvarez.googlepages.com/ARTICULOS-Lavulnerabilidaddelprotoco.pdf
En la pagina de Wikipedia que habla de la vulnerabilidad informa que puede ser mitigada utilizando iptables mediante connection tracking and rate limiting.
En la pagina de Wikipedia que habla de la vulnerabilidad informa que puede ser mitigada utilizando iptables mediante connection tracking and rate limiting.
Esta vulnerabilidad en la pila TCP/IP no tiene solución hasta el momento, todos los sistemas operativos están afectados, podríamos decir que es una vulnerabilidad del protocolo, siempre y cuando éstos tengan algún tipo de servicio que establezca conexiones tcp a la escucha.
No me gustaría dar ideas, pero por la misma regla de tres incluso los servidores dns podrían estar afectados, aquellos cuya respuesta se realizara via tcp y no udp como suele ser lo habitual.
Sunday, March 28, 2010
Editing android read-only file system
This lines also help to fix the route and ifconfig not working as expected from /system/bin/
mkdir /system/xbin
cd /system/xbin
ln -s /data/busybox/ifconfig ifconfig
ln -s /data/busybox/route route
mount -o remount,ro -t yaffs2 /dev/block/mtdblock6 /system
Setting up SSL/TLS vpn from Android phones
I did create a client.conf file almost similar for all my clients, one of them, the android phone.
Then created a simple script to start the vpn.
#again setting right path as ASE scripting for android uses other shell
export PATH='/system/sbin:/system/xbin:/system/bin'
cd /sdcard/openvpn/
su -c "openvpn --config /sdcard/openvpn/client.conf"&
Make busybox the default for android terminal
just enter on terminal Preferences and under Command line enter /system/xbin/sh and inside the initial comand set PATH to run commands from busybox and not from the default terminal.
export PATH='/system/sbin:/system/xbin:/system/bin'
after that ifconfig and route commands for example will work like a charm :-)
Tuesday, February 23, 2010
Reading about SQLite...
An extremely reliable open source relational database used by several MP3 players, the iPhone, Android and probably iPad also.
It was first designed by D. Richard Hipp in the Spring of 2000 while working for General Dynamics on contract with the United States Navy. Hipp was designing software used on board guided missile destroyer ships...
Sunday, February 21, 2010
Subscribe to:
Posts (Atom)
