Daring Fireball’s TitleCase Ruby Conversion

I recently took up the challenge from John Gruber and Dan Benjamin to port John’s TitleCase.pl Perl script to an equivalent Ruby version. It seemed to me that converting someone’s script to another language would be a fun experiment to help learn any language. I was right.

I set up a git repository at GitHub.

I decided to write an extension to the String class in Ruby, as that would allow you to use this String#titlecase method anywhere and you could therefore write a standard input processing script trivially with this library included via a gem. Writing the extension also gave me a great excuse to learn more about RSpec, a nice Ruby testing library. I wrote the tests in RSpec, but I admit my tests were a quick hack to get them working at 3 in the morning, not good spec tests. Maybe someday I will convert them into real sentences of intent, as they should be. Either way, it was fun to try out Test Driven Development, and using the autotest function of the ZenTest gem to watch the tests start to pass as the script came along.

So after a few hours of learning about RSpec, ZenTest, all the tests from Gruber pass, even the one he lists as not working with his script. I took a different approach in how to process the titles, so there are not as many gotchas to fix up after processing either.

If you find it useful, let me know. And of course, fork the repo and send back some more test examples and any bugs you find.

P.S. Daniel also converted my Ruby version to PHP. We are going to use it at BitLeap for various things. He had also said about seeing about making a WordPress plugin out of it. So, I will prod Daniel to see if he will setup a public repository for it.

BitLeap Cap Tower Destruction

We destroyed the cap tower in our old office at work. It was great, Andy gave it a good swat with a wiffle ball bat. I put together a video so you can see it in slow-motion too. Check out the video on the BitLeap Blog.

Update: And BitLeap has decided to do a free contest: Whoever comes closest to guessing the number of caps that make up the tower by February 1st, gets a $50 gift card to either Amazon, Starbucks, Apple or Barnes & Noble. Very cool, I wish I could enter.

Coloring in Reggy

So, I have already seen a few people not entirely happy with the way I implementing coloring of groups in the newest Reggy release. I figured I would just give my view of what I did and why.

My goal with Reggy from the beginning was to be simple and not look like junk. There are many other regular expression testers out there. If you like them, use them. I happen to think many of them look like dirt. Reggy may not be gorgeous, but it’s certainly not dirt either.

The first implementation of coloring was actually by a volunteer (Justin Bakse) who was nice enough to pass the code back to me to look over. It was a good start for sure. But it used an implementation that I just don’t want — for simplicity’s sake: you pick X amount of colors, then for each match the code picks one of the colors, then the next and so on, repeating. This is visually distinctive if you pick a bunch of crazy colors, but I am still thinking that picking 10 colors in the preferences is not the Mac experience I want to provide for people.

My implementation looks like this:

// Add new color to matched ranges
bool countUp = YES;
float r,g,b,a;
[[NSUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] objectForKey:@”match_color”]] getRed:&r green:&g blue:&b alpha:&a];
for ( unsigned int i = 0; i < [matchedRanges count]; i++ )
{
    NSRange thisRange = NSRangeFromString([matchedRanges objectAtIndex:i]);

    // Generate new color from base color
    if ( i > 0 && [[NSUserDefaults standardUserDefaults] boolForKey:@”color_submatches”] )
    {
        if ( r > 0.8 || g > 0.8 || b > 0.8 ) countUp = NO;
        if ( r < 0.0 || g < 0.0 || b < 0.0 ) countUp = YES;

        if ( countUp ) { r += 0.2; g += 0.2; b += 0.2; } else { r -= 0.2; g -= 0.2; b -= 0.2; }
    }

    [[testingStringField textStorage] addAttribute:NSForegroundColorAttributeName value:[NSColor colorWithCalibratedRed:r green:g blue:b alpha:a] range:thisRange];
}

Pretty simple I think. Get the color components of the match string color preference (r, g, b, a). Then for every match other than the first match, increment each RGB component by 20% (this is a 0 to 1 scale) or decrement depending on the component values. I came out with 0.8 as a maximum value by just testing a bunch of different match colors and found 0.8 to be around the acceptable range of readability against a white background for most colors. The increment or decrement step value of 0.2 was another value I just played around with until there was a good balance between having each color step look different, yet still provide a small enough value so as to allow as many steps as possible between 0 and 1.

If anyone has a more elegant solution, please propose it. I am not a genius, I just know what I like. And I don’t like having to pick a bunch of colors. I like the simplicity of using one color with differing brightness as it still seems that the user has control over the coloring, but maybe I could go for a color generation scheme that is based on color theories like complements or triads. Or maybe I am the only one that is this picky?

Reggy 1.3 Is Out, Get It!

I pushed out a new version of Reggy this morning.

Release Notes:

  • added preference to apply sub-match/capture group coloring: each match or capture group gets a slightly different shade of color — especially nice for nesting matches
  • added preference to automatically use the clipboard contents on startup for the regular expression and/or the testing string
  • added menu items to paste the clipboard directly into either the regular expression (Command+Shift+V) or the testing string (Command+Option+V)
  • added a new and improved Reggy icon (Leopard Compatible/Resolution Independent)
  • added help link for regular expression syntax preference (goes to wikipedia)
  • updated regular expression engine
  • simplified preferences window

Thanks should go to Steve Huff at the Harvard-MIT Data Center for requesting the startup clipboard preferences. It was a great idea that, along with the menu items to quickly paste into the fields, many people will be happy to see.

So anyways, Leopard’s icon size is big, and I mean big:

Reggy Leopard Icon

I had to redraw the icon this morning because the clipping icon I was using was swiped from Tiger. I figured it would probably be proper of me to not steal the clipping icon.

I am really excited to get onto developing a Leopard-only 2.0 version. I am starting to read through the new documentation now. Let me just say thank you to Apple for making developing stuff like Reggy fun and easy.

The Adobe Updater Is My New Favorite App…

TO HATE.

Those who use the newest of Adobe’s Creative Suites on old hardware (a 1Ghz PowerBook G4 for me) can sympathize I am sure.

My laptop is getting old, yes I know. But Adobe, your updater application slows my computer down more than Photoshop and Illustrator do! Now, I am kind of used to slow these days, so I normally wouldn’t complain too much if it weren’t for the craziness I witnessed this afternoon after rebooting from the latest system updates from Apple.

I was never happy with Adobe Updater, so I normally tell it to go away when it does come up. Given that, I had an update to install — Acrobat 8.1 Update. Fine, I just restarted, so I’ll let it go through before I start back on my work.

Maybe not a good idea.

Steps to update Acrobat 8 Professional

  1. Hit update on the Adobe Updater. (My CPU and HD will now be pegged for the install, Okay I am used to that.)
  2. Waiting about 10-15 minutes…

    waiting screenshot

  3. The install is seemingly 90% completed or so. Now a dialog comes up that says some items need “repaired”. Items like the Safari PDF Plugin, eww, no thanks — too slow. So I uncheck that and let it go to town “repairing the PDF Printer”.
  4. Woops, I see a dialog that says “Wait For App Shutdown Title” — “Please click OK when other apps have stopped” with both Cancel and OK buttons. What? Wait a moment, wait for what app to stop? The updater? Because that’s the only app really running in the Dock. Confused, I click OK.

    It returns. I click OK, again… I see a pattern emerging here.

    looping screenshot

    After a few bouts of click madness just for fun, I click Cancel. I have no idea what that means. The dialog doesn’t read well obviously. Cancel could mean destroy the computer immediately for all I know.

    But then it works. Five minutes later, I am greeted with this screen:

    completed screenshot

  5. Looking at Acrobat’s information in Finder it is indeed updated to 8.1.0.

Utterly slow, confusing and just plain bad Adobe, for-shame.

UPDATE: Looks like Gus Mueller loves the updater too. Thanks for the links Daniel.

Reggy Screenshots

I just made a small upgrade on Reggy’s website for those of you who haven’t used Reggy.

_Screenshots_

Enjoy

Reggy v1.2 Is Ready for You

Are you ready for it?

So, now we have an appcast for you to follow on the new Reggy website. Did some last minute tweaks to make me happy and now it is up on the servers, so go get it!

