Quick news update and a fun article.

So now I’m in the midst of adding ssh to my iPhone app. I fount this fantastic project: DropBear SSH implementation

I will post the HOWTO and code when done. Is is coming along great.

Next, I am working on a cross-platform project involving a program that works under: Linux, Solaris, OSX and Windows. How’s that for crazy?
Needless to say, the program is filled with:


#if defined(ENVIRONMENT_LINUX)
#elif defined(ENVIRONMENT_OSX)
...
...

Madness. But it works!

Next… Ok, this is something that has been bothering me for a while now: “Pre-processor Keyword Indentation”

Old C/C++/Objective-C compilers insisted that pre-processor keywords started on column one(1). That was like a million years ago (in compiler design).
Today, pre-processor keywords can start at any column! So can we stop with this stupid programming already:


#if defined(MYDEFINE)
#if defined(MYDEFINE2)
#define XTRA2
#endif
#endif

And switch to modern-day programming:


#if defined(MYDEFINE)
        #if defined(MYDEFINE2)
                #define XTRA2
        #endif
#endif

Thank you!!!!

And last, this is a story I picked up: Russian Developer vs idiot hacker I wish everyone thought like this guy. Enjoy the article!

Movie break: The Girl With the Dragon Tattoo

I got this movie from iTunes and from the first minute I knew that this was going to be great. And it was!

Check out the trailer here.

This movie is a very cool detective story with many weird twists. Also many cringe worthy moments.

You won’t be disappointed!

For adults only.

Create New User for OSX using simple script.

I needed a script to create a new user for OSX. So I wrote one. It is pretty complete. Including bells and whistles. Enjoy!

Click here to view.

Click here to download.

String <=> NSDate <=> UNIX-Time and back again

Ok, this little item took a bit to figure out, but here it is:

