Importing contacts the hard way
Three days ago, I got my Nokia N9 and everything was fine.
One day later I flashed PR1.2 onto it. This broke Contact synchronization via Exchange. No matter what I tried, I couldn’t get it to work.
The synchronization not working is one thing, but not having the contacts on the phone at all is pretty bad, so I needed to find a way to bring them on there.
The N9 doesn’t support importing contacts from any files. The next best thing that came to my mind, were QrCodes.
Easy-peasy, just open up Google contacts, point the phone camera to the QrCodes of one contact after another and save it. But wait! Google Contacts doesn’t show any QrCodes. So I had to generate them myself. Of course I could upload the exported file with all contacts to a website and get back the Codes, but that’d mean that I’d transfer all my contact data to some strange website - not an option either.
The Linux program qrencode can convert contact data to a QrCode. That’s easy enough. Just use:
qrencode -o name.png “`cat name.vcf`”
Toying around, I found that Vcard was the only format supported by both Google Contacts export and the N9 Qr Code program.
So, the last problem I had, was that I’d have to download every contact’s vcard file. That’s a lot of work.
I ended up, exporting all the contacts at once and writing a Python program to separate the data into files for each contact:
(It’s uggly code, I’m not using Python that often…)
from vobject import readComponents
file = open(‘contacts.vcf’)
io = StringIO.StringIO(file.read())
string = io.getvalue()
for vcard in readComponents(string):
filename = vcard.fn.value+”.vcf”
filename = filename.replace(” “, “.”)
filename = filename.lower()
out = open(filename, ‘w’)
v = str(vcard.serialize())
Afterwards, I used a (very small) Shellscript to generate the png files:
for line in *.vcf;
qrencode -o $line.png “`cat $line`”
(You can use my code under the WTF Public License 2.0 http://sam.zoy.org/wtfpl/COPYING)
full privileges to ‘root’@’%’ in MySQL
I just had the problem that I was unable to do certain things when logged in as root to a remote MySQL Server. I was wondering a bit why this was, after all, I’m root.
The problem turned out to be quite simple. MySQL has two root accounts. One is root@localhost (when coming from localhost, obviously) and on is root@% (when coming from any other host).
The root@% hasn’t full permissions by default. Changing this is quite simple:
1. Login from localhost
mysql -u root -p
2. Change permissions for the remote root account
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’;
That’s all :)
cron based alarm clock playing podcast on N900
To make getting up in the morning easier, I’d like my phone to play the latest episode of the InfoSec Daily Podcast that comes out while I’m sleeping.
That wouldd be totally doable with a proper cron daemon.
When I reset my N900 lately, I finally got around installing a cron daemon.
http://wiki.maemo.org/Fcron explains how to install Fcron on the Nokia N900, I just followed all their steps.
The first problem I had afterwards was, that I was unable to use fcrontab -e with the default user account. That sucks! I could not find a solution for this problem, but a workaround: As root user, just do
fcrontab -u user -e
Now you can edit the users crontab :)
To do the alarm clock with the podcast, I need two scripts: One downloading the newest episode and a second one playing it. I start the first one about 45min befor the second, as I can’t predict how long it will take to do the download.
I’m using the GPodder Podcast client on my N900 (that thing’s amazing!). Luckily, Gpodder offers a command line interface that can be called via the gpo command.
The download script looks a bit like this:
gpo update http://feeds.feedburner.com/InfosecDaily » download.log
gpo download http://feeds.feedburner.com/InfosecDaily » download.log
The second script was a bit trickier. The main problem is, that mplayer, for some reason, doesn’t work from within the cronjob. So I decided to use ffplay.
That didn’t fully solve the problem though. ffplay absolutely wants to spawn a window, even when started with the “-nodisp” option (that’s apparently a bug that’s solved in newer versions of ffplay).
This requires the SDL variable to be set, and that’s normally not the case from within the script.
The script looks like this:
cd /home/user/MyDocs/Podcasts/InfoSec\ Daily\ Podcast/
/bin/ls infosec-daily-podcast-episode-* > episodes.list
episode=$(sort -n episodes.list | tail -1)
echo $episode » /home/user/play.log
DISPLAY=:0.0 ; export DISPLAY
ffplay -nodisplay $episode » /home/user/play.log 2> /home/user/error.log
Both scripts are only started during week days, the second one at the time I want to get up.
There’s still a minor problem: When I run the second script manually as user, ffplay runs fine, using about 20% of the CPU, according to htop. But when started by the cronjob, ffplay uses 100% and still has minor lag.
I couldn’t figure out why this is or how to solve it yet :(