Saturday, September 04, 2010

A baby, A baby, I have a baby!

On September 1st, 2010 (1 week before her due date) at 3:24am, after 25.5 hours of labor (23 of it back labor with no epidural), my daughter - Sophie Elizabeth - came into the world. She weighed in at a grand 9 pounds 11 ounces and measured 19 inches. So, average length baby, above average weight. She's what the nurses referred to as LGA (Large for Gestational Age).

Labor started around 2:00 AM on August 31st. Katie was in a lot of discomfort because of the back labor. We put her in a warm bath, and I massaged the back of her hips. We checked in the birthing center at 8:30 AM. Katie, at this point, was dilated to 3cm.

After several more excruciating hours of back labor, Katie had progressed to the point they though it was a good idea to move her to the tub (5cm). She got in the warm tub and was very grateful for the warm, relaxing water.

After many more hours, and with a friction rash developing on her back where we were massaging, she had progressed to 8cm, and plateaued there. The midwife suggested we break the water to help the labor along. We were hesitant and decided to hold off for a little while longer to see if walking around and a birthing ball could help the labor progress (as well as try to move baby anterior instead of posterior to relieve the back labor).

About an hour after this, Katie still had not progressed and was in a lot of discomfort because of the continual back labor. We consented to breaking the water in hopes of getting things to move along. There was some meconium in the water, but not very much. Katie got back in the tub and the intensity of her contractions was noticeably more intense.

After 3 more hours of laboring, Katie was still just at 8cm. Something was holding up labor. However, the good news at this point was that when we broke the water baby moved anterior, which meant an easier exit for baby.

Because Katie had not progressed, we transfered to the hospital (at about 12:00 am), so that we could get some drugs to help ease the labor and help it progress.

