Monday, December 28, 2009

OSX on a PC

My kind boss bought me an iPod Touch as an end of year gift, and naturally I wanted to write software for it, but (there is always a but), you need a Mac to write software for the iPod/iPhone, which sucks. There is two solutions to this problem, one is to buy a Mac, which I don't have the cash for, or get OSX running on my PC.

Due to financial reasons the latter was the only option, so I obtained an iAtkos install CD for Leopard. Following a few YouTube videos I did a base install, only to discover that my PC is not very mac friendly.

My PC has the following hardware:

  • AMD Phenom II X2 550 @ 3.1Ghz

  • ASUS M2N32-SLI Deluxe Motherboard

  • PCIe nVidia GeForce 8600GT

  • 2GB DDR2 Ram



After a day of messing around with install options it became aparrent that things just would not work on this motherboard until I discovered an obscure post of a forum somewhere where someone just moved the video card into the 2nd PCIe slot on the board. I initially dismissed it, but in the end, out of desperation, I tried it, and it fixed it!.

For others that have the following symptoms, try moving the video card.


  • Boots to a blue screen, then goes black

  • Mouse is inverted (up is down, left is right)

  • Mouse is VERY jerky



Once that was sorted out, I soon discovered that the on-board ethernet would not function, being a nForce chipset, and after reading numerous posts, there was only a partial working kext for it that did not support SMP, and would crash under heavy load. Again, I was going to give up, but found another obscure post referencing an updated ethernet driver, which I tried, and the system became rock solid with both cores enabled.

I do not use the onboard audio, I use a SBLive, so I installed the Kx driver for Mac OSX and it started to work instantly!

The last thing to get working was the nForce SATA, and PATA. The iAtkos came with a driver that worked, but not too great. I found an updated driver called SuperNForceATA which was compiled for Snow Leopard (10.6), and would not load on my sytem, it did however come with the source. So I downloaded xCode and compiled it for 10.5, installed it, and off it went.

I now have a FULLY functional Mac OSX install on a PC

I have decided to start a page dedicated to WORKING osx kexts in the next few weeks. Enough for now, have to go and help out the wife :)

Monday, December 7, 2009

The ultimate media storage solution

I am the kind of person that has trouble making decisions in little things, and I am also the kind of person that hates a messy file system, so when I ran out of room on my media PC, I had to add another HDD to the machine to store more data, which presented a problem for me.

You see, I already had two other disks in the machine for storage, a 500GB and a 1TB disk, which were already fairly well sorted with all of my movies on the 500GB, and TV Shows on the 1TB. But adding a third disk would mean that I would have to split my TV Shows onto the third disk making it harder to manage since I would have to hunt for the show I would want to watch between the two disks.

The only solution I knew of to this problem was a RAID1 (stripe) array, which would combine all three disks into one huge disk... but there are issues with this, the partitions could only be as large as the smallest disk (500GB), and if one partition/disk is lost, all the data is lost.

I was just about to give up when I remembered something I read somewhere a while ago called LVM, or Logical Volume Management. I was investigating it for server backup since I manage multiple servers at work with 99.99% uptime requirements. LVM is very promising for that too, but it was perfect for this as well.

You see, LVM is a layer of abstraction on top of the physical hard disks, sort of like Virtual Memory, where the operating system and software see 2GB of RAM available, but you only have 1GB of physical ram, and a 1GB swap partition on your HDD.

I was able to combine all three disks into one huge volume, and it was so easy to do too. Here is the df output of my media machine now (note, as of writing, 2TB is the largest HDD available on the market).

# df -H
Filesystem Size Used Avail Use% Mounted on
/dev/hda1 39G 13G 27G 32% /
tmpfs 1.1G 0 1.1G 0% /lib/init/rw
udev 11M 762k 9.8M 8% /dev
tmpfs 1.1G 4.1k 1.1G 1% /dev/shm
none 1.1G 4.1k 1.1G 1% /dev/shm
/dev/mapper/skx--vol-BulkData
2.5T 1.2T 1.3T 49% /media/BulkData


