Archive for the ‘Matt's World’ Category

New EasyBatch 1.5 build

Sunday, August 23rd, 2009

A new build of EasyBatch 1.5 is available for download. This fixes a typo in one of the contextual menus, and fixes the help button’s positioning during window resizing. This update is a minor one for just these aesthetic tweaks, and does not update or change any of EasyBatch’s functionality, but any users who would like to update to the most recent build can get the latest download by clicking here.

Thanks for trying EasyBatch!

Cocoa Quickies: Sort an NSDictionary by keys

Friday, August 21st, 2009

If you’ve ever needed to sort an NSDictionary by its keys, you’ll quickly discover that this functionality is missing from the NSDictionary class. This is because the order of keys in an NSDictionary is undefined (really, the concept has no meaning in an NSDictionary in the first place). So the basic process to follow is:

  1. Put the keys into an NSArray for ordering
  2. Sort the NSArray
  3. Traverse each key in the NSArray and obtain the -objectForKey

Here’s the code. (Note: this method uses its own bubble sort algorithm, but you could easily replace this with NSArray’s built-in sorting methods if you wanted to):

-(NSMutableArray*)bubbleSortDictionaryByKeys:(NSDictionary*)dict
{
	//this method takes an NSDictionary and performs a basic bubblesort
	//on its keys. It then returns those ordered keys as an NSMutableArray.
	//You can then traverse the original NSDictionary and retrive its
	//ordered objects by simply stepping through each key in the NSMutableArray.

	if(!dict)
		return nil;
	NSMutableArray *sortedKeys = [NSMutableArray arrayWithArray: [dict allKeys]];
	 if([sortedKeys count] <= 0)
		return nil;
	else if([sortedKeys count] == 1)
		return sortedKeys; //no sort needed

	//perform bubble sort on keys:
	int n = [sortedKeys count] -1;
	int i;
	BOOL swapped = YES;

	NSString *key1,*key2;
	NSComparisonResult result;

	while(swapped)
	{
		swapped = NO;
		for(i=0;i<n;i++)
		{
		key1 = [sortedKeys objectAtIndex: i];
		key2 = [sortedKeys objectAtIndex: i+1];

		//here is where we do our basic NSString comparison
		//This can be easily customized.
		//See the options for -compare: in NSString docs
		result = [key1 compare: key2 options: NSCaseInsensitiveSearch];
		if(result == NSOrderedDescending)
		{
		//we retain for good form, but these
		//objects should still be safely
		//retained by the dictionary:
		[key1 retain];
		[key2 retain];

		//pop the two keys out of the array
		[sortedKeys removeObjectAtIndex: i]; // key1
		[sortedKeys removeObjectAtIndex: i]; // key2
		//replace them
		[sortedKeys insertObject: key1 atIndex: i];
		[sortedKeys insertObject: key2 atIndex: i];

		[key1 release];
		[key2 release];

		swapped = YES;
			}
		}
	}

	return sortedKeys;
}

And here’s an example of how it can be used:

    NSDictionary *test = [NSDictionary dictionaryWithObjects:
                         [NSArray arrayWithObjects:
@"4",@"3",@"1",@"2",@"6",@"5",nil]
               forKeys:  [NSArray arrayWithObjects:
 @"dog", @"cat", @"apple", @"big bear", @"zebra", @"porcupine", nil]];
    NSMutableArray *keys = [self bubbleSortDictionaryByKeys: test];
    NSEnumerator *arrayEnum = [keys objectEnumerator];
    NSString *aKey = nil;
    NSString *str = @"";
    while((aKey = [arrayEnum nextObject]))
    {
        str = [str stringByAppendingString:
               [NSString stringWithFormat:
               @"\nKey: %@ -> %@", aKey, [test objectForKey: aKey]]];
    }
    NSLog(@"%@",str);

Output:

Key: apple -> 1
Key: big bear -> 2
Key: cat -> 3
Key: dog -> 4
Key: porcupine -> 5
Key: zebra -> 6

