Si la máquina virtual no se cae o se apaga el pc, aquí un ejemplo rápido de generación de gráficas limpias. Un script python en servidor es el encargado de generar los datos y pasarlos via json, parseando de manera muy manual los datos de Yahoo Weather. Cualquier modificación iría encaminada a utilizar un mecanismo más estandard de tratamiento xml.
El resultado:
http://dani.homeunix.org/meteo/
el código fuente en:
http://github.com/daniguerrero/meteo
Saturday, August 28, 2010
Friday, August 20, 2010
Probando las bicis p'ublicas de Lyon
La verdad es que est'a muy bien montado, con estaciones de bicis por todas partes, y bastantes carriles bici, ojal'a se extendiera pronto por todo el mundo y se dejara de lado cada d'ia m'as tanto coche.
Este es el paseo que he dado con el MyTracks en el G1.
View Pista Ciclista in a larger map
Total Time: 00:26:58
Moving Time: 00:24:45
Distance: 6.09
Distance Unit: km
Average Speed: 13.58
Average Moving Speed: 14.77
Max Speed: 27.9
Speed Unit: km/h
Elevation Gain: 241
Min Elevation: 210
Max Elevation: 272
Elevation Unit: m
Sunday, August 15, 2010
Notes - Python time string to timestamp
>>> from datetime import datetime, date, time
>>> import time as _time
>>>> # Using datetime.strptime()
>>> dt = datetime.strptime("21/11/06 16:30", "%d/%m/%y %H:%M")
>>> dt
datetime.datetime(2006, 11, 21, 16, 30)
>>> tt = (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.weekday(), 0, -1)
>>> tt
(2006, 11, 21, 16, 30, 0, 1, 0, -1)
>>> stamp = _time.mktime(tt)
>>> stamp
1164123000.0
>>> o = datetime.fromtimestamp(stamp)
>>> print o
2006-11-21 16:30:00
>>> import time as _time
>>>> # Using datetime.strptime()
>>> dt = datetime.strptime("21/11/06 16:30", "%d/%m/%y %H:%M")
>>> dt
datetime.datetime(2006, 11, 21, 16, 30)
>>> tt = (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.weekday(), 0, -1)
>>> tt
(2006, 11, 21, 16, 30, 0, 1, 0, -1)
>>> stamp = _time.mktime(tt)
>>> stamp
1164123000.0
>>> o = datetime.fromtimestamp(stamp)
>>> print o
2006-11-21 16:30:00
More info with all string codes for date/time here:
http://docs.python.org/library/time.html#time.strftime
Thursday, August 12, 2010
Notes - Run a Unix virtualbox machine during boot time
In order to save some memory and cpu on your host machine instead running virtual machines through the X system (windows like method :-p) you can use this method.
Probably you have installed Virtualbox with your user, and that installation will store the VirtualBox config files.
You need to copy all those files to the home directory of your new system user vbox and then change permissions to own the files,
by doing something like:and make sure your virtual machine file allow write permissions to your vbox user or group:Once this is setup you can move to add a init script to your linux box, in my case a Ubuntu Lucid box.
#Create a system user for VirtualBox
root@yourmachine:/imadirectory#useradd -r -m vbox
#add it to the right group (note that I'm using the same name for
#the group, not very educational)
root@yourmachine:/metoo#usermod -a -G vbox vbox
You need to copy all those files to the home directory of your new system user vbox and then change permissions to own the files,
by doing something like:
root@yourmachine:/home/vbox/.VirtualBox#chown -R vbox:vbox *
root@yourmachine:/media/sda1# ls -l | grep openbsd
-rw-rw-r-- 1 dani vbox 1239450112 2010-08-12 21:29 openbsdserver.vdi
#! /bin/sh
### BEGIN INIT INFO
# Provides: Starts local virtual machines
# Required-Start: $local_fs $remote_fs $syslog $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
N=/etc/init.d/virtual_machines_local
VBOX_RUNNING=`pgrep -c VBoxHeadless`
set -e
case "$1" in
start)
if [ "$VBOX_RUNNING" = 0 ]
then
logger "trying to boot vboxheadless.."
echo "Starting headless virtual machines."
sudo -i -b -u vbox /usr/bin/VBoxHeadless -s \
openbsdserver -vrdp off
else
echo "VBoxHeadless already appears to be running"
fi
;;
stop)
if [ `pgrep -c VBoxHeadless` != 0 ]
then
echo "Sending acpipowerbutton to VMs...."
logger "Sending acpipowerbutton to VMS...."
sudo -i -b -u vbox /usr/bin/VBoxManage controlvm \
openbsdserver acpipowerbutton
I=0
echo "Waiting for successful shutdown: \
60 seconds (or less)."
while [ `pgrep -c VBoxHeadless` != 0 ] && [ $I -lt 60 ]
do
sleep 1
I=$(($I + 1))
echo -n "."
done
fi
;;
reload|restart|force-reload)
;;
*)
echo "Usage: $N {start|stop}" >&2
exit 1
;;
esac
exit 0
Make sure you add it to default start / stop scripts with the proper runlevels, and install if necessary acpid on the guest system, so it can receive the signal acpipowerbutton to shutdown gracefully.
update-rc.d virtual_machines_local defaults
Sunday, May 30, 2010
Python notes - Timestamp to Datetime
>>> 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
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"&
Subscribe to:
Posts (Atom)