To set this up is very simple... instead of re-writing a whole bunch of info though, I will point you to an excellent beginners guide to setting this up on a machine that has already been installed and configured.

I highly recommend LVM for a media machine, it is so nice to have all my data in one location, and not have to think about where to put things, or where I out them when I want to watch them.

Tuesday, December 1, 2009

Flex Array vs ArrayCollection

I have been teaching myself flex for the past few years now and I finally have a firm grasp on how arrays should be used, and the difference between an ArrayCollection and an array.

People like to just assume that if your using Flex that you should just know all about event driven programming, well, I didn't, I came from procedural programming, and still today prefer it.

Well, for those that want to know whats so special about an ArrayCollection, here it is...

A basic Array (not ArrayCollection) is a primitive object, it has no special abilities whatsoever, it is just an array, where on the other hand, an ArrayCollection is an EventDispatcher and also has alot of nice extras that come in handy.

If you are trying to make a propery to be bound to, use an ArrayCollection, and don't be lazy, perform updates to it, do not "removeAll", and then re-add items to it, you will get all sorts of UI glitches if you do.

When items are added/removed from an array collection a "CollectionChangeEvent" is dispatched, this can be VERY handy. For example, drag and drop can be a nightmare to get right between controls, and so many people over complicate the whole mess.

If you listen for the CollectionChangeEvent and just set the "dragEnable", "dragMoveEnable" and "dropEnable" properties of your two controls, you will recieve "ADD" and "REMOVE" events when items are dragged into and out of the ArrayCollection.

If you implement these add/remove events you can bind the collections to user objects without a single line of code in the front end.

Anyway, enough theory, here is some example code:

*Note, this is psuedo code

public class MyClass {
private var _dp1: ArrayCollection = new ArrayCollection();
private var _dp2: ArrayCollection = new ArrayCollection();

public function myClass(Items: Array): void {
for each(var o: Object in Items) {
_dp1.addItem(o);
}
_dp1.addEventListener(CollectionEvent.COLLECTION_CHANGE, e_collectionChange);
}

private function e_collectionChange(event: CollectionChangeEvent): void {
var o: Object;
switch(event.kind) {
case CollectionChangeEventKind.ADD:
for each(o in event.items) {
if (_dp2.contains(o))
_dp2.removeItemAt(_dp2.getItemIndex(o));
}
break;

case CollectionChangeEventKind.REMOVE:
for each(o in event.items) {
if (!_dp2.contains(o))
_dp2.addItem(o);
}
break;
}

[Bindable]
public function get dataProvider(): ArrayCollection {
return _dp1;
}

[Bindable]
public function get removedItems(): ArrayCollection {
return _dp2;
}
}
}

This class will automatically maintain a a 2nd data provider "removedItems" as the dataProvider has its items removed/added, not very useful, but a good example. It could be bound to two lists with drag/drop properties set. Usage is simple:

<mx:Application creationComplete="init()">
<mx:Script>
private var myclass: MyClass;
private function init(): void {
myclass = new MyClass([1, 2, 3, 4]);
}
</mx:Script>
<mx:VBox>
<mx:Label label="Drag Between">
<mx:HBox>
<mx:List dataProvider="{myClass.dataProvider}" dragEnabled="true" dropEnabled="true" dragMoveEnabled="true"/>
<mx:List dragEnabled="true" dropEnabled="true" dragMoveEnabled="true"/>
</mx:HBox>
<mx:Label label="Removed Items">
<mx:List dataProvider="{myClass.removedItems}"/>
</mx:VBox>
</mx:Application>


In my next post I will describe how to use this to create a class that tracks changes for submission to a back end server, using a mix of both Arrays and ArrayCollections.

Blog

Well, here is my first blog.


This will be used for documenting issues in programming languages as well as other random rambles and postings.