mihai.ibanescu.net

July 1, 2009

python: the dangers of assert

Filed under: Babbling — misa @ 14:50 -0400

I ran into a piece of code that looked like this:

import threading

class A(threading.Thread):
    def run(self):
        self.foo()

    def foo(self):
        assert(threading.currentThread() != self, "Blah?")
        print threading.currentThread() == self

a = A()
a.start()
a.foo()
a.join()

In the original code, there was no a.foo() invocation, because that would have triggered the assertion. Or so it was thought. I added it for my own edification.

The intention was for the foo() method to be callable only from within the running thread. In my quick test above, a.foo() should have failed.

There were two problems with that piece of code. First, it was not failing. Second, in python 2.6 you get a warning whenever you use assert with paranthesis. This is very deliberate, since assert is not a function. Using paranthesis will simply pass a tuple to the assert construct, and the tuple will always evaluate to True.

Very dutifully, I removed the paranthesis, and moved on to do some other things (and I even forgot I did it). A few days later, a coworker reported problems with the code.

As it turned out, the assert was hiding a very old bug - the condition should have checked for equality, not inequality. But since the condition _and_ the error message were paranthesized, the code passed no matter what you did. Removing the warning uncovered the problem, probably 3 years later.

June 1, 2009

Probable causes for errors

Filed under: Babbling — misa @ 13:26 -0400

If you needed an excuse-of-the-day look no further than the DMTF specs for CIM.

The CIM_Error class has a ProbableCause property which can have a long list of values:

http://msdn.microsoft.com/en-us/library/cc150671(VS.85).aspx

“Toxic Leak Detected”, “Ice Buildup”, “High Winds”.

In a way, I feel refreshed to see the potential causes for the world’s problems are no more than 129.

May 30, 2009

27-mile week

Filed under: Running, Sports — misa @ 11:38 -0400

Yes, I ran more than a marathon.

Unfortunately, spread over 6 different days.

Last week I ran 24 miles (4 days 4.5 miles each, a longer weekend 6-mile run), and this week I wanted to increase the distance by 10%. That was 6 days with 4.5 miles each - tomorrow is rest day.

I am not training for anything at the moment, so I am pretty happy, especially after coming from a 3-week vacation where the only running I did was a 15-minute downhill Tâmpa in Bra?ov. I will probably try to keep it at this level, I have no interest in increasing the weekly distance at this point.

Sprained ankles

Filed under: Running, Sports — misa @ 11:30 -0400

Thankfully, the title is not about me.

I was running my usual trail course today and found a lady who sprained her ankle so bad, the pain almost made her pass out. I helped her hop on one leg to a house less than 100 yards away, where a very nice gentleman drove her home.

She mentioned that she doesn’t want to go to urgent care because she recently got laid off and has no medical insurance. This is so sad on so many levels. Silly economy. Stupid medical system.

May 8, 2009

Dinner in Vienna

Filed under: Babbling — misa @ 8:03 -0400

Flying back from Romania, we had a one-night layover in Vienna, Austria, and we spent the evening sightseeing.

Here is the dinner-on-the-run we got from a supermarket (we wanted to use the daylight for pictures, so we chose to eat at the hotel instead of a restaurant in the city).

The Limburger was not “ripe” yet (i.e. it was still firm; as with the Camembert, if you let it outside for a few hours, it will become soft and spreadable - and extremely smelly). Off the supermarket shelves, one only gets a hint of how rotten it will become.

In the train that was taking us back to the hotel, every time I was opening by backpack, I was afraid the HAZMAT unit will show up and throw us out.

The cheese strudel was pretty good too, but it had no good story behind it.

April 12, 2009

“We know your vehicle best”, dealership says.

Filed under: Uncategorized — misa @ 7:05 -0400

Recommended tire pressure in my wife’s Honda Fit: 32 PSI.

Actual tire pressure, almost 2 months after the car was at the dealership where they rotated tires and adjusted pressure, with no intervention from me ever since: 40, 32, 35, 37 PSI. Measured at cold (not driven for a day).

Given that we’ve seen the tires slowly lose pressure in her vehicle (dropping from 32 to 25 in about a month, thus triggering the onboard sensor several times in the past), makes me wonder how much air they’ve put on Feb 16th.

Autopark Honda, I’m watching you.

March 29, 2009

What? No rain?

Filed under: Orienteering, Running — misa @ 21:23 -0400

The past two events (Lake Johnson Night-O, directed by yours truly, and Schenck Forest) were extremely wet, coming after several days of rain _and_ with rain during the event.

Today’s event at Umstead didn’t look great either if you were to trust the weather forecasts at the beginning of the week. However, as the event got closer and the forecasts predicted the rain would stop some time Saturday night, we’ve seen a lot of people registering. I know because I happen to be on the list that gets the notifications.

Today was a bit windy, but otherwise sunny and - what a change - dry! Mostly. There was still a lot of mud everywhere, and on some steep hills I felt like skiing. But coming back with my clothes completely dry, that’s definiltely different.

