Thursday, July 1, 2010

Folding bluetooth keyboard works with new iPhone 4

My wife got me the new iPhone 4 for Father's Day. One of the reasons I wanted it, over an Android phone, is that Apple's iOS 4 supports bluetooth keyboards. I always thought it would be very cool to be able to use a full keyboard with a smart phone.

I read on a forum that someone was able to pair their iPad with the "iGo Stowaway Ultra-Slim Bluetooth Keyboard." This keyboard is no longer made, but it usually gets good reviews, and appears to still be for sale on Amazon and other on-line venues. Essentially, it's a full-size keyboard that folds in half.

I found a slightly-used iGo Stowaway for sale on Craigslist for $60.00, and purchased it today. I'm pleased to report that it does in fact pair up with my new iPhone 4, and works great. The Stowaway was not designed with the iPhone in mind, so there are some special function and character keys that don't do anything. But it looks like all the standard letters, numbers, symbols, navigation, and editing keys present on the average computer keyboard, work. (That being said, I haven't done a thorough test of all the keys, yet.) I am very happy to find that the arrow keys work, since moving the cursor around on the iPhone's touch screen is a bit challenging.

Monday, April 19, 2010

Korn (ksh) and Bash shell script for determining leap year

Based on the algorithm in Wikipedia, this script takes a four-digit year as an argument, and determines whether or not it is a leap year. Obviously not super-useful in itself, the "if" line could be incorporated into a larger script. Appears to work in ksh and bash, but not sh.



year=$1

if [ $((year%400)) -eq 0 ] || \
( [ $((year%4)) -eq 0 ] && [ $((year%100)) -ne 0 ] )
then
echo "leap"
else
echo "not leap"
fi

Tuesday, April 6, 2010

Dynamic korn shell (ksh) variable assignments

This might seem like a strange thing to want to do, but imagine you read in a list of user names, and for each one you want to store some info, such as the assigned shell.

Now, you could just put user names in one array, and the info in another array, and rely on the fact that both arrays will have the same index order.

But, you can also use "eval":

$ name=bob
$ data=/bin/bash
$ eval "$name=$data"

And to "de-reference" your dynamic variable:

$ eval "echo \$$name"
/bin/bash

This also works:

$ eval echo "$"$name
/bin/bash