Remoting to Xcode

This one took me an embarrassing amount of time to figure out.

Turns out when remoting from Windows to OSX the control key doesn’t get sent quite right.

When following most Xcode tutorial on hooking up IB objects with code involves a control + drag. This does not work when one remotes from Windows.

Instead the alternatives is to go to the Connections Inspector view on the right tabs, and drag and connect from there.

Tagged ,

Continued Fraction

After a 6 month break, I’m back at project Euler again.

One of the new problems: continued fraction calculation, I find it really odd that there’s no a lot of good source on a step by step algorithm to calculate it. So I’m just going to write it here, in python.

#calculate the sqrt of a number as a series of continued fraction co-efficient
num = 22
sqrt = Decimal(num).sqrt()
if math.ceil(sqrt) != math.floor(sqrt) : #wish I know a better way to check this
    while count < 100 : # wirte out the first 100
        count = count + 1
        sqrt = Decimal(1) / (sqrt - Decimal(math.floor(sqrt)));
        print (sqrt)

Also learning python, which is pretty fun.

Windows 8 app dev challenge

Microsoft is having another one of their developer app challenges, this one is directed at Windows 8 platform.

The prize this time is a Asus Windows 8 RT tablet, so I decided to throw my hat in the ring and give it a go.

Similar to last time the condition is simply to be the first 50 developer to finish 4 apps and publish them.

Unfortunately this type of challenges doesn’t give the developers any incentives to produce worthwhile app, the challenge is merely to see how fast one can churn out working software that fits the minimum functionality requirement to be an app.

I managed to be one of the 50 lucky one to finish the challenge on time, with a mixture of new apps and windows 7 phone ported app. I have to admit, the tablet is quite fun to play with.

The other impact of the competition is that now, I am registered with the Windows 8 app market place, I’ve got Windows 8 installed on my desktop, and Visual studio all set up to go. It is awfully tempting to write more apps now.

Starting my CFA Level 1 exam prep

This year I’ve decided to learn some new things.

CFA certification have always been something of interest to me, I have many colleagues working on the certification and I have always wondered if I would go down this path someday.

So after some egging on from a friend, I decided to go all in and registered myself for the Level 1 exam in June 2013.

After going through about 20% of the materials I’ve noticed something unexpected, most of the materials are applied mathematics. It was a pleasant surprise that made me feel better about my chances of passing the exam.

Tagged

Double check locking in Java

We all know the double check locking bug in Java right?

Noticed this issue in one of our static singleton constructors.

public static FXRateService getInstance() {
        if (fxRateService == null) {
		synchronized(FXRateService.class) {
			if (fxRateService == null) {
				fxRateService = new FXRateService();
			}
		}
	}	
	return fxRateService;
}

This is a particular problem, if getInstance() is accessed by two threads, there is a chance that the FXRateService returned will be uninitialised. One of the known solution would be simple to create the service eagerly, via a static declaration statement.

My boss however, from a .net background came up with another solution involving adding an additional boolean to signal the thread.

private static boolean ready = false;
public static FXRateService getInstance() {
        if (!ready) {
		synchronized(FXRateService.class) {
			if (!ready) {
				fxRateService = new FXRateService();
				ready = true;
			}
		}
	}	
	return fxRateService;
}

He argues that this way, the 2nd thread will always wait until the boolean becomes true before proceeding to the synchronized code. This seems to make sense at first glance, however due to the way Java Memory model works, it is still not correct.

Though the synchronized block guarantees only one thread will enter the block at one time, the order of execution can still be reordered by the compiler depending on the implementation of the JVM. It is entirely possible for ready == true before fxRateService is properly initialised.

Tagged ,

Subtle equals bug in Java

The findbugs fairy discovered a little issue in my projects.

Bug: com.bfm.appl.blimp.marketdata.FXPricingSecurity overrides equals in PricingSecurity and may not be symmetric
Patternid: EQ_OVERRIDING_EQUALS_NOT_SYMMETRIC, type: Eq, category: CORRECTNESS

This class defines an equals method that overrides an equals method in a superclass. Both equals methods methods use instanceof in the determination of whether two objects are equal. This is fraught with peril, since it is important that the equals method is symmetrical (in other words, a.equals(b) == b.equals(a)). If B is a subtype of A, and A’s equals method checks that the argument is an instanceof A, and B’s equals method checks that the argument is an instanceof B, it is quite likely that the equivalence relation defined by these methods is not symmetric.

Clear as mud? Let’s have a look at an example:

Continue reading

Tagged ,

Jacob and Excel

I’ve recently have to do some Excel integration with Java.

It was a very interesting challenge, I had to play around with COM and Dispatch stuff, things I have never touched before from a pure Java world.

After some investigation with the different libraries available, I’ve decided to try it Jacob. One of my requirements was to be able to read the data from Excel’s spreadsheet in memory, these data could have been altered constantly from external sources without been saved to to file system.

Using Jacob I was able to read all the workbook’s title, worksheets within the workbook, and the cells and their data all in memory. Basically anything functions from the Visual Basic editor within Excel was available from the Jacob’s API.

Continue reading

Tagged , ,

Dice Roller hit 1.1

New features added:

  • Now a modifier can be added to each dice type. This is particularly good for table top RPGs.
  • A total counter for the sum of all dice rolls.

Get the new version at: Windows Market Place.

Tagged

I won again, apparently.

After submitting my four new windows phone 7 applications.

I’ve gotten confirmation from Dave Glover of Microsoft that I’ve won the 2012 Nokia phone challenge.

Now to think of what to do with the 2nd phone, once I receive it.

The other exciting news is that the apps I’ve submitted have started to generate revenue for me on the side as well.

My first dip into the world of commercial app development is very exciting!

Tagged ,

Nokia Microsoft phone app challenge 2012

Just got myself involved in the next wp7 dev challenge. Need to think of a few ideas for my next suite of apps.

Tagged ,