The doctor inserted an internal fetal monitor (He screwed the thing into my baby's scalp! What a monster), and we got the anesthesiologist over to give Katie an epidural. The epidural eased all of her discomfort (since she went numb from the cauda equina down) and she had progressed to a complete 10cm within 15 minutes. They let her "rest and descend" for about an hour to recover some of her energy.

Due to exhaustion (2 hours of sleep, and such a long labor) her contractions weren't intense enough to help push baby out much. She was put on a pitocin drip to help the contractions and we began pushing the baby out. (In my opinion, there has got to be a better way to push than that. Sheesh).

After about 10ish contractions worth of pushing (about 1.5 hours), and a very large episiotomy, Sophie came into the world. They did some lung suction (because of the meconium), then whisked her off to the NICU because she was having trouble breathing.

They put her on CPAP for an hour, then kept her their for observation for another 30 minutes, at which point she was deemed stable and transfered to the nursery.

In the nursery, she was given her first bath. I was there, but too tired to think, and didn't ask for the opportunity to do the honors. Her vitals were taken, and she was handed over to me. Our nurse was informed that she was ready, and I took a seat to wait for the nurse and just hold my baby. Over 30 minutes later, and a brief nap in the chair with Sophie, I asked where the nurse was. Apparently she had forgotten Sophie was ready (or been busy and not yet had time).

The nurse came rushing to the nursery, and Sophie was transfered to Mother and Baby, where Katie was very anxiously awaiting really meeting her baby. She was finally able to hold Sophie, after many many long hours. I dare say, there isn't quite anything so sweet as the love a mother has for her newborn babe.









Our album of Sophie pictures can be found here:: http://www.flickr.com/photos/killermonk/tags/sophie/

Thursday, August 05, 2010

Mercurial Extensions when using Apache/HTTPS and hgwebdir.wsgi

Today I spent about an hour at work trying to get the Mercurial Notify hook working with our https/hgwebdir.wsgi setup.

After countless searches, I wound up reading about all the possible mercurial config sections that are possible. Then I stumbled across the [trusted] section.

It states "Mercurial will not use the settings in the .hg/hgrc file from a repository if it doesn't belong to a trusted user or to a trusted group". www-data, by default, is not a trusted group.

So I added this section to my global hgrc file (/etc/mercurial/hgrc)
[trusted]
groups = www-data


And, like magic, it started working.

One thing that should be noted. If the user pushing their changes does not specify a username for the push it will use 'www-data' as the user. Just a gotcha.

Wednesday, April 14, 2010

PHP Factories/Python Factories - Dynamic Class Instantiation

I have been a full-time PHP developer for the last 5 years. Recently, I have begun to branch out my skill-set and learn Python. I struggle with this because there are a lot of the fundamental basics of the language (Python) I do not fully understand. Things you learn in big expensive boring books or through experience.

I am a big fan of the factory design pattern. I use it a lot in PHP, and I find it very useful for initializing things that all use a common interface are base class. See my GeoCoder Extension written for the Yii PHP Framework. I use a factory for loading the driver I want to use.

I was trying to figure out how to do this kind of thing in Python and was struggling. Having been in PHP so long, I am used to a language that is almost as bad as Perl for adding the ability for coders to write Read-only psychotically dynamic code. See PHP Variable variables.

So, after much searching, I found a starting point, and have touched it up to be a little more flexible. The difference in code length will show why I like PHP so much some times. However, the *args and **kwargs do make the Python implementation more powerful for passing arguments to the constructors. In PHP, I just use an init() function and pass an associative array instead.

PHP Code:
/**
* This function does not do file inclusion
* it assumes an autoloader is in place for that
*/
function Factory($class, $options) {
$instance = $class();
$instance->init($options);
return $instance;
}

/********************/
/** USAGE **/
/********************/
class MyClass {
public function __construct() {
}
public function init($args) {
foreach ($args as $key => $value) {
$this->$key = $value;
}
}
}

$instance = Factory('MyClass', array('language' => 'PHP'));


Python Code:
def Factory(fqcn, *args, **kwargs):
"""
This function takes a fully qualified class name (fqcn)
then imports and loads it
If there is no qualifier, or the qualifier is 'global'
then it tries to load the class from globals()
"""
paths = fqcn.split('.')
modulename = '.'.join(paths[:-1])
classname = paths[-1]

if modulename == 'global' or len(modulename) == 0:
klass = globals()[classname]
else:
__import__(modulename)
klass = getattr(sys.modules[modulename], classname)

if len(kwargs) > 0:
return klass(**kwargs)
elif len(args) > 0:
return klass(*args)
else:
return klass()

####################
## USAGE ##
####################

class no_args:
def __init__(self):
pass

inst = Factory('global.no_args')

class two_args:
def __init__(self, arg1, arg2):
self.arg1 = arg1
self.arg2 = arg2

inst = Factory('two_args', 'first', 'second')

class named_args:
def __init__(self, arg1='arg1', arg2='arg2'):
self.arg1 = arg1
self.arg2 = arg2

inst = Factory('named_args', arg2='second')

# Something real
import sys
root = Factory('Tkinter.Tk')
app = Factory('Tkinter.Frame', master=root)



Some people may be thinking "Hey, but what about 'type', isn't that easier to use for this?". In answer to your question: Yes, but No.

Creating a new "instance" of a class with type is very easy. But it does NOT create an instance like most people would think it would. Just try it out, you'll see what I mean.
class myObj(object):
def __init__(self):
print "Object Initialized"

def doAction(self):
print "Object in Action"

real_inst = myObj()
real_inst.doAction()

pseudo_inst = type('myObj', (myObj,), {})()
pseudo_inst.doAction()

dynamic_inst = type('myObj', (object,), {})()
dynamic_inst.doAction()


"But," you say, " pseudo_inst worked just fine!". Well, what is the point of a dynamic factory if you have to have a static class reference in there to make it work? And, thus, the 16 lines of factory goodness were created.

Disclaimer:
I realize the examples here don't require a factory. They are just examples. If you know what factories are and the concepts behind them, you will be able to see where this kind of thing can be useful.

Happy Coding