Just a quick note to anyone (Steve) who may be reading the feed for this blog: I've decided to start using FeedBurner, mostly just to provide email subscription for people who don't know what RSS means but also because I'm curious. I've been told that many news aggregators don't follow redirects, so you may need to update your feeds to the new URL: http://feeds.feedburner.com/BlogDotFitzellDotCa
And for anyone who would rather receive an email when there are new posts, use this link: http://www.feedburner.com/fb/a/emailverifySubmit?feedId=2122389&loc=en_US
Friday, 27 June 2008
Friday, 20 June 2008
Bash: using the read command
While I normally use awk or sed to pull a piece of information I want out of a line of text, it doesn't work as well when you need multiple pieces of information. Well it works fine for displaying multiple pieces of information, but if you want them in variables to use later?
I once wrote a script that used declare to do the equivalent of this:
Ewww... Now I know there's a better way: the "read" command. You could do something like this:
You can also do like so:
You can even loop over all the lines of input. Let's take the /etc/passwd file as an example. Since that file uses a colon as a separator, we first need to set the IFS variable which determines what characters are used as field separators.
As pointed out here, this is also one way to deal with a file containing a list of filenames that may have spaces in them:
I once wrote a script that used declare to do the equivalent of this:
declare `w | head -1 |
awk '{ print "DAYS=" $3 " " "USERS=" $6 }'`
# now do something with $DAYS and $USERS
Ewww... Now I know there's a better way: the "read" command. You could do something like this:
w | head -1 |
(read -a FIELDS
#do something with ${FIELDS[2]} and ${FIELDS[5]})
You can also do like so:
ls -l | tail -1 |
(read perms dunno user group \
size month date year file
echo "$user: $file")
You can even loop over all the lines of input. Let's take the /etc/passwd file as an example. Since that file uses a colon as a separator, we first need to set the IFS variable which determines what characters are used as field separators.
cat /etc/passwd | (IFS=:
while read user pass uid gid desc theRest; do
echo "$user: $desc"
done)
As pointed out here, this is also one way to deal with a file containing a list of filenames that may have spaces in them:
cat list | while read f; do
ls -l "$f"
done
Monday, 16 June 2008
Teenage Voting
I was reading an article on ChangeThis.com about the education system in the US and there was a quote that read:
The only case I can find is a BBC article stating the the Isle of Man has lowered their voting age to 16. This seems a reasonable enough action to me, despite the call by others (one example from a Maclean's article parodied here) that the age should be raised to 21 because "young people today have essentially tuned out". Yeah, preventing them from voting will really help them tune back in.
New York City apparently proposed a bill to lower the voting age to 16 and so have California and a number of other states, but as far as I can find, none have yet passed. The arguments in favour include: getting teenagers used to voting; that they pay sales and, often, income tax without any control over where the money goes; that they can be tried for crimes as an adult after 16 but can't affect the laws; that 18 is a bad age to start voting because students are heading off to college and have too much other stuff on their plates; and (most important to me) that they have more invested in the future than anyone else. I'm not even that old and I already have a slight trepidation at trusting "kids today" to cast a vote, but I'm still young enough to remember that I had perfectly valid and rational opinions in highschool.
I don't even know if you need to lower the voting age. The Californian bill initally proposed that "each 16- or 17-year-old's vote count as half an adult vote and each 14- and 15-year old's vote a quarter" (reference) but that was dropped before the bill was floored. Or what if, for example, everyone over 12 but under the voting age (whether it be 16 or 18) was invited to the polling stations and given a different ballot to cast. It would have the same choices but would only be advisory: the results would be reported, which would provide feedback to government, engage youth, and introduce them to the voting process. If you're concerned about children just voting randomly or following their parents (not that it really matters: adults do the same anyway) there could be a place on these ballots for written comments. They're informational anyway and what better way to get feedback from interested youth. I don't know... just a wild idea.
My favourite quote was in an article discussing a California bill to preregister 16- and 17-year-olds so they would automatically be ready to vote when they turn 18. A Republican assemblymam who was against the bill says:
This makes me want to start my normal rant on party politics and career politicians, but I won't. In the end, though, the issue isn't so much specifically about youth. It's about politicians who have been elected by the current system being reluctant to change it. Whether the issue is proportional representation, holding polling days on weekends, or reducing the voting age (all of which could potentially increase voter turn out and the accurate reflection of their vote), the status quo seems just too tempting.
I don't think that's correct. Rather, the education system is one of the few major institutions to deal essentially entirely with children; and children are dealt with pretty much universally as if they were living in an autocracy. That got me thinking about engaging teenagers in democracy. I wondered if there mightn't be some forward-looking European nation that included the under-18's somehow in the process.Our educational system is the only major institution in our country that officially recognizes autocracy (in contrast to democracy) as its principle type of government.
The only case I can find is a BBC article stating the the Isle of Man has lowered their voting age to 16. This seems a reasonable enough action to me, despite the call by others (one example from a Maclean's article parodied here) that the age should be raised to 21 because "young people today have essentially tuned out". Yeah, preventing them from voting will really help them tune back in.
New York City apparently proposed a bill to lower the voting age to 16 and so have California and a number of other states, but as far as I can find, none have yet passed. The arguments in favour include: getting teenagers used to voting; that they pay sales and, often, income tax without any control over where the money goes; that they can be tried for crimes as an adult after 16 but can't affect the laws; that 18 is a bad age to start voting because students are heading off to college and have too much other stuff on their plates; and (most important to me) that they have more invested in the future than anyone else. I'm not even that old and I already have a slight trepidation at trusting "kids today" to cast a vote, but I'm still young enough to remember that I had perfectly valid and rational opinions in highschool.
I don't even know if you need to lower the voting age. The Californian bill initally proposed that "each 16- or 17-year-old's vote count as half an adult vote and each 14- and 15-year old's vote a quarter" (reference) but that was dropped before the bill was floored. Or what if, for example, everyone over 12 but under the voting age (whether it be 16 or 18) was invited to the polling stations and given a different ballot to cast. It would have the same choices but would only be advisory: the results would be reported, which would provide feedback to government, engage youth, and introduce them to the voting process. If you're concerned about children just voting randomly or following their parents (not that it really matters: adults do the same anyway) there could be a place on these ballots for written comments. They're informational anyway and what better way to get feedback from interested youth. I don't know... just a wild idea.
My favourite quote was in an article discussing a California bill to preregister 16- and 17-year-olds so they would automatically be ready to vote when they turn 18. A Republican assemblymam who was against the bill says:
The truth is, when you're young you tend to think like a liberal. As you get older and wiser … you tend to become more conservative.Ha! So we shouldn't even help register young people to vote because they'll be liberals! The article goes on to say that Democrats killed legislation to require voters to show photo ID, and that Republicans killed legislation to allow citizens to register on voting day.
This makes me want to start my normal rant on party politics and career politicians, but I won't. In the end, though, the issue isn't so much specifically about youth. It's about politicians who have been elected by the current system being reluctant to change it. Whether the issue is proportional representation, holding polling days on weekends, or reducing the voting age (all of which could potentially increase voter turn out and the accurate reflection of their vote), the status quo seems just too tempting.
Bash: printing the alphabet
(Sorry for the geeky topic, non-geeky readers)
Most have probably run across the "seq" command that will let you generate a list of numbers:
Most have probably run across the "seq" command that will let you generate a list of numbers:
$ seq 1 4But you can do similar with "echo" for a list of letters:
1
2
3
4
$ echo {a..d}
a b c d
$ echo {a..d}{a..d}
aa ab ac ad ba bb bc bd ca cb cc cd da db dc dd
Wednesday, 11 June 2008
Think work sucks?
globeandmail.com: Think work sucks?
Actually, yes. Yes, I do.
Ok, let's be clear here: I like doing work but I don't really like the "traditional" work environment (an ironic term given the short length of time we've been working this way). Sarah forwarded me this article on ROWE (Results Only Work Environment) and all I can say is "Yes! Exactly! Has someone finally clued in?". Well, and also "Who came up with that name?". Maybe administrators love the name...
The idea is that you stop defining an employee's work in terms of hours in the office (or even hours worked, period) and start defining and measuring in terms of results. I've been lucky that most of my career so far has allowed me flexibility around the hours I work: a late morning here, a long day there, a banked day from working on the weekend, and so on. And I've always taken the attitude that, if I'm getting the job done, I don't need to feel too guilty if I spend a few minutes looking at a friend's photos while at work. But I've still always had to count hours because ultimately that's what I'm being paid for.
The difficulty with implementing a system like this, of course, is that it's easy to see if someone is sitting at their desk but much harder to determine whether they've achieved what you asked them to do. Plus you have to make sure your employees know what they're being asked to do. This may take more effort from managers to define tasks, set goals, and establish metrics. You might have to actually have those performance review sessions and dust off the 360 degree evaluation forms. But isn't this what managers are supposed to be doing anyway?
The end result is that there is just no excuse for not getting work done. As far as I can tell everyone wins, except possibly the guy in the back corner who hasn't done any actual work in 20 years. Maybe he gets motivated and actually finds himself happier? Maybe that's wishful thinking...
P.S. I don't think this ideas at the root of this are new or particularly insightful but if it's being adopted at all (and apparently Best Buy uses it) then that seems new.
P.P.S. What happens when employees start to feel like they're just being given a "harder" task than their co-workers?
Tuesday, 10 June 2008
Lipograms
Wandering through the bookstore at the airport in Kuala Lumpur, I came across this book. What caught my eye was not the title, but the claim on the front cover that the book was a lipogram and contains no E's. No E's?!! E is the most common letter of the alphabet. You can't even use "the" or "we" or "me" or "he" if you can't use E. How can you possibly write an entire novel without the letter E? At first I thought it was a joke but a quick skim certainly didn't turn up any occurences. Apparently the author wants to write one book for each letter of the alphabet... sheesh.
Tuesday, 27 May 2008
Two-way traffic
A few weeks ago we hired a driver and drove for two and a half hours (on the first day of a holiday weekend, no less) to one of the Great Wall sites. We thought we had negotiated a price that included road tolls so I was surprised to find us on small toll-free highways in so much traffic. I spent a good portion of the way there looking at sometimes-solid-sometimes-dotted expressway markings on the map that seemed to be running largely parallel to our route and telling myself that perhaps it just wasn't open yet. But the expressway isn't really the point of this story.
On several occasions, I've observed a certain traffic phenomenon here and this trip provided a good illustration. In China, you see, when someone or something on the road is in your way, you just... go around. Even if it means moving into an empty space in the oncoming lanes. Ignoring the danger of an accident, it seems reasonable enough at first glance: save yourself some time, keep the traffic flowing.
An hour or more into the trip we came along a particularly heavy patch of traffic and, as we inched along, I began to suspect what had happened: you see, this section of road had five lanes of traffic in total but there were four lanes going our way. Not a normal distribution. Sure enough as we moved along we came to a point where there were suddenly four lanes going the other way and ours all merged into one. Can you picture this? There was now one through-flowing lane in each direction and, in the middle, three lanes of traffic coming each way facing head-on into each other.
You can picture how this would happen: one direction slows up for some reason, someone darts around into a gap but doesn't make it back in because the traffic is moving slowly and there are no gaps. This blocks the traffic coming the other way and cars further back in that line, in frustration, dart around the stopped traffic ahead and find they can't get back in because the traffic has stopped. This is similar to the effect known as shockwave traffic, which produces traffic jams from something as simple as one car slowing too quickly in heavy traffic. Scientists in Japan recently managed to recreate this effect in a controlled environment. If you've never heard of this, check out the video mentioned in the above article or check out this computer simulation (click on "1: Ring-road" once it loads). Then you'll understand why that huge traffic jam you're stuck in often has no obvious cause when you get to the end of it. If you want to read more, check out here and here.
So, as the traffic keeps backing up, cars keep trying to go around and end up blocking more and more lanes. If the cars would only cooperate, they'd all get where they're going faster. Because everyone's trying to maximize their own forward progress, however, they end up in near gridlock. This kind of greedy algorithm reminds me of the Prisoner's Dilemma.
On our way home, we came upon the same patch of road and came to a complete stop for 15 minutes. Eventually, somebody opened a side street that had been blocked off and we were able to begin diverting around the stalled traffic into the countryside. As we moved our way forward, guess what I saw laid out in front of us?
Yup, 5 lines of traffic all pointing in the same direction...
On several occasions, I've observed a certain traffic phenomenon here and this trip provided a good illustration. In China, you see, when someone or something on the road is in your way, you just... go around. Even if it means moving into an empty space in the oncoming lanes. Ignoring the danger of an accident, it seems reasonable enough at first glance: save yourself some time, keep the traffic flowing.
An hour or more into the trip we came along a particularly heavy patch of traffic and, as we inched along, I began to suspect what had happened: you see, this section of road had five lanes of traffic in total but there were four lanes going our way. Not a normal distribution. Sure enough as we moved along we came to a point where there were suddenly four lanes going the other way and ours all merged into one. Can you picture this? There was now one through-flowing lane in each direction and, in the middle, three lanes of traffic coming each way facing head-on into each other.
You can picture how this would happen: one direction slows up for some reason, someone darts around into a gap but doesn't make it back in because the traffic is moving slowly and there are no gaps. This blocks the traffic coming the other way and cars further back in that line, in frustration, dart around the stopped traffic ahead and find they can't get back in because the traffic has stopped. This is similar to the effect known as shockwave traffic, which produces traffic jams from something as simple as one car slowing too quickly in heavy traffic. Scientists in Japan recently managed to recreate this effect in a controlled environment. If you've never heard of this, check out the video mentioned in the above article or check out this computer simulation (click on "1: Ring-road" once it loads). Then you'll understand why that huge traffic jam you're stuck in often has no obvious cause when you get to the end of it. If you want to read more, check out here and here.
So, as the traffic keeps backing up, cars keep trying to go around and end up blocking more and more lanes. If the cars would only cooperate, they'd all get where they're going faster. Because everyone's trying to maximize their own forward progress, however, they end up in near gridlock. This kind of greedy algorithm reminds me of the Prisoner's Dilemma.
On our way home, we came upon the same patch of road and came to a complete stop for 15 minutes. Eventually, somebody opened a side street that had been blocked off and we were able to begin diverting around the stalled traffic into the countryside. As we moved our way forward, guess what I saw laid out in front of us?
Yup, 5 lines of traffic all pointing in the same direction...
Subscribe to:
Posts (Atom)