PowerShell quickie: expanding the properties of a variable inside a string

Here’s something that gave me a bit of trouble: I was attempting to run a script to upgrade a bunch of SharePoint solutions, and I wrote it like this:

dir –Recurse –Filter *.wsp | %{ stsadm –o upgradesolution –name $_ –filename $_.FullName –allowgacdeployment –local }

Now, that actually works, but since I hadn’t tested it before, I figured I’d echo the command out first, so I tried this:

dir –Recurse –Filter *.wsp | %{ echo "stsadm –o upgradesolution –name $_ –filename $_.FullName –allowgacdeployment –local" }

Which is all well and good, except it echos out something like the following:

stsadm –o upgradesolution -name Foo.wsp -filename Foo.wsp.FullName -allowgacdeployment -local

The reason this happens is that the string expansion in PowerShell has no way of knowing that I meant to expand the property instead of printing out the literal characters. Having figured this out, the next thing I tried was:

echo "${_.FullPath}"

Which doesn’t work either. Crap. I’m not familiar enough with the PowerShell syntax to explain why that is, but after a moment of pondering I finally figured out something that does work – expressions:

dir –Recurse –Filter *.wsp | %{ echo "stsadm –o upgradesolution –name $_ –filename $($_.FullName) –allowgacdeployment –local" }

The $() syntax allows us to evaluate any arbitrary expression, which is then inserted into the string. Yay!

Protocol-relative HTTP URLs

If you’re visiting a web page over an SSL encrypted connection, you might sometimes get an annoying “mixed content” warning. In essence, the browser is telling you that yes, the page itself was delivered over HTTPS, but other bits were not, and that may or may not mean that you’re in danger.

From the developer point of view, having to build every URL so that the protocol is taken into account can be tedious. It might equally well be the case that your framework of choice already handles this. If so, good for you.

However, there’s another escape hatch not known to most people: protocol-relative URLs. You write the url without the protocol and following colon, and the client will choose whichever protocol was used to retrieve the page, like so: //server:port/path/to/resource.html

Not sure how often this is actually necessary, but there you go. 🙂

Chapter 5: But I Can’t Because…

(This is part 5 in a series of posts where I document my progress through reading Becoming a Technical Leader: An Organic Problem-Solving Approach by Gerald Weinberg, answering the questions at the end of each chapter)

1. Do you know someone whose leadership style you particularly admire?

“Try to create a short career biography of this person, characterized in MOI terms. If possible, interview the person to check your perceptions.”

I can’t really name anyone for this exercise. This has been the primary reason I’ve been sitting on this blog post – the rest of it has been ready for quite a while now. I’ll just have to move on, unfortunately.

2. When was the last time you made a major change in your career?

“Which do you remember best, the factual details, or the feelings?”

I think the one and only major change so far has been leaving my first job after nearly seven years. I was primarily anxious, and afraid that I wouldn’t be good enough for the “real world”. Definitely feelings.

3. How did you react the last time someone you know well made a major career change?

“What else does that tell you about yourself?”

I was happy for that person, and a little envious. I felt like they were going somewhere, while I wasn’t. It’s mostly an issue of low self-esteem.

4. What change in your career have you made that you still don’t fully accept?

“don’t fully admit to others? to yourself? Can you now let go of it? Why?”

I’m not sure what this question is asking. A change that I wasn’t actually fully aware of, and hence don’t accept it, or a change that was forced on me? Either way, I don’t think I have any good examples.

5. Can you remember the first major decision point in your career?

“Can you still recall your feelings? Were you afraid to take the step? Was your fear justified? Was it worth it anyway?”

See question 2. Yes, I was afraid. Yes, I think the fear was justified, because I didn’t think we had ever assessed our actual competence level realistically. It was worth it, though. The next time I moved to a new job, I wasn’t anxious, and I think I made a point of looking at the right things when making the decision. I also got valuable experience from that job.

6. What are your choices for the next major decision point?

“What happens to your body as you contemplate each possible alternative? What messages pop into your mind?”

More or less direct responsibility. More or less of time in the spotlight. Less seems comfortable, but a bit boring. More makes me nervous and excited. The messages are along the lines of “do you want to make a difference or not?”

7. Have you ever been appointed Leader of anything?

