Finding an item in an array of PSCustomObjects

(This is mostly so I can find it again someday when I need it again.)

When working with REST interfaces with PowerShell it’s pretty common to get JSON responses that have information that is returned as arrays of PSCustomObjects. If you need to update a property of one of those objects you can’t just do something simple like:

In order to set the value of a property you’re going to have to find the index of that particular object in the array and then manipulate it directly. Thankfully this is easier than it sounds because we have access to the static methods of the .Net Array object, and FindIndex in particular. The previous example actually ends up being something like this:

Standardized Tests for Standardized Parameters

Something that you find when writing PowerShell modules to wrap API functions for external systems is that a lot of your functions tend to have a consistent subset of parameters that get used for things like credentials and specifying an endpoint. For example in the private TeamCity module that I maintain the parameter block for every function that interacts with a server has:

(Whether that is the best pattern I’m still not sure, but it’s beside the point of what I’m talking about here. If you have better ideas I’d love to hear about them!)

If you are writing good unit tests for your functions you need to test those parameters in every single one of those functions and ideally you want to test those parameters consistently to make sure that FunctionA doesn’t use them slightly differently than FunctionB. Additionally if I find a better way of testing those parameters I don’t want to have to update¬†dozens (or more!) of Describe blocks. There had to be a way of writing those tests once and then calling those tests¬†consistently when testing every one of those functions and it turns out to be pretty simple.

The trick is to consider that Pester is pretty consistent about scope inside the Describe and Context blocks so if we were to dot-source some external file in the correct context we should be able to inherit anything that’s in that file. Declaring variables with consistent test values and wrapping tests inside of a function definition means that we can do the dot-source in the scope of a Describe block and then reference those variables and call those sets of tests in every function’s tests.

For example, let’s start with a file called “StandardTests.ps1” that defines two variables and a function to test those two variables:

Then making uses of those variables and tests might look something like this:

The only thing left is to run the tests!
Successful Test output

Reporting Pester Code Coverage Metrics to TeamCity

As previously mentioned I’ve been doing a lot of work with PowerShell modules at work where I have recently gotten all the parts for a full continuous delivery pipeline working for those modules. A big section of that pipeline runs through TeamCity and while the existing ability to have Pester test results show up in the build results is really great, code coverage is slightly less obvious but in the end fairly simple.

The trick is to use the -PassThru parameter with Invoke-Pester and then use TeamCity’s build reporting interaction to get the values into the system. The end result will look a lot like this:

Pester code coverage right in your TeamCity build results!
Pester code coverage right in your TeamCity build results!

New Marvel Trades on Nook (12/26/2011)

New Marvel Comics Available on Nook 12/26/2011

I find that it is often nice to be wrong, and yesterday’s bumper crop of releases is very welcome. I wasn’t expecting to see any more titles for at least a week and honestly only checked very late last night on a whim. Obviously I need to be more diligent about that daily checking.

Six of the sixteen new collections are from regular titles and the others are limited run titles of one sort or another including the “X-Necrosha” event collection which spans multiple titles (I’ll have to ask Sigrid Ellis if that one is worth buying or not). It is good to finally see a Fantastic Four collection though I’m not familiar with this particular writer or his storyline. Ghost Rider has never been a character I really understood but it is good to see an increase in the diversity of characters from the Marvel U. IIRC Spider-Man: Blue was pretty well received though I couldn’t tell you why and it might be awhile before I get around to finding out for myself.

However it’s not all good news. Remember last week when I said they were doing the Ultimate books right? Well this week sees the release of Ultimate Spider-Man volumes 5 and 6. Last week had the release of volume 3. Where is volume 4? Maybe stuck in someone’s email inbox somewhere…

No tag for this post.

Part Commonality: 2×1 Invert 45 Slope vs 1×2 Technic Brick

In the conversation on the TwinLUG list about the recent proposal for a change to the Micropolis module bases, there was an assertion that the use of 2×1 Inverted Slope 45 bricks would be a problem because they weren’t as common as Technic bricks.

I didn’t quite disagree, however it seemed like a strong assertion to make without actually researching the available data. So I did.

The result is the following graph which plots the number of sets that each part appears in from 1977 through 2011, the avg number of sets per year, as well as the trendline for the appearance of the part. Absurd overkill for the conversation? Absolutely, but it was fun to put together.

No tag for this post.

Pie Test

Just a post to test a new plug-in. This should include a tweet from my account…

Verdict on Heroica: Pretty decent, but needs serious rules tweaks. ForEx: Big monsters need more health. Need reward for killing monsters.
@Cavorter
Nathan Stohlmann
No tag for this post.

A few words about exercise

Last fall I sold my duplex and moved in with my partner, her partner, and their kids. It’s a small house but in a very nice neighborhood and while I miss many of the things about living alone it is really nice to be living with family again.

One of the downsides of moving into a very small house with four other humans, three dogs (at the time: the eldest, Toby, unfortunately died a week and a half ago), many rodents, and assorted insects and arthropods is that there is not much room for one’s existing very nice recumbent exercise bike. We finally did find a space for it sometime around February but I have yet to get it out of storage and move it into the dark and cramped basement to find out if that space will work or not.

The reason the exercise bike exists in my life at all is that during my divorce I knew I needed to do something to stay active and I fondly remembered my high school days when I would go out and spend time by myself biking 10-30 miles around the countryside so I got the aforementioned recumbent. That first winter and the five subsequent years it was a simple reminder and easy task to just get on and do 15-30min with easy access to watching TV or even playing Xbox from it. Two years ago I borrowed my dad’s mountain bike to test the theory that if I had a real bike I might make use of it to even get around town and while the experiment was not an unqualified success it did essentially show that Have Bike, Will Travel. With finances showing more positive aspects than they had in years, April was the time to finally invest in the results of that experiment.

I knew from the borrowing experiment that a mountain bike was not what I needed. While the front shocks would sometimes be nice, more often I found I was too mushy a ride and absorbed too much energy. Likewise when I replaced the knobby tires with decent road tires half way through that summer the effort required to bike to work was reduced immensely and the reduced vibration in the handlebars improved ride comfort in the handlebars by a frankly immeasurable quantity. So I knew I didn’t need a mountain bike or really just about any of it’s features except for a nice wide handlebar. I also knew from past experience that the head down posture of a road bike was a sentence to back torture so it was time to head out and look into cruisers and hybrid styles.

I stopped first at the Roseville location of Erik’s Bike Shops and after looking through the racks and getting the attention of a really very friendly and helpful sales person pretty much ignored the cruisers and went straight for the hybrids. The Giant Cypress was a good start but felt a bit too much like the mountain bike, albeit with more grace and more trim profile. The Cannondale Quick series seemed to be about the best match of price and features but still didn’t quite feel right. A third option that I don’t remember the make or model had a really nice gearing system internal to the rear axle but didn’t really seem to be worth the $200 price premium. Having done enough car shopping with my parents in my youth it was time to get a quote for a Quick 1 and head out to my next stop to see what else was available.

The plan had been to move on to a local independent and then over to REI as a final stop, but my search ended at that local independent. The Bicycle Chain at Larpenteur and Lexington in Roseville (in the same strip mall as Key’s) turned out to not only have exactly what I was looking for as well as having a really top notch staff, but also to have everything cheaper then Erik’s and the prices at REI that I had checked online. It’s not a big store but they make good use of their space to carry a pair of wheels for just about everyone and everything, and even have some unicycles for the daring. I rode a different model of Giant that I found as unimpressive as the Cypress and then tried a closeout 2009 Specialized Sirrus Elite and fell in love. It’s light. It’s smooth. More importantly it’s fiendishly comfortable even when cranking really hard up the long hills endemic to my new neighborhood. Better yet I spent the same amount on this bike with a huge slew of accessories and upgrades (new pedals with ultra-smooth bearings, fancy computer, bright lights, and a car rack) as that quote from Erik’s that was summarily recycled when I got home.

Now that it’s home I have been pretty uneven about actually using it. Commuting to work from here in anything but a car is completely different kind of exercise: In frustration and fear of life and limb. 16 miles isn’t really so far except when it’s through some of the most bike un-friendly portions of this otherwise very bike accommodating metropolis. Sure I could add another 15 miles onto that trip and do it in great comfort along a whole series of trails but, like the mass transit system around here, if you are going anywhere but one of the downtowns you are screwed and 31 miles in one direction to get to work is a bit much. Thankfully my partner came up with a better idea for more exercise.

She and her partner have been sending their kids to classes at Circus Juventus since the kids have been old enough to do so. Seeing them learn the circus arts has been amazing and incredibly fun so when J suggested that we sign up for the summer session of the Circus Arts for Adults class, I thought about it a bit and said yes anyway.

Three classes into our 8 class session I can say that I am thankful they are honest in the print description of the class in saying that pretty much everyone is accommodated no matter experience or ability. I am not precisely the most agile or dexterous person I know and I never learned to do such basic physical tricks as climbing a rope or doing a cartwheel. But for all that I am having a blast. So far we have done Triple Trapeze, German Wheel, Globes, Tumble Track, Tumbling/Acrobatics, Mini-Tramp/Vault, Spanish Web, Low Wire, Pyramid, Trampoline, and Low Casting. Of those I have found that flips and rolls are the easiest, which I’m partially thanking early experience playing goal in soccer and later experience with Aikido, while just about anything involving the use of my arms is the hardest. I have also probably done more push-ups and crunches/sit-ups/whatever they’re called these days in the last three weeks then over the course of my entire lifetime. It’s hard. It’s incredibly exhausting. I can not always raise my arms above my shoulders afterwards. It is worth every penny and very highly recommended.

No tag for this post.

Care for a good game?

As part of my moving effort I am culling things like books and clothes, but I also need to trim down my game collection. If you would like any of the following games, please contact me before 9/25/2009. I am not willing to ship and you must be willing to pick up in South Minneapolis. Thanks!

The Awful Green Things from Outer Space
Sagarian
Cathedral
Mama Mia
Mancala
Bean Trader
Settlers of the Stone Age
Wiz-War
Warhamster Rally
Starship Troopers
Ork and Squat Warlords (Warhammer Epic 40k set)
How to Host a Murder: The Class of ’54

Update: Awful Green Things, Bean Trader, and Cathedral have been spoken for.

Before I forget…

Had been intending to post this for awhile, but I’ll just clip down a bit and get this chunk out there at least.

In the last big snowstorm I ended up with a pretty hefty ding and honestly had a great experience with Progressive getting it repaired. The whole thing was fast, easy, and relatively cheap. Bonus: due to the nature of the ding it didn’t even mess with my insurance rates.

The only downside of the insurance thing was that I had a 2008 Pontiac G6 GT for 6 days while my car was in the shop. I think the most positive thing that I can say about that thing was that it sure did go fast in a straight line. Otherwise the controls were just all around bad, especially seat adjustment. Badly placed, bad quality (felt like I was going to break the seat height adjustment just touching it), and just over all irritating. I also just couldn’t get comfortable in the thing. The seating felt like it was designed to have me lying on my back the whole time and resisted any effort to sit otherwise. Don’t even get me started on the enormous blindspot caused by the front right pillar.

No tag for this post.