Checking if your app uses UUID

After May 1st, apple will be rejecting apps with uuid in the codebase.  If you are looking for a way to ensure that you are not using uuid in your code base, click on your break points tab and setup this link in the symbolic link breakpoint text.  This is super helpful if you are using third party extensions and cannot directly search the code base: eg. AdColoney.

GIT: Reverting to a previous version

I had a rough time in google finding a simple way to revert. Panic doesn’t seem to help. If you manage a team, this will save you many times. ANYWAY, to revert to a preview GIT version:

git reset 01742d7c04c8889f73b071a3dfc54e0ff76572cf
git reset –soft HEAD@{1}
git commit –message=’Reverting to 01742d7c04c8889f73b071a3dfc54e0ff76572cf’
git push
git reset –hard
git status

And now your company can move on…..

Objective-C using Sha1

In a recent project I was using sha1 to hash the mac address. In an interesting note: CC_SHA1_DIGEST_LENGTH is larger than CC_MD5_DIGEST_LENGTH.


+ (NSString *)sha1MAC:(BOOL)uppercase colons:(BOOL)colons {
    NSString *result = nil;
	NSString *useMac=nil;
	char* macAddressString= (char*)malloc(18);
	NSString *macAddressRaw= [[NSString alloc] initWithCString:getMacAddress(macAddressString,"en0") encoding:NSMacOSRomanStringEncoding];
    if(uppercase && !colons)
    {
		useMac= [[macAddressRaw uppercaseString] stringByReplacingOccurrencesOfString:@":" withString:@""];
    }
    else if ( uppercase && colons )
    {
		useMac= [macAddressRaw uppercaseString];
    }
    else if ( !uppercase && !colons )
    {
		useMac= [[macAddressRaw lowercaseString] stringByReplacingOccurrencesOfString:@":" withString:@""];
    }
    else if ( !uppercase && colons )
    {
		useMac= [macAddressRaw lowercaseString];
    }
	free(macAddressString);
	macAddressString = NULL;

    if(useMac) {
        unsigned char digest[CC_SHA1_DIGEST_LENGTH];
        NSData *data = [useMac dataUsingEncoding:NSASCIIStringEncoding];
        CC_SHA1([data bytes], [data length], digest);
        result = [NSString stringWithFormat: @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
				  digest[0], digest[1],
				  digest[2], digest[3],
				  digest[4], digest[5],
				  digest[6], digest[7],
				  digest[8], digest[9],
				  digest[10], digest[11],
				  digest[12], digest[13],
				  digest[14], digest[15],
				  digest[16], digest[17],
				  digest[18], digest[19]
                  ];
        result = [result uppercaseString];
    }
	[macAddressRaw release];
    return result;
}

Using php to detect mysql replication lag

require_once("/var/www/lib/functions.php");

function check_errors($host, $user, $pass)
{
	$errors = '';
	echo "\nChecking: ". $host. " " . $user. " " . $pass."\n";
	$link = mysql_connect($host,$user,$pass);
	$res = mysql_query("SHOW SLAVE STATUS", $link);
	$row = mysql_fetch_assoc($res);

	if($row['Slave_IO_Running'] == 'No') {
		$errors .= "Slave IO not running on $host\n";
	}

	if($row['Slave_SQL_Running'] == 'No') {
		$errors .= "Slave SQL not running on $host\n";
	}

	if($row['Seconds_Behind_Master'] == 'NULL' || intval($row['Seconds_Behind_Master']) > 300 ) {
		$errors .= "Seconds FAR BEHIND, SQL not running on $host\n";
	}

	if ($errors != '' )
	{
		$errors .= "Error number: {$row['Last_SQL_Errno']}\n";
		$errors .= "Error message: {$row['Last_SQL_Error']}\n";
		$errors .= "Seconds_Behind_Master: {$row['Seconds_Behind_Master']}\n";
		$errors .= "Seconds_Behind_Master: {$row['Master_Host']}\n\n";
	}

	mysql_close($link);
	return $errors;
}

$errors = check_errors(DB_HOST_SLAVE_4, DB_USERNAME_SLAVE_4, DB_PASSWORD_SLAVE_4);
$errors .= check_errors(DB_HOST_SLAVE_3, DB_USERNAME_SLAVE_3, DB_PASSWORD_SLAVE_3); 

if ($errors)
{
}

Installing git on Linux [with missing python / zlib/ MakeMaker]

