Haiti Earthquake: Who's given what?

February 2, 2010
0 comments Politics

Haiti Earthquake: Who's given what? If I've understood it correctly, this is a mashup made on Guardian's API made by someone not at the Guardian. More photos here

What's interesting about this chart, which I've never seen like this before, is the last one where they show how much money various countries pledged versus how much they actually delivered. It's something I've also wanted to see because it opens up a whole new dimension of truth to the equation. For example, Canada has pledged USD 130m to the Haiti Earthquake but they only delivered 51% of what they pledged to the 2004 Tsunami crisis.

Healing Food Reference

January 27, 2010
0 comments Misc. links

Healing Food Reference Spotted this website called Healing Food Reference which is what the name says; a reference of food and their healing "power". From the home page:

"This site is part of a public education project created by Mike Adams, the Health Ranger, and hosted by Truth Publishing. Its purpose is to educate and empower consumers with information they can use to prevent and even help reverse degenerative disease. There are no commercial sponsors of this site, and neither Mike Adams nor Truth Publishing was paid anything to create this site."

Basically click on a type of food, for example tofu and you get a list of things it can help with such as fever and then from the fever page you can more foods that help.

At first I was a bit taken aback by the home page and huge amounts of text on it but once you're in it is so easy to use. Perhaps the reason the home page is jam packed with content is for his search engine optimization.

Guake, not Yakuake or Yeahconsole

January 23, 2010
4 comments Linux

I've been a big fan of Yakuake for a long time. It's a terminal you have open all the time in Linux that is shown and hidden, over any other windows, by a simply hit on the F12 button.

But as of more recent versions of Yakuake it has become really slow. It sometimes take 2-3 seconds from F12 press till you can type on the terminal. So I uninstalled it and tried Yeahconsole but I uninstalled it equally fast as I understood it was broken and didn't work at all despite being in the Xubuntu apt repositories.

Last but not least I ended up using Guake which not only works but also works really really fast. Screenshots here

Tip: creating a Xapian database in Python

January 19, 2010
5 comments Python

This cost me some hair-pulling today as I was trying to write a custom test runner for a Django project I'm working on that creates a test Xapian database just for running the tests. Basically, you can't do this:


os.mkdir(database_file_path)

Because if you do you end up getting these strange DatabaseOpeningError exceptions. So, here's how you do it:


import xapian
xapian.WritableDatabase(database_file_path,
                        xapian.DB_CREATE_OR_OPEN)

Hopefully by blogging about this some other poor coder will save some time.

Bookmarklet to replace the current domain with localhost:8000

January 17, 2010
1 comment Web development, Django

If you, like me, have various projects that do things like OAuth on Twitter or Google or you have a development site that goes to PayPal. So you're doing some Django development on http://localhost:8000/foo and click, for example, to do an OAuth on Twitter with an app you have there. Then Twitter will redirect you back to the live site with which you've set it up. But you're doing local development so you want to go back to http://localhost:8080/... instead.

Add this bookmarklet: to localhost:8000 to your browser Bookmarks toolbar and it does exactly that.

Here's its code in more verbose form:


(function() { 
   a = function(){
     location.href = window.location.href.replace(/http:\/\/[^\/]+\//,
            'http://localhost:8000/')
   };
   if (/Firefox/.test(navigator.userAgent)) { 
     setTimeout(a,0)
   } else {
      a()
   }
 })()

China wrecked the Copenhagen deal

December 23, 2009
0 comments Politics

"Copenhagen was much worse than just another bad deal, because it illustrated a profound shift in global geopolitics. This is fast becoming China's century, yet its leadership has displayed that multilateral environmental governance is not only not a priority, but is viewed as a hindrance to the new superpower's freedom of action. I left Copenhagen more despondent than I have felt in a long time. After all the hope and all the hype, the mobilisation of thousands, a wave of optimism crashed against the rock of global power politics, fell back, and drained away."

From the brilliantly informed and well articulated article How do I know China wrecked the Copenhagen deal? I was in the room

Just so you know, I love China, but there's a lot of things I hate about it too. Admittedly, any country in their position would perhaps do the same as the force of people getting rich is more powerful than almost anything else. Please do take the time to read this article as it helps to give an interesting perspective on the post-Copenhagen-conference talks.

Migrating with South on a field that uses auto_now_add=True

December 16, 2009
5 comments Django

I have a Django model that looks something like this:


class MyModel(models.Model):
   modify_date = models.DateTimeField(auto_now=True)
   ...

Retroactively now I wanted to add a field called add_date which uses the auto_now_add=True trick. The migration used in this project is South which is great but doesn't work very well with the auto_now_add=True because the field doesn't have a straight forward default. So, first I changed the field to this:


class MyModel(models.Model):
   modify_date = models.DateTimeField(auto_now=True)
   add_date = models.DateTimeField(auto_now_add=True, null=True)
   ...

Notice the null=True which is important. Then I used startmigration to generate the code for the forward and backward to which I added a this stuff:


class Migration:

   def forwards(self, orm):

       db.add_column('myapp_mymodel', 'add_date', orm['myapp.mymodel:add_date'])
       for each in MyModel.objects.all():
           # since MyModel is referenced elsewhere I can work out the oldest date
           oldest_date = get_oldest_related_date(each, 
                              default=each.modify_date)
           each.add_date = oldest_date
           each.save()

That way all old records will have the date (not entirely accurate but good enough) and all new records will automatically get a date. Is there a better way? I bet, but I don't know how to do it.