Wednesday, September 9, 2009

Has Twitter taken over?

I feel a bit guilty for not blogging in a long while. It seems that all I do is send pithy tweets about something or another and don't find the time and opportunity to write something (semi-) thoughtful.

This is rather unfortunate :(

Saturday, July 25, 2009

[geek] Splitting django views

Geekiness ahead; you have been warned.

Steve wrote a post about splitting django views. Consider this as another viewpoint / way of doing the same.

The primary problem is to split django's views.py into multiple different modules, ostensibly to make them smaller and more modular (duh).

To begin with, I'm not entirely certain the problem exists - in MVC or MD paradigms, the view is typically very tiny and almost entirely devoid of logic. It is there only to reflect changes made to the model. Consequently, it is unclear that the views.py needs splitting at all. I have not done enough large scale django development (my projects have been of the tiny homebrew variety), so lets assume that views become unmanageable in the long run and need to be split up.

Lets say you have a setup and have the following directory structure:

> ls
__init__.py manage.py* settings.py urls.py urls.py.orig views.py

and views.py looks like this:

> cat views.py

from django.http import HttpResponse

def index(request):
return HttpResponse('index')

def foo(request):
return HttpResponse('foo')

def bar(request):
return HttpResponse('bar')

Now we'd like to break apart views into a directory, so we change it to:
> ls -R
.:
__init__.py manage.py* settings.py urls.py urls.py.orig views/

./views:
bar.py foo.py index.py

where each file in the views directory has its own little function:

> cat views/foo.py

from django.http import HttpResponse

def foo(request):
return HttpResponse('foo')

At this point, note that there is no __init__.py at all.

The original url resolver obviously will not work because it looks like this:
urlpatterns = patterns('',
(r'^foo/', 'views.foo'),
(r'^bar/', 'views.bar'),
(r'^$', 'views.index'),

So we change that too:
urlpatterns = patterns('',
(r'^foo/', 'views.foo.foo'),
(r'^bar/', 'views.bar.bar'),
(r'^$', 'views.index.index'),

and the site is back up as normal.

I think this approach - explicit directions in urls.py is much cleaner and much more inkeeping with django's spirit of avoiding magic. Note that the other approach which basically imported all functions the minute __init__.py was touched would maintain the urls.py mappings, thus saving a bit of work. However, I think it would confuse the heck out of people, not to mention result in wierd name collisions if any of the individual view files happen to export the same function.

Tuesday, July 14, 2009

The Sotomayor Hearings

There was a point when watching the GOP self-destruct brought a bit of joy. The GOP felt like such an alien party - anti-intellectual, anti-everything except God - a party from another planet. Then came the 2008 elections, the Dems won and things were great.

Given their resounding defeat, one would have thought that they would have regrouped and introspected a bit and tried to figure out what went wrong, how they alienated their base and led the most colossal eff-up in the history of the U.S.

But one would be wrong.

Instead they decided to continue on this path of bigotry, racial hatred, and just common thick-headedness. What better proof than the way Jeff Sessions, Ranking member of the Judiciary Committee, manhandled Judge Sotomayor. Quoting the transcript:

"So first, I'd like to know, do you think there's any circumstance in which a judge should allow their prejudices to impact their decision-making?"


"But the statement was, "I willingly accept that we who judge must not deny the differences resulting from experience and heritage, but continuously to judge when those opinions, sympathies and prejudices are appropriate." That's exactly opposite of what you're saying, is it not?"


"...but isn't it true this statement suggests that you accept that there may be sympathies, prejudices and opinions that legitimately can influence a judge's decision?..."

"...I just am very concerned that what you're saying today is quite inconsistent with your statement that you willingly accept that your sympathies, opinions and prejudices may influence your decision-making."

Is Sessions possibly trying to make a point that a person can be completely unbiased? That his or her background cannot affect a judgement? Is it humanly possible? The answer, of course, is no - it is not possible to be unbiased and even if we think we are unbiased, we are not. This is not a statement that I make loosely - the race iat and other literature in psychology would be able to show this easily.

Sotomayor's point was so rational.
"I think the system is strengthened when judges don't assume they're impartial, but when judges test themselves to identify when their emotions are driving a result, or their experience are driving a result and the law is not."

Brilliant.

What is really sad about all this is that the GOP comes out as really bigoted and prejudiced and trying to browbeat a Judge into submission. Not to mention hysterical when a bunch of white guys accuse a latina of being rascist.

This self-destruction of the GOP is very bad for several reasons. For one, I actually agree with a bunch of their ideals - fiscal conservatism, smaller government (never mind that they oversaw some of the biggest increases in government and spending in the past century). But the other, more important reason is that in order for a democracy to function, and to be strong and vibrant, it needs a strong opposition. Having the Dems in absolute power is very, very bad, just as bad is it was when the Repubs were in absolute power: balance is irrevocably lost.

So Dear GOP: Please get a grip on yourselves. Obama checkmated you with Sotomayor - you cannot possibly block her nomination and every minute you pull stupid stunts like the one Sen. Sessions did, you hemorrhage latino votes. Its not a battle you want to fight. And when you do fight, please fight with dignity. Healthy debate is what we want, not mindless Limbaugh-esque repetition of false facts, hearsay and opinion.

Sunday, June 21, 2009

[books] Pride and Prejudice and Zombies

Pride and Prejudice and Zombies Pride and Prejudice and Zombies by Seth Grahame-Smith


My review


rating: 3 of 5 stars
Picture this:

The Bennet girls are at a ball. They are upset because Mr. Darcy made some disparaging remark about one of them or their mum. Blah blah blah.

Suddenly, the windows are shattered and the person nearest the window falls victim to the unmentionables, who quickly devour their brains. Because, as everyone knows, there is nothing a zombie likes more than brains.



This book has it all - Jane Austen with her proper romances, haughty bachelors and haughtier spinsters all looking to find the right husband or wife - and Grahame-Smith with his unmentionables (zombies), chinese kung-fu, japanese katanas, ninjas (yes, that's right, ninjas) and other formidable weaponry.



The book is so absurd that it makes you laugh at loud - the section at the end where the author puts in a list of things for classrooms of students to explore is some of the funniest writing I have read.



I want to give this book a higher rating - simply because I admire the author for the courage to write something so patently absurd and the publisher for going along with this. However, at the end of the day, the work is still Jane Austen and no army of ninjas is going to help save the utterly boring romances that Ms. Austen wrote.



This is definitely a library pick.


View all my reviews.

Friday, May 1, 2009

[books] Forever Peace

Forever Peace Forever Peace by Joe Haldeman


My review


rating: 3 of 5 stars
Not as good as Forever War, but not bad at all. A vision of utopia where there are means to connect everyone to a global hivemind that basically causes them to lose the will to kill each other. Interesting, some new concepts and some exploration of this idea. A bit heavy on wierd sexual stuff, a bit unnecessarily so, and a bit light on exploring the other side of what pacification of an entire species would do.


View all my reviews.

Photos from the India trip.






Let me know if you cannot follow the links to Kristin's picasa album.

Monday, April 13, 2009

Flaky internet test

Trying to see if blogger deals with a flaky internet. The internet at home (in Mumbai) where I am right now is rather flaky - pings to google.com range from 300ms to 2s depending on unknown factors. I think its because of the interesting wiring that the "electrician" and the "phone wallah" conspired to put in and convinced my dad that it was fine (because, you know, if you split a phone cable in 2, both lines are just fine, no extra noise from crappy connectors or anything). It also randomly goes OFF. Annoying as hell.

stech and I have a common blog on wordpress (because she likes that more than blogger) at http://bloggingindia.wordpress.com and we have lost two posts already because the stupid wordpress background save *does* *not* *work*. So, so, annoying.

So far, blogger seems to be better - its saving just fine and we'll see with the publish if thats better as well.

Edit: Success! Score +1 for blogger.

Tuesday, April 7, 2009

[books] Losing My Religion: How I Lost My Faith Reporting on Religion in America

Losing My Religion: How I Lost My Faith Reporting on Religion in America-and Found Unexpected Peace Losing My Religion: How I Lost My Faith Reporting on Religion in America-and Found Unexpected Peace by William Lobdell


My review


rating: 4 of 5 stars
An excellent book by a journalist about his journey embracing Christ, investigating the Catholic Church and eventual parting of ways with religion in general.



It really is a book in 3 distinct Acts:

Act 1 - From arreligious to an evangelical to (almost) a Catholic:

Its unclear whether Lobdell was an atheist to begin with (I think not), but he clearly was not a practicing Christian. A rough patch in his life led him to turn to God and seek support and solace in the Church. He has nothing but good words for the church that he joined and the people he met. All of them come across as very rational, yet very devout. They support him and help him get on the road to becoming a devout Christian.



Act 2 - Investigating the Catholic Church:

Lobdell was the religion reporter for the LA Times when the Catholic child molestation scandal broke. He investigated various such allegations and returned disgusted as what he saw as a fundamental breach of trust - the priests were supposed to be spiritual shepherds for their congregation and they abused this trust to permanently mess up the very children that they were trying to teach. What made him even angrier was systemic failures in the Catholic Church to expose known child molesters; instead the Church treated it as an internal matter, merely dismissing priests or even worse, moving them to other parishes where the pattern of abuse continued. The Church used its might, money and lawyers to squelch any complaints or protests whatsoever from the children that had been thus abused.



Act 3 - Embracing Atheism:

Investigating the church really seemed to cast a shadow upon Lobdell's faith. This led him to dig deeper and investigate the underbelly of the Christian faith - televangelists, preachers who claim to faith heal, the Trinity Broadcasting Network (largest Christian TV station in the world) and look at the economics of what was going on. Again, what seemed to make him really angry was not the millions that the preachers (or their churches) were making but the straightforward duping of the congregations and complete abuse of their trust. He notes stories of quadriplegics and terminal cancer patients given false hopes that they would walk out of church, healed (they weren't). What's even more heartbreaking is that people would put their faith in God and the faith healers and stop taking drugs thereby making things worse (and in some cases dying).

Lobdell talks about how it was hard for him to let go. He had a difficult time dealing with death - what happens after and if he was going to hell for abandoning God. He talked to friends and preachers about his loss of faith and certain qustions about God that had been bothering him - and didn't get any answers that he considered good enough. Its unclear if this was so because he had already made up his mind and was talking to these preachers almost as "due diligence" or out of a genuine need to resolve things.



On a personal note, the third act of the book really resonated with me. I went through something similar when I left the Jain fold around 2000. Its hard to deal with the fact that there is this life and then that's that - ashes to ashes, dust to dust. But if you come to terms with that, it makes life really nice. The worst that can happen to you is death. Every moment past is never coming back, so enjoy it to the fullest. Doing something you don't like to do is a monumental waste of time. Its also "simple". I don't have internal conflicts about being an engineer doing science by day and talking in an unknown language to beings whose existence is unprovable at night. I don't have to come to terms with reconciling faith and evolution or having to deal with things that I cannot measure (or view someone's measurement of the same).



All in all, a great book. Highly recommended.


View all my reviews.