Category Archives: Babbling

List comprehension (done bad) for everybody!

As I was trying to fix a test, I found this masterpiece of Python code (edited a bit to highlight its resourcefulness):

def getModuleHooks(self):
    ModuleHooks = []
    for path, dirs, files in os.walk('/some/directory'):
        for file in [filename for filename in files]:
            if fnmatch.fnmatch(filename, '*.bar'):
                joined = os.path.join('hooks', file)
                ModuleHooks.append(joined)
    return ModuleHooks

There are several offenders there: iterating over a list comprehension, and using the variable from inside the comprehension outside of it (I didn’t even know it’s possible).

Should be a candidate for thedailywtf.com

And the Oscar goes to…

After today’s World Cup Final, I am even more committed to boycott Soccer (or Football for the other 99.9% of the nations out there) by not watching it.

Too much acting. Too much cheating.

Imagine this discussion with your child (and no, it didn’t happen to mine, but I am sure it could):

“Daddy, who is Cristiano Ronaldo?”

“He’s this very famous player that earns millions per year.”

“Wow, he is really good. Look at his skills. The other team can only stop him with fouls, see? Look at the replay, you see how they… Oh, wait… They didn’t even touch him. He just fell off his feet and the other guy got red carded.”

“Well, you see, sometimes they play a little bit of acting,  you know, to improve their odds…”

“But isn’t that cheating?”

“It is, but…”

“So why do I get punished if I cheat at my test, or I am called out for plagiarizing, but they get away with it? And they have no shame that everybody will see the replay, and realize how crooked they are? Including the referees who got fooled for a second, and will get (rightfully) stonewalled after the game? And why is FIFA’s slogan ‘Fair Play’? Is it really fair to cheat?”

I am not original, I read some of these opinions on other sites. I am sure a lot of people feel the same. I am just wasting zeros and ones here.

Spain deserved to win, they were the better team (although I must admit I did not watch the whole game). Netherlands did not deserve the silver medal, after all the theatricals they played. No matter how talented Robben is, I lost all respect for him the moment he fell off his feet and claimed a penalty kick or whatever he was claiming when he was booked.

I am sure that, 4 years from now, I will forget all this, and I will waste other 90-minute chunks of my life. And I will again feel sorry for that. If FIFA does nothing to make the game what it used to be, I am afraid the game is doomed.

“The hardest thing to learn is that which we think we already know”

I saw this quote, quite some time ago, on a friend’s page, attributed to Robert A. Heinlein.

For some reason, it never struck me as something that would be generally applicable. Until several days ago, when I started to think some more about it.

The world was the center of the Universe. It took some serious effort to change that.

I guess we tend to not question what we already know. It would not be very productive if we did, at least not at every step.

But maybe on occasion we should stop and think about what we know – is that really the truth?

More than once (and too much over the past couple of days) I’ve seen us defending a position, not because it was the right one, but because we needed to justify the decision. You may notice that, sometimes, if you point something out to a person, they tend to become very defensive and argue, sometimes fiercely, what they think they know.

It happened to me before, and probably continues to happen all the time. As usual, I am better at spotting this in other persons than in myself. After all, I know myself, why would I be wrong? I’ve seen it happen to friends, to people I love, in them dealing with their own problems (in which at least I have no stake, which is the reason I can claim impartiality). It is heart-breaking how blind we can be when we try to justify (what I perceive, as an outsider, as) the wrong decision.

If I am allowed to quote from a movie, “Vanity, definitely my favorite sin.” I cannot  think of a better explanation that pride for this struggle to realize when we’re on the wrong wrong side of the fence, when it comes to human relationships.

Science may be wrong in some of its assumptions (just like in the geocentric example above), and that would have nothing to do with pride. But one person admitting their mistake takes a lot of un-learning.

If only we could see the difference between right and stubbornness.

Is there a cure for my Al Baraka addiction?

I seem to be a sucker for whatever Al Baraka (on Hillsborough Street, right next to the I-440 ramp) sells.

