Just in case I forget,

1) Partition sdcard into 2 partition, refit (~20mb) and ubuntu partition
2) Install ubuntu onto the ubuntu partition using vmware
*) might want to configure ubuntu from vmware. like on verbose boot screen so would not stuck at black screen for very long (boot from sd card can take time)
3) Put refit efi folder into refit partition, and run enable.sh
4) During bootup hold option and select Refit. Got 2 partition appear, but not sure whats the difference between the 2

Pain in the ass:
Alternate install requires you to press alt+f1 to show command prompt. like omg bbq >< wasted so much time on that

I’ve been wondering how to apply a convolution matrix to an image; most tutorials on the web simply stated apply the convolution matrix to the individual points of the image, but what exactly constitutes a point? Is it the value of the pixel (32bit), or the individual rgba channels (8 bits each) of the image?

Turns out its the latter. Apply the convolution matrix to each channel of the image and you’ll get the filtered image. Don’t forget to clamp down the values to 0 and 255 or you’ll get a seriously colour messed up image.

Guess I should have realised but image processing has a seriously steep learning curve.

In Java, it is tempting to think that a private attribute cannot be modified by any method outside of the class it is defined in. After all, this is the purpose of the visibility modifiers. However, this is only always true for immutable object attribute. With a mutable object attribute, it is possible to modify the content of the attribute outside of its class.

Consider the following code:

class Trainee {
    private String name;
    private Module module;

    public Trainee(String name, int marks) {
        this.name = name;
        this.module = new Module(marks);
    }
    public Module getModule() {
        return this.module;
    }
    public String toString() {
        return this.name + " scored " + this.module.getMarks();
    }
}

class Module {
    private int marks;

    public Module(int marks) {
        setMarks(marks);
    }
    public void setMarks(int marks) {
        this.marks = marks;
    }
    public int getMarks() {
        return this.marks;
    }
}

public class TraineeDriver {
    public static void main(String argv[]) {
        Trainee trainee = new Trainee("Sam", 40);
        System.out.println(trainee);

        Module moduleOutside = trainee.getModule();
        moduleOutside.setMarks(100);
        System.out.println(trainee);
    }
}

Will produce the output

Sam scored 40
Sam scored 100

We have successfully modified the module attribute, even though the visibility of module is private!

Wait what?

So how did we manage to modify the module marks? I draw your attention to the following snippet from the above code:

public Module getModule() {
    return this.module;
}

Recall that all non-primitive (not int, char, boolean, float etc) “variables” in Java are essentially pointers to objects (aka object references). This is the reason why we cannot compare two Strings with the == operator. (Doing so compares whether the two Strings refer to the same object in memory, and not whether the two Strings are lexicographically equal)

Thus, the getModule method above returns the object reference to the module attribute in the object. With this object reference, we can perform all the public methods of the object. In particular, we can call the setMarks method to modify the marks. And doing so would definitely affect the module attribute in the trainee object, as they are referring to the same Module object!

class Trainee {
    private Module module;
    public Trainee(String name, int marks) {
        // let us assume this.module holds the address 0001
        this.module = new Module(marks);
    }
    public Module getModule() {
        // return address 0001
        return this.module;
    }
}

public class TraineeDriver {
    public static void main(String argv[]) {
        // moduleOutside holds address 0001!
        Module moduleOutside = trainee.getModule();

        // We are modifying the object at memory address 0001!
        moduleOutside.setMarks(100);
    }
}

Okay, so technically, we did not modify the module attribute in the trainee object. The module attribute in the trainee object still holds the address 0001. But since the Module class is a mutable class, we are able to modify the content of its object after creation, as long as we have the address of the object. This, however, is probably not the intended outcome of the programmer. The programmer had expected that the method caller would receive a copy of the object, not the object reference!

Mutable v.s. Immutable

So what are mutable and immutable class? Immutable class means that the content of the object cannot be modified after its creation, and the opposite holds true for mutable object.

For example, consider the following snippet:

class MutableMarks {
    private int marks;
    public MutableMarks(int marks) {
        setMarks(marks);
    }
    
    // the following method changes the private attribute marks
    public void setMarks(int marks) {
        this.marks = marks;
    }
}
class ImmutableMarks {
    private double marks;
    public ImmutableMarks(double marks) {
        this.marks = marks;
    }
}

The difference between MutableMarks and ImmutableMarks is that MutableMarks has a mutator, setMarks, that allows its user to modify one of its attributes. Examples of immutable classes in Java are String class and Integer class. Examples of mutable classes are the Date class and Stringbuilder class.

We can see that immutable objects would not suffer from this issue.

Workarounds

Naturally, as this behavior is most likely not intended, we would need to modify our program to ensure correct outcome. The first and most obvious solution would be to simply make our Marks class immutable. In fact, it is a good practice to design classes that are immutable, as being immutable immediately brings about a whole host of benefits.

