Cody and Shaina in Toontown

I wrote a book when I was 11.

Cody and Shaina in Toontown

Read the rest of this entry »

Serial commas and PHP

I love serial commas (putting a comma before “and” in a list. I.e. one, two, and three). People call them old-fashioned and clunky, but they really help with clarity (see this article for an example).

The thing I don’t like about serial commas is trying to automate their formatting. I can’t find examples anywhere, so here’s my PHP code to do it. The way I use it is a while() loop after querying a database, but it will work with any loop (i.e. a foreach’d array). $num_authors is the total number of records. $count_authors is set to 1 before the loop.

The code

Update: Charismatic Programmer posted a much better way to do this in the comments section. This is their method:

function serial_comma($array)
{
     $size = sizeof($array);
     switch($size)
     {
          case 0:
          case 1:
               return reset($array);
          case 2:
               return join(' and ', $array);
          default:
               return join(', ', array_slice($array, 0, $size – 1)).', and '.$array[$size - 1];
     }
}

Example:

$array = array('Anthony Bourdain', 'Mario Batali', 'Thomas Keller');
echo serial_comma($array);

Produces:

Anthony Bourdain, Mario Batali, and Thomas Keller

The old code

if ($num_authors == 1)
{
	echo $author;
}
else
{
	if ($num_authors > $count_authors)
	{
		if (($count_authors + 1) == $num_authors)
		{
			if ($num_authors == 2)
			{
				echo "$author and ";
			}
			else
			{
				echo "$author, and ";
			}
		}
		else
		{
			echo "$author, ";
		}
	}
	elseif ($num_authors == $count_authors)
	{
		echo $author;
	}
      	else
	{
		// error message
	}
	$count_authors++;
}

Animas, awkward, and amazing

My insulin pump broke today.

The first thing I did was panic—my broken pancreas replacement was broken! I looked at the lunch I’d just sat down to eat (hash browns, eggs, and strawberries with vanilla yoghurt) and weighed my options. First thing was call the 24/7 Animas support line where I spoke with the very friendly Jodi. She gets my details, asks a few questions about what happened to the pump, and we determine that the problem was due to water damage. I hadn’t noticed it, but there was a small tear in the rubber. I’d dropped it in water a few days ago but, since it’s water resistant and I got it out of there right away, I didn’t think much of it.

Jodi says she is going to contact the Canadian rep, who will call me as soon as possible to arrange a replacement. I head out to the nearest pharmacy to pick up some syringes to tide me over; my phone rings halfway through the 5-minute walk. A rep from Montréal verifies my info, makes sure I’d be home within the hour, and tells me she is about to call the local rep from Richmond—they’d come by with my new pump as soon as possible.

Blown away by the customer service, I figure I should pick up some syringes in case the delivery was late and continue to the pharmacy. That’s when it gets awkward. I’m walking into a non-regular pharmacy and asking to buy syringes, so I have to work out a back story that balances the truth without giving too many details and falling into “that’s too elaborate you intravenous drug user. I will sell these to you anyway, but rest assured it will be combined with a look of condescension” territory.

I’m feeling confident—I had my broken pump with me, which isn’t exactly a common thing to have, as proof—before realizing that I don’t know anything about syringes. Even before my pump, I used this fancy pen system that made accuracy a lot easier than the standard stick syringes. Instantly, my mind floods with all kinds of questions: what kind of syringes do I ask for? Has syringe technology changed in the past decade? What if I get the wrong ones? Should I browse through different models, or just take whatever they give me?

I get the to counter and say something like “diabetes syringes broke my pump, please.” Unsurprisingly, I have to repeat myself. After some more ramblings about what was wrong and what I need, the clerk calls over the pharmacist. I finally vocalize what I need, and he goes to the back to grab a couple bags of syringes; turns out they haven’t changed at all in the past 10 years. Excellent. I buy a pack, and head back home.

