EARTHQUAKE!! OK.. it was only a 3.9

Just before 8:00AM, while reading, I got that sinking feeling. “Hm.. crap.. that’s an earth quake!”. It was mild, sort of like the little warning you’d get when a big-un is about to unleash some havoc. Then.. quiescence. But, you know a quake when you feel one. It’s nothing like a bus or truck driving by.

At any rate… about an hour later a friend of mine shot me a link from the Seattle Times, so I went and checked the USGS site again (my first check was only for my local area.. it was so small I figured it was local). Turns out it was far away, far south of Olympia.

M3.9 – Washington

Magnitude 3.9 - Tuesday, November 16, 2010 at 15:51:08 UTC

At least my PTSD did not kick in this time, although, I did start to get a little anxious. Geez. PTSD sucks… really.. I can’t image how bad it can get for our troops..

Short Course R/C Racing – 1/10th scale trucks

Radio Control, it’s an addicting little hobby. Well, maybe not so little, and certainly not inexpensive! Regardless, it’s fun!

Wednesday past a friend of mine (I blame you Carr.. I blame you for all of this) told me about this in-door R/C racing track in Bremerton, very close to my house. So we headed over there and checked it out. Wow.. OK, who knew that was in our little town.

This place is not just some po-dunk room with some plywood ramps and piece of tape across the floor to mark a start/finish. No, this is a real racing joint here! Specially formulated clay track surface, plenty of combo jumps, including a nice double-triple right before the finish line. And to top it all off, they have a legit set of transponders for down to the fraction of a second real timing. This is bona fide indoor R/C off-road racing!

Thinking this would be a pretty cool thing for for the kids to check out, we headed over to the track Saturday morning to check things out. Unfortunately, they not only found it cool, but they loved it! I say unfortunately, because.. well, these things are not exactly cheap!.

After quite a bit of reading on the internet, talking to a number of local shops and R/C racers that I’ve started to meet, it was pretty clear, that the truck to start off with is the Team Associated SC10.

This truck is not your Wal-Mart R/C special. This thing is the deal.

Using a 2.4 GHz digital 3-channel pistol-grip controller, 3300kV brushless motor (equivalent to a 550 class heli motor), big programmable speed controller, and a chassis that is tough enough to hit a wall at 35mph, bounce off and keep running… you have some SERIOUS fun!

The only modification we made to hit the track was an update skit plate and front bumper. All the people running the truck said it’s the only thing it needs. And after finding out how easy it is put one of these things into the wall at full throttle, I understand!

The first truck, and I suspect there will be more, actually belongs to my daughter. She’s really quite into this thing. After we spent almost 3 hours practicing last night at the track, we brought it home and spent about 1/2 hour taking it apart, cleaning, checking bearings and putting it all back together again. I think these are going to be valuable experiences and lessons for her.

I can’t wait for race night, and I think she’s pretty stoked too!

iCIDR App – found in some interesting places

iCIDR 1.2 (available soon)
While checking my Apps stats, I noticed that most of my sales have been from Europe. Europe? Really? How / Why? Germany and Italy were in there too, not just English speaking countries. So I had to ponder, just how many places are listing my ‘New’ app in their App Store Aggregators? Well, I found these links to my iCIDR app in a number of locations, a couple of which surprised me:

AppShopper

AppShopper has link to the App listed under ‘Utilities’. So far not enough rating activity has occurred to report.

Appolicious

Site is also showing no ratings for the app at this time.

GiveApp

GiveApp in Japan is currently listing the App as well. No reviews or comments yet.

storedApps

This site seems to be giving it a score of -1 right now. I’d sure like to find out why.

SMARTPHONE Soft

Currently only a couple of hits, not reviews or comments yet.

3GSiPhone.com

No comments or ratings. Plus the HTML the scrapped off another site (AppShopper.com) has one of the screen shots overlaying the text. Nice. 😐

DeMartini Videos

OK, this one is out there. It’s one of those click aggregation, sites. And no, I did not include the link, if you want to send them click revenue, you can find it with Google, it’s on the LAST page or results. Currently my App is no longer mentioned, but the cached version on Google shows it was pulled / scraped off another page because of my last name. And no, I am not related (as far as I know) to that clown at Electronic Arts in San Mateo.

