Log in home

Here is my Blog, Enjoy

A place on the internet where I spout my ramblings.

About Projects

A Go program organization technique

Go is not an Object Oriented language (well not by Java standards!), but it does have some properties of OO languages. Code and data are tied together by having methods on types, method promotion allows for types built from other types and interfaces allow for abstraction.

Deciding how to factor objects before actually using them is a hard thing to do well. And in most typed OO languages adding a class is not trivial. Interfaces are simple. If i want to create a new "class" of something its just:

type store interface {
Add(name string, data []byte)
Find(name string) (data []byte, found bool)

Later after doing some programming, i find i need multiple implementations for Add():

type store interface {
Find(name string) (data []byte, found bool)

type adder interface {
Add(name string, data []byte)

Now I can make a type to implement the store interface, given a type *FooFind that implmenets Find() from the store interface:

type FooStore struct {

And so on. This allows you to just add the complexity that is needed.

But then we come to a problem, let's say an adder implementation BarAdder would like to use Find(), so we create a NewBarAdder(s store) *BarAdder. But now we have a chicken and egg problem, BarAdder requires a store which it also implementing, so is unavailable now. But here comes some Go goodness, we just create:

type storeHandle struct {

This implements store, but the interface field is initially just nil. So:

type BarAdder struct {
s store

func NewBarAdder(s store) *BarAdder {
return &BarAdder{s}

func (b *BarAdder) Add(name string, data []byte) { ...

handle := &storeHandle{}
store := &FooStore{NewBarAdder(handle), &FooFind{}}
handle.store = store

This is a simplified example, in a more complicated store interface with more methods, an Add() might use some subset of the methods. The type implementing Find() could also be built this way to allow it to call other store interface methods also.

Another benefit of organizing this way, is an implementation can modify an existing implementation. Eg:

type namePrefixAdder struct {
prefix string

func (n *namePrefixAdder) Add(name string, data []byte) {
n.store.Add(n.prefix + name, data)

store = &namePrefixAdder{handle.store, "blah"}
handle.store = store

This allows a package to be factored into as just as many types as needed, and tends to result in well defined structs tying data and code together very neatly.


Nvidia proprietary drivers and Ubuntu 12.04 redraw

Using nvidia-settings, changing power saving mode to maximum performance fixes this problem. It gives better performance than below but i assume uses more power.

One thing that took me a long time to fix was, small of regions windows not getting redrawn when modified. After trying countless things, the option was in compiz config settings manager (ccsm).

To fix, in CCSM->Workarounds it i set:
"Force complete redraw on initial damage"
"Force fullscreen redraws (buffer swap) on repaint"

Now this works very nicely indeed....

Thanks to all the people working on Ubuntu/Linux software!!!


Tweaking Ubuntu 12.04 to run on a Macbook

Update 2

  • Ubuntu looks better with it's default color profile. Probably not worth changing. 
  • With the latest NVidia drivers I've found the options I set below are not needed (apart from the brightness one). 
  • Also see new post on how to get Nvidia/Compiz to work together nicely.


After using the above setup for a while, I've updated some things.
I found you can't really replicate the way the fonts look in OSX, so it's better to set your font configuration to using hinting (I am using medium hinting). This makes the fonts look crisper more like Windows. With this setting using a default of DejaVu Sans as your default Sans font in Chrome looks good. In fact most of the sans fonts that are installed by default look better with some hinting.
The trackpad mtrack driver works much better if you install it from source:
sudo apt-get build-dep xserver-xorg-input-mtrack

Download the source from https://github.com/BlueDragonX/xf86-input-mtrack/ .

cd xf86-input-mtrack/
automake -c --add-missing

I then just replaced the driver

sudo mv .libs/mtrack_drv.so /usr/lib/xorg/modules/input/

Original post:

I have a 2009 Macbook its model number 6,2. Running Ubuntu 12.04 Precise Pangolin.

The OS install is pretty straightforward. The instructions are here. Notes on those install instructions:

  • You have to burn a CD, booting off of USB never worked from me.
  • I used the specific install ISO for 64bit Mac computers. Available here.
  • The Ubuntu installer asks you to create an an extra parition for booting, in addition to the normal filesystem/swap parititons.
At the end you should end up with a working Ubuntu Install. But here are some tweaks to make the hardware work well.

Graphics card

The model I have has a NVidia 9400M graphics card which shares memory with system RAM. The Nouveau drivers as well as the NVidia driver version that is installed by default cause instability after a while resulting in lockups. I ended up installing the latest Linux driver from the NVidia website. I am using version 304.37. This worked well but I still had some X server crashes, while not as bad as complete lock ups are still annoying. I've disabled some options in my xorg.conf in the nvidia device section:
Option "IndirectMemoryAccess" "Off"
Option "NoFlip" "True"
Option "DynamicTwinView" "Off"
This seems to make my system more stable. I also added:
Option "RegistryDwords" "EnableBrightnessControl=1"
To fix the brightness controls.
If the Nouveau driver works for you I would stick to this.


By default the color profile of the screen is bluish, different from the warmer profile in OSX. To get the same color profile, boot OSX and save the default color profile to an ICC file. This can be done by using system preferences -> display -> color -> open profile -> save as. Then you can load this file in Ubuntu, I used the xcalib utility to do this, available from the apt repositories.
I found the fonts by default didn't look as good as on OSX, especially in the web browser using the Macbook laptop display. The best results I achieved was to use grayscale anti-antialiasing, except for font sizes 13 point and smaller which I set to use subpixel anti-aliasing. And to not use any hinting. The second thing was to set the default sans-serif font in the Chrome web browser to "Nimbus Sans L" this seems most like Helvetica/Arial used on the web alot. (See Update below.)
I configured the fonts using /etc/fonts/conf.d. Here is my listing of that directory:
10-no-sub-pixel.conf 10-unhinted.conf 11-lcd-filter-lcddefault.conf 20-fix-globaladvance.conf 20-unhint-small-vera.conf 30-subpixel-for-small.conf 30-urw-aliases.conf 40-nonlatin.conf 45-latin.conf 49-sansserif.conf 50-user.conf 51-local.conf 53-monospace-lcd-filter.conf 60-latin.conf 64-01-tlwg-kinnari.conf 64-02-tlwg-norasi.conf 64-11-tlwg-waree.conf 64-12-tlwg-loma.conf 64-13-tlwg-garuda.conf 64-14-tlwg-umpush.conf 64-21-tlwg-typo.conf 64-22-tlwg-typist.conf 64-23-tlwg-mono.conf 65-fonts-persian.conf 65-khmer.conf 65-nonlatin.conf 69-unifont.conf 70-force-bitmaps.conf 80-delicious.conf 89-tlwg-garuda-synthetic.conf 89-tlwg-kinnari-synthetic.conf 89-tlwg-loma-synthetic.conf 89-tlwg-umpush-synthetic.conf 89-tlwg-waree-synthetic.conf 90-fonts-nanum.conf 90-synthetic.conf 90-ttf-bengali-fonts.conf 90-ttf-devanagari-fonts.conf 90-ttf-gujarati-fonts.conf 90-ttf-kannada-fonts.conf 90-ttf-malayalam-fonts.conf 90-ttf-oriya-fonts.conf 90-ttf-punjabi-fonts.conf 90-ttf-tamil-fonts.conf 90-ttf-telugu-fonts.conf 99pdftoopvp.conf README
The only custom file in that directory is 30-subpixel-for-small.conf which contains:
    <match target="font">
        <test name="size" compare="less_eq">
        <edit name="rgba" mode="assign"><const>rgb</const></edit>
I also used the myunity utility ovailable from the repositories to configure the fonts using the GUI to match the fontconfig files. I just set the Hinting to none and Antialiasing to grayscale.


The default Xorg synaptics driver was not working that well, it was too sensitive and didn't handle multitouch well. I ended up removing the xserver-xorg-input-synaptics package and installing the xserver-xorg-input-mtrack using apt. 
This driver has a configuration file at /usr/share/X11/xorg.conf.d/50-mtrack.conf. 
I am still tweaking the options here, but the trackpad is ok to use now.

Day to day use

So due to some stupidity on my part my OSX partiton doesn't boot any more. So I am using my Ubuntu/Mac every day, and I think it's interface is nearly as good as OSX. That combined with IMHO a better underlying infrastructure in Linux ie system/network software, open file systems and better compatibility and user software that works for you, like being able to copy songs from your Ipod, makes the system on balance better than OSX/Mac.
more posts