“Did people begin to assume that you, as Leader, would now handle situations that they could perfectly well handle themselves? How did you deal with these situations? Were you so taken with your new status that you tried to handle them yourself, rather than delegating them where they belonged? How did your actions affect the group’s later reactions to you as Leader?”

Worse. I was so taken with my status, that I tried to handle things even when nobody asked me to! It lead to tension, bad decisions and me realizing that I wasn’t anything close to a real leader.

8. Next time you are appointed Leader of some group, keep a list of situations …

“… in which people assume that you as Leader will come up with the crucial ideas, but in which you exercise leadership by changing the environment so as to encourage them to do it. Keep going until you have at least ten items.”

Um, OK.

9. Have you ever felt when appointed Leader that you were essential to the group?

“What did the group do when you were not around? What did they do when you eventually left? Could there have been some sort of self-fulfilling prophecy in operation?”

See question 7.

10. For some group you work with, consider ho much of your influence in that group derives from your appointed position.

“How much comes from your idea power? How much from enhancing the idea power of others? Are you satisfied with this mix?”

Influence from appointed position is something I’d like to mostly do without. Most of my influence tends to come from my own actions and ideas. So far, I haven’t been very good at enabling others, except when paired with someone who is a good match with me.

11. Tomorrow morning change your traditional breakfast in some way.

“Notice if your day changes.”

I seemed to be a bit more focused in the morning, having a routine-breaking thing I needed to do.

12. For the next two weeks, change your breakfast each day according to some new idea each day

“(such as fewer or more calories, faster of slower preparation, more or less wholesome, more interaction with other people, less interaction with others, more appealing to look at, thirty minutes later, thirty minutes earlier, in a different place, using different utensils, hot instead of cold, cold instead of hot, more liquid, less liquid). Note what, if anything, is happening to you, and summarize the effect at the end of the two weeks.”

After a couple of days I settled into a mode, where I expected that my morning routine, while being routine, would change every day. I tried to avoid planning too much in advance, so I had to think on my feet to respond to the changes. I’d go as far as to say I was a bit more prepared for routine things to change in other areas of my day.

13. Tomorrow change the way you interact with some person you see frequently.

“Try to do it in such a way as to improve your interaction. Note the results.”

A tiny bit of conscious effort daily can have a huge positive impact on interaction, at least when both parties are naturally inclined to get along anyway. 🙂


Previously: Chapter 4: How Leaders Develop  Next up: Chapter 6: The Three Great Obstacles to Innovation

Duct tape, pine cones, a Swiss Army knife and a virtual machine or two

Today, two things that amaze me to no end:

First, a set of tools for functional testing, that allow me to write .NET code that talks to a Java server which starts a web browser, and makes it load JavaScript which then calls back to the server, and somehow this setup works and allows me to control multiple web browsers in a coordinated manner!

Second, something I thought about today only after I left work was still bugging me when I got home. So I fired up my Windows XP Mode, used it to open a VPN connection (via a web browser!) to work. Through the VPN I then used Remote Desktop to connect to my work desktop. On that desktop, I fired up my Windows XP Mode, and used it to open a VPN connection (standalone client, this time) to a network hosting a production server. Through the VPN I then used Remote Desktop to connect to the server, wherein I fired up SQL Server Management Studio to run a query against the production db.

what would mcgyver do

The most amazing thing?

While in Management Studio, I selected the query I had written, and hit Ctrl+C.

Then, I moved focus back to the computer I was physically on, opened Notepad, and hit Ctrl+V.

And it worked.

Don’t let anyone tell you programmers can’t get their shit together. If copy-paste can work reliably through that many layers, it can’t all be doom and gloom. 😉

PS. Longer-than-usual wait on Chapter 5. I’m not procrastinating, I’ve answered most of the questions already. Some of them, however, were exercises spread out to the next two weeks, and I can’t really write down the results until I have them. 

The whole idea of “learn a new language every year” is that you are a programmer. Programming is what you do. You are defined by being a programmer, by writing code. That is you, right? And it is a type of craft, and it requires craftsmanship. And in order to develop that in yourself, you learn a new language every year, and you develop yourself as a programmer.

Network problems

A few weeks ago I tried installing Visual Studio 2010. The installer failed a couple of times, but after the successful install, I quickly had to remove it because of an issue that came up: every program that tried to access the network simply hung instead of running.

Uninstalling VS helped, so I figured the beta was buggy and forgot about it. Until yesterday, when installing VMWare Workstation 7 caused the exact same issue. Obviously the culprit had to be something else, then.

I had installed a NetLimiter 3 trial  a while back, and let it expire since I decided I didn’t need it after all. Having a hunch that it might be the root cause, I tried to uninstall it. However, the state of my OS was such that even the uninstall failed.

Fortunately, a reboot later, I was able to first uninstall VMWare, then reboot again and finally remove NetLimiter. And wouldn’t you know it, after reinstalling VMWare, everything still works. So apparently VMWare did something with the network that NetLimiter really didn’t like.

This also means I wrongly blamed VS 2010 Beta 2 for the issue, so it might be appropriate to give it another shot. I’m really looking forward to trying ReSharper 5, particularly Structured Patterns and Call Tracking.

Good times.

Plenty of Fail

I’ve kept quiet recently mostly due to a single reason: I’ve encountered a person at work with whom I find working particularly difficult. I’m uncertain as to how I should phrase the situation. Objectively, his style of interaction and mine don’t match, and Unfortunately, the topic of the day is a different kind of fail.neither one of us is willing to adapt to the other.

Subjectively, he drives me fucking nuts.

I don’t want to cast blame, but I’m inevitably going to, anyway. He comes to ask me a question, interrupts me mid-answer, visibly ignores me when I’m trying to emphasize a point that I feel is essential in understanding what I’m trying to say, zones off, and acts in a seemingly arrogant way. He doesn’t respect me as a developer, regardless of the countless times he’s dropped a problem in my lap and I’ve solved it for him. And rest assured, every time he does something that I find genuinely good, I commend him for it. And if I find that I was wrong and he was right, I admit it. Right away, even.

Now, my style of discussing things may be a bit extreme to some people. I raise my voice when I get frustrated, particularly if I have to explain the same thing FOR THE SIXTH GODDAMN TIME AND YOU’RE IGNORING THE ANSWER AGAIN, AREN’T YOU, AAAARGH STAB STAB STAB.

Easy now. Deep breaths.

As I was saying, my style may not suit everybody, and for a while I was willing to accept that the fault might be entirely in me. Intellectual honesty demands me to admit that I might be the cause.

However, having discreetly approached the issue with fellow workers, five people out of five found him exceptionally difficult to work with. So although I’m certainly responsible for my part, maybe, just maybe I’m not entirely wrong in pointing a finger in his direction.

A bit of Great Success, too.

This friction (which hadn’t quite escalated this far at the time) was one of the primary reasons I agreed to a job interview at Sininen Meteoriitti, back in August.

I’ve only been to a couple of interviews during what passes as my career. But there was one distinct difference between this one and the ones I had been to earlier. I decided to bring my personal quirks on the table from the get-go, and I kept an eye on how they reacted to me. In essence, I did what I should have done every time, and interviewed them right back.

In September, I got a call from Meteoriitti. The caller told me they couldn’t hire me yet, but would it be OK if they kept my contact details anyway? Of course, I said, and pushed the idea to the back of my head, feeling a bit disappointed, since in my book “later” means “next decade, if ever.”

Apparently not so for Meteoriitti. Just over a month later I got another call, this time saying it’s a definite “Go” if I’d still be interested. Hell yes I was!

So yeah, I’m switching jobs again, after only a year and a half. But I’d like to emphasize, that while I took the interview mainly because of things I was dissatisfied with at my current job (and felt I was unable to change at the time), I’m taking the job because I really feel that things clicked here.

Let’s see how I can rock the boat there. 🙂

Security warning redux

Back in January I wrote about the security dialog for downloaded content in Windows Vista. Today, Jouni Heikniemi explains the mechanism behind the warning. In my post I pondered thusly:

Obviously the information about the original location of the file is stored somewhere, otherwise the button couldn’t have appeared when I moved it there.

Well, perhaps it isn’t that obvious. Jouni gives an example of the metadata stored within:


So the metadata identifies the originating zone. I’m left wondering why I wasn’t able to grant full trust without moving the file back to the original location. Perhaps there is more than one stream?

Practice what you preach

Time management

I keep telling myself I’d like to try a stint of project management. Preferably something safe, like the mini-software-project I’ll tackle at some point in my undergrad studies.

