Saturday, November 24, 2012

How To: Prevent use of global menu in Ubuntu Unity

I didn't really mind when Ubuntu switched from using Gnome to their own Unity Interface. Today however, I've had issues with two desktop applications which were unable to play nicely with Unity.

The first one was the preview version of IntelliJ IDEA 12 which is due to be released next month. I reported the issue on the JetBrains Issue Tracker so hopefully it'll get resolved by the time it's released.

I later decided to use Gimp to create a new wallpaper for my desktop. After maximising the window I found that I was unable to access any of the menu options as the dropdown menus appear behind the application. Thankfully a very good post on askubuntu.com showed a quick workaround for the problem. By adding "env UBUNTU_MENUPROXY=0" to the 'Exec' line in the '.desktop' file you can force an application not to use the global menu.

So in the case of Gimp you would do:
$ sudo vim /usr/share/applications/gimp.desktop

Then edit the 'Exec' line to look something like this:
Exec=env UBUNTU_MENUPROXY=0 gimp-2.6 %U

Sunday, August 12, 2012

Using recursion to find prime numbers

Occasionally I like to go back over basic programming concepts by doing simple programming exercises. It's a good practice that I think any developer can benefit from. Today I've been doing some JavaScript and found myself needing to do a google search to remind myself about recursive functions as they're not something I use often. There seem to be loads of horrible examples out there so I've decided to post the code I ended up using.
for (counter = 1; counter <= 23; counter++) {
    if (isPrime(counter, counter -1)) {
        console.log(counter + " is a prime numer.");
    }
}

function isPrime(number, step) {
    if(step <=1)
        return true;
    if(number % step === 0) {
        return false;
    }
    return isPrime(number, step-1);
}

Thursday, June 21, 2012

How To: Get Android ADB working on 64-bit Linux

I recently did a clean install of Fedora 17 on to a Sun Ultra 40 Workstation to use as my development environment at work. The Android SDK requires the 32-bit versions of glibc, ncurses-libs, libstdc++, and others. On an Ubuntu based system this would be handled using ia32-libs. On Fedora however you need to be a little more specific about the individual packages. If using a 64-bit Fedora installation you'll need to run something similar to the following.
$ sudo yum install alsa-lib.i686 glibc.i686 glibc-devel.i686 ncurses-libs.i686 libstdc++.i686 libzip.i686 libX11.i686 libX11-devel.i686 libXrender.i686 libXrandr.i686 SDL.i686 zlib.i686 zlib-devel.i686 mesa-libGL.i686
This is similar to the way in which the dependencies are downloaded on Arch Linux using the multilib and lib32 packages:
# pacman -Syu multilib-devel lib32-zlib lib32-ncurses lib32-sdl gcc gcc-multilib gcc-libs-multilib binutils-multilib libtool-multilib lib32-glibc

Wednesday, May 02, 2012

How To: Fix Nvidia graphics issue in Ubuntu 12.04

Since updating my Ubuntu system to 12.04 I have been experiencing problems with the machine hanging. After spending considerable time reading through forum threads, I found that the solution was to remove the Nvidia driver that was installed via the Ubuntu repositories (v295.40) and manually install the latest driver from Nvidia (v302.07).

The first step was to download the driver from  the Nvidia website:
http://www.nvidia.com/object/linux-display-amd64-302.07-driver.html

Make sure that the file is executable:
$ chmod 755 NVIDIA-Linux-x86_64-302.07.run
Before running the desktop environment needed to be stopped:
$ sudo stop lightdm
Then using Ctrl + Alt + F6 to get to another command prompt I ran the file as root:
$ sudo sh NVIDIA-Linux-x86_64-302.07.run
The installer was able to detect that I had dropped back to the Nouveau driver and gave an option to disable it on next reboot. I agreed to this option then rebooted using:
$ sudo shutdown -r now
This time the system had booted up without the Nvidia or Nouveau drivers so I repeated the steps to stop the graphical environment and run the installer again. On completion I was able to reboot my system into what is now, once again, a stable system.

Saturday, April 28, 2012

UCubed 2012

Today I'm at MadLab (Manchester Digital Laboratory) for a free event called UCubed. The purpose of the event is to encourage people to get involved with the GNU/Linux community, with the main focus being on Ubuntu and Debian based distributions.

As always it's a good opportunity to meet other people with a passion for software as well as a variety of talks to take part in. These type of events are really good for anyone with an interest in computing. There's always something you can learn.

Today Alan O'Donohoe is doing a talk about the Hack To The Future events that he's organising and Julian Skidmore is on site promoting FIGnition which is a build it yourself 8-bit computer.


MadLab host all kind of events worth going to, so if you happen to be in the area check out their events page to see what's available.

Tuesday, April 10, 2012

European Road Trip

