Splitting VCF files using Python

I recently did a fresh install of Ubuntu 11.10. I forgot to export my contacts from Evolution and was horrified to learn these are not stored in a flat file and the database is not compatible between versions (great work Evolution devs).

Some poking around on the internet led me to a Perl file to that was able to get the data. Then some Python work let me format it correctly as a VCARD (.VCF) file. But when I tried to import it I didn’t get all my contacts. More sleuthing led me to realize that only the first 75 were being imported. I wrote this short Python script to break up my 190-contact VCARD file into parts that had no more than 75 entries. I hope it will help you out too!

Quick Fix: Unity sidebar and panel are missing!

The jury is still out on the Unity desktop for me. I certainly didn’t need to switch away from Gnome, but I’m a long time supporter of Ubuntu so I’m giving it a go. But when I was messing around trying to get a PS3 SixAxis controller working with Portal 2 today I managed to make the sidebar and panel disappear. What’s more, Alt-F2 wasn’t bringing up the run command dialog. Luckily I had Guake running so I was able to use the virtual terminal.

Now if you search around, a lot of folks will tell you to run “unity –replace”. This made the windows jump around but didn’t fix the problem. On Lucid I would have restarted Gnome, calling the gdm daemon to restart. But there’s no gdm here. I searched around on that topic and found that gdm has been replaced by lightdm. So, if you hose your Ubuntu 11.10 desktop UI and need to reset it (without rebooting) use this new command:

sudo service lightdm restart

I hope this is helpful!

Quick Tip: Pause any process you want in Linux

 mike@krusty:~$ pidof ffmpeg
 22730
 mike@krusty:~$ sudo kill -STOP 22730
 [sudo] password for mike:
 mike@krusty:~$ sudo kill -CONT 22730

Holy crap, how come it took so long for me to figure out you can pause a running process in Linux and restart it later? I was looking at the manual page for the kill command (man kill) when I started wondering what the CONT option is used for. It turns out that it is paired with the STOP option (and a couple of others) which can be used to pause a running process. Here’s a quick rundown of the process:

  1. Find the PID of the process using the ‘pidof’ command
  2. Pause the process using that PID (22730 for example): sudo kill -STOP 22730
  3. Go about your business
  4. Restart the process when you’re ready: sudo kill -CONT 22730
What can you use this for? Well, if you’re doing something processor intensive, like transcoding video, you might want to regain your CPU power for a quick task. This lets you do that.

Python parallel port control

 

Looking for a really easy way to control your project from a computer? If you have a parallel port which isn’t used you’re in luck. Python has a module that makes it easy to toggle the pins on the parallel port

First install the pyParallel module. It’s in the Ubuntu repositories:

sudo apt-get install python-parallel

To use the module just import it, instantiate an object, then write or read from that object.

import parallel
parPort = parallel.Parallel()
parPort.setData(0x01)

Now, this threw a permission error for me. But a bit of searching led me to find that you need to remove the lp module and insert the ppdev module:

sudo rmmod lp
sudo modprobe ppdev

This module will load again next time you reboot. Consider blacklisting it if you are using automated Python scripts that need parallel port access.

That’s it! Don’t you love Python? Of course there are some additional functions availalbe for this module so check the documentation to see what else can be done.

My over-the-air Television library and how you can build your own

Amanda and I finally cut the cord about two years ago, after having spent quite a bit of time developing a replacement for Cable television. We started to realize that many of the shows we watched were on broadcast television, and others we could wait for on DVD or watch legally online. Since cutting the cord we’ve never had any regrets and it’s because we always have something on the server to watch.

My setup uses one server running MythTV to record shows from an antenna I built. Those shows are transcoded and stored on a networked folder to be played back by various front end hardware running XBMC. After the break I’ll share all the hardware and software details that make this happen.

Continue reading