Wednesday, October 13, 2010

Debugging BAD_ACCESS

If BAD_ACCESS bothers you and you have no idea where it come from, try enabling NSZombies


Enabling NSZombies

The solution to overreleased objects are the zombies. When this feature is enabled, a dummy object (a zombie) is kept on the place of every released object, thus allowing to debug objects which were released already. Very easy to enable:

Double click your executable in the “Executables” in XCode
Open “Arguments” tab
In “Variables to be set in the environment” (that’s the list at the bottom, be careful which one you edit) click the “+” button and for name of the variable enter “NSZombieEnabled” and for value “YES”
Voila!

Now instead of wondering what’s going on and which exact object produced the problem, you’ll see exactly which class is the trouble maker, and you’ll debug it quite fast.


http://www.touch-code-magazine.com/how-to-debug-exc_bad_access/

Thursday, September 16, 2010

Realise that you cannot tap on the last button for UIActionSheet? No fear.

I have this problem and after google. change the following

[menu showInView:self.view];

to

[menu showInView:[[[UIApplication sharedApplication] windows] objectAtIndex:0]];

The main reason is the tabcontroller will block 65% of the bottom view. although you cant see it, it is there. All thanks to the following blog.


http://runmad.com/blog/2010/04/uitabbarcontroller-and-uiactionsheet-65-percent-less-hit-point/

Tuesday, August 31, 2010

How to get composite name from ABRecordRef

ABRecordRef *person = (ABRecordRef *)[allPeople objectAtIndex:i];
// Display Name
NSString *displayName = (NSString *)ABRecordCopyCompositeName(person);

Trim String in Object C

This is how to trim a string and remove whitespace and newlines:

NSString *trimmedString = [dirtyString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];


For other character sets, refer to
http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSCharacterSet_Class/Reference/Reference.html#//apple_ref/doc/uid/20000157-SW5.

Sunday, August 15, 2010

how to rename in Mac OS

This is a command based solution. Works for Leopard, Snow Leopard or anything with ZSH

duck% zsh
duck% autoload zmv
duck% zmv '*.jpg' '$f:s/2_/518_/'

Sunday, July 25, 2010

How to show alert for iOS?

This is how you can show an alert box in iPhone or iPad app.


In your code include the following:

UIAlertView *alert = [[UIAlertView alloc] init];
[alert setTitle:@"Confirm"];
[alert setMessage:@"Buy This?"];
[alert setDelegate:self];
[alert addButtonWithTitle:@"Yes"];
[alert addButtonWithTitle:@"No"];
[alert show];
[alert release];

Then implement this in the delegate, in this case, the controller which calls UIAlertView.

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
// Yes, do something
NSLog(@"Yes!");
}
else if (buttonIndex == 1)
{
// No
NSLog(@"No!");
}
}

how to list files in iOS

This is how you can list files in your iPhone apps.

NSFileManager *manager = [NSFileManager defaultManager];
NSArray *fileList = [manager directoryContentsAtPath:documentsDirectory];
for (NSString *s in fileList){
NSLog(s);
}

How to test if file exist in iPhone iOS

BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:somePath];

Friday, July 23, 2010

How to get Application Name with code

Below is how you can get the name of your application with code.

[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]

Wednesday, July 21, 2010

How to enable SQL debugging for Core Data in XCode

Right click on the project executable and click “Get Info.” Navigate to the Arguments tab and add the following argument: “-com.apple.CoreData.SQLDebug 1″.

When the project is running, you should see the sql used in the console.

Thanks to http://www.raywenderlich.com/934/core-data-tutorial-getting-started

Tuesday, March 30, 2010

Tuesday, March 16, 2010

How to access ext2 or ext3 file system from Mac OSX


I have always wanted to access my Ubuntu harddisk in my Leopard. For months, google has been telling me not possible but, today came as a surprise, you are able to do so by installing fuse. Fuse is a user space file system which allows system to read different type of file system provided the developers has followed the Fuse inferface. It is originated from Linux and it has been ported to Max OS. Man, I really like FOSS. For more infor in fuse, http://fuse.sourceforge.net/