Jozef designed a beautiful and very challenging course. The Green course was longer than our Red usually is (6.7km), and Red was 7.4km. If that doesn’t sound much, maybe I should add the elevation changes that pretty much killed my legs by the time I got to control 13 (out of 19). By then I was obviously no longer thinking straight, I lost probably at least 10 minutes looking for control 16 after I passed it probably by 30m. Then I lost a few minutes at control 19 (the last), a trivial one, because I took the wrong clearing (which was not mapped), instead of the obvious one with some man-made objects in it.

In a way I wish I stopped after #13 and call it a Green day; on the other hand I found out how out of shape I am (not that I didn’t know, having skipped some of my runs for wimpy reasons like “the trail is wet” and “I’m too tired to wake up”). 106 minutes of running (and walking towards the end) proved to be quite tough on those hills. Once the results are posted, I’ll know how bad I did compared to others.

I probably need to train for a specific goal, maybe I’ll set one after we come back from vacation in Romania, mid-May-ish.

To quote a slogan I read on a t-shirt: “procrastinators, unite tomorrow!”

(to be fair, I know I will not train while on vacation, except for maybe a food contest, so there’s little reason to plan for something now).

February 24, 2009

reCaptcha

Filed under: Babbling — misa @ 21:12 -0400

Today I finally got to read about the idea behind reCaptcha. Yes, I am behind.

I found it both very clever and a step closer to the Matrix.

February 16, 2009

Scheduled Service at Car Dealership - Long Rant

Filed under: Babbling — misa @ 23:08 -0400

For about 7 years now, I’ve been changing the oil in our family cars (and doing other maintenance tasks too). It originally started as learning something new, then I thought I am saving some money. Now I think I am saving time, because I can change the oil in the middle of the night, in my garage, instead of trying to work my schedule and the kids’ around an appointment at some shop I might trust (no, I no longer trust Merchants or the like, but that’s another story).

Actually, I think in my ‘04 Matrix the only oil change I did at the dealership was the first one. And I planned on having the first oil change in my wife’s Honda Fit done at the dealership too, with the next ones done by yours truly.

My wife’s previous car was a Toyota Corolla, so it’s been very easy - both cars accepted the same oil filter and the same oil grade. The Honda being different, I did a bit of research on the Internet for good oil filters, got scared by shipping prices and decided to buy an oil filter at the local dealership when I do the first oil change.

So I did. Oil filter was $7 and change (plus $0.32 for the washer that Honda recommends to replace with every oil filter change - no comment on this). A bit more than buying it online, but less if I were to include shipping for a single item. It’s obviously better to buy a multi-pack and save on shipping, or buy a quality non-OEM filter (since the OEM ones are not necessarily the best or reasonably priced, according to several forums). A quart of 5W20 oil was $2.57 per quart (regular, not sythetic) - again, not a terrible price for a retail quart - but I decided to not buy the oil just yet. This was at the parts store inside the dealership.

After the oil change, I looked on the invoice. OK, $16 for labor, $7 for the oil filter, $0.32 for the washer, 4 quarts of oil at $2.57 per quart, plus taxes - somewhere at $35. They threw in a free carwash too.

But then, I started to think. OK, the oil filter was the same price as the one in the parts store. If I can buy online 6 oil filters for $27.19 and 6 washers for $0.96, I am sure their real price is much lower. Maybe it was separately packaged just like the one in the store, so whatever.

However, I know from watching the Toyota dealer perform oil changes that they do not waste their time with oil in quart-size bottles - Fred Anderson had an oil circuit that was probably fed from barrels of oil sitting somewhere in the corner. Manufacturers usually choose the same oil grade for most of their fleet, so it makes sense for the service shops to buy it in bulk. I am sure Honda does the same (if they don’t, they’re morons). But I don’t expect them to invoice me for the oil at the same price as the retail store.

One of the big revenue streams for car dealers is service - and they probably want customers to return. I would have been happy to see on the invoice the oil being $0.50 per quart (probably more than they pay) with a labor of $30 instead of $16 (since it took exactly an hour for the whole thing). Looking at things side by side, I may have said: ok, I definitely can’t beat the price for the oil filter they buy in bulk, or the oil they buy by the ton, and the labor is reasonable - I’ll be back here for the next oil change!

But if what they charge me for parts is what I would pay for parts at their store, which I know I can beat by shopping on the Internet, then their story for convincing me to be a returning customer is a lot less compelling.

Sorry Honda, I hope you can do your service better next time (when I buy the next car from you).

February 7, 2009

Gorgeous day for around-the-home activities and mapping at Lake Bond

Filed under: Orienteering, Sports — misa @ 18:53 -0400

After a stretch of cold days, today started at 34°F (at least started _for me_, when I stepped outside around 8:45 for a quick run). After that, trimmed the crape myrtle in front of the house (by then the temperature got above 65°F), went for a couple of hours back to Lake Bond with my son (throwing rocks and twigs in the lake is fun!), then back home for an hour and a half, then back to Lake Bond (third time!) to do some mapping on the North-Western side of the park - and I ran out of daylight.

All in all, a great day to spend most of the time outside.

Older Posts »

Powered by WordPress