My nerdiness has grown up: thoughts on the Science and Technology Museum

I’ve been in Ottawa for the last 9 days visiting with my parents. Today we were supposed to drive to Montreal, see a couple of museums and have dinner with my brother, but a major snowstorm was moving in, and we decided to call it off. (Good thing, too, because Montreal was hit really hard and we would have had a horrible time.)

As a consolation, my dad and I decided to go to the Science and Technology Museum. I don’t think I’d been there since my teens, and jumped at the chance rediscover all the cool sciency stuff that had thrilled me as a budding nerd.

I’ve been in Ottawa for the last 9 days visiting with my parents. Yesterday we were supposed to drive to Montreal, see a couple of museums and have dinner with my brother, but a major snowstorm was moving in, and we decided to call it off. (Good thing, too, because Montreal was hit really hard and we would have had a horrible time.)

As a consolation, my dad and I decided to go to the Science and Technology Museum. I don’t think I’d been there since my teens, and jumped at the chance rediscover all the cool sciency stuff that had thrilled me as a budding nerd.

It was kind of disappointing, to be honest. Most of the old hands-on exhibits designed to teach little kids about science were gone. I remember one place where you could measure your hand-eye reaction time, another where you could create an electric arc between two poles, by cranking a handle over and over. And there was another big huge pendulum thing, filled with sand, swinging over a large circular space, and as it swung it traced its arcs on the floor below, back and forth, left and right. (There may have been more than one pendulum, too, though I wouldn’t swear to that). I think that last one was replaced by an interactive exhibit and quiz on Canada’s energy policies. Where the pendulum/pendula used to be, is now a big planet Earth. Where you could fill up swinging buckets with sand, are now four or five monitors where you can answer simple questions about renewable energy sources, your energy consumption, whether or not politicians, corporations or individual people should make the decisions about Canada’s energy future, and so on.

Still around, though: the Archimedes screw. Also still around: the gravity well simulator, where you could roll a little metal ball and watch it circle around the central hole as though it were actually orbiting it. They’ve got a similar device at Science World in Vancouver. But this one, in Ottawa, doesn’t use balls anymore (it used to, right? I think it did), instead using coins. And yes, coins do work pretty much as balls do—except loonies, their corners slow them way down—but that’s just weird. Did they run out of little balls at some point? Were toddlers swallowing the balls or something?

I didn’t actually use money, but I saw a family try it. I hope they were able to collect their money afterwards.

Other familiar stuff: the big locomotives. In my mind’s eye I kept seeing them as absolutely gigantic, five storeys high at least, instead of the 12–15 feet high they really are. We got to climb in the engine rooms and figure out what all the levers and gauges were for, and imagine what life must have been like for these men, zooming along at almost 100 miles an hour, only a couple tiny windows allowing you to see ahead, constantly having to monitor the health of this metal monster you’re riding, and shovelling coal in its maw…

CPR 3100

CPR 3100 engine

Oh, and the Crazy Kitchen is still there. Always popular with the kiddies, even though back then I was too sensitive to motion sickness to really enjoy it. But that’s not so much of a problem these days, and, well… just like the locomotives, the kitchen is way smaller than I remember. I went through it in just a few seconds, and it never occurred to me to stay and enjoy the spatial distortion.

But here’s the thing: what if the museum had remained completely unchanged from the days of yore? And what if I found out the old games and exhibits weren’t quite as awesome as I remember? The Archimedes screw kept me amused for all of 10 seconds and a couple photos. The big locomotives were better, since I could read up on their history and enjoy them on more levels than as a kid.

Likewise, the new exhibits: on the Canadian space program, the cool science that came out of it; on cars, from the very oldest to the newest and coolest electric ones; on Canada’s energy use and resources, kind of didactic but overall very good; on communications, networks and connections, featuring old-timey phones, radios, computers and TVs (plus, interesting history and Canadian milestones); other interesting science instruments. All of that was very, very awesome and educational, and—nerdy and precocious as I was—I don’t think I could have appreciated what they had to offer when I was younger.

Electric eels

Old calculating tools

I realise now I was doing the museum a disservice by seeing it only through my nostalgia goggles, and not giving the new stuff a chance. Things change, and that’s okay. I’ve changed, and that’s more than okay. Nowadays I get to enjoy googling Anik satellites and lovely arithmometres (so deliciously Steampunk!), tagging Flickr photos and of course blogging about it. My nerdiness has grown up, that’s all.

On the way out I donated $5, all the cash I had on me. Though the museum doesn’t have the magic I remember, it has a different magic, and is still just as kick-ass as it ever was. Although, my biggest disappointment? The gift shop didn’t have the cool phrenology head that was on display alongside other 19th-century paraphernalia. Now that would have been a hell of a souvenir!

Phrenology model

Movie review: The Hobbit: An Unexpected Journey

A not-very-long book stretched into three full-length movies? Part of me was dubious, but I trusted Peter Jackson, Fran Walsh and all the others to respect the source material and deliver another great trilogy.

A not-very-long book stretched into three full-length movies? Part of me was dubious, but I trusted Peter Jackson, Fran Walsh and all the others to respect the source material and deliver another great trilogy.

I was right. An Unexpected Journey added a lot of material to the story (from the beginning up until Thorin’s company is saved from the orcs by the Eagles and deposited in Beorn’s land) but it never feels like padding—well, except the present-day scene between Bilbo and Frodo, which I think was necessary to tie in to the earlier movies, but probably should have been moved to the third installment. Then again, maybe not; I don’t know exactly how the story will play out.

So in addition to the book’s basic story, we’re treated to: Azog the Goblin, just a footnote in the books, now an ongoing villain probably for the remainder of the trilogy; Elrond, Galadriel and Saruman returning for an meeting of the White Council, discussing the Necromancer and what to do about him; Sylvester McCoy making a surprisingly awesome appearance as the druid-wizard Radagast the Brown, going around on a sled pulled by giant rabbits and briefly facing off against a Nazgul; a flashback of Smaug attacking the Lonely Mountain, following an absolutely dazzling look at a Dwarf city in its full glory; and various little bits of world-building taken from appendices or later books.

All great stuff, and that’s not even counting familiar elements brought to life: our old friend Gollum, alternating between creepy-sweet and murderous-creepy; the heart-stoppingly poignant rendition of “Far Over the Misty Mountains Cold,” which I saw in the trailers but still got me; edge-of-your-seat action; the lovely shots of Hobbiton.

Yes. A beautiful movie, and a wonderful start to another masterpiece. Can’t wait for next year!

Argument 2 passed to db_delete() must be an array, string given

Sometimes it’s the stupid little things that trip you up. Just recently, I encountered an odd problem with db_delete() which I couldn’t figure out at the time; and, in fact, kept barking up the wrong tree until I found a proper example to work from. Even then I didn’t realise what I’d been doing wrong until yesterday.

Sometimes it’s the stupid little things that trip you up. Just recently, I encountered an odd problem with db_delete() which I couldn’t figure out at the time; and, in fact, kept barking up the wrong tree until I found a proper example to work from. Even then I didn’t realise what I’d been doing wrong until yesterday.

Very simply, I was calling db_delete() with an IN condition, like so:

$mytable_res = db_select('my_table','mt')
  ->distinct()
  ->fields('mt',array('key'))
  ->execute();

$key_arr = array();
foreach($mytable_res as $row) {
  $key_arr[] = $row->key;
}

db_delete('my_other_table','mot')
    ->condition('iid', $key_arr, 'IN')
    ->execute();

The first thing you’ll notice is that I should have been using db_query->fetchCol() to get the array, instead of tediously building it via PHP. I didn’t twig on that until later, because running that db_delete gave me an error: Argument 2 passed to db_delete() must be an array, string given

What did that mean? Googling didn’t really help. It was either something so obvious it didn’t bear mentioning, or something so obscure no one was talking about it. After a bit of thought I found an example to work from in the Drupal code base; specifically, in function aggregator_aggregator_remove modules/aggregator/aggregator.processor.inc:

