The Rules
  • Feel free to leave constructive criticism, or point out a better way to do something.
  • Personal attacks or flames, on me or anyone else, will be deleted.
  • Past history has shown that 99% of comments I can't read (i.e. those in other languages) to be spam. Therefore, any comment I can't read will be removed.
  • I'm pretty mellow concerning profanity, but excessive (as determined subjectively by me), bad language will be removed.

Friday, April 30, 2010

Downgrading packages in Arch Linux

On occasion (actually today was the first time) there is need to downgrade a package in Arch Linux. Yesterday I did a `pacman -Syu`, which upgraded gcc from 4.4.3 to 4.5.0. Today, I learned that 4.5.0 is unable to compile Moab. You'd think that a new release of your trusty compiler would work at least as good as the last one, but that's a topic (spelled R-A-N-T) for another day. When this catastrophe strikes, you can do the following to recover.


1. On my Arch system, package files are kept in /var/cache/pacman/pkg. Go there.

2. Find the desired package. In this particular case, /var/log/pacman.log told me that yesterday I upgraded from 4.4.3-2 to 4.5.0-1. So my working compiler up until yesterday was gcc 4.4.3.

3. "Upgrade" to the desired package: `pacman -U gcc-4.4.3-2-x86_64.pkg.tar.xz` and `pacman -U gcc-libs-4.4.3-2-x86_64.pkg.tar.xz`

4. Also in my case I'll want to stick with gcc 4.4.3 for a while now, so you can modify the IgnorePkg line in /etc/pacman.conf as follows:

IgnorePkg = gcc gcc-libs

This causes pacman to skip over gcc and gcc-libs when you do a system-wide upgrade (mine prints a warning to say it's being ignored, which I don't consider to be a bad thing).

Thursday, April 8, 2010

Terminal colors, all-day readability, and Arch Linux

A recent system upgrade broke my terminal colors. I don't know what exactly it was, or how it happened, but I opened a new terminal window, did a `ls`, and all my directories were bold and blue again. I personally find this difficult to read as I use a very dark blue background in my terminals (something on the order of #111133).

The solution:

Run the following command to create a default dir_colors file (the file that generates the colors for the ls command):

    `dircolors -p > ~/.dir_colors`
Then, add the following to your .bashrc file:
    # set the TERM variable to a color-enabled type (xterm-color)
export TERM="xterm-color"

