Blog

September 17, 2015 18:42 +0000  |  Django Python 0

I ran into something annoying while working on my Tweetpile project the other day and it just happened to me today on Atlas. Sometimes, removing code can cause explosions with migrations -- even when they've already been run.

Example:

  • You've created a new class called MyClass.
  • It subclasses models.Model
  • It makes use of a handy mixin you wrote called MyMixin:

    class MyClass(MyMixin, models.Model):
        # stuff here
    
  • You create a migration for it, run it, commit your code and congratulate yourself on code well done.

  • Months later you come back and realise that the use of MyMixin was a terrible mistake, so you remove it.
  • Now migrations don't work anymore.

Here's what happened:

Creating a migration that's dependent on non-Django-core stuff to assemble the model (think mixins that add fields, or the use of custom fields etc.) means that migrations has to import those modules to run. This is a problem because every time you run manage.py migrate it loads all migration files into memory, and if those files are importing now-non-existent modules, everything breaks.

Solution:

It's an ugly one, but so far it's the only option I can figure: manually collapsing the migration stack. Basically you make sure you've run all of the migrations to date, then delete the offending classes, delete all of the migration files, and recreate a new empty migration:

$ cd /project/root/
$ ./manage.py migrate
$ rm -rf myapp/migrations/*
$ touch myapp/migrations/__init__.py
[ modify your code to remove the offending fields/mixins ]
$ ./manage makemigrations myapp

Now run this in your database:

DELETE FROM django_migrations WHERE app = 'myapp' AND name <> '0001_initial';
UPDATE django_migrations SET applied = NOW() where app = 'myapp';

The new single migration created won't be importing the removed classes, so everything will be ok, and you have the added benefit of not having so many migrations to import. Note however that this may cause problems with migrations from other apps that may have been created dependent on your now-deleted migrations, so this may start you down a rabbit-hole if you're unlucky.

I hope this helps someone in the future should this sort of thing present itself again.

September 10, 2015 22:38 +0000  |  Family Grandpa

Grandpa was an impossible man -- both in that he was difficult to be around at times and in the amazing life he led.

Here was a man who was not only 100% confident that he had the answers to everything, but he was going to do you the immense favour of pointing out everything you're doing wrong -- you know, for your benefit.

I remember a particular Christmas gathering at which he persisted in his argument with his two atheist grandchildren that "God" created everything: "Who made this?" he would ask, "and who made this?", repeatedly pointing to random objects in the room. There was no winning an argument with him, you could only hug him and say "I love you Grandpa".

This would usually buy you a few minutes.

One of my earliest memories as a child is that of my father's disapproval of my grandfather's spending money on my brother and me. His refrain "Money is for spending!" will forever be a part of me. I think that deep down, Grandpa was a bit of a hedonist, but it was the simple things in life that did it for him. He loved his car, his boat, that obnoxious talking fish, and of course, he loved his family.

It's easy to forget in this era of smart phones, but we all owe a great debt to him for the hours and hours of home videos he took of all of us as we grew up. There are videos of my mother as a child, my parents getting married, the many barbecues and Easter gatherings -- all painstakingly preserved, transferred between formats over the years. This was a labour of love for him: the preservation of memory for three generations. How sad it is that he should leave us all such a gift when he himself appears so seldom in the frame.

Take a moment to consider what he accomplished in his lifetime:

  • He escaped Communism with his family to start a new life in a country where he didn't even speak the language.
  • He then proceeded to found multiple businesses across Canada employing dozens of people.
  • He supported every member of the family, either financially, with skills training, or simply with a place to sleep when one of us needed it.

He was undoubtedly an egoist and a pain in the ass, but he was also unabashedly generous and unconditionally loving.

Grandpa was an unyielding force in this world, and we are all so fortunate to have had the opportunity to be part of his life. He will forever be an inspiration to me.

True to form, Grandpa died on his schedule and no one else's. The world may be a lot quieter without him in it, but there's no doubt in my mind that it is also greatly diminished.

He'll wait for us right here.

My grandfather died peacefully in his sleep on Sunday night. He is survived by his wife, two daughters, three grandsons, and one great-granddaughter. He was 91.

September 03, 2015 08:27 +0000  |  Canada Politics 3

The body of a child, washed up on a Turkish beach

I'm posting the image here for all to see. If this bothers you, good. This is exactly the sort of thing that should bother you. Your reaction proves that you are a good person, capable of empathy.

If you're anything like me, feelings of grief and sadness were followed, after some wallowing, by a deep sense of helplessness and anger. This image, and the issues behind it are terrible -- what can I do about it?

The honest answer is that I don't know. No one thing, no ten things I can think of doing would even begin to solve the problem of finding these people a safe place to live.

The problem at this juncture, from what I understand, is two-sided: political will on the receiving end, and in some cases (at least for that of Turkey), an unwillingness to be decent human beings when it comes to the treatment of refugees. In other words, the problem is political: people need to get out of Syria and the rest of us won't let them. Instead we're collectively sitting idly by while bodies wash up on beaches.

It seems to me that the solution to all of this is to remind everyone of our collective capacity for empathy. If our cowardly leaders won't move on this issue it can only be out of a lack of empathy, and they therefore should be replaced. This is why I'm posting this photo: because we need to be upset about this.

This is a solvable problem. The number of refugees coming out of Syria are great, but manageable: 7million. If Europe alone were to accept all of them tomorrow, this would represent a mere 2% increase in population, and there's no reason that Europe alone should have to bear the strain of such an influx. The United Nations has asked Canada to accept 10,000, and I can only assume that other countries have had similar numbers asked of them.

It's time to make our voices heard on this issue and step up to help. We're a human community after all and that is a dead child on a beach.

August 09, 2015 19:26 +0000  |  Christina 14

It's hard to get around to everyone when you know people all around the world. I've already called one person and woken them up because I got the timezones wrong, and these days, most of us don't even use phones. I've broken the news to all of my immediate family at this point, so I guess it's about time for a proper announcement: Christina and I are going to get married.

A brief FAQ if you will:

What? When?

We're not sure yet. Hell, I just proposed yesterday. The reality of our move to the London in November along with the end of her PhD and her starting a new job at the same time dictates that we won't be having any sort of shindig until well into 2016 at the earliest.

Why?

Because it's Christina. It's always been her. It just took me this long accept it. Thank the gods she's so patient.

What's the story with the proposal?

Some time ago, Christina mentioned in a rather off-hand sort of way that she always imagined that when she was proposed to, it would be on a hill. This sat in my brain for a good long time, in no small part because we live in the Netherlands, where hills are at a premium.

She also told me in no uncertain terms, that if/when I got around to asking, she wanted to pick her own ring. Whether this is a remark on my taste in jewelry, or her own investment in lifetime-hardware, I leave that to the reader to decide.

With these two bits of information in hand, I decided to put together a little jewelry box with a piece of string, knotted into a circle to look like a ring. I then convinced her that we needed a day off from work, and that we would best burn that day off, at the old fortress around Naarden -- also the site of our (sort of) first date. We made sandwiches, chilled out under a tree (atop a man-made hill), and that's where I gave her the box.

Was she surprised?

Yes. Which surprised me. I was sure she'd seen all of this coming.

Is this because you need visa help entering the UK?

Absolutely not. In fact, we won't be hitched until we're settled in the UK anyway. Besides, from the looks of things on the visa front, our marital status won't really help us.

Where is it going to be?

My Grandmother asked that if I did get married, that it'd be in Greece, so she'd have an excuse to go there. That, coupled with the fact that we both love Greece, and that it's the kind of of place that could really use the money right about now, are two very compelling reasons to hold it there.

Obviously, it's way too soon to settle on anything at this point though. We've got time to work out the details and I'll keep you posted at our fabulous new domain name (It redirects to this blog post for now).

Can I come?

Sure! Probably. It depends on who you are, how big the wedding's going to be, etc. etc. I hope so.

May 26, 2015 17:27 +0000  |  Canada Politics 2

Canada's Senate has been getting a lot of flack lately from the suspended/disgraced former senators like Conservatives Mike Duffy and Pamela Wallin to most recently, moves by the Senate to block/amend/rewrite the Reform Act, a bill I personally think is long overdue.

Every party has a different idea of what to do with the Red Chamber. The Greens want to reform it by electing senators, the Liberals simply kicked all Liberal senators out of their caucus, the Conservatives want to elect them, but aren't interested in actually going through the process of getting provincial approval, and the NDP wants to outright abolish the Senate -- though they've been unsurprisingly silent on exactly how they'd do that in the face of a constitution that guarantees the Senate's existence.

How it Works Right Now

For those of you who don't know, this is how the Senate currently works in relation to your vote:

  1. You vote for a candidate to represent your riding in the House of Commons.
  2. The winner in your riding goes to Ottawa to represent you, and whichever party holds a plurality of votes after an election forms government, with the leader of that party given the role of Prime Minister.
  3. The government does its thing until one day a Senate seat becomes available by way of only five options:
    • A senator dies
    • A senator reaches the age of 65
    • A senator leaves the Senate of their own volition
    • A senator is kicked out of the Senate
    • The House of Commons votes to increase the size of the Senate
  4. When this happens, the Prime Minister can put anyone (s)he wants into that Senate seat. Typically these are "friends of the party", or just friends of the Prime Minister.
  5. That senator sits in the Senate and votes on bills coming from the House of Commons until they die, reach 65, leave, or are kicked out.

When Party A is elected, the Prime Minister might appoint 10 senators over the course of her term. When her party is ousted by Party B, the new party now has to contend with people in the Senate who might oppose anything too extreme, since they're from a different party. This is what is lovingly referred to as "sober second thought".

What the Parties are Suggesting

On the face of it, the Senate seems like an insane tool for democratic governance, and I won't deny the fact that there's a lot of room for improvement, but I want to go on record saying that I think the positions of all the major parties are deeply flawed here, and in the case of every party, self-serving:

  • The Green Party want a proportionally elected senate. Given that the current system currently offers the Greens exactly 0 seats, elections make sense for them. Additionally, proportional elections serve the Greens well because their vote is spread wide across the country.
  • The Liberals kicked the sitting Liberal senators out of caucus, but know that this was more about optics than anything else. These senators are still loyal to the party, to the ideals of the party. They lose nothing, and nothing is gained for anyone but Liberals.
  • The Conservatives want an elected senate, which fits with their mantra of "more responsible government". The only problem is that their own actions over the last decade have shown that they use the electoral process to reduce voter turnout and drive up wedge politics, and then strong-arm the political process to get their way. In a fully elected system, there'd be nothing in the Prime Minister's way to do everything (s)he wants.
  • The NDP want to abolish the senate, a move that works for them since they've never had a seat in there anyway. Given the nature of our constitution, it's also a pipe dream that they can market as something the public can easily comprehend and support. It does nothing at all to ensure appropriate checks on power in our system.

I want to make the case that the senate is a good thing. That for all of its flaws, the purpose it serves is just too important to abandon (as the NDP would suggest) or politicise (as the others have stated).

Why Elections are a Bad Idea

The typical solution of "just elect them" is one that's already been tried and found wanting. For the test case, you need only look South to the United States where they elect:

  • A President
  • Congressmen
  • Senators
  • Judges
  • District Attorneys
  • Sheriffs
  • ...and many more

The result is a deeply polarised society, with judges and senators less concerned about their jobs than they are about getting re-elected. A sheriff's sex life, rather than their track record is made relevant to whether or not they can enforce the law. There is no concept of "sober second thought" because every time a congressman or senator votes on an issue, they have to worry about "how this will play with the voters".

This isn't to say that all elections are bad. They are after all a pillar of democracy. No, I'm arguing that just as an elected governing body is crucial to democracy, a sane political process also requires the existence of a body that is not beholden to the whims of the public. The public is fickle, emotional, and historically grossly uninformed. Purely elected bodies are measureably less stable, more erratic, and more polarising.

This was the idea behind Canada's Senate, and it's still a good one: a place where people can come together and debate, amend, approve, and reject bills passed by the elected House. It's a check on the power of the House, which is beholden only to the electorate.

If you introduce elections to this equation, you undermine the whole value of the senate: the lack of fear in decision making. Worrying about re-election means worrying about the whims of the short-term: anti-science, religious nutbaggery, and war-mongering. All of the emotionally-charged issues underlining every political action based on recent events, presented outside of the broader historical context. This is is a recipe of instability and a tyranny of short-term thinking.

Alternatives

If we shouldn't abolish the Senate, and we shouldn't elect it, then what alternatives do we have? I don't pretend to have all of the answers, but if someone were to make me Emperor for a Day, I might propose something like this:

  • Candidates for Senate seats are nominated by sitting members of the House of Commons
    • One nominee proposed per MP
    • Nominations are secret so party whips can't manipulate MPs.
  • Whenever a senate seat is made available, one is randomly selected from the list of 308 candidates.
  • Senate terms should be 20years to allow for long-term policy making, while allowing for gradual changes over time.
  • Violations of Senate rules (citing the Duffy and Wallin cases here) should be met with investigation and/or suspension and public trial if need be.

I'm curious about what others might think about this, and would invite other proposals -- anything to preserve the ideals of the Red Chamber while working to root out the cronyism we're currently saddled with.

One thing's for certain though, all of the major parties are making recommendations that are bad for the country in the long term, and unsurprisingly, they're all recommending policy that works best for them.

May 03, 2015 19:40 +0000  |  Energy Environment The Economy 1

A few days ago, Elon Musk and Tesla announced the release of their new Powerwall system to much fanfare. It's being widely recognised as revolutionary and a gateway to the democratisation of energy production, but I think that the media is focusing on the wrong aspects of this story.

While it's true that Powerwall makes personal power generation more feasible, I would argue that this doesn't even scratch the surface. The real value of this technology is in the potential to delegate mass energy storage to smaller subsystems and, in so doing, effectively eliminate much of our addiction to fossil fuels.

What Powerwall Is

A photo of the powerwall

This is Tesla's Powerwall. Essentially it's a nice-looking box that hangs on the wall that can power your home for a day or two (more if you live in an apartment). It can charge off a personal solar array or wind turbine or, more importantly, it can be charged simply by connecting to your city's power grid.

The magic of Powerwall is in the details:

  • It's Cheap. At $3500 USD, it's a viable option for millions of people, which is nice for those who like expensive toys, but the real value is in the fact that this price point allows utilities and industry to apply this technology at a massive scale.
  • It's Versatile. Designed to be used in the home or chained together to form a serial super battery for large venues and industrial-grade buildings, Powerwall can be applied at the scale required where needed.
  • It's Unencumbered by Patents. Tesla has a standing policy on opening its patents to the world so that other companies can develop competing or compatible technologies without the fear of crippling lawsuits.

How We Manage Power Right Now

All of this is interesting from a technical perspective, but I want to talk about the potential to drastically change how we manage energy use in our cities.

One of the most difficult issues with power management is that it must be generated as needed. That is to say, the power you use when you turn the lights on at home was generated far away, often hundreds of kilometres away, and it was done so with the expectation that it will be used right away. Indeed, it has to be used right away because there's nowhere else for it to go other than into light bulbs and dishwashers across the grid.

A diagram of what our energy generation/use looks like now

The result is a power generation diagram that looks a lot like this. The entire network is essentially divided into two parts:

  • Base load is the power used regardless of the time of day. The network is built with the understanding that at any given time someone, somewhere will be using that power, so this power is generated using methods that are difficult to adjust, like nuclear or sometimes hydro.
  • Peak load is the power generated as we need it. We add more generation in the mornings and evenings and taper off considerably at night. You can only manage this variable nature if you make use of less rigid generation technologies. Typically that means coal or natural gas, though in some parts of the world, hydro is also a viable option.

The take away is this: fossil fuels are necessary for our current system because they're the only proven technology that can manage the variable nature of our energy needs at peak times. Nuclear reactors take days to start and stop and wind and solar are dependent on the weather. Fossil fuels can be spun up and down on a whim and for roughly a century this has been the one and only way to provide reliable power to the masses.

What Powerwall Means for Our Current Situation

Powerwall has the potential to change all of this. With a battery in every home (or even just every neighbourhood), any form of power generation is viable: simply dump that energy into the grid and let the batteries stabilise the flow. Powerwall eliminates the need for variable power generation and, by extension, fossil fuels.

A diagram of what our energy generation/use will look like with cheap, ubiquitous batteries

Instead, we get a power distribution that looks more like this, with the base load still generated by big industrial forces like nuclear, but with the added possibility of making better use of renewables like solar, wind, and even tidal & geothermal.

The Outlook

This is so much bigger than allowing upper middle class yuppies to power their espresso machines with solar power. Cheap and ubiquitous battery technology is the missing link in responsible energy production in the coming century.

Fossil Fuels vs. Renewables

Coal, oil, and natural gas (methane) can still play a part in the short term, but, in the long term, the market will inevitably move away from them, as it's impossible to compete with free energy beaming from the sun. Governments will delight in being able to appear "green" as they move with the market to curb CO₂ levels in the atmosphere.

The Democratisation of Power Generation

And of course there's the story everyone appears to be running with: the democratisation of power generation. This will be an exciting change too, as shopping malls, factories, and even apartment buildings opt for local generation as a means of supplementing or even avoiding the grid. I honestly don't think that so-called "democratic power" will be the primary means of generation, but this will undoubtedly play a part.

Excited

So yes, I'm excited about the whole thing. So much so that I checked whether Tesla was hiring in Europe (they don't appear to be interested in software developers, pity). Powerwall and technologies like it are a Really Big Deal and so far from what I've seen, much of the media hasn't quite grasped this. I'm convinced however that that all of the above is Musk's grand plan and that this reality is not lost on the heads of power utilities around the world.

April 27, 2015 11:19 +0000  |  Netherlands 1

Today is Kingsday, the day when Amsterdam turns into an orange urban nightmare. Traditionally, we've managed to get the hell out of town for this weekend, but as Christina is rounding the final stretch of her PhD, leaving town for a long weekend is no longer an option for her.

So I'm here, holed up in our apartment, the Dutch chaos bubbling outside. It's hard for me to describe this to someone who's never seen it, so instead, I offer you this YouTube video.

April 17, 2015 10:40 +0000  |  Multiculturalism Travel 2

Back in 2002, I was living in Ottawa working for a terrible company with some really terrible people. One of these people, upom returning from a trip to Madrid, went on at length about how scary and dangerous it was.

Oh Daniel, no one should ever go there. People ride around on scooters and slash open your bags just to steal from you. Everywhere you look, there are criminals!

Jodie was a horrible person, a racist, and an idiot, and yet I let her depcition of this city poison me against it for more than a decade. Thankfully though, I managed to ignore her just long enough to book a flight, and I'm glad I did.

Madrid is a curious place. Like most European cities, it's very old, the product of repeated wars over the centuries. The architecture is a mix between traditional Muslim and French styles, but taller, with a gradiose, almost Austrian influence. The city has managed to make itself both heavily pedestrianised and car-friendly... it just depends on where you go.

There are a number of wide open public spaces, used for markets and restaurant patios, chained together with a long series of pedestrian-friendly, walkable malls. Everywhere you look there are bakeries, tapas bars, and churro cafés, along with a (presumably new) littany of toursit-centric cuisine: doughnuts and hamburgers.

I had four days in Madrid, so I took my time getting to know the city. I took one of those fabulous Free Madrid city tours, where Ramón gave us all a brief history of the city including the trading lands between the Muslims and the Catholics, the Inquisition, and the Royal Family. I learnt about Carlos the Bewitched and the slutty inclinations of Queen Isabella I. If you've never been on one of these free tours, I can't recommend them enough. I've never been disappointed and I never regret tipping well.

I spent a good few days just wandering the parks. Madrid has two primary green spaces and at least a dozen other ones peppering the city. The Parque del Retiro is the more traditional European park: manicured and maintained as an open public space with fountains and statues everywhere, the park is filled with the sounds of children playing, and buskers looking to entertain. Young couples are everywhere, making out in the grass, and there are tourists like me, wandering the park, camera in hand, shooting at everything.

There's also a statue tribue to Satan there. Apparently it's the only one in existence.

On the East side of the city is Casa de Campo, a massive park in the style of Vancouver's Stanley Park only THREE TIMES THE SIZE. The former hunting grounds of the Royal Family (and battle ground during the Spanish Civil War), Casa de Campo has a lake, and a yacht club, and an acquarium, and a zoo, and a gondola, and... I have no idea, because in an entire day, I could only visit a fragment of it. My one regret from this visit was not spending more time there. One of the locals told me that they've worked very hard to keep the park diverse, with samplings of trees from all over the world.

My favourite memory from Madrid however has to be the flamenco performance & dinner that I attended on Tuesday night. At no other time during my visit were the multicultural origins of the city (and I suppose, Spain in general) more apparent than when I sat at the foot of that tiny stage. Flamenco, it would appear, is as our tour guide suggested of Spanish culture: "we take other ideas, and keep what we like". The music is deeply layered, and rythmically complex. The performance is effectively improvised between five musicians and at least one dancer, making it a sort of "Spanish jazz" in style. The cobbling together of artists is reflected in the clear connections to foreign roots, specifically Muslim. It was almost like attending an intimate call to prayer, but with a sense of shared joy and excitement.

And then there were the dancers.

Flamenco isn't so much a performance as it is a shared religious experience. The dancer steps onto the stage and allows the music to fill them, proceeding to do whatever feels natural. It's inspiring to watch and so difficult to describe, but they're not dancing so much as serving as a vessel. Elizabeth Gilbert explains this best in her TED talk, where she talks about how when onlookers shout "Olé!", this is a way of invoking "god", that somehow, in that moment, he is working through the performers. I didn't quite understand her when I first heard this, but now it makes complete sense.

I'm now on a high-speed train on my way to Seville, enjoying a leisurely 210kph. I'm not sure if I'll ever return to Madrid, but I'm glad I took the time to see it. As a Canadian, it's interesting to visit a place that has undergone a sort of multicultural experiment -- albeit unintentionally -- mingling Christian and Muslim, Spanish, French, and Austrian styles and traditions over the centuries. From where I'm sitting, it was a success.

March 04, 2015 13:58 +0000  |  Employment Ripe NCC 0

My boss just sent this to me:

[List of Employee names and Me],

As agreed verbally, I'm requesting you to work on the weekend of 28-29 March, in order to attend the RIPE Atlas Hackaton. Your attendance at the evening socials is optional (and not recognised as extra hours).

According to the HR policy [link to policy on our intranet], you're entitled to compensation for this. Please let HR know if you prefer monetary or VAC days.

Cheers, [Boss' Name]

"Welcome to Europe" he said jokingly.

I just wanted to post this to stand in sharp contrast to how companies tend to work in Canada, ie:

You're working this weekend. No we're not paying you for it. If you're not ok with this, you're replaceable.

Back home, there's a lot of talk about "Work/life balance", but employers here actually understand what that means and practise it.

March 04, 2015 00:23 +0000  |  Blogger 4

It's just past 1am as I type this. Christina is curled up next to me in bed, trying to sleep, but I'm still up, hacking away at this site. This site, my labour of love now for more than a decade has just undergone its sixth update.

Mostly a face-lift, version 6 of my blogger now sports a sexy new image gallery and a pretty template that should make it easier to read stuff.

Technically speaking, I'm running Django 1.7.x now, and I've dropped support for the built-in comments framework (as it was deprecated already) in favour of a custom system that supports markdown properly. There's also tonnes of UX changes, and I've switched to Bootstrap 3 for all of it.

Please take a look around and let me know what you think, and if you find any bugs, please let me know.