Dispatches from Andyland "Your reality, sir, is lies and balderdash and I'm delighted to say that I have no grasp of it whatsoever!" — The Adventures of Baron Munchausen

November 30, 2007

What a way to make a first impression

Filed under: Uncategorized — Andrew @ 10:33 pm

I was listening to Radio Lab’s podcast episode Space Capsules. It seems to be a set of outtakes to their episode on Space, and asking people what they would put on the record sent out on the Voyager spacecraft sending a message to sentient beings in outer space.

The thought that I most strongly left from that program is that Neil Gaiman is at best quirky, and at worst an evil, evil man. His ideas of what to send included The Wizard of Oz and Lou Reed’s Street Hassle and try to figure out what we are like from those. He said he loved the idea of thousands and thousands of alien social scientists trying to decode the British version of The Office.

So let me get this straight: We launch two space crafts that travel tens of thousands of years and by some off chance happen to come in contact with some sort of intelligent life out there the first thing we should try to do is mess with their heads? (or whatever they have.)

Actually, it might be fun.

November 23, 2007

a few hacks to make powershell usable

Filed under: Uncategorized — Andrew @ 11:36 am

I eventually relented and made a function called that did both the get-childitem (also known by its aliases of gci, ls, or dir) and the sort by time. trying to find the first or the last file in a directory is common, and the “ls|sort LastWriteTime” is too cumbersome. After that, I made a function called “dir/w” that does “get-childitem $Args | format-wide”. I kept typing it in by accident.

Another problem that I had was a couple of batch files that depending on quirks of the cmd.exe calling environment. Things that would map a couple of drives and then set a couple of environment variables, etc. The Powershell environment is similar to a Unix shell where a new script or something sets up a new context, variables are changed in that context and disappear when the context ends. There is a special way of running a script in the current context rather than starting a new one. They even call it “.” just like the bourne shell does. I’m not at a point where I can rewrite the scripts in powershell, since I may switch back and forth between cmd.exe and powershell or might be on a machine that doesn’t have it installed yet. So I have a small powershell script that will execute the batch file and then call set to echo all the environment variables, finally the powershell side of things will find those strings and set their values:

& cmd /c “batch.bat && set” | foreach-object { ($_ -match “^([a-z0-9]+)=(.*)” ) -and ( set-item env:\$matches[1] $matches[2] ) }

In some ways, using powershell seems a lot like a small functional programing language, but with data passing through pipelines rather than lists. The “foreach-object” (alias foreach or %) is like a map or mapcar. The where-object (alias where or ?) is like filter or Perl’s grep. The select-object (alias select) can pull out pieces of object in the pipeline, and group-object (alias group) will combine things. I haven’t found anything that directly maps onto reduce() or zip(), and have wished I had them. Actually, I think zip() might be hard to do since a pipeline is roughly equal to one list, and zip() needs two. In some cases reduce() can be implemented in terms of foreach-object (especially since foreach-object has BEGIN{} and END{} blocks.)

November 13, 2007

Windows Powershell, now that I have some practical experience with it

Filed under: Uncategorized — Andrew @ 10:58 pm

Now that I’m doing more Windows development, I’ve had a better chance to try out Windows Powershell in a day to day environment. I think I’m at the point where I see some of the advantages it has over traditional shells; why it has to be different than its predecessors ( not and upgraded cmd.exe, and not a port of the Unix bourne shell.) but at the same time annoyed at it for its own quirks, not just its differences.

First, to explain why its a big deal at all, and why I want to be using it instead of Cygwin’s bash port or cmd.exe: Cygwin has the nice tool and filter toolset, but since there are cases where the Cygwin Unix emulation interferes with the windows based utilities; and those are the ones that I eventually need to work with. I’m thinking of things like path its differing views of the filesystem when passed between Cygwin and Windows components. (If a Unix tool reads the PATH environment variable, it won’t be in the format it wants.) The cmd.exe shell that is included in windows quite have the power of the shell (even with the cmd.exe/e:on extensions) and doesn’t have nearly as good a toolset of utilties to string together.

I feel wary of the way I’m continuing making direct comparisons to the Bourne shell, but its an environment that I’ve long been comfortable and content with. Its a shame that I’m coloring Powershell with /bin/sh colored glasses, but I need some sort of frame of reference, and people with familiarity with the bourne shell would understand why a useful command line environment is important. So I guess in furthering down this path, I have this succinct explanation for someone who uses and appreciates a Unix shell environment.