Today’s way of killing money:

  • fresh lamb, locally grown (from Salisbury, NC)
  • Baba Ghanouj (metal can, but who cares, as long as the contents are good)
  • Kurdish olives. Pickled, not very salty

Every time I go there I discover something new that I really have to try. I hope there’s cure for that.

20 years later… (or: the ends justify the means)

20 years ago, on this day, Romania’s president at the time, Nicolae Ceauşescu, fled under pressure from the large popular uprise which we call The Revolution.

Three days later, they were executed, after something that pretended to be a trial. Over the past days, a Romanian newspaper ran the timeline of the events, tracking the movements of Ceauşescu and his wife. The trial was filmed, and it exposed the truth about “revolutions”: in order to gain legitimacy, both for the Romanian people and for the foreign governments, they needed to show there was a trial. They also needed the former president executed, partly as an attempt to stop the attacks from terrorists (special forces allegedly trained by the former president as elite units that would protect him) against the population and the military forces.

20 years later, said terrorists are still nowhere to be found. The attacks were just various branches of the military not knowing what to do, and pulling the trigger against each other.

20 years later, the goal of the trial is ever more obvious: the new political class (which was really not that new to begin with) needed no roadblocks from the old president; they wanted the president eliminated, and they came up with a plan that would help their recognition from the rest of the world as a legitimate government.

The accusations against Ceauşescu were not sustainable in a real court. 20 years tend to erase some of the bad memories from the terrible times of his reign, so I may be missing a lot of the details about how bad it used to be (and, believe me, communist Romania was bad). But the new political class decided that the ends justify the means.

In the end, I personally believe that people give the institution of presidency too much credit. (And this applies not just to Romania, pre or post December 1989). I believe Ceauşescu was being presented with a very rosy picture about Romania, by the people around him, some of them who eventually were the ones to kill him. He was an old man, some argue he was senile, and the powers behind the curtain liked the status quo, until it became non-profitable. He was merely a symbol – the symbol of the extreme-left communism, in a Europe that was trying to get rid of the East-West separation. He probably truly believed in his ideas, completely oblivious to the real economic and social facts. His ignorance could be blamed on his age or medical conditions, but I would much rather blame it on his entourage that handled the smoke and mirrors.

December 22, 1989 – I remember that my parents were coming back from a visit from my grandparents, and I was home, alone, vacuuming and cleaning up for Christmas. And, for some unknown reason, I turned on the TV. This makes very little sense now for me, just like it probably does not make any sense for you – but we were only having 2 hours of TV per day, and most of it was just news anyway. There usually was nothing (as in no signal) on a Friday morning. And yet, there he was, talking about something I did not pay attention to. And then the audience (which was normally cheerful and would acclaim him after each sentence) started booing him. That was unheard of! An hour or so later, when my parents came home, they would not believe me.

And from that point on, Romania was glued to the TV – the same thing we all ignored for the most part until that day.

Fall activities

A quick update on my non-work related activities.

A lot of orienteering lately:

  • Quick white course at Lake Bond with my daughter a few weeks ago.
  • A very eventful Birkhead Wilderness run. You can read the report in the comments – I don’t think there was one single participant to get all the controls right. I messed up the first two and had a relatively clean run after that, especially after I started to pace count.
  • A quick Bond Park sprint. I kind of had the home field advantage, and I was still slower than the fast runners.

I ran for the first time with the Raleigh Trail Runners. I knew I signed up for pain, and pain it was. 2.5 miles at a slow speed, 6 uphill sprints on the Graveyard Hill at Umstead (off of Old Reedy Creek), and back 2.5 miles; last 2 miles were 7:50 and 6:50 minutes respectively. Maybe we were trying to make it back before it got too dark. As I said to the other (3) runners, it’s no surprise so few people sign up for hill sprints.

My daughter started to take piano lessons, so a piano had to be acquired. We got a digital piano which seemed like a good compromise of quality vs. price.

Between fixing stuff up around the house I’d like to get back to some recreational programming (picking up Flex would be nice).

python: the dangers of assert

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.

Probable causes for errors

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.

Dinner in Vienna

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.