Erlang has long had a love hate relationship with external code. There is now “experimental” code in the latest R13B03 release that has support for what they are calling Native Implemented Functions. It is a very basic interface with only 4 functions required to be implemented and a struct and macros for defining your public interface from your native C code. I am got the example code from Paul Joseph Davis’s blog to work. It took some delving into GCC compiler options on OSX and getting Erlang compiled with ./configure --enable-darwin-64bit flag. Now that I have an example working I am re-thinking my inet_mdns implementation. The fact that I can’t get gen_udp:send/4 to work on port 5353 cripples my implementation. I have about 80% of the mdns spec implemented, but without being able to send on source port 5353 it is just a partial solution. I am thinking about just using the Apple mDNSResponder code that is cross platform and I know it works in Java, Python and Objective-C. It shouldn’t be too hard to get a NIF based glue layer working. Since my target platforms are really OSX and Linux and maybe Solaris, I might as well spend some time seeing what I can get working.

 

I am using XCode 3.2.1 for some Cocoa development and I really miss the OPTION-CMD-L short cut in Intellij IDEA that re-formats your current source code file as you have it configured. I found you can get something similar but not as powerful by doing a Edit -> Select All and then CTRL-I in XCode 3.2.1. Not as configurable but it fixes up misaligned braces and other minor annoyances.

 

I have tried all the available plugins for WordPress to do inline code formatting and syntax highlighting. None of them do exactly what I want, which is no scroll bars horizontally or vertically and none of them support Erlang. So I found the best way to get exactly what I want is to use SubEthaEdit and do a Select All and use the Edit -> Copy as XHTML. Yeah it is a mess of ugly XHTML. But I just paste it into the HTML view when creating a post and I am done with it.

 

This is Objective-C code for listing all the files and directories below a given directory. I wrote and tested this on OSX 10.6.2 and XCode 3.2.1.

/*
 This is example code of how to walk a directory recurisively
 and create a flat list of fully qualified names for all the files
 and directories under the supplied virtual root directory.
 */

#import <CoreServices/CoreServices.h>
#import <AppKit/AppKit.h>
#import <stdarg.h>

int main (int argc, const char * argv[])
{
    int result = EXIT_SUCCESS;
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSUserDefaults *args = [NSUserDefaults standardUserDefaults];
    NSString *dir = [args stringForKey:@"file"];
    NSMutableSet *contents = [[[NSMutableSet alloc] init] autorelease];
    NSFileManager *fm = [NSFileManager defaultManager];
    BOOL isDir;
    if (dir && ([fm fileExistsAtPath:dir isDirectory:&isDir] && isDir))
    {
        if (![dir hasSuffix:@"/"])
        {
            dir = [dir stringByAppendingString:@"/"];
        }

        // this walks the |dir| recurisively and adds the paths to the |contents| set
        NSDirectoryEnumerator *de = [fm enumeratorAtPath:dir];
        NSString *f;
        NSString *fqn;
        while ((f = [de nextObject]))
        {
            // make the filename |f| a fully qualifed filename
            fqn = [dir stringByAppendingString:f];
            if ([fm fileExistsAtPath:fqn isDirectory:&isDir] && isDir)
            {
                // append a / to the end of all directory entries
                fqn = [fqn stringByAppendingString:@"/"];
            }
            [contents addObject:fqn];
        }
        
        NSString *fn;
        // here we sort the |contents| before we display them
        for ( fn in [[contents allObjects] sortedArrayUsingSelector:@selector(compare:)] )
        {
            printf("%s\n",[fn UTF8String]);
        }
    }
    else
    {
        printf("%s must be directory and must exist\n", [dir UTF8String]);
        result = EXIT_FAILURE;
    }
    
    [pool drain];
    return result;
}

 

Here are a couple of aliases I create on a fresh OSX machine.

alias dir=‘ls -AlGh’
alias spot=‘mdfind -onlyin . $1

The dir alias is all the most useful ls options all at once.
mdfind is the command line interface to the Spotlight service on OSX. You can use the option -name to restrict the results to only search file names.
The spot alias is the most useful options that I use all the time. A faster replacement for find.

PS1="\[\e[0;37m\][\[\e[m\]\[\e[0;32m\]\u\[\e[m\]\[\e[0;31m@\[\e[m\]\[\e[0;32m\]\h\[\e[m\]\[\e[0;37m\]]\[\e[m\] \[\e[0;37m\][\[\e[m\]\[\e[0;34m\]\w\[\e[m\]\[\e[0;37m\]]\[\e[m\]\n"

Here is what it looks like:

shell preferences

shell preferences

© 2012 Jarrod Roberson: Programming Missives Suffusion theme by Sayontan Sinha