October 31, 2005

Happy Halloween

Happy Halloween - it’s a rainy, foggy, spooky night here in Chicago as you can see below.
halloween_05/IMG_1986

I was busy saving the matrix this weekend…I had a pretty good time. :-)
halloween_05/DSC00090

October 28, 2005

The air smelled distincively of celebratory cigars…

…as the White Sox rolled through downtown Chicago. I wandered down to the parade during lunch today to check out the parade and rally the city was throwing for the Sox. It was insane!
White Sox Parade

The streets were packed, as you can see. People were climbing over everything - signs, street posts, planters, bus stops, TV vans…anything to get a better glimpse over the sea of people that swarmed the downtown Chicago area. I happened to settle down just under the L at Lake and La Salle when the parade started going by. One of the floats managed to nail the bottom of the L tracks as it went under, temprorarily holding up the parade. Luckily nobody got hurt and they got it unstuck and were on their way again. The players also had to duck as they went through as they were on the top of double-decker busses…it was pretty close. There was also confetti and shredded sun-times newspaper (the best black and white confetti one can get on short notice, I suppose) all over the place.

It was a pretty crazy scene, but a lot of fun to be down there amidst all that. The best was this little girl whose father put her up on a walk sign. She eventually wanted to get down but her father had her sister on his shoulders and couldn’t get her because there were so many people. She started pouting for a bit, but then started posing for cell-phone photographers such as myself. ;)

Girl on Walk Sign

I have a few more photos on flickr.

October 26, 2005

Lazy

I just realized I’ve only made two posts for the entire month of October…wow. Sorry about that…guess I’ve been busy with life. Lots of busy weekends - vacation, work, having fun. I have lots of pics to post so hopefully I’ll get around to that sometime. :)

October 12, 2005

Bloglines adds shortcut keys

Some of you may know that I use Bloglines to read my rss feeds. I don’t know how long this has been enabled, but I just saw tonight that Bloglines has added shortcut keys, ala Gmail!

Bloglines Shortcuts

I’ve only used it once and it’s already making reading my feeds so much easier!

Thank you, Bloglines! This rules! No more uncomfortable scrolling with my trackpad/nubbie/scrollie wheel.

Hrm…I wonder if this has anything to do with Google releasing Google Reader the other day… ;-)

October 9, 2005

Decimal Math in shell scripts

I was reading about inserting random delays in cron jobs and was surprised when I saw this code to get a random number:
# Grab a random value between 0-240.
value=$RANDOM
while [ $value -gt 240 ] ; do
value=$RANDOM
done

I thought, there’s got to be a better way to get a random number within a specific range. I mean, that kind of seems like a waste of CPU cycles, particularly when $RANDOM can be anywhere in between 0 and 32767. And a quick test verified that was exactly the case. On average (out of 500 samples), using that method to get a random number below 240 requires 134 attempts. Not a horrid performance impact, but enough to get my anal retentive brain in a twist.

My first thought was to use the expr command to do some simple math to properly adjust the $RANDOM variable into the desired range. But soon enough, I realized the expr only deals with integers…bummer. Looking around to see what else I could use for decimal math, I eventually came across the dc command - a reverse-polish desk calculator:echo -e "6\nk\n$RANDOM\n32767\n/\n1\nk\n240\n*\np" | dc | cut -f1 -d.

This definitely seems to be faster.

time echo -e “6\nk\n$RANDOM\n32767\n/\n1\nk\n240\n*\np” | dc | cut -f1 -d.
104

real 0m0.003s
user 0m0.003s
sys 0m0.002s

COUNT=0; time while [ $RANDOM -gt 240 ]; do COUNT=`expr $COUNT + 1`; done; echo $COUNT

real 0m0.445s
user 0m0.158s
sys 0m0.297s
295

Update: After pondering the comment below, I realized this can be done in bash by using factors of 100 to resolve the integer math issue. There are several ways to do this, but here are a couple options:

RAND1=`expr $RANDOM \* 100`; FACTOR=`expr $RAND1 \/ 32767`; DIV=`expr $FACTOR \* 240`; RESULT=`expr $DIV \/ 100`;
or
expr $(expr $(expr $(expr 9264 \* 100) \/ 32767) \* 240) \/ 100

They appear to take about the same time, around 0.050s real time and 0.015s sys time.