Archive

Archive for the ‘programming’ Category

a better .pythonrc?

January 24th, 2009 Bob No comments

Over on this blog, I pointed out a bug in some code. Stupid blogger won’t let me format a better version, so I’ll post it here:

try:
    import readline
except ImportError:
    pass
else:
    import rlcompleter
    import os.path
    import atexit

    class irlcompleter(rlcompleter.Completer):
        def complete(self, text, state):
            if text == "":
                readline.insert_text('\t')
                return None
            else:
                return rlcompleter.Completer.complete(self,text,state)

    readline.parse_and_bind("tab: complete")
    readline.set_completer(irlcompleter().complete)

    # Restore our command-line history, and save it when Python exits.
    history_file = os.path.expanduser("~/.pyhistory")
    if os.path.exists(history_file):
        readline.read_history_file(history_file)
        def save_hist():
            import readline
            readline.write_history_file(history_file)
        atexit.register(save_hist)

    # Clean up the namespace.
    del readline
    del os.path
    del atexit
Categories: programming Tags:

would Camus’ code be elegant or absurd?

December 12th, 2008 Bob No comments
Categories: god, programming, religion Tags:

who’s a lazy bum?

May 25th, 2008 Bob No comments

I’ve always been happy to read that laziness in a programmer is a virtue. How much work is it really to open iTunes, make sure the Music library is selected, click File->Import, navigate to the desktop, select the folder that contains the songs I want to add, pick that folder, wait for the import to finish, switch back to the desktop, and finally drag that folder of songs into the trash?

Too much work for me. Just typing it all tires me out.

So here’s my first Automator workflow, saved as a Finder plugin.

You can download it here.

Open it, then File->Save As Plugin…, name it, ‘Import into iTunes’, and now it’s just right-click on that folder of songs, then More->Automator->Import into iTunes.

Time for a snack.

Categories: OSX, programming Tags:

how many columns is correct?

February 28th, 2008 Bob No comments

My first elisp function knows.

(defun eighty-columns ()
  (interactive)
  (set-frame-width (selected-frame) 80))
(global-set-key (kbd "C-c 8") 'eighty-columns)

Categories: emacs, lisp, programming Tags:

simple descriptions of recursion, monads, and closures

December 17th, 2006 Bob No comments

Joachim Durcholz gives the simplest descriptions of recursion, monads, and closures that I’ve run across in a post to comp.lang.scheme:

Don’t give recursion a name, say “yes, a function is allowed to call itself – just make sure that every invocation does some real work”.

Don’t give monadic I/O a name, say “functions aren’t allowed to have side effects, the code just generates a description of the effects”.

Don’t give closures a name, say “you can pass around an unevaluated ‘expression with holes’, just consider that the variables that were defined at the place where the expression is written will be taken from that place, not from the place where the thing will be evaluated”.

Categories: programming Tags: