Preventing Flash Builder debugger timeouts in Firefox

Nov 13th, 2011 | Filed under Flash

If the debug session terminates unexpectedly when using the Flash Builder debugger to debug a Flash project in Firefox, this problem can be solved by going to about:config and changing dom.ipc.plugins.timeoutSecs from its default value to -1.

Customizing the background of an UINavigationBar

Jul 17th, 2011 | Filed under iOS

To customize the background image of the navigation bar, you can create a separate class extending UINavigationBar and override its drawRect method.

To do that, first create a new class named STNavigationBar with the following definition in the STNavigationBar.h file:

@interface STNavigationBar : UINavigationBar {
}

Then, implement the drawRect method in the STNavigationBar.m file:

@implementation STNavigationBar
 
- (void)drawRect:(CGRect)rect {
    UIImage *barImage = [UIImage imageNamed:@"STNavigationBar.png"];
    [barImage drawInRect:rect];
}
 
@end

After creating this class, you can now use it anywhere you need a navigation bar with this particular style. In Interface Builder, specify STNavigationBar instead of UINavigationBar under Custom Class > Class.


Selecting the background image based on the current device

To support both iPhone < 4 and the Retina Display, it would be best to create two images, one for each resolution. The resolutions at which the navigation bar is rendered are:

  • iPhone < 4: 320 x 44 px
  • Retina Display: 640 x 88 px

To detect this, you can inspect the screen’s scale factor.

@implementation STNavigationBar
 
- (void)drawRect:(CGRect)rect {
    UIImage *barImage;
    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] &&
        [[UIScreen mainScreen] scale] == 2) {
        barImage = [UIImage imageNamed:@"STNavigationBar88.png"];
    } else {
        barImage = [UIImage imageNamed:@"STNavigationBar44.png"];
    }
    [barImage drawInRect:rect];
}
 
@end

Determining CPU endianness at runtime

Jun 12th, 2011 | Filed under C, Programming

Since the short 1 is represented as 00 00 00 01 on big endian machines and 01 00 00 00 on little endian machines, it’s a rather straight forward matter to detect the endianness of a machine, by simply looking at how it stores a short.

#include <stdio.h>
 
int main() {
    unsigned short i = 1; // store a short
    char* p = (char*) &i; // convert the short into an array of bytes
 
    if (p[0] == 1) {
        // if the first byte is 01, then it's a little endian machine
        printf("Little endian\n");
    } else {
        // otherwise, it's a big endian machine
        printf("Big endian\n");
    }
 
    return 0;
}

Deleting a remote branch in git

May 31st, 2011 | Filed under Git

To delete a remote branch, run:

git push origin :branch