a life of coding

Friday, April 29, 2005

Doing Nothing in Bash

Going on what is probably a record, this is the THIRD post today. Technically, the Ninja post was a draft from a couple of weeks ago, but for the sake of THREE posts in one day, I'm just going to pretend that I wrote it today. And now, on with the post...

What is your favorite way to do nothing in /bin/bash? In C, there is ";" (on a line by itself); in python, "pass". But in bash, how do you go about doing nothing? I know what you are going to ask, so I'll just lay it out there: If there is a while loop, and the condition of the while loop is the result of the command you are executing, then there is nothing to be done in the body. Unfortunately, bash doesn't seem to like this - so, something has to go in the body. Obviously there are many things that can go there, so we should have some metrics for picking one. The first metric, is that doing nothing should be easy. The second, it should be fast. So to this end, here are a few things to try:
  • touch /dev/null [Keystrokes: 15. Runtime: 0.02s]
  • sleep 0 [Keystrokes: 7. Runtime: 0.03s]
  • A=0 [Keystrokes: 3. Runtime: 0.00s]
So far, it looks like A=0 wins. It does have a side effect for the command, but that seems like an easy enough thing to get around.

Mac OS Coding Ninja

http://www.drunkenblog.com/drunkenblog-archives/000513.html

There are people who write code to make a living, and then there are people who live to write code. I like to call these people coding ninjas. Jonathan Rentzsch is one of these people, and like most other people in this catagory, you've probably never heard of him, but chances are good that he has improved something that you like. The drunkenblog link is a lengthy interview with him, and if you are interested int programming, you'll enjoy it.

Here are some selected notes that I took:

Multithreading in Cocoa requires that AppKit commands be done in the main thread:
  • '-performSelectorOnMainThread:withObject:waitUntilDone:'

Memory management in C++ can sometimes be quirky - using an standard idiom can help:

Quotes:
"The key thing for MP programmers to keep in mind is to know when to use C's 'volatile' keyword."
"I get the sense that in order to get to great software, you have to iterate through bad software designs. If your ego is tied up on an early bad design, you never become great. So you learn to throw away your best paragraph and move on."

The Virtue of Desktop Management

Having used different flavors of Unix, one thing that have always felt was lacking from Mac OS X is a better application switcher. The best traits of the Dock is having your applicatino icons instantly visible while still being hideable, and scalable without losing information (via magnification). The worst ones are the reliance on using the mouse, the way icons move when magnified, screen real estate lost to a reasonably sized dock, and the annoyance of having to move the mouse away and back to hide a dock which has accidentally popped up.

What I really miss from CDE (a common cross-Unix desktop) is virtual desktops. I would say that I miss this from Linux, but my experience with desktop switching in Linux has been marred with inconsistent, poorly engineered, and overly complicated systems that never managed to make me more productive. So my chief requirement for a desktop switcher is simplicity: does it let me be more productive?

http://virtuedesktops.sourceforge.net/
Virtue is an open source virtual desktop system that was mostly written by one person. In my experience with software (especially Mac vs Linux software), I have found that a single person can often produce a cleaner system than any horde of developers. Virtue is simple, yet it provides a lot of features. There is an Actions system that lets you bind any task to a keyboard shortcut or mouse shortcut (a la hot corners in Exposé). It includes graphic primatives to differentiate desktops, like tint (tint your wallpaper, or make it a solid color) and text (put labels in the corners of your screen). And most important of all, it has transitions (like Fast User Switching) between screens. This is important because I am a graphics whore, and I suspect many Mac users are.

Get Virtue, play with it, love it, if you are a programmer, add your favorite features to it. With any luck, Apple will rip this off too.

Monday, April 11, 2005

Pearls of Unix

Sometimes, you really need to find something in a type of file. Grep -r is often too slow because of other large files in the same directory as your source. Here's one solution to the problem:

find . \( -iname '*.c' -or -iname '*.cpp' -or -iname '*.h' \) -exec grep -H searchstringhere {} \;

This will limit your search to .c, .cpp, and .h while still showing the filename of any matches (grep's -H option). Unfortunately, Windows has heavy processes that take much much longer to spawn than *nix... Since each found file spawns a grep process, this optimization might not save you any time under Cygwin.

Monday, April 04, 2005

Motorola wants to Podcast your radio

Hehe, I would love to listen to this channel... somehow, I have long been a fan of the Angry Person genre (Engadget):
One of my favorite stations is my Angry Woman channel. It crosses decades and genres. I've got some Avril Lavigne, some Blondie, Janis Joplin, Alanis Morissette. There's jogging music, workout music - next we'll see an I Just Broke Up radio station. Music that fits your tastes for that moment.
Synposis:

Motorola wants to offer XM, podcasting style: sync your stations overnight at home, listen to them all day. Time-sensitive content (news, traffic) will be delivered over cellular.