So to start, 

1. go to http://code.google.com/p/macfuse/ and download the latest version

2. go to http://sourceforge.net/projects/fuse-ext2/ and download the latest version. You should be able to download dmg format under the "Files" type

3. Install macfuse first

4. Install fuse-ext2

5. Reboot and you should be able to read ext2/3 formated drive.

PS: Just a note, there is another ext application for Mac however, I tried and it does not work for me.

Sunday, February 21, 2010

How to install iPhone SDK 3.1.2 with xCode 3.1.4 on Mac OS X 10.5.5

After a clean install, I need to install the xCode with iPhone SDK again on Mac OS X 10.5.5. However, you should see an error telling you that it support 10.5.7 and above. To resolve this, you can do the following.

1. Edit the file /System/Library/CoreServices/SystemVersion.plist under superuser mode. I like to use vim

sudo vim /System/Library/CoreServices/SystemVersion.plist

The password should be your user password.

2. Change all the 10.5.5 to 10.5.7

3. Save and exit.

4. Start installing!

Problem with HFS+ Journal - Bad Journal Magic

I think i am just not suitable to use HFS+. I though Journal will auto recover faster and easier, in the end I am more problem. The whole thing started when My eeepc starts to hang/crash randomly especially after a major shift to the machine. I serious thing some parts is spoil or loose from the recent dismantle of the machine.

In short, after the recent crash which cause me to reinstall my Mac OS, I choose to use HFS+ Journal believing that it will recover easier. However, after it's first crash, I have this problem, Bad Journal Magic Number or something similar. Which means, it cannot read the first journal node. I have not found any solution to recover this but to make the device boot again, this is how you can turn off the journal bit.

1. Boot with Mac OS X dvd
2. Launch terminal
3. Run the following command
/System/Library/Filesystem/hfs.fs/hfs.util -N /dev/disk1s1
4. Close Terminal
5. Run Disk Uitility
6. Select the correct partition and run "Repair Disk"
7. After it shows, partition repaired, run "Verify Disk" again to verify

Good luck! Anyway, I think I cannot get along with HFS+.

How to enable Bookmark Sync in Mac

Download the latest Google Chrome from here. The version should be 5.0.307.9 beta and above.

Initially I wanted to list down how to enable it from 4.0++ beta but after upgrading I realize it is available widely, so this simple example. Enjoy!

Saturday, February 20, 2010

New Layout!

I have just change a new template. At least this looks more presentable for quotes, maybe i should try to do my own customization on the template when I have time. :)

Restoring MBR on Linux and Mac OS on eeePC

Bad things happens all at one go. My Mac OS crash on me and I am not able to recover from the B-Node problem.

Recover Grub2 for Ubuntu Karmic
--------------------------------

1. mount the harddisk consist of Ubuntu Karmic by clicking "Places -> XXGB File System"

2. open terminal and do a tail

mount | tail -1

3. You should see something similar

/dev/sda2 on /media/0d104aff-ec8c-44c8-b811-92b993823444 type ext4 (rw,nosuid,nodev,uhelper=devkit)

4. Check the boot partition by

ls /media/0d104aff-ec8c-44c8-b811-92b993823444/boot

You should see something similar

config-2.6.18-3-686 initrd.img-2.6.18-3-686.bak System.map-2.6.18-3-686
grub lost+found vmlinuz-2.6.18-3-686
initrd.img-2.6.18-3-686 memtest86+.bin

If this is wrong, then your partition is wrong.

5. Now everything is correct and is time to recover. Run the following to install GRUB into the correct directory and drive name.

sudo grub-install --root-directory=/media/0d104aff-ec8c-44c8-b811-92b993823444 /dev/sda

If you get BIOS warnings try:


sudo grub-install --root-directory=/media/0d104aff-ec8c-44c8-b811-92b993823444 /dev/sda --recheck

