Sunday, 3 February 2013

Suppressing command window when using pyinstaller for pygtk projects

You've built a GUI project with PyGTK and now you want to package it all into one neat .exe (for Windows) using pyinstaller. If you run the .py just on its own, you would have noticed that a command window opens up in addition to the GUI. This is fine for debugging, but not when you want to deploy it as an application. If you use pyinstaller, it's very easy to do this. When you run pyinstaller just like this: --onefile -F -o output_dir python_file
three things are created:
  • A python_file.spec file.
  • A dist folder (where your .exe goes).
  • A build folder.
Open up the spec file with an editor and set console=False in the exe section. Then run pyinstaller with the -w otpion and this should suppress that command window when you invoke the exe. --onefile -F -w -o output_dir python_file
The solution was obtained from here.

Monday, 24 September 2012

Using sed to add text to the beginning or end of every line in a file

Add "bla" to the beginning of every line in a file:
sed -i 's/^/bla/' filename
Add "bla" to the end of every line in a file:
sed -i 's/$/bla/' filename

Wednesday, 20 June 2012

Exporting and backing up iPhone contacts

Since I'm changing jobs, I'll have to give up my company iPhone. The problem is that since I use Linux, iTunes doesn't work. For photographs, I use Google+'s Instant Upload feature which backs all my photos up in the cloud. Backing contacts up is a little bit tougher. Luckily, there's a very simple app that does this. It's called My Contacts Backup and all you have to do is choose which format you want your contacts exported in (csv or vcf). It takes just a few seconds and when it's done, you can email yourself the file. Simple.

Wednesday, 2 May 2012

How to un-warp suction cups

A while ago, someone gave me their GPS device because they bought a new one. The suction cup had been stored very badly in the box for many months such that it was totally warped and wouldn't stick to any surface. There's one really easy way of "resetting" a warped suction cup. Dunk it in boiling water for a few minutes. The rubber becomes pliable and the cup regains its original shape. Problem solved.

Sunday, 5 February 2012

404 error with Drupal6's install.php and Ubuntu 11.10

If you get the 404 error when invoking the install.php script after installing Drupal, it might be that the configuration file is not in place. Just issue this command:
$ sudo cp /etc/drupal/6/apache.conf /etc/apache2/mods-enabled/drupal.conf

Sunday, 22 January 2012

Using Dropbox to do server-side coding (PHP)

A friend and I are working on a collaborative project to do some server-side coding. We've decided to use Dropbox for this purpose. Apache picks up pages from /var/www/. Just make a symbolic link to your Dropbox folder in order to get this working:
$ cd /var/
$ mv www wwwOLD
$ sudo ln -s /home/yourusername/Dropbox/foldername www
You will get a "forbidden" error if you do just this. In order to get it all working, you need to change the permissions on your Dropbox folder:
$ cd /home/username
$ chmod 755 Dropbox
This way any changes made in foldername on Dropbox can instantly be viewed in your browser.

Sunday, 18 December 2011

Enabling audio output over HDMI with Ubuntu

I assembled a new computer recently. It's an awesome piece of machinery:
  • Mainboard: Zotac H67-ITX Wifi.
  • Processor: Intel Core i5.
It was important for the mainboard to have HDMI output because I wanted to connect the computer to my TV (an LG 32LE5500) and have a complete media-center in my living room. When I connected the machine to my TV (which is connected to a Dolby 5.1 sound system) with an HDMI cable, there was no sound! Here is one solution: Create this file if it doesn't already exist: /etc/asound.conf. In this file, put the following:
pcm.!default {
  type plug
  slave {
    pcm "hw:1,0" #delete the first hash for sound over analog
#    pcm "hw:1,1" #delete the first hash for sound over optical
    pcm "hw:0,3" #delete the first hash for sound over hdmi
    rate 48000
This should direct sound to the HDMI. There is one downside though: you can't use the sound controls to control the sound. In fact, nothing seems to have any effect. Luckily since the sound is coming via the TV, I can use the remote to control the sound until I find a solution. Once I find it, I'll post it here.