Adjusting to the new version of Pylab and Mayavi on Ubuntu 12.04

It seems the IPython and Pylab packages has also been updated in 12.04 and thus removing the old ipython -wthread flag that would ensure Mayavi plots to be run in a separate thread. Running with the flag causes this error to show up:

[TerminalIPythonApp] Unrecognized flag: '-wthread'

Without this flag, the Mayavi plots lock up the UI and hangs. If you want to get the possibility back to rotate and play around with the plots, just start IPython the following way from now on:

ipython --pylab=qt

This will launch IPython with the Qt backend and threading. Using only –pylab does not include threading. For easy and quick access, add the following to a file named .bashrc in your home folder:

alias pylab='ipython --pylab=qt'

From now on you can launch IPython just by typing

pylab

in a terminal.

Posted in Mindseye, Programming, Python, Python, Ubuntu | Tagged , , , , , , , | Leave a comment

Using the same script on installs with different EPD versions

In the newest version of Enthought’s Python Distribution (EPD) on Ubuntu, the plotting package has been moved from enthought.mayavi.mlab to the shorter and more general mayavi.mlab. This does however mean that if you, like me, need to work with different versions of EPD on multiple systems, will experience the following error from time to time:

ImportError: No module named enthought.mayavi.mlab

Now, to avoid switching the import statement every time you switch systems, you can make Python check if one of the versions is installed during import. If it is not, we’ll tell it to try the other. This is done in this simple command:

try:
    from enthought.mayavi.mlab import *
except ImportError:
    from mayavi.mlab import *

Just replace any other similar import statements the same way and your code should once again be working across all your installations.

Posted in Mindseye, Programming, Python, Python, Ubuntu | Tagged , , , , , , , , , , | Leave a comment

Modifying keys on a Norwegian Linux keyboard to resemble those on a Mac

A friend of mine is switching between a Mac and a Linux machine, causing some readjustment whenever he switches keyboards. The most urgent fixes were to move the curly and square braces together with the backslash and dollar sign. Basically to map the keys as follows:

