Saturday, August 28, 2010

Jugando con jquery, flot, prototype y python

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

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

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.

#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
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:
root@yourmachine:/home/vbox/.VirtualBox#chown -R vbox:vbox *
and make sure your virtual machine file allow write permissions to your vbox user or group:
root@yourmachine:/media/sda1# ls -l | grep openbsd
-rw-rw-r-- 1 dani vbox 1239450112 2010-08-12 21:29 openbsdserver.vdi
Once this is setup you can move to add a init script to your linux box, in my case a Ubuntu Lucid box.

#! /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

 

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.