If you’d like to find out more, and possibly pick up a copy yourself, click on the App Store icon.

Price: 99 cents

iCIDR - David DeMartini

iMy Objective-C / iPhone App Development FAQ

Organizing ones learned lessons does not take much effort. The key is consistency, documenting things in a common mode (such as a binder, or a small note book, etc.). For decades I have preferred to use small bound ‘journal’ type books. Once full, the retire to my book-case for future reference. They have been incredibly useful over the years, holding esoteric bits of data generally accessible by myself recalling the rough dates I wrote relevant code, or learned a new programming language, reference that with the dated pages in the books (I ALWAYS date the pages in my notebooks) and voila.. if I had a personal epiphany, I recorded it there.

This time, I’m trying something a little different. Taking those same notes, but this time making them public for others to hopefully gain from the things I’ve learned. So, on with the show.


Creating a multi-line NSString object

If you have battled with maintainability in long NSStrings, I found the simple solution. Oddly, a couple of hours searching on the web did not even get close to showing me this. I just used some old C language line continuation syntax, figured out how Objective-C like to do it, and voila…, problem solved.

It’s quite simple really. The trick is the slash right after the closing double-quote. If you have whitespace, iOS 4.x will nick you with a warning. It still compiled and ran, but a warning is there for a reason, and this syntax throws none.

As with all these sorts of posts, I hope it helps someone else.

		NSString* appStoreLink = @"http://itunes.apple.com/us/app/icidr/id400066695?mt=8&ign-mpt=uo%3D4";
		NSString* msg = [NSString stringWithFormat:\
					 @"Check out this cool App I found in the App Store!\n"\
					 "\n"\
					 "%@ helps you understand CIDR Block IP notation.  It's packed with some great "\
					 "features I think you'll find very useful.\n"\
					 "\n"\
					 "Version %@ of %@ is available now, just follow this App Store for more information:\n"\
					 "%@"\
					 ,appName
					 ,version
					 ,appName
					 ,appStoreLink];

yes, that’s REAL code from one of my apps.

Dismissing a Keyboard after UITextField input

Strategy entails using the keyboards ‘Return’ key to signal that one is done. Seems useful, but only if you have a single line text input. In my case, that’s what I’m looking at, single line input, so that’s the solution I’m going to try.

First things first, rename the Return key to Done. Ah… so now you see how to prompt the user to hit the enter key when they are ‘Done’. Tricky. Dirty-tricky? Maybe, but it will work.

WAS:

This is accomplished by changing the ReturnKey property dropdown available in the UITextField property inspector. The dialog looks like this:

Dialog dropdown to change the 'Return' key to 'Done'

NOW:

OK, that was the EASY part… the next part requires cutting some code, over-riding some methods and thinking a few things through.

The tricky part is understanding that you need to make sure your object has implemented UITextFieldDelegate. This is how that might look:

@interface seeView : UIViewController <UITextFieldDelegate> {
    UITextField* seeTextField;
}

Following that you’ll need to enable viewDidLoad (boilerplate code) and implement some delegation:

- (void)viewDidLoad {
	
	UITextField *seeText = (UITextField *) [self.view viewWithTag:102];  // try to locate the object with the tag
	seeText.delegate = self;  // assign a delegation.
	[super viewDidLoad];
}

But the fun is not quite over yet.. The textFieldShouldReturn method will need to be defined to execute the abandonment of the first responder:

// Should trap all Keyboard Return Events
- (BOOL) textFieldShouldReturn:(UITextField*)textField {
    [textField resignFirstResponder]; 
    return YES;
}

You also need to know something about wiring classes and the File Owner together in the relevant Nib file. But you know how that plays out already, right?

UPDATE: 19-NOV-2010

After banging my head into the table for, uh, about 3 hours trying to get the ‘viewDidLoad‘ method to fire off… while digging around in the dusty corners of sites.. I FINALLY found THE ANSWER to this dilema. So.. now I’m going to add it in here so I don’t effing for get as well!!!

Make sure your Tabs have the type set to the NIB type NOT UIViewController!


Display only numbers for certain keyboard events

It turns out this was just as easy as changing the Return button on the main keyboard to read Done. The same dropdown is play. The option I selected was Numbers and Punctuation. It looks like this:

