I’ve just put the finishing touches on a silly little project I’ve been working on this week called emoooo.com
Check it out 🙂
flvThing is released
I’ve released flvThing on the www.automagic-software.com web site. It seems to play every flv file I’ve thrown at it quite nicely 🙂
The flv files are played using the installed flash player which is hosted inside a WebView control. The application creates a tiny very stupid web server that serves up the flash files as well as the flv file for the flash player to load. It seems to work pretty well 🙂
OmniGraffle is SO cool!
I’ve been building a simple little app to play FLV files on the Mac and I should be releasing it some time over this weekend. I needed to make some icons and I threw them together in OmniGraffle Pro. Go check out www.omnigroup.com for more details.Â
Â
I’ve used it a few times for this sort of thing. Here’s an example of what somebody who has no graphic design skills can accomplish very quickly ;)Â
Â
Â
Â
Â
I’m pretty happy with it 🙂 It looks pretty good shrunk down to 128×128 and the alpha channel comes out when I export is as a PNG :)Â
Â
Blog spam and other stuff
I finally got around to cleaning up the spam on this blog.
Unfortunately it looks like I zapped a couple of legitimate comments in the process however 😉
I’ve been really busy of late working and looking after the monster baby (who just recently turned 1 year old).
On the train to and from work I’ve been building a simple little database tool for myself. I’ll probably be releasing an alpha some time soon (although when soon is I could not say exactly 😉 )
It’s a Objective-C cocoa app that connects to pretty much any database that has a JDBC driver.
It features syntax hilighting, simple code completion for SQL syntax (and I’m working on making it do code completion for database objects) and the big feature for me is tabbed based query results along with tabbed documents. It’s already pretty usable, although I still jump back to CocoaMysql on occasion for some things. If you’re feeling brave and want to give it a try feel free to email me at daniel@automagic-software.com
Multiple ruby on rails applications under different folders served by Apache on Mac OS X
I’ve been doing quite a bit of development recently using Ruby on Rails under Mac OS X. Unfortunately it can be a little tricky to get rails apps deployed nicely under Apache. The machine I’m using is an aging G4 with very little RAM so running rails apps in CGI mode is very slow! Initially I tried FastCGI, but I found it to be unreliable :(Â
After a bit of looking about on the net I came across SCGI ( http://www.mems-exchange.org/software/scgi/ ) and some code to use it to run rails. apps ( http://www.zedshaw.com/projects/scgi_rails/ ).Â
Installing these pieces is pretty straight forwardÂ
Â
1. download and install the SCGI apache moduleÂ
2. install the cmdparse gem (sudo gem install cmdparse)Â
3. install the highline gem (sudo gem install highline)Â
4. install the SCGI rails runnerÂ
5. configure your rails apps for SCGI by executing scgi_ctrl config in each rails app root folderÂ
Â
Make sure that each of your rails apps has a different port selected in the config/scgi.yaml fileÂ
Â
Next we need to update the Apache config file /etc/httpd/httpd.confÂ
Â
LoadModule scgi_module libexec/httpd/mod_scgi.soÂ
AddModule mod_scgi.cÂ
Â
<IfModule mod_scgi.c>Â
# matches locations with a dot following at least one more characters, that is,Â
# things like *,html, *.css, *.js, which should be delivered directly fromÂ
# the filesystemÂ
<locationmatch \..+$>Â
# don’t handle those with SCGIÂ
SCGIHandler OffÂ
</locationmatch> Â
</IfModule>Â
Â
Alias /app1 “/Library/WebServer/RailsApps/app1/public”Â
SCGIMount /tbgmon 127.0.0.1:9999Â
<directory “/Library/WebServer/RailsApps/app1/public”>Â
Options +FollowSymLinksÂ
Order allow,denyÂ
allow from allÂ
</directory>Â
Â
Alias /app2 “/Library/WebServer/RailsApps/app2/public”Â
SCGIMount /app2 127.0.0.1:9998Â
<Directory “/Library/WebServer/RailsApps/app2/public”>Â
Options +FollowSymLinksÂ
Order allow,denyÂ
Allow from allÂ
</Directory>Â
Â
Now we start each of the SCGI server processes by running the scgi_ctrl start command in each rails app root folder, bounce apache using sudo apachectrl graceful and the rails apps should be up and running from http://localhost/app1/ and http://localhost/app2/Â
Â
That is only half of the story however. We need to have the SCGI server processes start when the machine boots. The way to do this under Mac OS X is to create a startup item. A startup item consists of a couple of files in a folder under /Library/StartupItems. One is a .plist file and the other is a shell script.Â
Â
Create a folder called SCGI under /Library/StartupItems and then create the file StartupParameters.plist with the following contentÂ
Â
{Â
Description = “SCGI”;Â
Provides = (“SCGI”);Â
Uses = (“Web Server”);Â
}Â
Â
Next create a file called SCGI and paste in this textÂ
Â
#!/bin/shÂ
Â
##Â
# SCGIÂ
##Â
. /etc/rc.commonÂ
Â
StartService ()Â
{Â
    echo “Starting SCGI servers”Â
    Â
    pushd /Library/WebServer/RailsApps/app1/ > /dev/null ; /usr/bin/scgi_ctrl start ; popd > /dev/nullÂ
    pushd /Library/WebServer/RailsApps/app2/ > /dev/null ; /usr/bin/scgi_ctrl start ; popd > /dev/nullÂ
}Â
Â
StopService ()Â
{Â
    echo “Stopping SCGI servers”Â
    ps ax | grep scgi | grep ruby | awk ‘{print $1}’ | xargs killÂ
}Â
Â
RestartService ()Â
{Â
    StopServiceÂ
    StartServiceÂ
}Â
Â
RunService “$1”Â
Â
According to the SCGI rails runner docs there is an option to choose the root folder of the rails app, but I couldn’t get it to work. I suppose I should contact the author about it one of these days ;)Â
Â
Now with any luck the next time your machine reboots the SCGI servers should be started and Apache should forward requests on to your rails apps.Â
The joys of coding with a child on your lap
Well, for one you can only do it one handed!
Also you have to be ready for sudden lunges towards the keyboard. Bang bang bang go the keys. Oops a wrong click or an inopportune Enter and say goodbye to all that work.
Still it is nice for the little one to see what Daddy does all day, even if I have to spend most of the time stopping her from eating any CDs and other things I’ve foolishly left just within reach 😉
The monster child expresses her undying love for Daddy’s G5
Cocoa bindings
I have to say that Cocoa bindings are one of the coolest things to some to Cocoa in a long time.
It takes a bit of getting used to however, and the documentation isn’t the greatest. One of the things that had me stumped for a bit was how to have a button‘s enabled flag depend on more than one edit field having a value. There was only one Enabled binding. It seems that Interface Build adds more Enabled bindings as you create them. So you add an Enabled binding, and all of a sudden in the bindings tab appears Enabled2. Add another one and what do you know Enabled3 magically comes into existence 🙂
I spent a little while looking to see if there was some way of doing something like Enabled = IsNotNull(field1) and IsNotNull(field2) and IsNotNull(field3), when all I had to do was just add them in.
It’s nice when the tools are smart like this, although it would also be nice if there was some documentation that said something like this would happen. I guess I should have know it would do that since it makes sense for it to do so. One of the nice things about Apple software is that it tends to just work (most of the time).
The cocoa rendering system is really nice
For a secret project I’m currently working on I needed to make a NSTextView that resized its contents so that it was always fully visible regardless of how many lines of text were in there. Coding something like that under Windows would have been pretty awful (especially since the text needs to still be editable), but cocoa made it a snap. Just make sure that the ratio of the control bounds and the parent controls frame is correct every time the text changes 🙂 The more I use cocoa, the more I want to use it, and the less I want to go back to other systems.Â
Â
From what I understand the Microsoft .Net stuff would allow a similar approach, and the Java swing libraries would definitely allow itÂ
Blog APIs
It can be quite annoying when an application claims to support an API and actually doesn’t 🙁
I’ve been working on BlogThing off an on for about a week or so. Originally I used a bit of the metaWeblog API and a bit of the MovableType API. I’ve since standardized on metaWeblog and removed the references to MovableType. 🙂
Now, I’ve successfully tested BlogThing against WordPress and Typo however, Blojsom, while it claims to support the metaWeblog API it soon becomes apparent that this is not the case 🙁
Accessing the string and attribute data in a NSTextView
NSTextView stores its data in a NSTextStorage object. NSTextStorage descends from NSMutableAttributed string, so that gives us a clue.Â
The easiest thing to do is to make a category on the NSAttributedString class to do whatever it is you want containing something like the following.Â
Â
    NSRange range;Â
    int i;Â
    int L = [self length];Â
            Â
    i = 0;Â
    while(i<L) {Â
        // get all the attributes we are interested inÂ
        NSDictionary* attributes = [self attributesAtIndex: i effectiveRange: &range];Â
        NSAttributedString* attPart = [self attributedSubstringFromRange: range];Â
        NSString* part = [attPart string];Â
        NSFont* font = [attributes objectForKey: NSFontAttributeName];Â
        NSColor* color = [attributes objectForKey: @”NSColor”];Â
        NSParagraphStyle* paraStyle = [attributes objectForKey: NSParagraphStyleAttributeName];Â
        NSShadow* shadow = [attributes objectForKey: NSShadowAttributeName];Â
        NSURL* link = [attributes objectForKey: NSLinkAttributeName];Â
        Â
        NSTextAttachment* attachment = [attributes objectForKey: NSAttachmentAttributeName];Â
        Â
        // process your attributed string pieces hereÂ
Â
        i = range.location+range.length;Â
    }Â
