Tagged Revision Log Messages in Mercurial

March 12th, 2010

I work at YouGov and we use the Mercurial for revision control.

We tag every release in a MAJOR.MINOR.BUGFIX format. 2.32.2 for example.

Recently I wanted to get a summary of the commit log messages for each of the tagged revisions. Here is the magic command that got me the output that I wanted:

# get all log entries for releases tagged with a 2.31 MAJOR.MINOR
hg tags | grep 2\.31 | cut -c33-36 | xargs -L1 hg log -r

cw

Evolution of a Haskell Function

March 11th, 2010

I’m going through Real World Haskell trying to get a handle on the Haskell programming language. Python is my current language of choice, but I like to learn new programming languages too.

So last night I was going over the chapter that introduces ‘let’, ‘where’, ‘case’ and guards and I wanted to try them out. I contrived a simple situation where I thought I could use them.

Read the rest of this entry »

Link: PiCloud Overview

March 11th, 2010

Here’s a great overview of using PiCloud that goes beyond “hello world” type stuff.

For those of you who don’t know, PiCloud is a cloud computing platform for Python that aims to simplify the task of running code in “the cloud.”

cw

Aubrey

January 6th, 2010

Our family is so excited and blessed to welcome Aubrey into the world.

Baby Aubrey

She was born this morning at 7:11am EST. She weighed in at 8lbs. 1oz. and is 19″ long. Mom and baby are doing well. I’m doing great! :-)

cw

On Tree Houses and Software

November 12th, 2009

From the ShopTalk blog:

The Minimum Viable Tree House

A case-study in what not to do with your software project.

Beautiful Coroutines

October 20th, 2009

Some guy on some other blog wrote this. His name sounds familiar …

Beautiful Coroutines: Cooperative Concurrency in Python using Diesel

cw

Diesel

September 23rd, 2009

I’ve been working with some friends on getting a startup off the ground. We just released one of the core libraries that our software is built on.

Announcing Diesel!

cw

What I did this past weekend

September 21st, 2009

This past weekend, I enriched some soil. I know it sounds cool, but really, it was freakin’ awesome.

I started with light brown dusty dirt in a “flower bed”. It might have even been tainted with nuclear waste. Nothing grows in it. Ants prefer to make their nests in the concrete sidewalk adjacent to it.

So I started in on the dirt. What did I start in on it with? A real-deal pick ax. Oh. Yeah. I didn’t let up either. OK, I did let up, a few times in fact. That dirt was hard. Harder than the hands of any of the Cleveland Browns’ wide receivers. That hard.

After I was done with the pick ax, I started in with the shovel. I loaded the dirt into a wheel barrow. I pushed the wheel barrow into the woods. I dumped the dirt. I proceeded to iterate over these steps until at least a ton (weight) of the dirt was in a pile in the woods.

If I were a retired guy prone to exaggeration and I was watching me, I’m pretty sure I would have said “That guy must have hauled twenty, maybe thirty tons of dirt! He was speed shiftin’!”

Let’s take stock of the situation. In the front yard I have … less dirt. In the woods I have … more dirt. Aha, but also in the woods, I have my secret weapon. An even bigger pile of leaves, from last fall. They have been lying in wait, decomposing, for just such a moment as this.

Now I haul wheel barrows full of dirt/decayed leaves to the front. Load after load. Iterations. Piles of dirt/decayed leaves. I spread the dirt/decayed leaves in the “flower bed”.

It used to be light brown, almost sand colored. Now it is brown like coffee grounds - or decomposed leaves - and it is enriched.

cw

Crushed

June 27th, 2009

“Julio!”

There was no answer.

Though drenched with sweat, the summer heat was no match for the desperation of a father for his son. Racing through the field, the leaves on the cornstalks met Gustavo’s skin like slender green blades. He didn’t even notice the pain as he closed the gap between himself and where he had last seen his son.

As he burst free from field where he toiled, he nearly toppled over the children. Julio’s playmates were frantic. Tears streamed down their faces carrying the the dust of the pasture from their eyes. Gustavo hardly halted for a second.

He had already heard their cries from a long distance off, and he had heard the cry of his son.

