« January 2007 | Main | April 2007 »

February 21, 2007

Vim syntax files and highlighting

For about the 4th time, I've wasted an hour trying to figure out why my highlighted searches in vim would highlight the searched for phrase with white text on a yellow background; which is virtually unreadable. Since I work on about 4 different computers, I usually just scp my .vimrc to each computer and I'm good to go, however, the search highlighting problem would always reappear when I starting to use a new host.

I use vim with a black background. In the past, I've put the following command in the file .vim/after/syntax.vim:
highlight Search term=reverse ctermfg=0 ctermbg=3 guibg=Yellow

Vim will source any files in the after directory when it's done doing all of the other normal runtime sourcing. With the above command, my searches would now be highlighted with black text on a yellow background.

When troubleshooting syntax issues, I've found the following commands to be eminently helpful.
:highlight - will show you all of the defined highlight groups and with a sample of what syntax
highlighted text will look like when applied. It also gives you the definition string for each group.

:help syntax (gives you all you need to know about syntax highlighting)

:help group-name, shows you some of the most common syntax groups and if syntax highlighting is working properly, what each group looks like with your current syntax profile.

In order to make this fix a bit more portable, I took the line from .vim/after/syntax.vim and put in in my .vimrc. I'm not sure why I didn't think of putting it there in the first place.

if &t_Co > 2 || has("gui_running") syntax on set hlsearch highlight Search term=reverse ctermfg=0 ctermbg=3 guibg=Yellow endif

If you're curious about the if statement, it just means, the terminal has more than 2 colors, or is gvim. You can read more output codes like &t_Co (number of colors) with
:help terminal-options

Posted by mark at 2:49 PM | Comments (2)

How should the church answer the MySpace revolution?

My friend Andy recently posted a great blog entry about communication, social networking and what that means for relationships. He quotes Stephenie Bennett of BreakPoint,

"Using MySpace broadens the reach of interpersonal communication but also tends to devalue and diminish the richness of relationships by truncating the process of communication itself."

You should read the rest.

Posted by mark at 9:32 AM | Comments (0)

February 17, 2007

MySQL hack of the day

I was doing some work on an older version of mysql (3.23.58 to be exact) today, and had to do a multi-table update, which isn't available on that version (at least I couldn't get it to work). Here's the relevant schema:

table contacts
id INT
donor_id INT (foreign key)
...

table donors
id INT
status ENUM ...
...

table temporary_donors_to_contact_ids
donor_id INT
contact_id

I was trying to backfill the donors table, and had to subsequently update the contacts table with the appropriate foreign key from the donor auto_incremented id. If I were on a current version of mysql the query would most likely look like something this: update contacts c, temporary_donors_to_contacts_ids t set contacts.donor_id = t.donor_id where c.id = t.contact_id; # untested, and sheer speculation. I do this type of thing so infrequently, there might be an elegant single query solution with this version of MySQL, but I didn't want to waste too much time since I was on such an old version.

Anyway, I was really pulling my hair out, when I thought of this terribly hacky solution that was so crazy I thought I'd post about it.

I quit mysql and ran this from the command line:

# mysql database -u mark -p -e "select 'update contacts set donor_id =', donor_id, 'where id =', contact_id, ';' from temporary_donor_to_contact_ids" > /tmp/donor_updates.sql # cat /tmp/donor_updates.sql | tail -n+2 > updates.sql # mysql database -u mark -p < updates.sql

Those of you familiar with mysql, know that when you run a query in the mysql client, it will output the results formatted in a table. When using mysql -e, it doesn't output the pipe delimiters. I was planning to strip those out using the venerable CTRL-V (Visual Block) mode in vim.

It worked so well, I just might use it again in the future -- metaprogramming sql statements ... very hacky, but pretty cool!

Update: I found in the mysql documentation that "Starting with MySQL 4.0.4, you can also perform UPDATE operations covering multiple tables." So, what I was doing wasn't possible with the version I was using.

Posted by mark at 3:39 PM | Comments (0)

February 6, 2007

Ice climbing trip

I just returned from my annual ice-climbing trip with my brother in law Dan, and our friend Ethan from Nashville. Dan and I left around 3:00AM on Thursday, picked up Ethan at JFK airport in NY, and arrived in North Conway, NH around 5:00PM.

On Friday, we climbed Standard Route, one of the coolest climbs in the area. It's rated 3+, and the ice was really fat. It's about 250 feet high. The first belay is in a cave about 100 feet up, with some great views.

On Saturday, after 6-8 inches of fresh snow, we hiked to Arethusa Falls, the highest waterfall in NH. It's a really scenic spot, and sheltered from the wind, which was nice since the wind was really blowing that day. We climbed right up the center of the falls. Right near the top, the ice was really slushy and you could see running water through the ice-screw holes. At one point I punched a softball sized hole through the ice and at that point the crust was only a centimeter thick. Anyway, it was pretty unnerving and cool at the same time.

Dan was hosting a Super Bowl party at his house, so we left at 2:52AM on Sunday in order to get back in time. Nate, you had better come next time!

You can see all of the pictures here

Posted by mark at 9:34 AM | Comments (0)