Booklog (March 30, 2011 – March 31, 2011)

Completed this period:

  • Blue Ice by Frank Ewert (82 pages): A really warm and compelling collection of six short hockey stories, 82 pages in total. Highly recommended as a good read and of interest to hockey fans.

This places the running total for books completed in 2011 at 22.

Django Models and Inheritance

One of the first stumbling blocks that I came across as I’ve been learning Django (a Python web framework) was when I tried to do some inheritance with my models in app/  It had to do with abstract super classes.

Intuitively, I assumed that Django would take super classes and figure out how they worked and ignore the abstract super (or base) classes persay and  generate the SQL for their sub (or derived) classes by properly negotiating the inheritance.

So I went ahead and did something like this:

class super_class(models.Model):

>>> field1 = models.BooleanField()

class sub_class(super_class)

>>>  field2 = models.BooleanField()

I was wrong. It generated the SQL tables for all of the classes, including the abstract super classes, which technically could be made to work, but is certainly not what I wanted.  While it isn’t very apparent in an example with just two models, it introduces too much complexity in the database design since it makes a table relationship for every inheritance.  We want tables for concrete super classes but not abstract ones.

So, on to my next intuition. I assumed that if I made my super class not inherit models.Model and made the sub class use multiple inheritance and inherit models.Model and the sub class, this would all work.  Seemed to make sense to me at least.  So, I did something like this:

class super_class():

>>> field1 = models.BooleanField()

class sub_class(model.Models, super_class)

>>>  field2 = models.BooleanField()

Again, I was wrong. While last time the result was convoluted and inefficient, this time the result was worse and clearly crippled. While the correct tables were displayed (ie. the super classes didn’t appear as a table), the fields from the Super Class (represented in my snippet represented by “field1”) were missing. I assumed that, perhaps, the model for the sub class would get “field 1” even though the super class was not inheriting model.Models.  I was wrong and stuck.

With some assistance from Michal Petrucha over at django-users, I was able to learn that I was indeed missing something.

In order to make what I was doing, I had to set a property within a Meta class embedded in my super class. Like so:

class super_class(models.Model):

>>> field1 = models.BooleanField()

>>> class Meta:

>>> >>> abstract = True

class SubClass(SuperClass)

>>>  field2 = models.BooleanField()

With this little modification, everything works as expected. I have my abstract super classes and sub classes, and the relationship between them works as I would expect. Abstract super classes  propagate their properties to the SQL tables of their sub classes, but don’t actually show up as a table of their own.

Thank you Django-Users and especially Michal in helping me to further my Django understanding!

Ancient Code on GitHub

I rarely speak about technical/programming things on this blog, but you may see that changing a bit.  Sometimes I find I don’t need a blog as an outlook to talk about technical things, as has been the case for years, and so then I blog on other things. And at other times, it is sort of nice to talk about my technical interests!

I’ve joined GitHub and just making some really quick perusals of it. It’s a really neat community. The easiest way to describe it is by the motto “social coding”.

So far my contributions have been limited to Gists, so no repository hacking yet (although technically a gist has its own little repository). What I’ve posted are basically old Python code snippets that I found laying around on my usb hd from back in the day. That’s “old” with a capital O.  Nothing close to profound, elegant, or significant.   If there was such a category, it would probably be filed as Ancient Throw-Away Code Snippets That Nobody Will Care About.

Here they are:

gist: 866208 A Demonstration of how to use a wxPython “Notebook” with panels (WARNING: old code)

gist: 862171 An incomplete experiment with building calendar functionality with the Python icalendar module

gist: 862159 Old code generating txt list of contents of a collection of zip files — shows zipfile module

gist: 861061 Some throwaway code I used to demonstrate the IDEA cipher with the PyCrypto library

gist: 861057 Some throwaway code I used to demonstrate the RC5 cipher with the PyCrypto library

gist: 861053 Some throwaway code I used to demonstrate the DES3 cipher with the PyCrypto library

gist: 861040 Some throwaway code I used to demonstrate the DES cipher with the PyCrypto library