ALT + 8 = [
SHIFT + ALT + 8 = {
SHIFT + ALT + 7 = \
SHIFT + 4 = $

To set up these fixes, the first thing you need to do is to go to System Settings and Keyboard Layout (might be hidden under Region and Language) and select advanced options. Here you need to enable “Key to choose third level: Left Alt”.

The next is to run the following commands:

xmodmap -e "keycode 13 = 4 dollar 4 currency dollar onequarter"
xmodmap -e "keycode 16 = 7 slash 7 slash braceleft backslash"
xmodmap -e "keycode 17 = 8 parenleft 8 8 bracketleft braceleft"
xmodmap -e "keycode 18 = 9 parenright 8 8 bracketright braceright"

To store these settings permanently, create a file named .bashrc in your home folder and add them to this file.

Posted in Efficiency, Ubuntu | Tagged , , , , , , , , , | Leave a comment

Installing Norwegian dictionary in TexMaker

I just came over a great LaTeX editor named TexMaker. It seems to fit my needs perfectly, with auto-complete and mapping between tex and PDF files. It does however not have a Norwegian dictionary installed, but this is easily fixed:

  1. Download the Norwegian dictionary pack from OpenOffice’s dictionary list, or use this direct link.
  2. Unpack the zip file and unpack the nb_NO.zip file inside this again.
  3. Open up TexMaker > Options > Configure Texmaker
    (It is under Preferences if you are using Mac)
  4. Go to Editor and click the folder icon to browse to your nb_NO.dic file.
  5. TexMaker should now use the Norwegian dictionary.

Enjoy!

Posted in LaTeX | Tagged , , , , | Leave a comment

Installing the nVidia driver in Kubuntu 12.04

Running the vanilla install of Kubuntu 12.04 worked incredibly well. It took me quite some time to notice that I was in fact using the open source noveau driver. Dual displays, desktop effects and all other first impressions worked without glitches. In fact, it was not before I tried to run Google Maps’ WebGL version that I started noticing some rendering errors. And according to the noveau project’s own webpages, the OpenGL acceleration is exactly where noveau is still lacking.

In addition, the graphics card seemed to heat itself more easily with the noveau driver.

Sadly this lead me to realize that I would still have to use the proprietary NVIDIA driver to make use of my graphics card and the applications I use daily. Even worse, getting this installed would prove to harder than in earlier versions of Ubuntu. I don’t know if this is due to using Kubuntu or not, but if you should experience some of the same symptoms, here is how I fixed it.

First of all, the symptoms were as follows after installing the nvidia-current package:

  • The computer started only with one display and with a very low resolution (640 x 480)
  • Enabling the nvidia driver using jockey-kde or jockey-text resulted in errors such as
    • ERROR: XorgDriverHandler.enable(): package or module not installed, aborting
    • WARNING: modinfo for module nvidia_current_updates failed: ERROR: modinfo: could not find module nvidia_current_updates
  • Finally, installing nvidia-current only gave the error:
    • Module build for the currently running kernel was skipped since the
      kernel source for this kernel does not seem to be installed.

So, if you experience any of these, the reason is most likely missing kernel source and header libraries. The fix is thankfully simple, just run the following commands in a terminal:

sudo apt-get update
sudo apt-get purge nvidia-current
sudo apt-get install linux-source
sudo apt-get install linux-headers-generic
sudo apt-get install linux-image
sudo apt-get install nvidia-current
jockey-text -e xorg:nvidia_current

After this, if you get no errors, try to reboot and run

nvidia-settings

after booting. Now you should be able to set up and use your system with full graphics acceleration.

Good luck!

Posted in Ubuntu | Tagged , , , , , , , , | 4 Comments

Launching apps from XBMCbuntu Eden

I just replaced an old Ubuntu install with the fresh live CD carrying XBMC. It has now been named XBMCbuntu, noting its inheritance a bit more than earlier. While running XBMCbuntu has its benefits with a pre-made nicely working setup of XBMC, it lacks direct access to applications like a web browser and for instance Spotify. One can boot up the LXDE desktop environment when logging in instead of starting XBMC in full screen, but that is kind of tedious if one wants the default behaviour to be a full screen home theatre PC.

Luckily there is an add-on called Advanced Launcher that you’ll find under “System > Settings > Add-Ons > Get more” in XBMC, but even though this includes a Chromium launcher by default, it fails to launch anything properly. Chromium is for instance launched without the maximize and close buttons, and on my first attempt, the URL bar was even gone. The reason is simple; when launching a command using the Advanced Launcher, it has not yet opened a window manager such as Openbox, which I believe is default in LXDE. The solution for me was found in this blog post, over at Setup Guides, where James Cole suggests adding a script that launches openbox before launching Chromium. And kills Openbox when Chromium is closed.

However, the solution proposed there works only for Chromium and you’ll have to set up a similar script for all applications you’d like to launch from XBMC. That isn’t too much work, but I figured one could make the script from Setup Guides a bit more general, taking the application to launch as an argument instead.

So the setup goes as follows:

  1. Install XBMC and the Advanced Launcher add-on
  2. Create a script with the following contents and save it somewhere in your home folder (to make it easily accesible from XBMC)
    #!/bin/bash
    openbox &
    $1
    killall -9 openbox
    
  3. Start the Advanced Launcher add-on
  4. Right click (or press C on the keyboard) and select “Create New Launcher”
  5. Select your script as the executable
  6. Type the command you want to run as the argument. This could for instance be “chromium-browser” or “spotify”
  7. Enjoy your new launcher!

To launch Spotify you’ll of course have to install that first. To do so, you might add a launcher to lxterm and follow the instructions on Spotify’s webpages.

Thanks to James @ Setup Guides for posting the original script.

Posted in TV | Tagged , , , , , | 5 Comments

Nanoparticles game reviewed by Nanoparticles Blog

If you are interested in real-life nanoparticles and not just the game I made with the same name, you should check out Nanoparticles Blog. Run by Niko Bärsch, CEO of Particular GmbH, a company that is in fact making real nanoparticles and nanomaterials in the lab. The blog has a good update frequency with posts about whats going on in the world of nanoparticles. He’s writing about everything from nanoparticle production, health concerns and new applications for both particles and nanomaterials.

Lately, Niko even wrote about the Android version of my game on the blog, which of course makes good reason to link back to them. In addition to the joy of being updated about the subjects I’m studying.

Posted in Games, Uncategorized | Leave a comment

Classical mechanics in HTML5 and Javascript

Ok, so we’re working on the home exam in classical mechanics and I decided to spend some time simulating the solution of the first exercise. Probably not the wisest way to spend time during an home exam, but what the heck. I’m learning some Javascript and HTML5, plus the fact that it’s always fun to verify results by looking at something moving!

So here you go. A pendulum on a cart.

I won’t go into details about deriving and solving the Lagrange equation for this system now, but I might get back to that at a later time. And of course there will be some added controls to this so you could set the initial positions, velocities and stuff. Sometime later, I hope.

Posted in HTML5, Javascript, Mindseye, Physics, Programming | Leave a comment

Passwordless access to MySQL by using sudo

Tired of remembering root passwords for MySQL on your servers? Fear no more, help is on the way.

I’ll assume that you have a Linux system set up with sudo and mysql already installed. Fire up a terminal and type

sudo su

Open up ~/.my.cnf in your favorite editor (the ~ points to the root account now).

vim ~/.my.cnf

and add the following contents:

[client]
user = root
password = yourpassword

Follow up with logging out of root:

exit

And run sudo to start MySQL. Remember to use the -H option to point all requests for ~ to root’s home directory:

sudo -H mysql

It is a simple as that :)

Posted in Databases, Ubuntu | Tagged , , , , , | 1 Comment

Developing MPI applications in Qt Creator

I have grown very fond of the ease and usability of Qt Creator lately, making it my main tool for developing anything in C and C++. Recently I started learning the MPI framework for doing large scale parallel programming and figured I wanted to try to make MPI play along with Qt Creator.

The first thing I noticed is that there is no problem using Qt Creator as an editor while compiling the MPI executable and running it from the command line. However, for the quick and easy testing of minor changes, running by pressing Ctrl + R in Qt Creator quickly came to a high place on my wish list.

After a quick search around the Internet, I found the necessary adjustments to make this exact thing happen. The steps are as follows:

Make Qt Creator use mpicxx instead of g++

To change the compiler in Qt Creator, you simply have to edit the .pro file of your project. Add the following lines, and Qt Creator will call mpicxx instead of g++:

# MPI Settings
QMAKE_CXX = mpicxx
QMAKE_CXX_RELEASE = $$QMAKE_CXX
QMAKE_CXX_DEBUG = $$QMAKE_CXX
QMAKE_LINK = $$QMAKE_CXX
QMAKE_CC = mpicc

QMAKE_CFLAGS = $$system(mpicc --showme:compile)
QMAKE_LFLAGS = $$system(mpicxx --showme:link)
QMAKE_CXXFLAGS = $$system(mpicxx --showme:compile) -DMPICH_IGNORE_CXX_SEEK
QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CXXFLAGS

This also sets the correct compile and link flags in addition to changing the linker to mpicxx as well. The DMPICH_IGNORE_CXX_SEEK flag is added to avoid some errors I experienced on Red Hat Linux 5.

Running the application with mpirun

Usually Qt Creator will simply run the generated executable after compiling, but to make use of multiple processors (which kind of is the whole point with MPI), you have to change the run settings of your project to a custom executable. This is done in the project configuration in Qt Creator under the Run tab for your project.

Add a Custom Executable run configuration and set the executable to /usr/bin/mpirun or any other path where mpirun resides on your system (run ‘which mpirun’ in a terminal to find it if you don’t know where it is). Then, set the arguments to

-n 2 yourexecutable

to run yourexecutable with 2 processors. Of course you’ll have to change yourexecutable to whatever your executable is named.

Adding a GUI to your MPI program

I advice you to not use MPI together with Qt GUI libraries. The reasons for this is that Qt has its own threading classes that are easier to use together with GUI elements in your application if you need them and the fact that if you want to run your app on any large scale cluster you might not be able to use Qt at all, depending on what packages are available on this cluster. A much better solution is to load config settings from a file in the INI format, using for instance the lightweight inih library and make this settings file writable from a Qt GUI application using QSettings to write this file.

The downside of this approach is that you won’t be able to implement any communication directly with the MPI process, but this could be worked around by for instance reading and writing to a progress status file if this is what you need.

However, it is not impossible to make Qt GUI applications play along with MPI, even though you might have to juggle a bit around with stuff to make it work flawlessly. Passing MPI broadcasts and such to all the other processes is definitely possible, and a relatively small example of how to do this is shown in this post by Tiffany Chong and Valencia Hare.

Posted in C++, MPI, Programming, Qt | Leave a comment