I was recently asked whether or not I’d be a good manager. I replied that I’d like to think so, because I have strong opinions on what makes a good manager. Of course, even if my opinions were based on something other than whatever feels good to me, that alone wouldn’t qualify me as one.

One aspect of project management is scoping things so that you can reasonably expect to finish the items in the scope, with the resources you have and within the expected time span. If succeeding there is a feature of a good project manager (and yes, it is), then I’m sorely lacking. See, after my vacation, I took two uni courses, both of which were programming labs. Having a fair bit of programming experience under my belt, I figured it’d be easy as pie. Six weeks is plenty of time. I went as far as tackling the other one, the Data Structures Lab, in C. I’ve never written a line of C before, bar the usual print(“hello world!\n”);

Of course, I can afford to make mistakes in lab projects. However, it’s somewhat disheartening to notice, that after eight years of professional programming for a living, I still suck at estimating both the amount of effort something will take, and the amount of actual programming time I can devote to something. And mainly because of arrogance.

“I love deadlines. I like the whooshing sound they make as they fly by.” –Douglas Adams

In fact, what makes this even worse, is that I made this exact same mistake back in early 2008 when I worked on my Java lab. I had six weeks, and I failed to consider that it’s six weeks of evenings and weekends. And now, just like then, I was insanely tired when I reached the finish line, and I didn’t have the energy to put the polish I would have wanted to the labs.

Incidentally, that’s one reason why I haven’t blogged for a while. I felt somewhat burned out after all that, and decided that my RSI-ridden hands needed a rest as much as my stressed-out brain did.

Compiler complainer error

Another mistake I’ve repeated is falling into the pattern of whining instead of changing things. I’ve been thinking about it for a while now, and I’m going to try something new: effecting change. I’ve tried to change things before, in a previous job, but mainly by either dictating things or arguing for or against things. In retrospect, it’s no wonder it didn’t work. I must have seemed like a total asshole.

This time, I’ll try a different approach.

I’ve identified a problem that I feel needs to be dealt with: too long feedback loops. We write code, and we get comments after a period that may turn out to be months long. At some point, the value of the feedback is less than the cost of the changes the feedback implies, because we’ve built other things on top the things we built before, and it becomes a lot like trying to change a bottom card in a house of cards.

To combat this, I’ve recruited a co-worker to help review code. My code, that is. I’m hoping in turn he’ll feel comfortable letting me review his code. And if this works out, we will see if we can get others to take part, and switch reviewer-reviewee-pairs often. The important bit is to keep it informal, keep the iterations short and make everyone feel it’s peer review, not review by superiors. That way, I’m hoping the feedback loop stays short, and the usefulness of the feedback is maximized.

Reviewing is also a great way to cross-pollinate knowledge and good ideas. I really hope this works out.

Awesome errors

Yeah, I know, it sounds like an oxymoron. But then you run across something like this:

Firefox failing to recover last session

First, it starts with an apology. Well, not exactly, the text is “Well, this is embarrassing.” But it’s funnier than “sorry”, and a lot of software that says “sorry” usually also throws its hands up in the air and give up on trying to help you.

It then expands on why the situation is embarrassing. “Firefox is having trouble recovering your windows and tabs.” That feature comes into play not only when you ask Firefox to save your session, but also when Firefox crashes – so there’s a good chance we just ran in to an error while trying to recover from a previous error.

Finally, “This is usually caused by a recently opened web page.” Ah, more information. This might help me avoid the issue in the future. I doubt that the cause was a web page in this case; it was probably more due to my whole laptop locking up for so long I got bored and did a hard reset. 🙂

Then it gives you an option: try recovering some of your session. Maybe you just wrote the perfect blog post, or tweet, or what have you, and you would really hate to lose it. Granted, there’s a possibility that one of the tabs you want to recover is the one that caused the problem, but clearly Firefox is putting in some effort, trying to help you.

There’s an article that sort of explains why I’m feeling so happy about this, but I can’t find it. I think it was by Joel Spolsky. Anyhoo, the gist is, when your customer encounters an error in your product and you own up, and then handle the situation really well, the customer will actually like you and your product more than they would have if the error never happened.

Firefox handled this in a way that made me like it more. Well done, Mozilla. 🙂

1 2 3 4 5 11