However, if we are unable to modify the nature of the class (say we want to have a Date attribute, which is a mutable), there is another solution, known as defensive copying. The idea is simple; instead of returning the object reference, we simply return a copy of a object with the same content.

    public Module getModule() {
        int marks = this.module.getMarks();
        Module copyModule = new Module(marks);
        return copyModule;

        // or more simply:
        return new Module( this.module.getMarks() );
    }

By the doing the above, we can ensure that the module attribute in the object remains unchanged.

Sleep deprivation

January 21, 2011

Spent a lovely day today. Attempted to shop, but we didn’t manage to get anything. Mainly is because we have spent a lot of time travelling, cause I am a damn zai underpaid tutor who cares about his student. We alighted from the bus stop too early, and took a leisure walk back. In short, it was an awesome day.

You, my friend however, has just cause her to act irrationally, and to be deprived of precious sleep. Please, go away and never come back. And stop ruining our day. Asshole.

December 3, 2010

Wow. Seriously. What the fuck. I normally don’t get angry over, well anything, but I feel my temper rising.

Of all people, you were the last I thought who would not only judge me, and be so utterly blunt about it.

You’ll say because we’re close, you’d want to be blunt. But that’s not an excuse to not fucking spare a thought on how others would feel when you blurt it out like that.

Perhaps it hurts more cause you are so close to me. But fuck man.

Well hopefully you’re not one of the three person reading this blog, cause I don’t intend for you to see it. I’m just angry and need a place to vent.

And hello, my three “readers”, whoever you are.

Stop Sleeping

November 11, 2010

Finals are incoming, yet I have this overwhelming desire of giving up.

I can’t sit still, I can’t study, Im in such a mess.

And I keep sleeping. And keep having weird dreams. In a way its good, dreaming makes you feel that you’re still alive.

But god damned finals.

Limping

September 15, 2010

Crap it seems like i may have torn my ligaments from ahm. And now I’m walking with this ridiculous limp, and it hurts like hell whenever I’m climbing up and down the staircase.

Most probably would be going down to UHC tomorrow to get a proper diagnosis. I hate the feeling of being injured. To add insult to injury (erm. pun?), I clocked an abysmal timing for the stupid run. Damn.

Have been doing some really stupid things lately. Must be the studying stress. Urgh. Soedar, stop doing stupid things, and start working!!

Oh man it hurts so bad :/

Run

August 7, 2010

左脚,右脚,左脚,右脚。。。

没想到自己会这样说,但近期,我爱上了跑步。

当你跨出双腿,一步一步的在繁忙的行人道跑时,时间似乎停留了。藏在心里的所有烦恼,所有顾虑,所有的未知数,都显得不怎么了。满脑袋所想的只是,

左脚,右脚,左脚,右脚。。。

跑完了该跑的距离后,汗流浃背,肌肉酸痛,却感觉很舒服,好像心灵从肉体解脱了。但,想了想,从跑步得来的快感和开心,也不只是暂时的。跑完,流了一身汗后,问题并没有奇迹般的消失和解决。

无常。人生的所有美满都是无常的。你的开心毕竟会成为不快乐。这是自然的定律,你和我和他都改变不了。我们又为何一直在追寻呢?跑阿跑,又想得到些什么呢,达到什么目的呢?我们,又为何在生命的长跑上,不停的在,

左脚,右脚,左脚,右脚呢?

Keys

August 4, 2010

今天,我们的那3把钥匙从我的钥匙扣掉出来了。不知为何,看着钥匙,心又一阵一阵的痛了起来。

虽然手上有那钥匙,但想了很久,却又记不起那锁头再哪了。但仔细的想了想,锁头在哪也不再重要了。

很多时候,答案总在我们手上,只不过在脑袋的问题变了。我们的要求变了,我们能给的也不足够了。人,总会受到环境朋友的影响,耳濡目染,不知不觉的改变。我们,说起来,也不只是两个普普通通的人。

钥匙再也不能开起心中的锁头了。

我以为我放下了,但看着手上的那3把钥匙,为何心还是一阵一阵的痛呢?

Cakes

July 14, 2010

I have given up. I am tired. I am a failure.

I have lost the passion, the desire, the fire.

Isn’t it funny, the one thing that you fight so hard for, suddenly doesn’t matter so much when you obtain it?

And isn’t it funny when you look back, you realized that all along, the cake is a lie?

Hope has always been the driving force of our species. The belief that somehow, against all odds, we can overcome and triumph.

Yet we somehow get blinded by hope. So much so that we remain oblivious to the one, simple truth.

It is not possible.

You’d think the truth will set you free. But really, all it does is trap you in.

Follow

Get every new post delivered to your Inbox.