gist: 861037 Some throwaway code I used to demonstrate the blowfish cipher with the PyCrypto library

gist: 861036 Some throwaway code I used to demonstrate generating hashes with the PyCrypto library

gist: 861011 Python Anagram Fetcher (WARNING: obsolete code)

gist: 860797 SermonAudioParser – A throwaway demo of using UniversalFeedParser to do some basic searches on the feed

gist: 866207 A sample Python StringValidator class (warning: OLD CODE)

The Best Gaddafi Quotes

Muammar al-Gaddafi is always a good source of entertaining, zany, ridiculous quotes. Sometimes it is that he says things that are flat out wrong. Other times, he says things that are glaringly, slap-in-the-face obvious. Other times he restates things and presents them as if they are different aspects of something, when they are really the same thing.

Here are some favorites:

  • “There is no state with a democracy except Libya on the whole planet.”
  • “Democracy means permanent rule”
  • “No representation of the people-representation is a falsehood. The mere existence of parliaments underlies the absence of the people, for democracy can only exist with the presence of the people and not in the presence of representatives of the people.”
  • “A woman has a right to run for election whether she is male or female”
  • “Women, like men, are human beings. Women are different from men in form because they are females, just as all females in the kingdom of plants and animals differ from the male of their species”
  • “I cannot recognise either the Palestinian state or the Israeli state. The Palestinians are idiots and the Israelis are idiots.”
  • “Another grave historical error is for several religions to remain in existence after Muhammad.”
  • “”Labour in return for wages is virtually the same as enslaving a human being.”
  • “All African nations look up to Libya, all the rulers of the world look up to Libya. Protesters are serving the devil.”
  • “I will stay in Libya till I die or death comes to me.”
  • “If a community of people wears white on a mournful occasion and another dresses in black, then one community would like white and dislike black and the other would like black and dislike white. Moreover, this attitude leaves a physical effect on the cells as well as on the genes in the body.”

Problems with Left vs. Right Classification

“This is a good place to enter an initial complaint about the use of the terms ‘left’, ‘right’, and ‘center’ in current political discussions. The usage implies that there is a single spectrum along which any particular packet of political views views may be located. Are you in favor of free trade and against high import duties? This, apparently puts you on the ‘right’. Are you in favor of extending the franchise in South Africa to black persons? Ah! You are on the ‘left’! And if you are in favor of both, then what? What if you disapprove of socialism (which puts you on the ‘right’) but also disapprove of dictatorships (which puts you on the ‘left’–unless the dictatorships in question happen to be Marxist, in which case, somehow, your disapproval now puts you back on the ‘right’)? Plainly, this usage is futile.”

— Jan Narveson in The Libertarian Idea, p.11

Interesting Thoughts on Gaddafi

Eric Margolis has some interesting thoughts on Gaddafi and Libya in this post.

“Gaddafi was never the same after Nasser’s untimely death in 1970. He grew eccentric, then very odd. He styled himself a revolutionary leader, not a head of state.”

“However zany and bizarre, Gaddafi was clever as a fox and had more lives than a cat. He survived many attempts on his life mounted by U.S., British, French and Egyptian intelligence.”

“In 2003, in a brilliant ploy, Gaddafi bought a pile of nuclear junk on the black market, then told Washington he was giving up his nuclear weapons program. The Bush administration fell for this ruse and ended its punishing boycott of Libya, thrilled it could claim a nuclear victory after finding no weapons of mass destruction in Iraq.”

“Gaddafi is a sad example of the maxim about absolute power corrupting absolutely. People like me who relish political theater of the absurd will miss the ‘Leader;’ but most of his people, I suspect, will not.”

Servetus and Calvin

Much is made of the case of Servetus, especially by people seeking to denigrate Calvin

Bruce Gordon, in his work Calvin (and at times he is very hard on Calvin) shows some interesting things that are often ignored by people who are eager to assault Calvin’s character.

The first take home lesson is that the situation is complex, there is a rich interplay of factors and actors that take part in this.

A. In Regard to Servetus the man:

First, we need to understand what sort of man Servetus was. Besides being a heretic according to all major mainstream religious traditions of that time and place  (an offence which almost all states at the time agreed was punishable by death),  Servetus seemed to be obsessive and wanting to get punishment.  As Douglas Wilson once said something to the effect of: Servetus was the kind of guy who would join a church just so he could get under church discipline and blog about it. Bruce Gordon’s research seems to confirm this.  Servetus was warned not to go to Geneva.

And, as Gordon puts it, his attempts to make contact with Calvin “bordered on an obsession”. In fact, he wrote 30 unanswered letters to Calvin.  So there is something out of the ordinary here. He did not seem to be at all sane. And to further led credence to this, even after he had been arrested and convicted elsewhere and escaped, when his trip as a fugitive led him through Geneva, he didn’t bother making a small alteration that would have allowed him to bypass Geneva.  And, not only did he not bypass Geneva, he went to Calvin’s church!

And then when Servetus had a golden opportunity to be transferred away from Geneva’s jurisdiction (the Genevan officials offered this), he turned it down.

Second,  Servetus specifically believed his arrival to Geneva had apocalyptic dimensions, making it especially provocative, back in a day when they took those sort of things far more seriously than they do now.

Third, Servetus was out of control in the trial in a way that would not be tolerated even nowadays.  Gordon recounts about how when Calvin was brought into the trial to question Servetus for his views, Servetus not only called Calvin the “agent of the devil” but maintained that Calvin should be put to death, not him.

B. About the case against Servetus and his arrest:

First, Servetus was arrested in accordance with Geneva’s laws, which Calvin did not establish.

Second, the desire to punish Servetus was not unique. As was mentioned, he had been arrested and tried elsewhere.   When rest of the Swiss churches was consulted, it was agreed by all that “the form of punishment should be left to the Genevan council”. There is reason to believe most other Protestant and Catholics, rightly or wrongly, wanted to see him punished too. And out of those that didn’t, many did so out of a grudge against people involved (ie. many of the ones that were opposed to Calvin wanted Servetus released, not because they were against punishing heretics, but because he was Calvin’s enemy).

Third, the Genevan officials wanted to transfer Servetus to another jurisdiction, but Servetus pleaded to remain in Geneva and face what was coming to him.

C. About Calvin’s specific role

First, Calvin’s role in the process was limited. In fact, given the power of the Genevan rulers, Calvin didn’t even have the power to excommunicate  people and those same rulers would certainly not let Calvin determine the course of the trial–they saw it as a power struggle. Gordon says “Calvin could not have Servetus executed. That was the decision of a council not well disposed toward [Calvin] and with which he was locked in battle over excommunication. Servetus provided an opportunity for the magistrates to demonstrate their authority over Calvin…[the] magistrates understood clearly that harbouring or exonerating a heretic would blacken Geneva’s name across Europe.”.

Second, Calvin agreed that heresy was a capital office, but did not want Servetus to die.

Third, even though Servetus called him a devil, Calvin argued that Servetus should be given a less painful form of execution.

Fourth, Calvin’s request for a less painful execution was rejected by the authorities–he didn’t not have the power to do that.

As a side note, many of the historical accounts that people depend on to vilify Calvin in this are known to be distortions spread by people who had an interest in vilifying Calvin’s character. We must also, I might add, be careful about superimposing our historical and political situations on previous eras, Geneva during Calvin’s time was a very different scene than we do now in typical 21st century Western culture.

I hope (naively) that everyone who appeals to Servetus to denigrate Calvin will read this. At the very least so that Calvin will not be blamed for something he didn’t do.  Anyone who knows me knows I am vigorously opposed to the state punishment of heretics (even if it is less extreme that capital punishment).

If they still have a critique about Calvin’s involvement and view of the relation of the state to heretics after they’ve read this (and I do too), at least they will have many relevant facts that will focus on the issues correctly. It’s very unnerving the way people who don’t like Calvin drag his name through the mud based on false (or misleading) information.

[Most of this can be sourced to: Calvin by Bruce Gordon – Ch. 13]


Get every new post on this blog delivered to your Inbox.

Join other followers: