You are viewing uncle_toby

The Geek Parade Below are the 10 most recent journal entries recorded in the "uncle_toby" journal:

[<< Previous 10 entries]

November 4th, 2008
09:57 am

[Link]

On today, the high holy day of, err, democracy

not me: I voted absentee. And you?

Current Location: home with the kit-kits

(3 comments | Leave a comment)

September 13th, 2008
10:49 pm

[Link]

David Foster Wallace is dead at 46
Wallace apparently committed suicide, sez the Times. Man, he's basically my age, though, ah, spectacularly more productive. Infinite Jest isn't one of my favorite novels, but it's certainly one of the books that's shaped how I understand wit. Someone who wrote novels as dark as Wallace's could have had a pretty dark vision of his own.

Anyone for a quick game of Eschaton?

Resquiat in pace, David. I'll read your books again and with a new eye.

Current Location: home with the kit-kits
Current Mood: grieving
Current Music: Simon and Garfunkle, "Kodachrome"

(1 comment | Leave a comment)

September 1st, 2008
12:00 pm

[Link]

so true
cat


Am I part of an excluded segment of society?

Current Location: home with the kit-kits
Current Mood: excluded
Current Music: "Cowboys," Portishead

(1 comment | Leave a comment)

August 26th, 2008
03:56 pm

[Link]

savagery


If your life feels like this, I understand. This is the refugee camp where stuffed mice are protected from the grasping razor-sharp kitteh claws by a few inches. But the kittehs are growing as fast as their stomachs can turn $4/lb cat food into kitteh poo. Growth is not good for refugee stuffed mice.

Current Location: heading back to work
Current Mood: tiredtired
Current Music: "E-boy the letter," REM

(Leave a comment)

August 24th, 2008
03:15 pm

[Link]

goatse, disney, and Rick.
I think it's very funny that in a Digg post showing Disney pix that imply the goatse horror is commented upon by a RickRolling. As a meta-commenter said, "goatse was the original, slightly more vicious Rick Roll." Each generation has to re-invent sex, drugs, and apparently goatse.

Current Location: home with the kit-kits
Current Mood: amusedamused
Current Music: "Buckets of Rain," Bob Dylan

(Leave a comment)

August 21st, 2008
10:57 pm

[Link]

paper clips and duck (sic) tape
This is relevant to TextMate users, not so much to others. Let's say you're writing some code, and it ends up looking like this:

# $Id:$
# this is the first line. this should be wrapped to the line above.
#
# This is a second paragraph that should be wrapped into some number
# of additional, I mean to say, extra lines.
#
# 1. First, we should wrap this line to somplace under the 'F' in First.
# 2. But this line is separate, and should begin a new odyssey of wrapping, wrappage?
# Either way, here in number two there's a lot to be said, and a lot to wrap.
# Really.
# 3. And one more.
# 3a. this is a long subpoint. These may not happen very often, but when they do, they can be very important.
# 3b. Other subpoints are short.
# 4. and so it goes.
#
# - First, we should wrap this line to somplace under the 'F' in First.
# - But this line is separate, and should begin a new odyssey of wrapping, wrappage?
# Either way, here in number two there's a lot to be said, and a lot to wrap.
# Really.
# - And one more.
# -- this is a long subpoint. These may not happen very often, but when they do, they can be very important.
# -- Other subpoints are short.
# - and so it goes.

very_important_function_immediately_below_comment()
self_version = "$Rev$"

# important whitespace above and below!

my_func <- function(x) {
# Here is an indented comment. Like its friends, it goes on for a long
# time, and it
# has some wrapping issues.
1 == 1
}


What a mess -- very hard to read. TextMate's reformat command (^Q) will make it worse because it's not very smart about what a comment looks like. In emacs, you can load filladapt.el (see below) and with a quick M-q, get this:

#!/usr/bin/env R
# $Id:$
# this is the first line. this should be wrapped to the line above.
#
# This is a second paragraph that should be wrapped into some number
# of additional, I mean to say, extra lines.
#
# 1. First, we should wrap this line to somplace under the 'F' in
# First.
# 2. But this line is separate, and should begin a new odyssey of
# wrapping, wrappage? Either way, here in number two there's a
# lot to be said, and a lot to wrap. Really.
# 3. And one more.
# 3a. this is a long subpoint. These may not happen very often,
# but when they do, they can be very important.
# 3b. Other subpoints are short.
# 4. and so it goes.
#
# - First, we should wrap this line to somplace under the 'F' in
# First.
# - But this line is separate, and should begin a new odyssey of
# wrapping, wrappage? Either way, here in number two there's a lot
# to be said, and a lot to wrap. Really.
# - And one more.
# -- this is a long subpoint. These may not happen very often,
# but when they do, they can be very important.
# -- Other subpoints are short.
# - and so it goes.
very_important_function_immediately_below_comment()
self_version = "$Rev$"

# important whitespace above and below!

def my_func(x):
# Here is an indented comment. Like its friends, it goes on for a
# long time, and it has some wrapping issues.
1 == 1
}

This functionality was really important for me in emacs, and TextMate has nothing like it (as far as I can tell). There's a solution, though: use emacs, as <http://gragusa.wordpress.com/2007/11/11/textmate-emacs-like-indentation-for-r-files/>this guy</a> demonstrated. (this might be obvious to someone deep in unix think: if you like what a tool does, can you coerce the tool to do that thing in your context?) The code below works with a easily configured TextMate bundle to push a comment in a file you're editing with TextMate out to emacs as a filter to reformat the comment, then paste it back into the document.

Go to Bundles -> Bundle Editor, create a new bundle, then create a command in that bundle. Paste the code below into the text box. This code is a simple python program that gets the comment in and out of TM and emacs. Then set the drop downs as shown in the screenshot.




For this to work, you need to have emacs available (the default version in OSX is good), and you need filladapt.el on your emacs search path; get it from the emacs wiki. If you have a directory at $HOME/emacs, put filladapt.el in it.

The python code below is pretty hacky, but there are reasons for some of it. The first is that I wrote this in about an hour and a half, and I haven't cleaned it up much. Furthermore, R's language definition isn't smart enough to recognize multi-line comments, so you can't use the Bundle's tool to export the scope to stdin. The only way to grab the comment is to dig it out of the file. Bug & style fixes most welcome.

#!/usr/bin/env python
import sys, os, collections, copy
from tempfile import mkstemp
from commands import getstatusoutput

elisp_snippet = """
(find-file "%s")
(push (expand-file-name "~/emacs") load-path)
(require 'filladapt)
(filladapt-mode)
(fill-region (point-min) (point-max))
(save-buffer)

"""

def get_data():
# yick. this could be a regexp (\n[^#])*(\n\s*#)+(\n[^#])*
fulltxt = [line.rstrip() for line in sys.stdin.readlines()]
line_ptr = int(os.environ['TM_LINE_NUMBER'])-1
comment = collections.deque()
comment.append(fulltxt[line_ptr])
start = sys.maxint
stop = sys.maxint
# migrate up, then down to get the rest of the comment.
for i in range(line_ptr-1, -1, -1):
line = fulltxt[i].strip()
if not line.startswith('#') or i==0:
start = i
break
comment.appendleft(fulltxt[i].rstrip())
for i in range(line_ptr+1, len(fulltxt)):
line = fulltxt[i].strip()
if not line.startswith('#'):
stop = i
break
comment.append(fulltxt[i].rstrip())
return fulltxt, comment, start, stop

def dump_lines(file_h, contents):
file_h.write('\n'.join(line.rstrip() for line in contents))
file_h.write('\n')
file_h.close()

file_contents, comment, start, stop = get_data()
file_contents = list(file_contents)

