The shared bits

Bacon grease

Mmmmm…..bacon grease…

We’ve been saving bacon grease for a while now and using it in cooking. There is something very satisfying about taking something that you might otherwise throw away and re-using it. We use it frequently in place of butter for greasing a pan to be used on the stovetop. Most recently for pancakes yesterday morning.

The grease keeps very well in a small glass container in the refrigerator covered with plastic and we simply add more grease to the container whenever we cook bacon on the stove.

We find that the grease provides a wonderful depth of flavor to whatever we cook with it and gives a hint of the smell of bacon.

BTW – this was typed on my new iPad…

Project Euler and Math

I’ve always had the sense that there was a lot of math out there that I didn’t know. There is a great deal of graphics math and crypto math and others that I’ve never felt I had much reason to explore – but I recently realized that there’s value in looking into some of this other math.

I’ve known about Project Euler for a while now but only recently did I start trying to solve the problems. My first approach to any problem was just to try to brute force it (I’ve got a speedy modern computer that can do math well, how long can it take to solve these?) but surprisingly it doesn’t always work. I find myself having to go out and do research. Learn about techniques and algorithms for solving math problems and apply them in my own code.

It’s been a wonderfully refreshing lesson in thinking outside my own box. I’ve found that I don’t always know the best solution. There are algorithm tools out there that some incredibly smart people have deduced/devised and learning of and about them is very good for my development both professionally and personally.

Add To Yojimbo with AppleScript

I’ve started using Yojimbo more as an Anything Bucket and I wanted an easy way to get stuff into it. I found several AppleScripts and they were all good, but they were for individual applications. I try to minimize how much I have to think about routine stuff – I’d much rather have code that just “does the right thing” so I set out to meld the scripts into a single one.

I’m quite happy with the results. I’ve got a single shortcut setup (⌘⌥Y) in FastScripts and I can use it in any of the apps that I need to capture from (Mail, Safari, NetNewsWire).

Direct download link

