Recently in Apple Category

Fun With Mac and 'say'

| No TrackBacks
This is officially what happens when a geek gets bored. A friend of mine was over tonight, and he showed me the 'say' utility on Mac OSX. Well, you can imagine where this went. Say no more:

#/usr/bin/env python

from htmlentitydefs import name2codepoint as n2cp
import re
import urllib2
import os
import time
import string

class HTMLDecode(object):
    '''http://snippets.dzone.com/posts/show/4569
       There is absolutely no reason for this to be in a class. I just put it in one.
    '''
    __slots__ = ['substitute_entity','dcdhtmlent']
    def substitute_entity(self, match):
        ent = match.group(3)
        if match.group(1) == "#":
            if match.group(2) == '':
                return unichr(int(ent))
            elif match.group(2) == 'x':
                return unichr(int('0x'+ent, 16))
        else:
            cp = n2cp.get(ent)
            if cp:
                return unichr(cp)
            else:
                return match.group()

    def dcdhtmlent(self, string):
        entity_re = re.compile(r'&(#?)(x?)(\w+);')
        return entity_re.subn(self.substitute_entity, string)[0]

class SpeakFarkHeadlines(object):
    '''This is what happens when you are bored and/or easily amused.'''
    __slots__ = ['headlines','speak']
    def __init__(self):
        self.headlines = []
        dcdr = HTMLDecode()
        response = urllib2.urlopen('http://www.fark.com')
        headline_re = re.compile(r'<span\sclass="headline">(.*?)</span>')
        while True:
            try:
                search = re.search(headline_re, dcdr.dcdhtmlent(response.next().encode('UTF-8')))
                if search:
                    self.headlines.append(search.group(1))
            except StopIteration:
                break

    def speak(self):
        for entry in self.headlines:
            print entry         # Below is nasty hack for shell string scanning and quotes
            os.popen('say \'%s\'' % string.replace(entry, '\'', ''))
            time.sleep(5)

app = SpeakFarkHeadlines()
app.speak()

Now just sit back and have a good chuckle.

My new iMac

| No TrackBacks
Well folks, after six long years of pulling out my credit card only to have that little something inside me pull away, I finally did it -- yes I got an Apple computer. And, what do I think about it? Well, I can't believe I didn't do it six years ago!

I decided on the 20" iMac. It took a whole 30 minutes and I was drowning in the abyss of elegant computing. The UI is absolutely fantastic, applications just work, bluetooth just works, and it's really so simple anyone can make their way around within a short amount of time. Now, one of the niftiest features is Ctrl-Cmd-D while hovering over a word in a Cocoa application -- instant dictionary. Or, how about Cmd-Shift-D, insant search for your files, applications or whatever else you need to find.

I installed VirtualBox and immediately put Linux Mint in a VM, and Cmd-F, voila, now I'm full screen in Linux Mint! Anyway, these are just a couple of the cool features I've tripped across. I opened up a terminal to pleasantly find the BSD userland around me. All the familiarity was there -- Perl, Python, Bash, and on and on.

I look forward to discovering all the little niceties Apple has put into OSX and continue using all the open source tools I have been using over the last 12 years. One thing of interest is PyCocoa application development. Apparently, XCode supports this right out of the box.

What else should I be looking for...