Archive for the ‘Mac Development’ Category

There’s trunk and then there’s whatever-ax-was-using

Tuesday, July 6th, 2010

feurig: ax have you gotten anything to work with deans post feburary lufa?
[1:29pm] ax: post feb. hmm, i’d have to look into my project files to remember which version i was usting
[1:29pm] ax: just a sec
[1:29pm] feurig: I was pulling my hair out with the may release and then I went back to the standard “what ever ax was using” and things started working
[1:30pm] feurig: you used the feb19 release on the midimonster stuff
[1:30pm] feurig: where is that (explicitive deleted) tourist????
[1:34pm] ax: yeah, /lufa_100219/
[1:35pm] ax: i like this ‘whatever ax was using’ standard
[1:35pm] ax:
[1:48pm] bzztbomb: That should be a source control tag

Why I hate DarwinPorts/MacPorts.

Tuesday, July 6th, 2010

Because they aren’t bsd ports.

  • They force you to carry redundant dependencies.
  • They do not allow you to fetch and compile the source files in a transparent way.
  • They do not give you clean access to the patches they use to make things work.
  • They haven’t had a current version of avr-gcc in over 4 years.
  • They just dont get it.

Today, I am working on a cross platform USB device which I hope to interface with ruby, python, and perl using libusb. The ruby bindings for libusb are for 1.0.xx which actually almost works on OSX nowadays. A quick sampling of using ruby-usb on osx, like most things embedded in apple land, is a trip more or less to hell. (see: http://www.jedi.be/blog/2009/11/11/ruby-usb-libusb/ http://www.ruby-forum.com/topic/192042) . Since most of my ruby is gem installed I just need a working version of libusb so I go to the darwin ports recommended above. Looking at the “raw” port file I see that there are really only two patches and so I go find them. They aren’t exposed for reasons that seem pretty stupid to me,  but I did find them at. http://libusb.darwinports.com/dports/devel/libusb/files/patch-libusb__io.c and  http://libusb.darwinports.com/dports/devel/libusb/files/patch-libusb__os__darwin_usb.c

When I downloaded the source file and went to wget the patches it got even more screwey.

wget http://libusb.darwinports.com/dports/devel/libusb/files/patch-libusb__io.c
--2010-07-06 00:28:13--  http://libusb.darwinports.com/dports/devel/libusb/files/patch-libusb__io.c
Resolving libusb.darwinports.com... 208.185.168.32
Connecting to libusb.darwinports.com|208.185.168.32|:80... connected.
HTTP request sent, awaiting response... 403 Forbidden
2010-07-06 00:28:13 ERROR 403: Forbidden.

I didn’t want to deal with it so I just saved the links in my browser and patched the source files manually. After that a

./configure; make && make install && make clean

let me do the normal ruby thing.

gem install ruby-usb

Just like on all the other operating systems.

Acid Testing Your Time Machine Backups

Thursday, February 4th, 2010

Disks Die, Laptops break, Bags are Stolen.

It’s more or less a fact of life,

In the 4 year process of transitioning from a noisy sun E-250 in the garage to something that could actually be in the same room with you I arrived at the above network arrangement.

Most of the my data is hosted by a central server and when I had more systems all of the home directories were NFS mounted (which is a major PITA on OSX). In the last hear I have worked primarily on my MacBook, occasionally syncing my projects with the file server. After migrating to leopard I purchased a 1 Terabyte external disk and backed up both the file server and my laptop using “Time Machine”. As I worked more and more on the laptop I did less and less syncing of the work to the file server. The thing about time machine is that its thoughtless. Set it up and as long as you get your laptop home and leave it on for a few hours and it should keep your work safe for you.

Two weeks ago My Bag was stolen.

On top of the work I had actively been doing I lost two active sketchbooks and in the end this loss is probably the most painful. Since I couldn’t immediately restore the data using the process described below, I spent much of last week recreating the designs for this months workshops. Once the critical work was done I turned to see what I could recover. I had used time machine to restore a couple of files I had foobared but I had never had to restore all 270G of data and applications. My Intel Imac did not have enough disk nor did it have most of the software. So I bought a 1T disk from Old Town Computers and “CarbonCopyCloner“ed a bootable operating system onto it and put it into my Intel Imac (Ernesto).

WHERE’S MY BACKUP?!?

After googling around I found that I was supposed to restore my files using the “Migration Assistant” tool. I had used migration assistant to move users and applications to new systems but never to restore files. When I first tried the migration assistant I mounted the disk remotely but I couldn’t see the backup. So I moved the disk to the target machine. Even then I only saw the option of restoring the server and not my laptop.
Panic set in until I found a file named with my laptops name and a .sparsebundle extension. Right clicking on this lets me open it with the appropriate mounting utility. But…. Not until it had checked the file system. Walking away and doing something else for a few hours let me come back to the image mounted. When I ran the migration assistant again the option of restoring the laptop was there.

SUCCESS!

Starting the restore process and going to sleep I woke to find that it had successfully restored all of my data and applications! I was only out the extra time on the designs and the actual property.

FAIURE.

Now all of my active work was on a disk which was large enough to also contain the rest of my images/music/video and web content which had been kept on the file server. Since I could see the fileserver’s backup and I was so happy with my success I tried then to restore the file server data.

Mounting your home directories on external disks on OSX is a lot like mounting them remotely. It just plain sucks. Half the time if I made any changes in the disks connected to the file server it would mount them in a different place. Then when you logged in it would create a new mount point and empty directory and you could not remount the disk where it was supposed to be until you removed the new directory.

When I restored the file server user I had few options. I could restore the user (giving an estimated size of like 20 meg , not the >400G I expected) and on the next screen I could restore the file system at the top level directory. This did not show me enough data to represent the data directory either. I could also have restored the entire system and then re-restored the Intel files over it but I really didn’t want to deal with the mess.

So I punted.

I just plugged the file server disk in and dragged my home folder to the new disk. I will probably test the restore process to the file server with the external disk attached to make sure the data is recoverable on that system. Once this is done I will reformat the time machine disk for future backups and send the file servers external disk to another state. In the mean time I will rest better knowing that my time machine backups actually work transparently while I work.

Postgres + Ruby + OSX=Multi Architectural Hell

Tuesday, December 29th, 2009

I was finally able to get my ruby/rails environment setup with my database of choice.

It wasnt easy as postgres will not build with more than one architecture at a time, I had gone through similar hell the last time I tried to build anything on OSX that had to compile against libraries made for different architectures. Fortunately the solution was relatively simple.

My database is running 64 bit and I use it for many other applications that are compiled against either multiple architectures including 64bit but also some which are 64 bit only.

Ruby on the other hand is compled for 32 bit which worked flawlessly on mysql and most of the other gems i installed when I got to the postgres it puked in weird ways and when I tried every third solution on the net it was always the same.

Bash-3.2# gem install pg
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
ERROR: Failed to build gem native extension.

The bottom line from one of the only success stories that I found on the net was that you either built everything 64bit or nothing. Easy enough if you want to build all of your dependencies by yourself. The whole point of gems is to have the tools work for you. I wasnt really able to figure this out in the web full of people beating their heads on the same problem each harder than the other and each reaching the same it doesnt work conclusion but I had the fortune of getting completely away from the web long enough to realize that only the client and libraries needed to match the architecture and since all interaction between rails and the database went through a socket the architecture of the client didn’t have to be the same as the database.

so going back to my postgres source tree i did a

...postgresql-8.3.6# make distclean

and then reconfigured the database using the prefix /usr/local32

..postgresql-8.3.6# ARCHFLAGS='-arch i386' ./configure --prefix=/usr/local32/

Then I just had to tel ruby/gem to use the 32 bit libraries. Since ruby uses pg_config I made sure that the 32bit version is in the path first.

# PATH=/usr/local32/bin/:$PATH ARCHFLAGS='-arch i386' \
gem install pg  -- --with-pgsql-dir=/usr/local32/

And we are off but my god what at PITA.

Embedding Quartz Compositions in Cocoa Applications.

Wednesday, January 28th, 2009

Yesterday I asked Greg Borenstein what he was using to do his really cool Arduino presentations to show the hardware alongside the code being used to program it. His answer suprised me. It was a simple Quartz Composition run using Composer. He used it to flip the views put out by his web cam so that they made sense from the users viewpoint. I have been seeing a lot of people using quartz composer to do testing and other cool graphic things.

An example I have been working with takes a camera that I had on a pole with a motor that moved it around like a periscope. The camera is sideways so the view has to be rotated. I did this by hand using Core Image this summer using filters and transforms but wanted to do it in Quartz Composer. The composition looks like this.

And the resulting image like this.

On the way down to UCSF last month I experimented with some code that embeds a quartz composition into an application.

You can download it from our svn repository ( https://ssl.tempusdictum.com/pubsvn/trunks/QuartzSnap/ add this url to your x-code scm repositories) and play with it. It builds into a standalone application.

Most all of the work is done by adding your composition to the xcode project and then placing a Quartz Composer View (QCView) from the objects library in your window using Interface builder. The only code I needed to make my application usable (to take pictures) was the action to save the view to a file.

——————————– CameraViewController.h —————————-


#import <Cocoa/Cocoa.h>
#import <Quartz/Quartz.h>

@interface CameraViewController : NSObject {

IBOutlet NSButton *SnapButton;
IBOutlet QCView *CameraView;
NSImage    *TheSnapShot;
NSData *theSnapData;

}
- (IBAction)DoSnapShot:(id)sender;
@end

——————————– CameraViewController.m —————————-


#import "CameraViewController.h"

@implementation CameraViewController

- (IBAction)DoSnapShot:(id)sender {
   theSnapData = [[CameraView snapshotImage] TIFFRepresentation];
   int runResult;
   NSSavePanel *sp = [NSSavePanel savePanel];
   [sp setCanSelectHiddenExtension:YES];
   [sp setRequiredFileType:@"tif"];
   runResult = [sp runModalForDirectory:nil file:nil];
   if (runResult == NSOKButton) {
     if (![theSnapData writeToFile:[sp filename] atomically:YES])
       NSLog(@”Well that didn’t work!”);
   }
}

@end

And that is pretty much it.

Compared to the several pages of code it took to get the same results using Core Image this was a snap.