This weekend my course work got put on hold by a rather unexpected journey through eight different countries within just four days. A week ago a good friend of mine asked if my girlfriend and I would accompany him as he drove his van to Budapest to help some in-laws move home. It seemed like a nice little adventure so we agreed and set off during the early hours of Friday morning on a round trip of over two and a half thousand miles.


We went via the A1 to the south coast to catch a ferry from Dover to Dunkirk, then headed east through Belgium into Germany where we stopped for food in Frankfurt and then again in Nuremberg where we got a hotel for the night. The following morning we headed south-east into Austria then Hungary, finally arriving in Budapest on Saturday evening.

We set off a little late on Sunday as loading up the van took a lot longer than we'd anticipated, although we still somehow managed to squeeze in a little sight-seeing before leaving the city. As we wanted to make the trip a little more interesting we decided to take a bit of a detour and head through Slovakia into the Czech Republic so that we could have a meal in Prague on the way.

The relaxed approach backfired on us however as by the time we left Prague it was pretty late and we still had a long way to go. A combination of closed roads and a lack of diversion signs in Germany meant that we wasted a lot of time making little progress so we decided to call it a night and managed to find a place to stay in Leipzig (which seemed like a German version of Milton Keynes). This meant us getting up at the crack of dawn on Monday as we had a ferry to catch and were still about eight hours drive from Dunkirk.

The drive west was an endurance test. This was made worse by the fact that somewhere around either the Netherlands or Belgium an entire network of roads had sprung up since the sat-nav had last been updated, resulting in a wrong turn being made and the best part of an hour wasted. We got to the docks in Dunkirk in time to see our ferry depart and had to wait it out a few hours for the next one. On the plus side though we didn't have to empty the entire contents of the van for border control. The final stretch up to Leeds seemed like an eternity but we finally made it back and still had time for a pub meal on the way.

Tuesday, March 20, 2012

How To: Install Arch Linux

Update: Some of the steps here are now deprecated.

Today I started a new position as a Software Developer at NTI Leeds. I'm going to be working on Android projects initially but may move on to iPhone development later in the year. As with most first days I spent some time setting up a development environment.

The machine I am using is a pretty average hardware spec, so I decided to install Arch Linux as it's supposedly pretty good for performance.

Arch Linux is a lightweight rolling-release distribution, that is to say that once it is installed the the system can be continually updated to keep up with the latest version rather than a new version being released periodically as is commonly done with other distros such as Ubuntu or Fedora. As Arch Linux can be a little more daunting for new users I have documented some steps on this page which I use for my system. As I use a 64-bit system and am in the UK some of these steps may need to be changed depending on your requirements. Additional help can be found on the Arch Linux Wiki.

Some steps to take during the Arch Linux Installation:

Most of the steps required can be found on the Official Installation Guide. Once the install cd has been booted you can start the installation process by using:
/arch/setup

Partitioning the Hard Drives:

When partitioning the hard drive I opted for setting fixed partitions using the Ext4 filesystem (it's a bit too soon to use Btrfs). On hindsight I think I would have been better off using LVM (Logical Volume Manager) and will do so next time. If you intend to do development work you may find /usr/lib taking up a lot of space. Also, ~/.pacmanCache can grow fairly large so it's a good idea to give yourself enough space. The installer uses the following defaults:
  • 32 MB ext2 /boot partition
  • 256 MB swap partition
  • 7.5 GB root partition
  • /home partition with the remaining space
Disk space is cheap so something like this is fine:
  • 32 MB ext2 /boot partition
  • 512 MB swap partition
  • 15 GB ext4 root partition
  • /home ext4 partition with the remaining space

Locale:

Some localization information is kept in /etc/rc.conf. This file is the main configuration file for the system so you will need to return here fairly often to change settings. For the UK make sure the LOCALIZATION block in /etc/rc.conf looks like the following:
# LOCALIZATION
# ------------
HARDWARECLOCK="UTC" 
TIMEZONE="Europe/London" 
KEYMAP="uk" 
CONSOLEFONT=
CONSOLEMAP=
LOCALE="en_GB.utf8" 
DAEMON_LOCALE="yes" 
USECOLOR="yes"
Now create the following file /etc/locale.conf and add the following:
LANG=en_GB.UTF-8
LC_MESSAGES=C
A list of available locales is stored in /etc/locale.gen. Edit the file and uncomment the lines for UK then save and exit the file (keep the US also as a fallback):
en_GB.UTF-8 UTF-8
en_GB ISO-8859-1
en_US.UTF-8 UTF-8
en_US ISO-8859-1
Once this is done you need to run locale-gen as the root user

Arch Linux Post Installation:

Once your new system has been installed it's time to start configuring it. First you'll need need some packages. Packages are installed on Arch Linux using pacman:
pacman -S 
Before we start installing any packages make sure that pacman is downloading packages from servers in your location by editing /etc/pacman.d/mirrorlist. On my system I simply uncommented all of the UK mirrors:
## Great Britain (Try GB first)
Server = ftp://mirror.lividpenguin.com/pub/archlinux/$repo/os/$arch
Server = http://mirror.lividpenguin.com/pub/archlinux/$repo/os/$arch
Server = ftp://mirror.bytemark.co.uk/archlinux/$repo/os/$arch
Server = http://mirror.bytemark.co.uk/archlinux/$repo/os/$arch
Server = ftp://mirror.cinosure.com/archlinux/$repo/os/$arch
Server = http://mirror.cinosure.com/archlinux/$repo/os/$arch
Server = ftp://mirrors.uk2.net/pub/archlinux/$repo/os/$arch
Server = http://archlinux.mirrors.uk2.net/$repo/os/$arch

## Ireland (if none in england try Ireland)
Server = ftp://ftp.heanet.ie/mirrors/ftp.archlinux.org/$repo/os/$arch
Server = http://ftp.heanet.ie/mirrors/ftp.archlinux.org/$repo/os/$arch
Once the file has been saved you need to run pacman -Syy to force a refresh of all package lists.

Install useful tools and libs:

As this is a 64-bit system if you install packages such as 'base-devel' you will encounter problems later when dealing with software that requires 32-bit libs. Use the multilib-devel instead to be able to deal with 32 bit and 64 bit.
pacman -Syu vim mlocate ntp multilib-devel lib32-zlib lib32-ncurses lib32-sdl gcc gcc-multilib gcc-libs-multilib binutils-multilib libtool-multilib lib32-glibc

Install 'sudo' and create a user that is a sudoer:

useradd -m -g users -G audio,lp,optical,storage,scanner,video,wheel,games,power -s /bin/bash 
pacman -S sudo
Now that sudo is installed you'll need to make your user a sudoer. This is done using 'visudo', however now that vim has been installed you can use the following to use vim as the editor:
EDITOR=vim visudo
My preferred way to do this is to uncomment the following line so that any user that belongs to the 'wheel' group can use sudo.
%wheel ALL=(ALL) ALL

Install audio:

Edit /etc/modprobe.d/modprobe.conf by adding the following (this is to ensure that the 'snd-pcsp' module loads last):
options snd-pcsp index=2
Now install alsa:
pacman -S alsa alsa-utils alsa-oss

Install a graphical desktop environment (Gnome 3 in this case):

pacman -S xorg xorg-server xorg-xinit xorg-server-utils xterm gnome gnome-extra gnome-system-tools dbus gdm gnome-packagekit gnome-settings-daemon-updates gnome-tweak-tool gnome-shell-extension-alternative-status-menu
To get Xorg to use my UK keyboard layout I had to edit /etc/X11/xorg.conf.d/10-evdev.conf:
vim /etc/X11/xorg.conf.d/10-evdev.conf
then add the following to the 'evdev keyboard catchall' section:
Option "XkbLayout" "gb"
If you want your system to boot into a graphical environment rather than the command line then you'll need to edit your /etc/rc.conf file again. This time you need to edit the DAEMONS section. It should look similar to the following:
# DAEMONS
# -------
#
DAEMONS=(syslog-ng dbus network netfs crond alsa gdm)

Install Firefox, Chromium, and some additional fonts:

pacman -S ttf-dejavu ttf-droid ttf-liberation ttf-ubuntu-font-family ttf-freefont ttf-inconsolata monaco-linux-font chromium firefox
That's it! By now you should have a light weight Linux environment to work in. At this point there was still much that I had to install such as git, subversion, Java, Android SDK, Eclipse and Sublime Text. When I get time I may write a follow up article.

Wednesday, February 15, 2012

My customised IntelliJ IDEA theme

During the last few years I have used an IDE called IntelliJ IDEA for Java projects. Unfortunately the default colour scheme is not much to my liking so I decided to create my own colour scheme inspired by the dark grey background and pastel colours that Sublime Text uses. Originally it was my intention to recreate the default theme of Sublime Text but after making a few adjustments the resulting theme ended up being rather different.

My IDEA theme can be downloaded here: Samael-IDEA-Theme.xml

The themes for IDEA are done using XML files which are kept in:
C:\Users\username\.IntelliJIdea10\config\colors
Or the equivalent config folder for Mac:
~/Library/Preferences/IntelliJIdea10/colors
IntelliJ checks the contents of the folder on startup, so if you add the file whilst using IDEA it will not be available in the IDE until you restart it.

Monday, January 30, 2012

Custom colours for Vim using Villustrator

If like me, you like to use visually appealing colour schemes within the terminal, check out Villustrator. This handy little web-based tool provides a visual way in which to create a custom colour scheme for Vim. Simply edit the colours to your liking then click the Download button and save the '.vim' file to:
~/.vim/colors/
Once this is done you will need to set your new theme by editing your vimrc file.
vim ~/.vimrc