The pasture wasn’t far now. Gustavo’s heart filled with a mixture of fear, love and rage as his eyes settled on the dark shape ahead beside the fence row.

Cavernous black eyes laced with red veins met the eyes of the overwhelmed father. The now giant bull that he had raised from a calf stood above the limp, bloodied figure lying in the dust.

“Father!”

The cry was one of desperation. The thunder of the hooves behind him surely drowned out his small voice. He glanced to his right and for a brief moment felt relief at the sight of his friends sliding under the fence to safety.

“This shouldn’t be,” the primal thoughts that raced through Julio’s mind told him. The animal must have broken free from its paddock and entered the previously empty pasture that was the children’s playground for the day.

It happened suddenly. The great horn hooked his light frame and sent him hurtling through the hazy air. The scene of the pasture swirled around him. Then the crunch of his back against the fencepost and the taste of blood and dirt in his mouth.

Before he could recover the hooves and horns of the great beast met him with blow after crushing blow. No more cries he made, only the involuntary sounds of air being forced from his now-beaten body.

The pain blanketed him like the heat from the midday sun blanketed the countryside.

“I’m finished,” he barely thought as consciousness mercifully began to depart him. Darkness was closing in all around.

A terrible sound tore across the pasture and reached the ears of the fading child. It was familiar to him. Again it sounded, cutting through the darkness of his consciousness like a sickle through wheat. Rather than adding to his misery, the deafening sound comforted Julio.

His father had arrived.

Before the first shells were finished dancing in the dust near his feet, Gustavo unleashed another round upon the treasured animal, now turned murderer. It reared away in fear and pain and stumbled to the ground a short distance from the child. The nearby ground shook as the great beast fell to the dust.

Casting his weapon aside, Gustavo cleared the fence and was at once by the side of his son.

Julio felt the whole world begin to shake, as visions of the farm where he lived flashed before his eyes. With his final act of consciousness before slipping into the darkness, he realized that he was in the arms of his father, who was rushing him off to undoubted safety.

.

Odd Old-Style vs. New-Style Class Behavior

May 21st, 2009

So we have some older Python code at work that uses old-style classes. We usually try and bring those up to date when we encounter them.

The other day one of the developers did that and one of our tests started failing. A simple change from:

class Foo:
    # stuff here

to:

class Foo(object):
    # stuff here

was all that happened.

Here is some code that encapsulates the problem and runs with some interesting results:

"""Two nearly identical classes with quite different behavior."""
 
class LameContainerOld:
    def __init__(self):
        self._items = {'bar':'test'}
 
    def __getitem__(self, name):
        return self._items[name]
 
    def __getattr__(self, attr):
        return getattr(self._items, attr)
 
class LameContainerNew(object):
    def __init__(self):
        self._items = {'bar':'test'}
 
    def __getitem__(self, name):
        return self._items[name]
 
    def __getattr__(self, attr):
        return getattr(self._items, attr)
 
if __name__ == '__main__':
    for cls in [LameContainerOld, LameContainerNew]:
        container = cls()
        print "Testing", cls
        try:
            'foo' in container
        except Exception, e:
            print "\tMembership in %s raised %r!" % (container.__class__, e)
        else:
            print "\tMembership in %s worked!" % container.__class__
        print "\t%s" % container.__getitem__

Here is some output from running that:

Testing __main__.LameContainerOld
        Membership in __main__.LameContainerOld worked!
        <bound method LameContainerOld.__getitem__ of {'bar': 'test'}>
Testing <class '__main__.LameContainerNew'>
        Membership in <class '__main__.LameContainerNew'> raised KeyError(0,)!
        <bound method LameContainerNew.__getitem__ of <__main__.LameContainerNew object at 0xb7d1c1ac>>

From what I can tell, when a membership test happens on the old-style instance, a membership test is done on self._items and it returns False. When the membership test happens on the new-style instance, it tries to treat it like a sequence and calls the __getitem__ method with index 0.

Does that seem like a correct analysis? Does anyone know why the behavior is different there?

Also look at the output for printing container.__getitem__. Isn’t __getattr__ only supposed to be called when the attribute isn’t present on the instance? Why does it return the __getitem__ method of self._items for the old-style instance then?

Very puzzling.

cw