Tuesday 26 June 2012

Using Pocket and its Bookmarklet on Windows Phone 7

I have a Windows Phone 7 smartphone, a HTC Trophy to be exact. I can't speak for iPhones or Android phones - since I've never used them - but I like my WP7 phone (just not in a religious way). It presents everything in a nicely laid out fashion, I really like the Live Tiles and how they give me information without having to go into apps to find out, and best of all for me it seems really simple; it just does enough for what I need it to do.

But this isn't a post about how I love Windows Phone 7, this is a post about a common scenario I face day to day.

Reading It Later

When on the go I'll read through my Facebook and Twitter feeds using WP7's built in social network integration - it's not fancy but boy is it faster than any dedicated Facebook/Twitter app you'd care to try. OK, enough of the hard sell, time to focus...

Often I'll come across a link that someone has posted pointing to a blog post/news article/video/whatever that I'll be interested in, which of course will pop open in IE Mobile. Sometimes I'll read it, but other times I just want to "read it later" - either the article is too small for a phone screen to read easily, I don't have time to read it all, or it's a video and I would rather not eat up my data contract.

So my current system of saving these one-off things to look at is to email the link to myself - very easy to do in IE Mobile using the "Share" menu option - but then I'll end up with loads of emails in my inbox which are just reminders for me to do something. I just feels like there must be a better way...

Enter Pocket

I asked friends and looked around and eventually settled on Pocket (formally Read It Later). All it does is collect links that you save via a number of methods which you can then look at later. I went with this one because although it doesn't have much in the way of direct WP7 integration there are at least two simple ways that I can save links to my Pocket account from my phone:
  1. Email the link to Pocket. Again quite simple thanks to the "Share" menu.
  2. Add a bookmarklet to your favourites to magically save links.
But if you look at the instructions they give, it tells you to drag and drop the bookmarklet to your bookmarks bar because they are assuming you are doing this from your PC, which is not something you can do on a touchscreen.

Adding Bookmarklets to your Phone

Fortunately you can add bookmarklets to your phone's browser, it's just not as intuitive. Here's how I did it for the Pocket bookmarklet but I assume the same process can be applied for other sites:
  1. From your phone's browser, go to the Pocket bookmarklet page to see the button that has the bookmarklet link.
  2. Press and hold the bookmarklet button to get the "right click" menu to appear, then tap "Copy Link".
  3. Tap the "..." on the browser's menu bar to see the main menu and tap "add to favourites".
  4. Clear everything in the Web Address field and paste in the bookmarklet link - a long string of JavaScript code.
  5. Enter a memorable name for it - I've called mine "+ Pocket" like the website suggests - and save it.
That's it, you've now got a working bookmarklet in your phone's favourite list. Now any time you see something on your phone's browser that you want to read later, just go to the favourites menu and tap the bookmarklet to save it to your Pocket account.

Friday 15 June 2012

Refactoring with WinMerge

A short post which I thought I would share since I found it useful.

The other day I was looking at some code and I knew that two functions were written in a very similar way, so I wanted to refactor them into just one function. But how do you see how similar they are? You could do it by eye, but there could be human error. Surely a better way is to have the two functions side by side so you can see the differences. And what do you know, there are tools out there that are designed to do just that.

So here is what I did:

  1. Copy the two functions into two separate temporary files.
  2. Compare those two files with WinMerge (or your favourite diff tool).
  3. Immediately see what's similar and what is different. Here's what I saw:

I can now see that a lot of it is very similar, giving me some indication of how I could refactor them into one function.

Sometimes the simplest solutions are the best. 

Wednesday 13 June 2012

Becoming a Father: One Year On - Part 1

I'd thought I'd choose a different topic to what I usually write about. My son is now a year old, 13 months to be exact - sometimes it is hard to believe it - so I thought I would give a retrospective on my transition into fatherhood.

To read all the other parts to this series, click on the links below:

Part 2 - The First Two Weeks
Part 3 - Getting the hang of things
Part 4 - The Accident

The tl;dr version: being a parent is hard! No, I mean really, really hard!

The Beginning

Last May 2011 my wife announced to me at an unfavourable hour that her waters had broken. After calling the midwife we were told to make our way to the hospital in order for my wife to be induced; apparently her waters were greeny-brown, an indication that our son may have passed his very first stool before being born. Because midwives get concerned that this may cause stress to the baby, they wanted to induce my wife to get things going.

For about 8 hours my wife was pretty much left alone hooked up to a monitor to check the baby's vital signs, with very little sleep for both of us (a sign of things to come. More on that later...) Only till the next shift did a couple of midwives come and attend to us, and attend to us they did: my wife then had round the clock care which was really good for her as she was getting upset at the lack of information given to us.

Perhaps you've seen how babies are born on medical shows? It takes a lot longer than that. From about 8am till 1pm my wife was fed some sort of hormone drip which was meant to kickstart labour. The midwives were very good to my wife, always chatting and taking her mind off things. Once I came back from lunch did I really start to see the affects, as my wife's contractions had started.

This was the bit where I came into the picture. Everyone knows from TV and films that the father is meant to stand next to his partner and encourage this very slow breathing technique through your mouth whilst your partner is screaming in agony telling you what you can do with that idea. My wife did not shout at me directly but was clearly feeling the pain.

We had planned lots of things during the birth, built into a sort of "birthplan". Here's what new parents learn very quickly: plans of any kind go right out the window. My wife had intended to be in a birthing pool to help with pain relief, but to be induced means constantly being hooked up to drips and monitors. Walking and different positions also became difficult since her mobility was restricted from all these machines. Gas and air helped but there came a point - which originally she said she would refuse - to get the big gun out: the epidural.

After waiting for an anesthetist (resulting in more screaming from my wife) one finally came. She was obliged to give my wife the legal stuff, such as side effects, consent etc, though my wife was sucking on the gas and air constantly and shouting "Yes! Anything!" at that point. It did help with the pain though, the only drawback being she couldn't even stand up anymore: the epidural is injected towards the base of the spine so it basically knocks out anything from the waist down.

We had a bit of a breather for an hour or two at that point, which gave the midwives a chance to discuss with the next shift what has been happening (this would be about 17 hours since we arrived at the hospital). Finally, the big moment had come: it was time to get this baby out.

The next bit has been censored. If my wife saw that I described the birth of our child in any detail whatsoever she would kill me!

...4 and a half hours later, our son entered the world! Now usually this is greeted by the baby taking their first gasp of air and crying, at least that is what I considered to be the norm. Not so my boy; he decided to basically keep quiet, thereby raising alarms and calling in what looked like every midwife, nurse and doctor on the maternity ward to see to him and get him breathing. Let's just say it was the most frightening experience of my life. But there was nothing to worry about in the end, he was breathing just fine and simply didn't want to make a fuss. Cheeky monkey.

He was cleaned up and handed to my wife, who was still completely off her head from all the gas and air she was basically breathing in like oxygen. But it was there, that special moment when you realise that you have a little person that you instantly love. I stayed for another hour or two and then drove home to try and get some sleep while my wife still had work to do giving him his first feed.

All in all it took almost 24 hours from start to finish. I was immensely proud of my wife, who worried she would never be able to do it, and amazed that there was now a new little person in our lives (not very little though; he weighed in at 8lb 11oz, so was hefty enough). As I collapsed into bed when I got home I vaguely wondered what the future would bring...

My boy, less than a day old, wondering where the hell he is
Next time: the first two weeks...