Keyboard after changing the property to 'Numbers & Punctuation'


Dismissing the Keyboard after any Button Press

** This is the 3rd thing I need to tackle. First I have to get some math stuff ironed out and tested, as well as some more advanced string deconstruction and manipulation. This will be an important thing to get worked out, since the keyboard will cover 1/2 my UI but the main button is still visible, meaning people will hit that instead of closing the keyboard first. That needs to be taken into consideration and coded for. People don’t want to click twice when they can click once. Seems pretty logical to me.


Regular Expression Solutions

About 8 hours of hunting, hacking, a little screaming and finally some yelling in rejoice.. I have sorted out, FINALLY a simple, contained example of Regular Expression executing in Objective-C. This may for work you, it may not. It might not have the error control you like, well.. you’re getting it for free so.. don’t get too worked up about it.

Basically, you’re going to need to use the regex.h C libraries to get it done. The upside is that it’s already on your system. Here is the snipped of code that I used to do some regexing on a string. Obfuscated since I’m not going to show exactly what I’m doing (oops.. my tin hat almost fell off). I’ve added a few comments. Now.. how did I learn this? By a lot of trial and error, frustrated looks at ‘iPhone Cookbooks’ that are so out of date 1/3 of the code is depricated… and then.. I found this little gem: Advanced Strings In Cocoa
so most of the credit goes to those that went before I.