data, data_name = mkstemp()
data = file(data_name, 'w')
last_lineno = stop+1
comment_lines = copy.deepcopy(file_contents[start:stop])
dump_lines(file(data_name, 'w'), comment_lines)

# yick! this should be piped via stdin
elisp, elisp_name = mkstemp('.el')
elisp_lines = [";; comment in file lines %i - %i" % (start, stop)] \
+ (elisp_snippet % data_name).splitlines()
dump_lines(file(elisp_name, 'w'), elisp_lines)


# execute emacs: here's where the work is done. note ONE hyphen in option.
# this runs ok from the cmd line but not from here. Interesting.
#status, output = getstatusoutput(
# 'echo "%s" | emacs -Q -script - ' % elisp_snippet)
status, output = getstatusoutput('emacs -Q -script %s ' % elisp_name)
if status !=0:
print "emacs crashed: return code=%s, dying. cmd-Z to get back." % status
raise AssertionError

reformatted_comment = [line.rstrip() for line in file(data_name, 'r').readlines()]
file_contents = file_contents[:start] + reformatted_comment + file_contents[stop:]
print '\n'.join(file_contents)
os.remove(elisp_name)
os.remove(data_name)

There are a lot of things emacs can do to source that we might want to call from TextMate.

I've put reformat on ^Z (don't forget the ^ key under your right hand), but you can put it on any keystroke TextMate can capture. Onward into history with more succinct, better formatted, and more informative comments!

(ok, what's the html for "don't collapse the whitespace" for my code example above? And livejournal ate my my screenshot, which it's never done before. Thanks)

Current Location: home with the kit-kits
Current Mood: pleasedpleased
Current Music: "Outlands," The Orb

(Leave a comment)

August 19th, 2008
12:09 am

[Link]

I think reality is slipping away

Using Photographs to Enhance Videos of a Static Scene from pro on Vimeo.

You take crappy video and a few high-res digital pix. This software mixes the photo detail & exposure into the video, creating scarily great video. Whoa.

Current Location: home with the kit-kits
Current Mood: busy
Current Music: "Ten Men," Morcheeba

(Leave a comment)

August 18th, 2008
10:12 pm

[Link]

noisy little kittehs
The very nice downstairs neighbor knocked on my door this evening: the building doesn't allow you to keep wildebeest in your apartment, he told me. They're little and their paws are soft, but the kittehs are very noise-creating when they've got the friskies.

But then they look like this:

Which is good, because otherwise shit like this would make me insane: At JFK Airport, Denying Basic Rights Is Just Another Day at the Office. The other day I was talking to an otherwise sane Truther. He told me that there's going to be some sort of Reichstag-fire incident in October, which the Bushies will use to keep themselves in power. Nah, I replied, there aren't enough National Guardsmen and cops who would enforce a coup attempt. Then I read this story about the Homeland "Security" people, and it just gets a little easier to buy into the paranoid delusion.

(btw, I call a Godwin point on myself)

Current Location: home with the kit-kits
Current Mood: busy
Current Music: "Feast of the Passover," The Congos

(Leave a comment)

August 5th, 2008
01:23 am

[Link]

pix of piglandia & kittehs
Here's where I spend most of my waking hours:


The battle for alfa-kitteh shakes the heavens, or at least annoys the downstairs neighbors:


They keep Stanyan Street under close patrol:

Current Location: home with the kit-kits
Current Mood: mellowmellow
Current Music: "Haze," Aes Dana

(Leave a comment)

August 2nd, 2008
03:28 pm

[Link]

baby's got game
As humans, we have many reasons to be glad we're not field mice. Wunnie and Zirrz provide me with daily reminders.



Current Location: home with the kit-kits
Current Mood: okayokay
Current Music: "Workingman's Blues #2," Bob Dylan

(Leave a comment)

[<< Previous 10 entries]

Powered by LiveJournal.com