$iids = db_query('SELECT iid FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchCol();
if ($iids) {
  db_delete('aggregator_category_item')
    ->condition('iid', $iids, 'IN')
    ->execute();
}

I adapted that to my own tables and fields (using fetchCol(), too), and it worked fine, but I still didn’t understand why my first attempt didn’t work. Finally, after some trial and error, I found the answer: db_delete doesn’t take a table alias. I was so used to using them in select functions that I automatically added one this time, and then kept on having a blind spot about it.

So, yeah. I wasn’t sure if I wanted to blog about this, but hey, we all make stupid mistakes, right? Might as well own it, learn, and move on.

Flying from Toronto

On Tuesday I flew out east to spend Xmas with the family. Sadly, for most of the trip I did not have a window seat allowing me to take awesome aerial photos—and they probably wouldn’t have been that awesome anyway, since from what I could tell most of Canada was under cloud cover. However, I got a window seat on my connecting flight from Toronto, and though the weather was still mostly overcast (and snowing in Ottawa) I managed to snap some good pics of the roads around YYZ.

On Tuesday I flew out east to spend Xmas with the family. Sadly, for most of the trip I did not have a window seat allowing me to take awesome aerial photos—and they probably wouldn’t have been that awesome anyway, since from what I could tell most of Canada was under cloud cover. However, I got a window seat on my connecting flight from Toronto, and though the weather was still mostly overcast (and snowing in Ottawa) I managed to snap some good pics of the roads around YYZ.

On the ground at YYZ

Taking off from YYZ

The SW end of YYZ

Dixie Dr & Courtnenaypark Dr E

Courtnenaypark Dr E & Hwy 410

Highways 401, 403, 410

Clouds

WordCamp 2012

Wow, it’s been almost two weeks since Vancouver WordCamp 2012, the awesome one-day conference on all things WordPress. As last year, the event was divided into Design and Development tracks. And again as last year, I went back and forth between the two. Let’s face it, the line between design and development can pretty thin.

Wow, it’s been almost two weeks since Vancouver WordCamp 2012, the awesome one-day conference on all things WordPress. As last year, the event was divided into Design and Development tracks. And again as last year, I went back and forth between the two. Let’s face it, the line between design and development can pretty thin.

Calm and Simple Code With Purpose

Jeremy Felt from 10up.com gave the audience some pointers on calm, effective and mindful coding. Rushed code means bugs, and you may think you’ll go back and fix them later but there’s always another deadline! Better to do it right the first time. Invest the time to perfect your craft. Dig into the Codex*, read the code, understand how things work and why they work the way they do.

As well, developers need to know what tools are available, when to use them, and when not to. Libraries like jQuery are already there, no need to add it in your plugins! Use caching when you must.**

Finally, we need to be mindful of our audience: developers in our team, or even ourselves six months down the line. Document your code, make it readable, whether you’re solo or part of a team. And if you’re working solo, get involved in community projects!***

*And don’t complain if it’s crap. You’re totally free to improve things!

**Memo to myself: read up on the WordPress Transient API, because I have absolutely no experience in it.

***I totally need to do that.

Documentation

John James Jacoby of Automattic came to talk about PHPDoc, a PHP documentation standard similar to JavaDoc. Documentation standards like that are about not wasting time and brainpower. It’s about (his words) not being an asshole, and not taking time away from other people or even your future self. Because you’ll be able to quickly get to what a particular bit of code is doing and why.*

JJJ also repeated Jeremy’s advice to get on the Codex and improve it if you’ve got something to say. It’s a great place to learn, because wordpress.org has lots of caretakers.

*The why is important. It’s easy to describe what is happening but why is the more interesting question.

S2Members—a membership plugin for WP

Rayhan Abdulmughnee of the Small Business Centre spoke about a S2Members. It was fairly narrow in its focus, which was a bit of a disappointment. Then again, I knew what I was getting into. The main reason I attended this presentation instead of one on a command-line-interface for WordPress, was that I was possibly about to start a WP project heavily dealing with user roles, and I thought this might give me some good ideas. I’m not sure if it did. That project ended up not happening, which was also a bit disappointing; I’ve never dealt with WordPress user management except in the most basic sense. Drupal, sure, I know it forward and back, but I would have liked a chance to dig into it on the WordPress side. Someday soon, I’m sure.

JQuery mistakes and how to avoid them

Back to the development track after lunch, to learn all about jQuery from Automattic’s Andy Peatling. This was an very intense presentation, dishing out all sorts of jQuery tips and tricks which I won’t list here (and honestly, some of which went over my head).

Caching in WordPress: Invalidation schemes

Oh, but the fun doesn’t stop there! Zack Tollman was up to tell us all about caching in WP, and schemes to refresh that cache when it gets obsolete. Cache versioning, transients, and again a lot of this was totally new to me.

How to make your WordPress site mobile-friendly

David Zille started out by giving some general tips on what a mobile theme needs: fast loading, visibility of the important elements, ease of navigation, and accessibility. Then he laid out various schemes to make your site mobile friendly:

  • a third-party service
  • a responsive theme
  • a separate mobile theme

Responsive themes (which I already have some experience in) use CSS and JavaScript behind the scenes, but the downside is that you’re serving your entire content to a phone. Plus, they can be difficult to maintain and build from scratch.

Separate mobile themes (which may come with plugins) avoid most of these pitfalls, but probably have issues of their own. It all comes down to your budget, skill sets, etc…

Food for thought, definitely.

The WordPress community

Vancouver’s own Christine Rondeau wrapped up the day to tell us about the WordPress community. And it’s real: it’s in the meetups and in the forums and the blogs and on IRC, and in events like this one. You participate to learn, to get referrals, make friends and say thanks. You know, Christine’s talk was another kick in the pants for me to get more involved. More than just going to meetups (which I do), I need to actually contribute something. There’s a theme I’ve been hacking away at on and off (based on my current blog theme, actually) I need to polish it up and submit it.

Oh, and I won a Code Poet t-shirt!

There was an afterparty, but I already had plans to ogle hot athletes in underwear at Celebrities, so I had to give that a miss.

Programmatically attaching image files to nodes in Drupal 7

I found the answer on Stackoverflow.

Simple, right? And this works fine if you’re attaching a brand new image.

I found the answer on Stackoverflow

I found the answer on Stackoverflow.

Simple, right? And this works fine if you’re attaching a brand new image. However, if you’re updating an image you’ll find that the styles don’t update after calling node_save(), and the image will not show up correctly on your site. You need one extra step: call image_path_flush() to regenerate that image’s styles before calling node_save().

//if the image is being updated, flush all its styles
image_path_flush($node->field_image['und'][0]->uri);

Reflections

A couple pics of stuff reflected in downtown Vancouver highrises.

A couple pics of stuff reflected in downtown Vancouver highrises.

The Block Building on Granville Street. I forget what the other building is. Scotiabank?

Block Building

Soft sunset clouds, taken near Georgia and Denman. It was a fine evening, and the light was just perfect.

Soft sunset clouds

Freelance Camp 2012

I attended my second Freelance Camp this weekend. I won’t try to summarise the excellent talks, because I’m still digesting all the nuggets of wisdom and working to put them in practice. I will say that I met some amazing folks who are doing amazing things, and I feel more energised than ever about my freelancing career.

I attended my second Freelance Camp this weekend. I won’t try to summarise the excellent talks, because I’m still digesting all the nuggets of wisdom and pondering all the great tools I learned about and working to put it all in practice. I will say that I met some amazing folks who are doing amazing things, and I feel more energised than ever about my freelancing career.

And of course, since I pretty much never come down to New West except for FLC, I snapped a few photos around the quay.

The world's largest tin soldier

Three Bridges

And a cute photo of a sparrow I took the day before. Such a pretty little thing!

Sparrow in the morning

Dawn and Dusk

My bedroom window, lit by the setting sun. Now that I think about it, I wonder at what hours and times of years it’s lit like that. Never really paid much attention to the Stonehenge that is the West End.

My bedroom window, lit by the setting sun. Now that I think about it, I wonder at what hours and times of years it’s lit like that. Never really paid much attention to the Stonehenge that is the West End. Food for thought, for sure.

My bedroom curtains

A pretty shot of Yaletown, from near Cambie & Pacific. Thank goodness I had my camera with me!

Yaletown dusk

The Sheraton Wall Centre towers, lightly kissed by the morning sun. This late in the year, I go for my workout just as the sun comes up.

Sheraton Wall Centre towers

The Storm Crow

Went to the Storm Crow, a nerd-themed pub on Commercial, for a friend’s birthday. The food was so-so, but cheap, so no complaints there. The real draw is the atmosphere: D&D-style posters, and card/board games to play. Plus, a truly astounding collection of “Choose Your Adventure” books.

Went to the Storm Crow, a nerd-themed pub on Commercial, for a friend’s birthday. The food was so-so, but cheap, so no complaints there. The real draw is the atmosphere: D&D-style posters, and card/board games to play. Plus, a truly astounding collection of “Choose Your Adventure” books. A few photos of the evening:

On the way there:

Leaf turning red

A bench

Playing Building an Elder God:

Building an Elder God