If you have a time string (in any format),
    and you want to save it as a UNIX time string (seconds since 01/01/1970),
    and later you want to convert back to normal time, then do:
	//
	// Ok, let's convert.
	NSString *dateStr = @"03 JUN 08 00:00:01";

	// Convert string to date object
	NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
	[dateFormat setDateFormat:@"dd MMM yy HH:mm:ss"];
	NSDate *date = [dateFormat dateFromString:dateStr];
	//
	// Convert to long integer
	NSString *strTimestamp = [NSString stringWithFormat:@"%d", (long)[date timeIntervalSince1970]];
	MLOG(@"UNIX Timestamp: \"%@\"", strTimestamp);

        ...
        ...

	//
	// Now, much later, convert back
	NSScanner* scanner = [NSScanner scannerWithString:strTimestamp];
	long long valueToGet;  // Remember: "long long" means 64 bit. Not a typo!
	if([scanner scanLongLong:&valueToGet] == YES) {
		//
		// Convert date object to desired output format
		NSDate *nDate = [NSDate dateWithTimeIntervalSince1970:valueToGet];
		[dateFormat setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
		dateStr = [dateFormat stringFromDate:nDate];
		MLOG(@"Back to Normal date: %@", dateStr);
	} else {
		ELOG(@"Could not convert UNIX time: \"%d\", to normal time",  strTimestamp);
	}
	[dateFormat release];

HOWTO Properly uninstall Xcode and re-install.

Ok, today I have a few items. I downloaded and installed Xcode 3.2.3 with the new iPhone 4.0 support. Well, it was a nightmare.

First, a quick note to those of you who want to install Xcode: Make sure to uninstall the previous version!!

You must run: /Developer/Library/uninstall-devtools --mode=all

if you installed Xcode somewhere else, then you must uninstall from there. Make sure you provide the complete path, when invoking the script. From the path it knows what to delete.

So, I installed Xcode 3.2.3 and It was ok at first. Later, I noticed that it would hang at times and one time it hanged the entire system.
I could not get the problem fail consistently so I gave up and removed it. Then I went back to 3.2.2.

Now everything is normal. Sheesh!

I guess I’ll wait for the next version and also wait for iPhone 4 SDK next version as well.

Posted in OSX, iPhone. Tags: . No Comments »

Xcode: Increment version for every build — Update V1.2 — 6/10/2010

Did you ever need a way to auto-increment the version of your code, based on build number?

Well, here it is!

First, I picked up the discussion at: davedelong.com. Then I expanded it a bit.

This is how it works:

First, create a new build phase in your target, and make it a “Run Script” build phase.
Then, Right click->Get Info, and click the “General Tab”.

Shell: /bin/bash
Script: ./Resources/plistVersionIncrement

Then, in your project directory, create a Sub-Directory: “Resources”.
Put this script there (make sure permission mask is: “755″ !) :

#!/bin/bash
#
# @(#)  Increment the version number in the project plist. V1.2.
#       Note:   The project plist could be in directory
#               "Resources" or the project root.
#               Personally, I avoid clutter in the project root.
#
#       Note:   This script should be invoked from the project root!
#
#       V1.2    Added checking for the INFOPLIST_FILE environment variable
#
#       Enjoy! xaos@xm5design.com
#
PROJECTMAIN=$(pwd)
PROJECT_NAME=$(basename "${PROJECTMAIN}")
#
#
# Let's see if the environment variable is set
if [[ "${INFOPLIST_FILE}" != "" ]]
then
   #   
   # This was passed from XCODE
   buildPlist="${INFOPLIST_FILE}"
   PROJECT_NAME=$(basename "${buildPlist}"| sed 's/^\(.*\)-Info.plist.*/\1/')
elif [[ -f "${PROJECTMAIN}/Resources/${PROJECT_NAME}-Info.plist" ]]
then
    #
    # This should handle the default behavior of the OSX file system
    # which is case insensitive.
    buildPlist="${PROJECTMAIN}/Resources/${PROJECT_NAME}-Info.plist"
elif [[ -f "${PROJECTMAIN}/resources/${PROJECT_NAME}-Info.plist" ]]
then
    #
    # Just in case the file system is case sensitive.
    buildPlist="${PROJECTMAIN}/resources/${PROJECT_NAME}-Info.plist"
elif [[ -f "${PROJECTMAIN}/${PROJECT_NAME}-Info.plist" ]]
then
    #
    # In case the plist is in project root.
    buildPlist="${PROJECTMAIN}/${PROJECT_NAME}-Info.plist"
else
    echo -e "Can't find the plist: ${PROJECT_NAME}-Info.plist"
    exit 1
fi
#
buildVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${buildPlist}" 2>/dev/null)
if [[ "${buildVersion}" = "" ]]
then
    echo -e "\"${buildPlist}\" does not contain key: \"CFBundleVersion\""
    exit 1
fi
IFS='.'
set $buildVersion
MAJOR_VERSION="${1}.${2}.${3}"
MINOR_VERSION="${4}"
buildNumber=$(($MINOR_VERSION + 1))
buildNewVersion="${MAJOR_VERSION}.${buildNumber}"
echo -e "${PROJECT_NAME}: Old version number: ${buildVersion} New Version Number: ${buildNewVersion}"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${buildNewVersion}" "${buildPlist}"

Now, in your program do:

NSString *myVersion = [NSString stringWithFormat:@"Version: %@",
    [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]];

Keep in mind that Xcode caches files, so if you want a new version to show up do: “Clean All” and re-build.

Updated on 6/8/2010. New script now checks for upper/lower case “resources”. Also forgot “*” in “myVersion”. Thx Bob D.

Updated on 6/10/2010. New script now checks for environment variable: “INFOPLIST_FILE” passed from xcode

UIViewController push new view crashes app

Synopsis:

From my main “UITableViewController” I want to show two different views….the app crashes…

Follow the discussion at: forums.macrumors.com

Status: Resolved.

Posted in iPhone. No Comments »

Memory Allocation Question with details

Synopsis:

I have a test program which just allocates one object and copies it. I get a leak though…

Follow the discussion at: forums.macrumors.com

Posted in OSX, iPhone. No Comments »

No Windows

Today is a major milestone for me. Today marks the first week, in many many years, that I am not running Windows in any machine in the house. Even Vmware. I didn’t even miss it. Oh well…

@Class quick HOWTO

I was in a 18 hour coding session and I needed to create a global class for all my projects. Never done it before but I figure it’s easy. Right? I have the Internet. No problem. ….Not!

First, I get this looong explanation from Apple. What? come on dude, I’m in front of the monitor for 18 hours, I don’t need proof of string theory… Geez!

Then I get all sorts of crap with similar results. Anyway, I figured it out, eventually.

So, for all my dear friends, here is a quick and easy example. I give you four files. Two files define the global class and two files define how the class is used. File one is the “.h” file of the global class. Let’s call it “Utilities.h”:

//
//  Utilities.h
//
//  Created by xaos
//

#import "foundationstuff.h"
#import "anyother.h"

@interface Utilities : NSObject {
	//
	//
}

+ (NSInteger) returnItDammit;

@end

Then we have the Utilities.m

//
//  Utilities.m
#import "Utilities.h"
#import "global.h"

@implementation Utilities

+ (NSInteger) returnItDammit
{
	static int mylocalcounter=0;
	mylocalcounter++;
	return mylocalcounter;
}
@end

You see what I’m doing here right? All I want is a function that returns a counter that gets incremented based on how many times it was called. Stupid and simple. Now here is the include file and main file of the class that will be using these “Utilities”. Here is the “ClassMain.h”

//
// ClassMain.h
//
// Nothing special here. No Mention of utilities.
#import "usualcrap.h"

And the main class file “ClassMain.m”

//
// ClassMain.m
//
#import "ClassMain.h"
#import "Utilities.h"
@class returnItDammit;

@implementation ClassMain
//
- (id) init
{
	NSInteger myint;

	myint = [Utilities returnItDammit];
	NSLog(@"Int: %d", myint);
	//
	myint = [Utilities returnItDammit];
	NSLog(@"Int: %d", myint);


	...
}

@end

The output should be:

Int:1

Int:2
See that? Nice and easy. Enjoy!
Posted in OSX, iPhone. No Comments »
  • Meta