wget http://git-core.googlecode.com/files/git-1.7.10.1.tar.gz
gunzip git-1.7.10.1.tar.gz
tar -xvf git-1.7.10.1.tar
cd git-1.7.10.1
yum install curl-devel expat-devel gettext-devel
yum install openssl-devel zlib-devel
yum install perl-ExtUtils-MakeMaker
yum install python-devel
make prefix=/usr/local all
make prefix=/usr/local install

Pushing code on multiple machines with git

I have converted to git after many good years with svn. Lately I have done more ops type work. I recently needed to push with git with quite a few servers. One quick way is in bash; see below. The machines list is literally just a file of machine name hosts. The /root/push/server path is where my git repro is at.

#!/bin/bash
cd /root/push/server
git pull
cd /root/push/
for i in `cat machine_list`
do
        echo "Syncing to: $i"
        rsync --exclude=.log -O  -vCr -e "ssh -i mykey.pem"  /root/push/server/www/  $i:/var/www/
done

Detect ipad with standard CSS

It is possible to detect ipad users and simply over ride their css properties. Most of the examples from the internet tubes didn’t seem to work. These did:

.ui-page {
	min-height: 480px;
}

@media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) {

	.ui-page {
		min-height: 1024px !important;
	}
}

@media only screen and (min-device-width: 961px) and (max-device-width: 2048px) and (orientation:portrait) {
/** Ipad3 ***/
	.ui-page {
		min-height: 2048px !important;
	}
}

Loading files locally from a iOS webview

Ran into this issue yesterday. I am using a webView to develop a prototype in HTML5. The problem is that my webView accesses an external file index.html. If you try and file the standard file:// protocol you will get strange security issues and the files wont load. The solution is below, basically we had to use myapp:// protocol which is defined by the iOS app.

#---- Place this by your webview

[NSURLProtocol registerClass:[NSURLProtocolCustom class]];

#---- "NSURLProtocolCustom.h"

@interface NSURLProtocolCustom : NSURLProtocol
@end

#---- "NSURLProtocolCustom.m"

#import "NSURLProtocolCustom.h"

@implementation NSURLProtocolCustom

+ (BOOL)canInitWithRequest:(NSURLRequest*)theRequest
{
    if ([theRequest.URL.scheme caseInsensitiveCompare:@"myapp"] == NSOrderedSame) {
        return YES;
    }
    return NO;
}

+ (NSURLRequest*)canonicalRequestForRequest:(NSURLRequest*)theRequest
{
    return theRequest;
}

- (void)startLoading
{
    NSURLResponse *response = [[NSURLResponse alloc] initWithURL:self.request.URL
                                                        MIMEType:@"image/png"
                                           expectedContentLength:-1
                                                textEncodingName:nil];

    NSMutableString *FileName  = [[self.request.URL.absoluteString stringByReplacingOccurrencesOfString:@"myapp://" withString:@""] stringByReplacingOccurrencesOfString:@".png" withString:@""];
    NSString *imagePath = [[NSBundle mainBundle] pathForResource:FileName ofType:@"png"];
    NSData *data = [NSData dataWithContentsOfFile:imagePath];

    NSLog(@"---- DATA URL");
    NSLog(imagePath); 

    [[self client] URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
    [[self client] URLProtocol:self didLoadData:data];
    [[self client] URLProtocolDidFinishLoading:self];
}

- (void)stopLoading
{
    NSLog(@"request cancelled. stop loading the response, if possible");
}

@end

LimeJS lime.scheduleManager

Just recently I started working with limeJS. I haven’t found many sites offering much example code, so I was going to start posting a few methods that seem important.

Moving an object

		    	var velocity = 6;

		    	var dty = function(dt)
		    	{
		    		var position = parent.bottomBlock.getPosition();
		    		position.y -= velocity * 1;
		    		this.setPosition(position); 

		    		//size of screen - height of asset
		    		if ( position.y < 480-79+10)
		    		{
		    			lime.scheduleManager.unschedule(dty, parent.bottomBlock);
		    		}
		    	}; 

		    	lime.scheduleManager.schedule(dty, parent.bottomBlock);

Local Development on iPhone with OSX and Charles Web Proxy

Great article on using Charles as a webproxy for you Iphone

“I recently had to do some development on the iPhone. Although the emulator is great, I wanted to test my website on an actual website. However, I did not want to do my testing on a world/company accessible location. Turns out, you can accomplish this task quite easily with Charles and OSX.”

http://deployfx.com/2011/08/local-development-on-iphone-with-osx-and-charles-web-proxy/