Fun with the “tilt-shift” effect…

Friday, July 24th, 2009

This is a photo I took at the Japanese Zen Garden in Portland, Oregon. It’s contrasted next to (on the left) a modified version of the image in which blurring has been applied for a “tilt shift” effect, along with a few other minor adjustments such as saturation, etc.

This is one of those things that is spreading quickly across the net, I’m seeing this effect everywhere. And for good reason – it’s very cool! It’s a lot of fun to make your photos look like they were taken inside a miniature model! :) If you’d like to learn more about applying a “tilt-shift” to your photos, just do a quick Google search and you’ll find plenty of tutorials.

Creature Comforts

Thursday, July 23rd, 2009

BravoTunes: Adjust the iTunes auto-launch pref

Thursday, July 16th, 2009

EDIT: With the 1.1.1 release, this feature can now be set in the preferences window.

When BravoTunes is opened, it can automatically launch iTunes. There is a checkbox labeled ‘Always Use This Answer’. It occurred to me, however, that if you click this option and then change your mind, there is no way via the preferences window to change this behavior (oops!).

So until I correct this in the next update, here’s how you can change this option directly, via the OS X Terminal, if you need to.

If BravoTunes is launching iTunes every time it starts up, and you want to stop that (or vice versa, you clicked “Don’t Open” and now you want it to launch iTunes), do this:

Step 1. Open up Terminal.app (you’ll find it in your /Applications/Utilities/ folder)

Step 2. Type the command below to enable iTunes auto-launching:

defaults write com.bravobug.BravoTunes launchiTunes -bool YES

Or, if you want to disable it so that iTunes doesn’t automatically launch:

defaults write com.bravobug.BravoTunes launchiTunes -bool NO

That’s all there is to it. I should also point out that if you have iTunes auto-launch enabled, you will typically want to quit BravoTunes before you quit iTunes. Under certain conditions if you quit iTunes first, BravoTunes may try to open iTunes back up automatically (which can be annoying – I’m working on fixing this behavior).

Thanks for visiting.

Thank you

Wednesday, June 24th, 2009

The blog has been a bit quieter than usual as I am slaving away on about 6 BravoBug projects at once, including some new stuff that hasn’t yet been announced here. But I wanted to write a quick personal Thank You to everyone who has registered their copies of EasyBatch, MiLife, IconBurglar, Blackout, MBB3k, or donated to Lotus. BravoBug is not a big company. And every single registration makes a huge difference in supporting these apps and letting me spend my time working on them, and I am grateful for that opportunity. I hope I can keep improving the existing apps, and I hope you will find that the projects in the works were worth the long wait.

Thanks again for your support! -Matt

When .7 does not equal .7…

Monday, June 15th, 2009

Here’s a fun little experiment you can do which is an interesting way of revealing some ‘gotchas’ with the internal math used by your computer. Here’s the code:

    float x;

    x = .5;
    if(x == .5)
        NSLog(@"x is .5");
    else
        NSLog(@"Whoah! X is actually %f",x);
   
    x = .7;
    if(x == .7)
        NSLog(@"x is .7");
    else
        NSLog(@"Whoah! X is actually %f",x);
   
   
    x = .7;
    if(x == .7f)
        NSLog(@"x is .7");
    else
        NSLog(@"Whoah! X is actually %f",x);

You can run this yourself, or just check the actual output below.

 x is .5
 Whoah! X is actually 0.700000
 x is .7

At first glance this might seem odd. You would expect that .7 is .7 is .7. But such is not the case as far as your computer is concerned. In the second example (where the values are found to be unequal, and yet the output appears to show that they are equal), the lack of the “f” on the end of the comparison value means that the compiler interprets that literal .7 value as a double. And a float with .7 is not equal to a double with .7. The specifics of why this is so can be explained by floating point math ‘lack of precision’, which is all fine and dandy, but at first glance it sure seems strange that .7 does not always equal .7, especially since .5 in this case always equals .5!

