Friday, May 11, 2012

Debug Ruby on Rails with Aptana Studio 3

1. Check if ruby-debug-ide is installed

$ gem list

2. If not installed, install ruby-debug-ide

$ gem install ruby-debug-ide

3. Open the project in Aptana Studio 3, App Explorer -> Gear icon's drop down menu -> Debug Server

debug rails with Aptana studio 3

4. Set a breakpoint in a file, e.g. index.html.erb
5. Open http://localhost:3000/<your path>/index.html in your browser
6. Aptana will ask you if open Debug perspective. Of cause. You can see the server stops at the break point.
201205112119.jpg

Wednesday, March 14, 2012

Rebuilding Code Sense and Syntax Highlighting on Xcode 4

Sometimes syntax highlighting does not work on Xcode 4. Syntax highlighting is an important feature to developers. But there is no "Rebuild Code Sense" menu on Xcode 4. We can do it with following steps:

1. Xcode menu: Window->Organizer

2. Go to Projects tab

3. Choose your project on the left panel.

4. Click "Delete…" button after the Derived Data on the right panel.

Xcode will start to rebuild code sense of your project.

Thursday, March 08, 2012

Diff and Merge Localizable.strings in git

The default code set of Localizable.strings is UTF-16. Actually I don't care what code set it is. But git/gitX/SourceTree does not recognize UTF-16 (Stupid!). They treat UTF-16 Localizable.strings as a binary file and reject to diff or merge. This is a very big problem if you work in a team.

Google says we can make git support UTF-16. I tried, but failed. I have to convert Localizable.strings into UTF-8. (Actually before converting, I have manually merged by myself.) Surprisingly, git/SourceTree still says it is a binary file and cannot diff. It's OK. Just commit. Git says it just because the history files are still UTF-16. If you make any new changes, git can diff and merge it. Great!

Thursday, February 16, 2012

Keyboard notification bug on iOS 5

When the soft keyboard appears, we need to re-arrange the UI controls. I move the control up a little bit in keyboardWillShow handler:

frame.origin.y -= CONSTANT;

control.frame = frame;

But there is an annoying bug (or behavior) about non-English language keyboard on iOS 5. If you are using English keyboard, you will receive keyboardWillShow notification once. It is good. But if you are using some language keyboard like Chinese, you will receive the same notification TWICE! That means the above code will move the control up twice.

Some non-English language keyboard has an additional line at the top, used to choose words. Sounds like that additional line causes this problem.

The solution is simple. Just use hard-coded positions. And the additional line on some non-English language keyboards may cover parts of your UI on iOS 5. You have to leave enough space for keyboards. If your textField requires English characters only, you can force the keyboard to show English:

textField.keyboardType = UIKeyboardTypeASCIICapable;

Tuesday, December 27, 2011

Scroll NSScrollView to Top

AppKit is old and is not as convenient as UIKit. But we have to use it on Mac app development.

"Scroll a scrollview to top" sounds easy, but actually it isn't. If you assign a documentView to a NSScrollView, you will see it scrolls to the bottom. (Very stupid!) The doc did not mention how to scroll to top. I found a way to control the vertical scroller. I can set the scroller to top, but the scrollView is still at bottom!

This post (http://stackoverflow.com/questions/4506391/nsscrollview-jumping-to-bottom-on-scroll) inspired me. I got the solution (of cause, I post my answer on stackoverflow too):

// Scroll the vertical scroller to top

if ([_scrollView hasVerticalScroller]) {

_scrollView.verticalScroller.floatValue = 0;

}

// Scroll the contentView to top

[_scrollView.contentView scrollToPoint:NSMakePoint(0, ((NSView*)_scrollView.documentView).frame.size.height - _scrollView.contentSize.height)];

Friday, December 09, 2011

Wrong info from proc_pidinfo

proc_pidinfo is a very useful function to get a Mac OS X process's info such as the size of resident memory, consumed CPU time.

However, sometimes, the returned info is not correct. For example, a little process's resident memory becomes 4GB. Apple does not provide any document about this function, and I did not see useful comments in the header files.

I am lucky enough to see code snippet in the Apple open source file: http://www.opensource.apple.com/source/lsof/lsof-28/lsof/dialects/darwin/libproc/dproc.c. When we call proc_pidinfo, we must check the returned value. If the returned value is not identical to the size of output data, the output data is wrong.

      nb = proc_pidinfo(pid, PROC_PIDTASKALLINFO, 0, &ti, sizeof(ti));
            if (nb <= 0) {
                if (errno == ESRCH)
                    continue;
                if (!Fwarn) {
                    (void) fprintf(stderr, "%s: PID %d information error: %s\n",
                        Pn, pid, strerror(errno));
                }
                continue;
            } else if (nb < sizeof(ti)) {
                (void) fprintf(stderr,
                    "%s: PID %d: proc_pidinfo(PROC_PIDTASKALLINFO);\n",
                    Pn, pid);
                (void) fprintf(stderr,
                    "      too few bytes; expected %ld, got %d\n",
                    sizeof(ti), nb);
                Exit(1);
            }
I checked the processes with correct info. They are all my processes (not system processes). Seems like my app runs in user mode and it does not have privileges to get info of system processes.