6. If all goes well, you should see the following.

Installation finished. No error reported.
This is the contents of the device map /boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'.

(hd0) /dev/sda

More information from below:

https://help.ubuntu.com/community/RecoveringUbuntuAfterInstallingWindows

Recover Boot Loader for Mac OS
--------------------------------

Give up. After googling for sometime, I cannot find any solution, might as well reinstall, since i have reinstall from the B-Node problem. Time is important now as I am rushing to complete my development.

Wednesday, February 17, 2010

Support Multi-Touch for eeePC in Ubuntu Karmic

I have upgraded my eeePC to Ubuntu Karmic for quite some time and I miss my muti-touch, especially when I have been using Mac OS recently. Thus my quest to enable it begins. After googling around, I realized that it can be very simple.

To enable 2 finger scrolling, do the following.

Activate at "System -> Preferences -> Mouse -> Touchpad -> Scrolling -> Two-finger scrolling"

According to https://wiki.ubuntu.com/HardwareSupport/Machines/Netbooks#Asus Eee PC 1005HA , you need to install a script from the following,

http://blog.twinapex.fi/2009/10/11/setting-up-multi-touch-scrolling-for-ubuntu-9-10-karmic-koala-linux-on-asus-eee-1005ha-netbook/

however, my works when I have enable the 2 finger scrolling. Wonder what does that script do.

Wednesday, January 27, 2010

eeepc refuse to boot

One day, my eeepc refuse to boot when I was playing with MacOS installation. It keep stuck @ the blank screen. After sending to the service center, they revived my eeepc. few hours later, i killed it again.

So instead of sending it back again, I decided to solve it myself. After googling and also from the TIPS from the engineers, I know I need to reset something but duno what. After dismantle the whole machine and also google around, the below is the steps to recover.

1. Take out battery and power cable
2. Press power button for 15-20s (different source got different timing, I guess the longer the better)
3. Locate the CMOS "button". It is a two trangle shape, just below the RAM, you need to take out the RAM cover and the RAM itself. You should see two triangle side by side.
4. Short the CMOS with a paper clip.

Put everything back and restart. It should work.

Tuesday, January 5, 2010

It is possible to recover data from brick iPhone!

My iPhone brick after installing Tethering from Sinful and I have not back up for a very long. Sad to say, there is no other way except to RESTORE! :(

But, to recover the file, there is always Linux to the rescue!


1. Restore iPhone using iTune
2. Use blackra1n to jailbreak
3. Install Cydia in the iPhone
4. After launch Cydia, you will need to wait a while for it to be ready.
5. When done, install OpenSSH, BSD Subsystem and Terminal
6. Launch Terminal in the iPhone
7. change to root first,
duck:~ mobile$ su
duck:/ root#
8. Make sure you have a SSH server running on your desktop
9. Execute DD from the iPhone and make a disk image over
duck:/ root# dd if=/dev/disk0 | ssh username@mydesktop-ip 'dd of=iphone-dump.img'
10.Next use software such as photorec, scalpel, foremost

[Update]

1. Due to my iPhone wifi problem, I have access the iPhone through USB tethering on a Windows machine. Google around for the software. Once the USB tethering is setup, you can access to the iPhone from your Linux desktop.

ssh root@192.168.1.1 'dd if=/dev/disk0' | dd of=iphone.img

2. After DD out the files, I realize I am DD out the whole disk which I am not able to mount as one drive, however data can still be recoverable with that image. There are two partitions in the iPhone. The best way is to DD out separately and also as a whole, cos you never know how they are repartition after restored, which comes to the next point.

3. SSD is written randomly, unlike using normal harddisk, after one large file(s) is deleted, iPhone will not write from the first free space. It will write as random. What does this means? It means your old deleted data may be overwritten during restoration. This happens to me as I am not able to fully recovered my photos. However, I believe some of the header are gone but we still can recover from the remaining data, provided I know how to reconstruct them. More research is needed.