When you have a Unix shell pipeline, and it has stages where it is building up a line (maybe with awk) doing some positional manipulation and then pulling of portions of the result, you may see a more elegant solution using Powershell. Since the items carries along the pipeline are objects and not text, the object can carry along additional information through the intermediate pipeline phases.

For example, if you wanted to take your current shell aliases, sort them by length, and then display their definition, you might do something like this:

alias|awk -F'[ ='"'"']' '{print $2, length($2),$4}'|sort -n -k2

Doing something similar in Powershell would be:

alias| sort { $_.name.length } | select name,{ $_.name.length },definition

where its sort takes something like a method, property name, or a block expression. The property “definition” is available at the end of the pipeline, even though it isn’t accessed or referenced in the intermediate stages. Since the values are typed (with conversions, like many dynamic languages) the advantages of Powershell can be seen with things that deal with dates or large numbers. (the GNU “du –human-readable” is nice, but you can’t sort or do arithmetic on it. Its tough to use “ls -l”‘s in computation too. )

Where I get annoyed with Powershell is actually when it follows the tool and filter paradigm to a fault. I’ve used older Unixes that used to have ls display in a single line, except maybe with a special ls -c flag (and often configured with an lc alias to do the same.) Eventually most Unix systems made a compromise between ease of use and the toolbox approach and made ls display in columns if the output is a terminal, otherwise display one filename per line. In Powershell, the get-childitem cmdlet (or its ls or dir aliases) presents a list of filenames. If you want it in multiple columns it needs to be piped through format-wide. For this example, ls|fw isn’t all that cumbersome to type, but the other ls switches, like the ones that sort by date turn into things like ls|sort LastWriteTime.

November 6, 2007

Daddy Daughter time

Filed under: Uncategorized — Andrew @ 12:10 am

When Michelle used to go to work or go out, she used to tell the girls that it was “daddy/daughter time.” That always seemed to make it seem much more special to them. It wasn’t just time that she wasn’t around, but time that they had my full attention. Time that they could make whatever they wanted. I have fond memories of take walks with Sam. Having Coffee and Hot Cocoa at Starbucks with Abbie. Playing musical instruments with them. All sorts of things.

Sam has gotten herself on a real Calvin and Hobbes kick; it started about a month and a half ago. We were at the synagogue, my kids had had enough and couldn’t sit still during the service anymore, so I brought them into the back hallway and tried to keep them amused enough so that they time would pass, but not worked up enough that they would make noise and disturb everyone still in the sanctuary. Eventually the crowd of kids that had escaped from the sanctuary was about two or three times my family, but I was figuring as long as the parents didn’t mind them out, the best thing that I could do to help all involved was to keep them in the entertained but quiet zone. One of the kids was a boy Sam’s age, and it seems that at least one of them has a crush on the other. The boy brought up that he had borrowed the book “Something Under the Bed Is Drooling” from the library, and started describing some of the strips from it.

(for any boy interested in my daughter, if you want to get on my good side, bringing up the comic strip Calvin and Hobbes will certainly win you points.)

After we got home, I mentioned to Sam that I had a copy of the book as well, and if she was interested she could borrow it. (and then when she saw the boy next, she could talk about the comic strips that she liked.) She read through that, and then that is when she went through the read through the rest of my collection. I didn’t know that Calvin and Hobbes was available through the schools Scholastic Books program, but now she’s loaning me books of comic strip collections when she’s done with them.

If this is the worst meddling I do in her love life, I think Sam will be fine with it. (The boy is a really sweet kid too, she could do a lot worse.) What is funny though is the way that it wound up being a shared topic of conversation between the two of us, too.


Another fun Sam and I are going to be working on is an electronics kit we bought from Lady Ada Electronics. Its her MiniPOV kit. I asked Sam if she’d be interested and she said that learning to solder might be fun, and that blinky light toys are always fun. I also bought a MintyBoost charger kit. Sam has a tendency to let her Nintendo DS and her iPod run down until they are nearly out of juice, and then panic when she can’t get them charged in time for whatever she wants to do with them. I figure the charger will be good for that, and the having a direct connection between a need of hers and the solution the kit provides will produce some motivation for it.

(I bought a second MiniPOV kit, because I want to try to build the brain entrainment kit I read about in Make magazine. I figured I didn’t want to take Sam’s kit apart to do it though.)

Powered by WordPress