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_key
More 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.