- (BOOL)validateString:(NSString*)seeStr {
	// Take the textField apart into pieces for computation
	NSString* pattern = @"^[:character:]$";
	NSString* result = nil;

	regex_t preg;
	int err = regcomp(&preg,[pattern UTF8String],REG_EXTENDED);	
	if(err) {
		char errbuf[256];  // This was the biggest mistake I was making, not using CHAR here
		regerror(err,&preg,errbuf,sizeof(errbuf));
		UIAlertView *av = [[[UIAlertView alloc] initWithTitle:@"Internal Error" message:@"ERROR Code 17" delegate:nil cancelButtonTitle:@"OK"otherButtonTitles:nil] autorelease];
		[av show];
		[NSException raise:@"CSRegexException" format:@"Could not compile regex %@: %s",pattern,errbuf];
	}
	
	const char *cstr=[seeStr UTF8String];  // This is another important bit of casting
	regmatch_t match;
	if(err = regexec(&preg,cstr,1,&match,0)==0){
		result = [[[NSString alloc] initWithBytes:cstr+match.rm_so length:match.rm_eo-match.rm_so encoding:NSUTF8StringEncoding] autorelease];
//		UIAlertView *av = [[[UIAlertView alloc] initWithTitle:@"MATCH!!!" message:result delegate:nil cancelButtonTitle:@"OK"otherButtonTitles:nil] autorelease];
//		[av show];
		return YES;
	}
	else {
		char errbuf[256];
		regerror(err,&preg,errbuf,sizeof(errbuf));
//		[NSException raise:@"CSRegexException" format:@"Could not complete a match %@: %s",pattern,errbuf];
		return NO;
	}

It worked like a charm, I used a very complex pattern (not shown here) for a long string validation and it was spot on. And quick. And it worked. I hope this helps someone.


String Splitting

It turns out that slitting strings is Pretty Easy, or at least a lot easier that I had expected. This is a part of my daily programming life.. string manipulation… and one of those most common manipulations are splitting things apart into arrays for iterative processing.

So.. how hard is it to do in Objective-C? Not had at all, in fact, it’s all that it takes!

NSString *msg = @"The Dog/Cat is lazy";   //  included here for context of msg
NSArray *parts = [[NSArray alloc] initWithArray:[msg componentsSeparatedByString:@"/"]];

Yeap.. that’s all it takes!!

Now let’s say the string was this: “The Dog/Cat is lazy”. And I want to get the first ‘part’ of that sentence, the part before the ‘/’. It’s as easy as pie (based on the line of code above):

NSString *aboutDog = [parts objectAtIndex:0];

So the variable aboutDog would contain the string at the first index (indexes start at 0 but you know that, because you’re not a sap developing for Windoze) and the value there is… TADA… The Dog. Fun. Easy… and if you know the index count (working on that) you can build a simple loop to do whatever you want!


NSString to Integer

The pain of robust variable casting… means you can’t be PERL/PHP lazy with your variables… you’d better know what you are putting in there, or where you are using it. So.. sometimes you feel like a nut uh.. string, and some times you don’t. Today I didn’t so off with it’s head! Sorta..

In this little story.. the string is named parts and I’m going to make a copy of it in the form of an integer with the name bits. So.. there you have my parts and bits all laid out for you to see (and if you’re a cute girl under 40, and you like what you see, give me a ring… uh huh). Uh.. digressing.. yeah.. code. Sorry. So that’s all there is to it. You’re welcome.

int      bits     = [[parts objectAtIndex:1] intValue];


Objective-C Math – just the basics Mama


App Store and Device Icon General Recommendations

General .png image sizes for Apple iPhone / iPad / iPod Apps:

App Store 512×512
.png
App Store Artwork Size (512 x 512)
App Icon 57×57
.png
App Icon
Spotlight Icon 29×29
.png
Spotlight

Add a line to UI View with UI Builder

Seems like a simple enough thing to handle, but I don’t see any elements that would provide this function.


Sending Things off to e-Mail Helper App

I finally had time to dig into this and find out how to make it all work.

There are a few things you must do to get In-App e-mail working. The first of which is to Add the Mail Framework to your set of frameworks. See the screen snipped here. The one you want is UIMessageFramework:

Once that has been added to your Framework, the fastest road to deployment that I found was to add the function right into the view you’re working with. Sure, it’s better from the statndpoint of pure OO programming to class this out, but I have a simple tool (from the standpoint of the UI, it was not simple for me to write the mathy bits) and it does not warrant strict OO policy enforcement.

So.. I just added the following (bold) to my View’s header file:

#import <UIKit/UIKit.h>
#import <MessageUI/MFMailComposeViewController.h>

@interface iCIDRViewController : UIViewController <UITextFieldDelegate, MFMailComposeViewControllerDelegate>  {

With the required framework referenced and appropriate delegation added, it’s off the the main code (.m) file.

You will need this block of code for the mail controller. Good news is that the SDK IDE will basically write the entire method for you, just need to add braces and you’re off:

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
	[controller dismissModalViewControllerAnimated:YES];
}

Finally, you write the bits for sending the mail. How you call this, is up to you. I used a ToolTab Navigation button to trigger it. Do as you please. As a bonus, I top my hand on multi-line (visually) singular NSString construction. Here is where the rubbers meet the roadies:

- (IBAction)shareApp:(id)sender {
	MFMailComposeViewController *picker = 
	[[MFMailComposeViewController alloc] init];
	picker.mailComposeDelegate = self;
	
	NSString* appStoreLink = @"http://itunes.apple.com/us/app/icidr/id400066695?mt=8&ign-mpt=uo%3D4";
	NSString* msg = [NSString stringWithFormat:\
					 @"Check out this cool App I found in the App Store!\n"\
					 "\n"\
					 "Version %@ of %@ is available now, just follow this App Store for more information:\n"\
					 "%@"\
					 ,@"1.0"
					 ,@"iCIDR"
					 ,appStoreLink];
	[picker setSubject:[NSString stringWithFormat:@"Check out this cool App I found (%@)",appName]];
	[picker setMessageBody:msg isHTML:NO]; 
	[self presentModalViewController:picker animated:YES];
	[picker release];
}


Random Character String Generation

Crude but effective. I know there has to be a better way to do this, but for today, for now, for the moment, it’s going to be this:

NSString *pool = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

-(NSString *) genString: (int) len {

    NSMutableString *rand = [NSMutableString stringWithCapacity: len];

    for (int i=0; i

530i Options Sheet

While at the dealer on Monday, I was able to get a printout of the factory options on the car. It’s good to know that the extra ///M parts on the car are as-shipped from BMW, not some post-delivery badge engineering activity.

The highlights, for me, are:

  • ///M Sport Suspension
  • ///M Leather Steering Wheel
  • Lt/Aly Wheels / Cross spoke 42
  • Satin Chrome
  • Alarm System (I only care because it gives me an insurance discount)


    Here is the full sheet:

    530i Build Sheet

  • iCIDR 1.0 just went live on the iTunes App Store!

    iCIDR 1.0 released November 1, 2010.

    iCIDR on the iTunes App Store

    CIDR CONVERT

    CIDR Convert(er) is a simple to use tool that allows rapid deconstruction and understanding of any valid CIDR block notation.

    For example. You’ve received a block of IP’s from your ISP. Maybe they are add-ons to your existing network. Perhaps you are deploying a completely new network. When you look at the provisioning worksheet and see the notation 17.251.200.70/25 you will want to know what IPs are part of that range. Instead of trying to do perform the 32-bit math in your head, or on a calculator, why not just use this handy tool? If you with a simple push of a button you’d have known:

    iCIDR - David DeMartini

    I look forward to creating more useful, and more entertaining apps before Christmas Time.

    Changing of the Guard. ML430 says goodbye.

    Times change, needs change, and thus, my mind changes too. So, with some regret, because it was a good solid vehicle, I have bid goodbye to the 2000 ML430 SUV that has taken me to CA several times, hauled furniture, electronics and been a nice comfy way to get to work. But, it was also a gas hog. Averaging around 17 MPG. It starts to take it’s toll when you’re daily commute comes in at just over 75 miles (round trip).

    But, I really didn’t want to be without my 4 doors. But I also wanted to buy something with a manual transmission. 4 doors, manual transmission, and NOT Japanese, those are almost completely exclusive requirements. Fortunately, not completely exclusive.

    What amounted to accidental fortune, while negotiating with a local dealer on an OK (almost-nice) 500SEL the owner of the dealership had returned this vehicle, after personally driving it for months, making it available for sale.

    2001 BMW 530i

    No sooner had it arrived on the lot, and the finance guy suggests that maybe I should at least look at the Beemer that came in. There was a deposit ahead of me on the MBZ anyway, so I couldn’t yet test drive it. I’m not in the habit of saying no to people what suggest I take their nice cars for a drive. I am a gear-head afterall.

    Within 10 minutes, I was in love. You see, this just happens to have a nice 24-valve 3.0L I-6 that is as smooth as silk, but not only that, it has a 5-speed MANUAL gearbox. As I rowed through the gears it was smooth, precise, confidence inspiring, and quick. Dare I say fast for a vehicle of this size! I made the test drive solo (I’ve never bought a car from anyone that insisted they go with me on a test drive.. it’s just not possible to really test drive a car with it’s owner on board.. honestly, it’s not), taking about 30 minutes to perform all sorts of tests. Speed, breaking, cornering, drifting, er.. turning, it all worked like a charm.

    The 530i drives like a car 1/2 it’s size. How they manage to build them this way, I don’t understand, but, this being my first BMW, at this point, I’m thinking it’s not going to be my last. I almost purchased an ///M3 about a year ago, but another buyer snapped it up before I made it to the dealer in Bothel. No matter, life takes many turns, and sometimes what seems like a negative in turn can be quite positive.

    We’re still on our honeymoon, but it’s we’re getting along wonderfully. I’ve driven it to work, and most recently out into the Cascade foothills, trying out it’s handling and real-world drivability. So far, I have not want, other than some new shocks, but that’s not an indictment against the car, it’s just that I like to freshen up all my vehicles with a really nice set of Bilstien shocks. Yes, Bilstien street valved shocks are just THAT good.

    My next empirical test will be the check the mileage. The car has an on-board milage computer, but I don’t trust those things as far as I can throw them. Only Fill-Drive-ReFill-Calculate method is the one I trust. That will likely be the next post.

    One interesting thing I have learned, and I must sincerely thank the private SF mailing list I am on for this, is this vehicle appears to have the factory sport package. This is evidenced by the ///M badged wheel, shifter and the very nice 3-piece BBS alloys (you can picture above) it’s wearing. I’ll check the VIN and see what I can find out about it, see if it is in fact a factory sport package, or if someone just did a little cosmetic and badge engineering. Regardless, I really REALLY like this car. But, I thought I might, considering I found myself laughing with great joy (dare I say giggling?) as I put my foot in the firewall and took off on the test drive.

    Another thing I have learned, is that I need to be VERY careful, er mindful, of my speed in this thing. It’s very easy to being going a lot faster than you should be due to how quiet the car it, even at 90MPH, er.. highway speeds.

    More to come…