Upon arriving home, I’m greeted with the smell of my uneaten lunch: delicious-smelling hash browns and eggs cut with fresh strawberry that I’d decided to leave on my table while I went to the pharmacy were calling to me. More weighing of options. I can use a syringe, deal with its lack of accuracy (0.05:1 compared to the pump), and eat my now-lukewarm lunch; or wait a bit for the new pump. Considering the anxiety that was now setting in post-”I need to fix this now!” adrenaline, I choose the latter and nervously surf the Animas website, looking at pump supplies.

The phone rings with its someone-is-at-the-door tone, and I let the delivery guy in. 10 minutes later, my brand new pancreas was programmed and subcutaneous. All told, the entire process took about an hour. On a Sunday afternoon. Amazing. And now I’m going to tag the hell out this, and cross-post with another site in the hopes that people googling for insulin pumps end up here.

Some backstory on the company: Lifescan is the diabtes division of Johnson & Johnson—they make the One Touch line of blood glucose monitors. My first monitor was a One Touch II, of which there is nothing I can complain about. The one time there was a problem with my monitor, I had a replacement delivered to home almost immediately, no questions asked. If I want to upgrade to the latest model, it’s just a phone call away.

In 2006, J&J bought Animas, a company who makes insulin pumps—they now report to Lifescan. When my endocrinologist heavily suggested I move to pump therapy in 2007, they were the first company I looked at. There are competitors, but none of them seemed to offer what I could get from Animas. Within a week I’d scheduled and met with a rep, and a few days after that I got a call saying my insurance had gone through and the pump was on its way. From there I scheduled an appointment with a nurse (who I stil have access to 24/7) who works with Animas and specializes in pump therapy—she came to my apartment, set up my pump with me, and life improved drastically.

So if anyone’s stumbled on this post from a search engine, go check out the Animas website and schedule an appointment with one of their reps. It’s a very pleasant experience and your pancreas will thank you for it. Diabetes is insanely stressful—having a company who has improved my life so significantly, and offers such incredible support, is easily the best thing that’s happened to my health.

tl;dr: Animas is really amazing and buying syringes is awkward.

The SHAWC Project

The SHAWC Project

I made The SHAWC Project this weekend. It’s a “photo project” I’ve ben doing for years, and now I can call it a Photo Project.

It’s very beta, but works in modern non-IE browsers for sure. Please participate!

Matthew Gruman – Mathy

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Download mp3.

Last winter a kitchen accident resulted in a “distal fingertip amputation” (i.e. I cut off a small part of my finger). So I made some math music on a keyboard.

Ani DiFranco & Utah Phillips – “Korea” (bass guitar tab)

Utah Phillips and Ani DiFranco

The tab

This one’s really simple, but one of my favourite bass riffs.

G|--4-----2-----------|
D|----5-----0---2-----|
A|--------------------|
E|-----------------0--|

-or-

G|--4-----------------|
D|----5---7-----------|
A|----------5---7-----|
E|-----------------0--|

The song

Listen here.

And I watched her through the rain coming through the ceiling and thought back to Salt Lake; and my father, Sid, who ran the Capitol Theatre. It was a movie house, but it had been an old vaudeville house, and he wanted to bring live performances back to the Capitol. In 1948, he invited Marian Anderson to come and sing there. And I remembered we went to the train station to pick her up and took her to the biggest hotel in town—the Hotel Utah—but they wouldn’t let her stay there because she was black. And I remember my father’s humiliation, and her humiliation, as I saw her singing there through the rain.

And I realized right then; I said “Brenden right then, I knew that it was all wrong; that it all had to change. And that that change had to start with me.”

Matthew Gruman – Hi Bye Uncle Matthew (ft. Ry-Ry)

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Download mp3.

My niece’s harmonica skills aren’t up to par yet, so I jammed with her phone message.

Distinct Variation(s): Graphic Design & Web Development

Distinct Variation(s)

I finally put up a portfolio!

Free Hugs!

Outside the Vancouver Art Gallery on February 14th, 2009.

Matthew Gruman – DLZ (TV on the Radio cover)

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Download mp3.

I made this today—hope you like it! I had a lot of fun making it.

« Newer Entries Older Entries »