What changed?

  • added user preferences
    • matched string highlight color
    • regular expression options
    • regular expression syntax
    • check for automatic updates
  • added automatic updates using the Sparkle framework

I hope you like the update. As always, feel free to file bug reports and feature requests on the issue tracker.

I plan on posting a bit of what I see for the future of Reggy soon for those who may be interested.

Reggy’s New Website

Reggy has a new home… reggyapp.com

I needed a site to host some things on to do Sparkle integration, so I went ahead and purchased the domain name to host with.

At some point I hope to do a real website with feeds and such, but for now it gives some information and links to places where Reggy can be seen and/or downloaded.

One of the real benefits of having this site is that hopefully you will be able to check just one place for updates to Reggy in the future.

Update on Reggy Development

Thanks to a few noble users, Reggy’s Bug Tracker is getting use. Most of the issues are feature requests and I am slowly getting time to get to them.

I already have preferences going. Here are a few screenshots to give you an idea of where it’s going:

General Preferences Screenshot

General Preferences Screenshot

Hopefully that will help some people out.

I am not going to release 1.2 until I get Sparkle going for automatic application updates. It looks like that will happen hopefully within this week or next.

Joost Mini-Review

So I was recently given a download from the Joost beta team. I was interested because I had heard some good (and some bad to be frank) things about it. I’ve heard talk about it being the “next big thing” or something. It seems that folks who are saying that have not tried it — while on 1.5Mbps cable.

I love the idea of getting TV over the internet, when you want it. We have not had a traditional TV set for over a year now I believe. Contrary to what some may think, we haven’t died missing out on American Idol or Are you as smart as a first grader? or whatever the “cool” shows are on prime-time nowadays. I am a nerd, I want to see nerdy things. I don’t want to have to watch 30 minutes of commercials just to see 30 minutes of actual programming. So we have gone without for awhile. iTunes has Stargate Atlantis (which isn’t always up to date, but whatever) and any other stuff we want to see usually shows up on Netflix.

I’ll not be long-winded for much longer, I promise. I installed Joost and went immediately to the National Geographic channel. And waited. And waited. After a bit more waiting, it skipped back to another program — the one I had selected before but decided to go past. So, it is beta, I’ll let a little slide. But the buffering is just not smart enough to use daily for me. It is constantly stuttering and the only way to stop it is to pause the program and wait (and keep waiting because there is no indicator that I can see to show you how much is buffered).

The other annoying thing is that you get seemingly random commercial breaks. I will give them points for making them small for now. But you have to wait for the commercials to load. So the process of commercials goes a little something like this:

  1. Watch programming (pausing every minute or so to buffer more without stuttering)
  2. See black screen randomly and wait 30-60 seconds (I presume this is the commercial downloading)
  3. Watch commercial (thankfully this isn’t too long)
  4. Programming seems to return almost immediately (big plus for that at least)

Also odd is the frequency of commercials. On one channel (say Off the Fence Docs) there are almost no commercials, but on another (say National Geographic) they seem to show up every 10 minutes or so. My only guess is that commercials may be up to the content owners?

So the final annoyance I found was that of the 5 or 6 different programs (on different channels as well) ALL of them, after awhile of watching, stopped suddenly and gave me a dialog saying something along the lines of “Sorry, but this program can’t be played right now. Check something else out. Error Number 121″ This is the ultimate annoyance. You are watching something and maybe 3/4 of the way in, it just says, “Oops, sorry, later punk”. I am not sure if this means that their aren’t enough peers to get the video from or what. The network seems to push uploads of around 10-25Kbps when watching programming, but the download really varies, going from nothing up to 70Kbps or so with some peaks a bit higher.

So overall, Joost seems like a neat idea. I am betting it will be a lot nicer for folks with high upload and download speeds (5Mbps/1Mbps), assuming that more people pick it up to increase the download speeds. But we’ll see how it shapes up over the next few releases. I am sure it’s not easy to get peer-to-peer TV to work well, but they are getting there hopefully. I really want Joost to succeed.

Will I use Joost regularly? Probably not. But it’s looking very promising.