(*

Add To Yojimbo Script

Matt Vanderpol
1.0 - 2010-02-18

Collects tag info and creates a new web archive or note in Yojimbo. Can cancel from tag
collection screen to cancel action.

Currently works from:
  NetNewsWire - creates web archive
  Mail - creates note
  Safari - creates web archive
 
Notifies via growsl on success or failure.

Based on work by:
    John Gruber (Create Yojimbo Bookmark From NetNewsWire - http://daringfireball.net/misc/2007/05/nnw-to-yojimbo-bookmark)
    Jom Correia (Create Yojimbo Note From Apple Mail - http://www.listsearch.com/Yojimbo/Thread/index.lasso?342#2169)
    Jim DeVona (Bookmark in Yojimbo - http://anoved.net/software/bookmark-in-yojimbo/)
   

*)


global gScript, gApplication

-- From: http://daringfireball.net/2009/01/applescripts_targetting_safari_or_webkit
on GetCurrentApp()
    tell application "System Events"
        set _app to item 1 of (every process whose frontmost is true)
        return name of _app
    end tell
end GetCurrentApp

on GetTags()
    -- prompt for tags
    set _tags to {}
    set _dlog2 to display dialog "Set tags (if any) for web archive:" default answer ¬
        "" default button 2 cancel button 1
    set _action2 to the button returned of _dlog2
    if _action2 = "" or _action2 = "Cancel" then
        tell application "GrowlHelperApp"
            notify with name ¬
                "Failure Notification" title ¬
                "Cancel Add" description "User cancelled adding item to Yojimbo" application name gScript
        end tell
        error number -128
    else
        set _answer to text returned of _dlog2
        if _answer is not "" then
            set AppleScript's text item delimiters to ", "
            set _tags to text items of _answer
        end if
    end if
    return _tags
end GetTags

on GenerateMessageText(m)
    tell application "Mail"
        set _sender to sender of m
        set _subject to subject of m
        set _date to date received of m as string
        set _contents to content of m
        set _messageString to "From:" & tab & _sender & return
        set _messageString to _messageString & "Subject:" & tab & _subject & return
        set _messageString to _messageString & "Date:" & tab & _date & return
        set _messageString to _messageString & return & return & _contents
    end tell
end GenerateMessageText

on AddWebArchive(h_URL, _tags, _title)
    tell application "Yojimbo"
        set _new_item to (make new web archive item with contents h_URL)
        add tags _tags to _new_item
    end tell
   
    tell application "GrowlHelperApp"
        notify with name ¬
            "Success Notification" title ¬
            "Import Success" description "Successfully imported \"" & _title & ¬
            "\" to Yojimbo" application name gScript
    end tell
end AddWebArchive

on AddNote(_contents, _name, _tags)
    -- create the new note
    tell application "Yojimbo"
        set _new_item to (make new note item with properties {contents:_contents, name:_name})
        add tags _tags to _new_item
    end tell
   
    tell application "GrowlHelperApp"
        notify with name ¬
            "Success Notification" title ¬
            "Note Created" description ¬
            "" & _name & "" application name gScript
    end tell
end AddNote

on run
    set gApplication to GetCurrentApp()
    set gScript to "Add To Yojimbo Script"
   
    tell application "GrowlHelperApp"
        set the allNotificationsList to {"Success Notification", "Failure Notification"}
        set the enabledNotificationsList to {"Success Notification", "Failure Notification"}
       
        register as application ¬
            gScript all notifications allNotificationsList ¬
            default notifications enabledNotificationsList ¬
            icon of application gApplication
    end tell
   
    if gApplication is "NetNewsWire" then
        set _tags to GetTags()
        tell application "NetNewsWire"
            try
                if (index of selected tab is not 0) then
                    set _tabNum to index of selected tab + 1
                    set _tabURLs to URLs of tabs
                    set h_URL to (get item _tabNum of _tabURLs)
                    set _tabTitles to titles of tabs
                    set _newItemTitle to (get item _tabNum of _tabTitles)
                    my AddWebArchive(h_URL, _tags, _newItemTitle)
                   
                else if exists selectedHeadline then
                    set h_URL to URL of selectedHeadline
                    set _newItemTitle to title of selectedHeadline
                    my AddWebArchive(h_URL, _tags, _newItemTitle)
                   
                else
                    error "No headline is selected."
                end if
            on error error_message number error_number
                tell application "GrowlHelperApp"
                    notify with name ¬
                        "Failure Notification" title ¬
                        "Import Failure" description "Failed to import \"" & newItemTitle & ¬
                        "\" to Yojimbo.  Error: " & error_message application name gScript
                end tell
            end try
        end tell
    else if gApplication is "Mail" then
        set _tags to GetTags()
        tell application "Mail"
            tell message viewer 1
                set _messageList to selected messages
                set _name to subject of item 1 of _messageList
                set _contents to ""
                repeat with m in _messageList
                    set _contents to _contents & my GenerateMessageText(m)
                end repeat
               
                my AddNote(_contents, _name, _tags)
               
            end tell
        end tell
    else if gApplication is "Safari" then
        set _tags to GetTags()
        tell application "Safari"
           
            -- identify the page to create web archive for, if any 
            try
                set h_URL to the URL of document 1
                set _pageTitle to the name of document 1
            on error
                return
            end try
           
            my AddWebArchive(h_URL, _tags, _pageTitle)
        end tell
    else
        tell application "GrowlHelperApp"
            notify with name ¬
                "Failure Notification" title ¬
                "Unknown Application" description "Don't know how to add to Yojimbo from " & gApplication ¬
                application name gScript
        end tell
    end if
   
end run

View in Readability AppleScript

I’ve been using Readability for a while now and it’s an amazingly cool tool. I highly recommend it for anyone who reads anything online.

In the interest of making things easier and more streamlined I’ve written an AppleScript that can load pages in Readability from various sources. The script is smart and “does the right thing” based on which app you’re running. I’ve only had a need for it from Safari, NetNewsWire and Yojimbo so that’s all it’s setup for but it should be easy to extend if you want.

I’ve got the script hooked up to a shortcut using FastScripts.

Direct download link

You will likely want to update the JS variable to match your own Readability styling.

(*

View in Readability Script

Matt Vanderpol
1.0 - February 15, 2010

Based largely on Adam Bell's code from http://macscripter.net/viewtopic.php?id=29702

Supports Safari, NetNewsWire and Yojimbo (bookmarks and web archives. Shows the current
web "document" with Readability (http://lab.arc90.com/experiments/readability/).

Yojimbo needs to open the URL in Safari because I don't see a way to run JS inside Yojimbo.

*)


global gScript, gApplication
set gScript to "View in Readability Script"
set gApplication to GetCurrentApp()

-- From: http://daringfireball.net/2009/01/applescripts_targetting_safari_or_webkit
on GetCurrentApp()
    tell application "System Events"
        set _currentApp to item 1 of (every process whose frontmost is true)
        return name of _currentApp
    end tell
end GetCurrentApp

set JS to "readStyle='style-newspaper';
    readSize='size-medium';
    readMargin='margin-wide';
    _readability_script=document.createElement('SCRIPT');
    _readability_script.type='text/javascript';
    _readability_script.src='http://lab.arc90.com/experiments/readability/js/readability.js?x='+(Math.random());
    document.getElementsByTagName('head')[0].appendChild(_readability_script);
    _readability_css=document.createElement('LINK');
    _readability_css.rel='stylesheet';
    _readability_css.href='http://lab.arc90.com/experiments/readability/css/readability.css';
    _readability_css.type='text/css';
    _readability_css.media='all';
    document.getElementsByTagName('head')[0].appendChild(_readability_css);
    _readability_print_css=document.createElement('LINK');
    _readability_print_css.rel='stylesheet';
    _readability_print_css.href='http://lab.arc90.com/experiments/readability/css/readability-print.css';
    _readability_print_css.media='print';
    _readability_print_css.type='text/css';
    document.getElementsByTagName('head')[0].appendChild(_readability_print_css);"



tell application "GrowlHelperApp"
    set the allNotificationsList to {"Success Notification", "Failure Notification"}
    set the enabledNotificationsList to {"Success Notification", "Failure Notification"}
   
    register as application ¬
        gScript all notifications allNotificationsList ¬
        default notifications enabledNotificationsList ¬
        icon of application gApplication
end tell

if gApplication is "Safari" then
    tell document 1 of application "Safari" to do JavaScript JS
else if gApplication is "NetNewsWire" then
    tell document 1 of application "NetNewsWire" to do JavaScript JS
else if gApplication is "Yojimbo" then
    tell application "Yojimbo"
        -- Can't use JS in Yojimbo so need to open in Safari and run script again
        set _selection to selection
        if length of _selection is 0 then
            tell application "GrowlHelperApp"
                notify with name ¬
                    "Failure Notification" title ¬
                    "Nothing Selected" description "No item selected to view in Readability from " & gApplication ¬
                    application name gScript
            end tell
            return
        end if
        set _item to item 1 of _selection
        set h_URL to ""
        try
            set h_URL to source URL of _item
        on error
            try
                set h_URL to location of _item
            end try
        end try
        if h_URL is not "" then
            tell application "Safari"
                activate
                make new document with properties {URL:h_URL}
                -- Now that document web page is open, call this script again to use readability
                delay 2
                set theUNIXPath to path to me as alias
                set thePosixPath to (POSIX path of theUNIXPath) as string
                run script (thePosixPath)
            end tell
        else
            tell application "GrowlHelperApp"
                notify with name ¬
                    "Failure Notification" title ¬
                    "No URL" description "Can't find URL to view in Readability from " & gApplication ¬
                    application name gScript
            end tell
        end if
    end tell
else
    tell application "GrowlHelperApp"
        notify with name ¬
            "Failure Notification" title ¬
            "Unknown Application" description "Don't know how to view in Readability from " & gApplication ¬
            application name gScript
    end tell
end if

Get Current Application with AppleScript

My recent applescript development required different action based on what application was currently active. Surprisingly, there is no good result for this from google. I pulled this out of a Daring Fireball code example (Writing AppleScripts That Dynamically Target Either Safari or WebKit) and am showcasing it so that others who are looking for the functionality can find it without too much effort.

on GetCurrentApp()
    tell application "System Events"
        set _app to item 1 of (every process whose frontmost is true)
        return name of _app
    end tell
end GetCurrentApp

set _app to GetCurrentApp()

Rebooting the blog

After letting it languish for well over a year, I’ve decided to return to the blog. I’ve realized that my life is marked by consumption. I’m subscribed to hundreds of blogs, I listen to audio books, I watch movies and videos online – but it’s all passive. There’s no synthesis. There’s no creation.

I know that I’ve got thoughts and ideas. I know we’re doing neat things around the house. I know that I’ve got things to share. I just need to make the effort to do more than simply consume.

With all that in mind, I’ve upgraded WordPress and installed a new, cleaner theme. I also really stripped down the categories because I felt like they were just too unwieldy. If you find something broken, let me know and I’ll see what I can do to fix it.

So, keep an eye on this space – the blog will be more than it was before and the focus will be changing. There will be less of the simple, one-off, un-related posts and more actual content. I’ve been working on some AppleScripts to help me keep track of stuff that I’ll be sharing and I’m going to talk more about what we’re doing around the house, in addition to internet technology thoughts at large.

Life After (Fake) Death

When I try to remember how I got here I keep coming back to the day I faked my own death to avoid a meeting with my lawyer.

Prince of Fun and Hijinks

Frederico, Prince of Fun and Hijinks, knew one thing and knew it well – ordinary times called for extraordinary measures.

Teaching Grammar

Gregory has really been picking up words lately and his sentence structure is really growing. On the whole, he’s doing well, he does stumble a bit over irregular verbs.

Gregory: Daddy’s belt was hanged up!
Me: No, Gregory, Daddy’s belt was hung up. Belts are hung, people are hanged.

The Long Dark Coffee-Time of the Blog

Quiet has it been here for a few months.
Busy have I been.
Busy with the house
Busy with work.
Busy with life.

Why is it coffee-time? Because coffee is the drink of choice. It’s where the caffeine grows.

What does this all mean?

The quiet is broken. Some words are coming. May they disjointed though be.

Now, sleep.

Categories