This is a perfect example of why sometimes it is important to understand the inner workings of how the processor actually performs its math and value comparisons, especially with floating point variables. I find this kind of stuff fascinating because normally as I code I think of the computer as processing these kinds of instructions in the most fundamentally logical and reasonable way (ie, .7 = .7 = .7), and yet it’s fun to bump into these little situations where things don’t behave quite the way you might expect at first.

In other news, for those of you who are visiting to check the status of the recent updates announced for several of BravoBug’s shareware apps (EasyBatch, IconBurglar, Blackout etc.), I wanted to thank you both for your support in registering and also for your patience, I am working on getting those updates out as quickly as possible. Thank you for visiting, -Matt.

Cocoa Quickies: Copy text (NSString) to the clipboard

Tuesday, June 9th, 2009

Here’s a quick and easy one that comes in handy every now and then. Most of the time you can just rely on Cocoa’s -copy methods sent from the Edit menu, but sometimes you want to deliberately place a specific bit of text on the Mac clipboard. NSPasteboard makes it easy:

-(void)copyToClipboard:(NSString*)str
{
    NSPasteboard *pb = [NSPasteboard generalPasteboard];
    NSArray *types = [NSArray arrayWithObjects:NSStringPboardType, nil];
    [pb declareTypes:types owner:self];
    [pb setString: str forType:NSStringPboardType];
}

By the way, the blog has been quiet this past week but it’s not due to a lack of activity. There’s quite a few big BravoBug releases being worked on simultaneously, so the blog’s been neglected a bit. But stay tuned, good stuff to come! Thank you for stopping by. -Matt

True Story

Sunday, June 7th, 2009

New! Lotus Meditation Timer 4.0

Monday, June 1st, 2009

BravoBug Software is happy to announce today the release of Lotus 4.0, a new update to its meditation tool for Mac OS X which provides several new features including sessions, a new ‘native-Mac’ GUI, and much more.

Check out the official press release below, or download Lotus right now. Lotus is free. If you find it useful BravoBug asks that you make a donation to help support its development.

FOR IMMEDIATE RELEASEBravoBug Software announces the release of Lotus Meditation Timer 4.0.

Contact: BravoBug Software – www.BravoBug.com

June 1st, 2009 — BravoBug Software announces the release of Lotus Meditation Timer 4.0

BravoBug Software announced today the release of Lotus Meditation Timer 4.0, a meditation aid for Mac OS X that provides a three-phased timer designed specifically to monitor meditation, yoga, or exercise routines. Lotus’ timers can be fully adjusted and set to play soothing non-obtrusive sounds when time has elapsed, and Lotus includes a dozen sound samples you can use – or you can choose any custom audio file.

Lotus is designed for ease of use, and takes advantage of the best the Mac has to offer: control your Lotus timers without leaving your cushion by using your Mac’s infrared remote, and use the Mac’s built-in speech synthesizer to announce the remaining time without looking at the screen. Lotus can also prevent your Mac from fully entering energy saver mode so that your timers can continue running even when your Mac falls asleep.

This new version of Lotus introduces ‘Sessions’, which saves frequently used timer settings so you can switch between your most common meditation routines quickly and easily. Lotus 4 also includes a new Mac GUI style in addition to its original two GUI skins, for users who prefer the ‘native’ Mac OS X look and feel. The new version of Lotus also contains several bug fixes and feature enhancements for improved usability and stability.

Lotus Meditation Timer 4.0 requires Mac OS X 10.4 or newer, and is freeware. Those who would like to support its development are encouraged to donate to it. The full download is available at: http://bravobug.com/lotus (2.3MB Disk Image).

BravoBug Software – a small Mac Shareware company dedicated to fun and unique freeware and shareware products for the Mac OS X operating system. More information available at www.bravobug.com or by E-mailing: info@bravobug.com.

DIRECT DOWNLOAD LINK:
http://bravobug.com/downloads/Lotus.dmg

WEBPAGE:
http://bravobug.com/lotus

###