# source my own .dir_colors file
if [ -f $HOME/.dir_colors ]
then
eval `dircolors -b $HOME/.dir_colors
fi
This will allow you to customize what colors describe what objects for the ls command.

I personally make the following changes in ~/.dir_colors:
- DIR 01;34
+ DIR 00;36 # directories are cyan and non-bold
Then, I go through and turn off bold (swap 00 for 01) for almost everything. The only things I leave bold are executables and sym/hardlinks. For more info on dir_colors, see
    man dircolors
or
    man dir_colors

Friday, March 5, 2010

Backup Now, Please.

I realize it's been over a year since my last post, and I have a bunch of stuff stacked up. But this was pretty slick and frankly, I don't want to lose it. So here goes.


The problem: Oftentimes when I'm working on a project, being the hard-drive-paranoid-soul that I am, as I finish a milestone I'll run a Time Machine backup, and also sometimes rsync my project directory to Dropbox. However, it annoys me to shift to the mouse/trackpad to run the time-machine backup, then switch to the Terminal to run the rsync backup.

The solution: A decidedly love-sided instance of my love-hate relationship with AppleScript

do shell script "/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper >/dev/null 2>&1 &"

property nullStr : ""
set defaultSrc to "/path/to/project/dir"
set defaultDest to "/path/to/destination/dir/in/Dropbox"

--- cancel actions from either of these dialogs will effectively cancel the script
set dropBoxSource to text returned of (display dialog "Dropbox backup source?" default answer defaultSrc)
set dropBoxDest to text returned of (display dialog "Dropbox backup destination?" default answer defaultDest)

if dropBoxSource is not equal to "" and dropBoxDest is not equal to "" then
set rsyncCmd to "rsync -rav " & dropBoxSource & " " & dropBoxDest
display dialog ("Run: '" & rsyncCmd & "'")
--- if the user cancels the dialog here, the rsync won't run. this is just what we want :)

--- set a 2-hour timeout for the rsync command
with timeout of 7200 seconds
do shell script rsyncCmd
end timeout
end if


I saved this applescript as an application, which I can then invoke via spotlight/Quicksilver/Alfred etc, thus removing the problem of hunting for the Time Machine menu.

DISCLAIMER:

The shell script that runs the Time Machine backup is a non-documented, non-supported, run-at-your-own-risk solution. It works for me, but I'm making absolutely no guarantees that it won't break something. For that matter, you ought to know what rsync does before feeling too comfy with the rsync backup either.

Tuesday, January 27, 2009

Breaking long lines in Vim

Vim allows you to set a line length at which to break long lines, which I use in text files to break at 80 characters. However, in source files, I don't want it to break lines right at 80 characters lest it break in the middle of something that doesn't want to be broken in.

So I put the following in my .vimrc as a shortcut to breaking at 80 characters only when I want it to:


map \br 80\|? r


This tells Vim to go to column 80, search backward for the previous " " (space), and replace it with a carriage return.

I use this primarily for breaking comment lines at 80 characters. If Vim is set up properly (I can't remember the setting off the top of my head, but maybe I'll post it here later) the new line you inserted will be marked as a comment also (in the case of # or " comment markers, as this will obviously work with C/Java style multi-line comments).

Sunday, November 30, 2008

Vim Sneakiness

One of the things that I like most about Xcode is the auto-insertion of a closing curly-brace on the second line below whenever I enter an opening curly-brace, and the insertion of the cursor on the line in-between them. However, at heart I'm still a Vim guy, and tonight I got tired of actually typing that closing curly-brace. So, to make Vim automagically create my curly-brace blocks for me, I did the following.

In my .vimrc, I place the following lines


if has("autocmd")
autocmd FileType c source ~/.vim/brace.vim
autocmd FileType cpp source ~/.vim/brace.vim
autocmd FileType objc source ~/.vim/brace.vim
autocmd FileType java source ~/.vim/brace.vim
autocmd FileType pl source ~/.vim/brace.vim
endif


brace.vim is very simple, containing only the following line:

imap { {<CR>}<Esc>O


This causes typing a opening curly brace to immediately insert a Carriage Return character (equivalent to pressing return/enter) then inserts a closing curly-brace, then switching to command-mode and "typing" O to place an insert-mode cursor on a newly-inserted line above the closing curly-brace.

If anyone has a better way to do this, I'm open to suggestions.

Tuesday, October 28, 2008

Here's a handy little tool I've used often...

Problem: In several applications, I've found the need to pop up an alert/message window telling the application user that something went wrong, or that something they did wasn't kosher.

Solution: NSRunAlertPanel. Little macros like this one are additional reasons I love programming for the Mac. But to make it a little more useful, I created a method call that makes a dummy alert with an ok button and a given message. It looks like this:



-(void) displayAlert:(NSString*) alertMsg {
NSRunAlertPanel(@"Alert", alertMsg, @"OK", nil, nil);
}


The actual NSRunAlertPanel macro signature looks like this:


NSRunAlertPanel(NSString *title,
NSString *msgFormat,
NSString *defaultButton,
NSString *alternateButton,
NSString *otherButton)


Other parameters can be added to the method signature to create more full-featured alerts. I created the method solely to remove the NSRunAlertPanel call (which can be a big method call) from the logic of what I'm doing at the moment and replace it with a short method call that does what I want it to.

Sunday, October 26, 2008

Publishing a Bonjour networking service with NSNetService

So I'm working on an undisclosed (but totally awesome) iPhone/iPod Touch app for CS 598R (a capstone/senior project class), and have developed the following procedure for publishing a Bonjour service. I'm posting it here so I can always know where to find code that does what I want.

Feel free to use the code, just don't blame me if it doesn't do what you want it to...

You can see the basic sample code here, or on the BYU CocoaHeads site here.