How I made a toast!

Abhishek Jain
Better Engineer
Published in
4 min readNov 2, 2018

This is not an actual toast recipe if you are looking for one.

“pullman’s loaf with fill” by Amy Shamblen on Unsplash

Yeah, none of that.

Now that it’s out of theway, let me tell you how I made a Burnt Toast. Am I making sense yet? Probably not. But I will, soon.

I work at Intel in Hillsboro, Oregon. Those who don’t know where Hillsboro is , it is a suburb of “Portland”, where the dream of 90’s is still alive. Or is it?

This is where Portland is

Anyway, when I got married to love of my life, she moved to Vancouver to be close to me (and also her new job ¯\_(ツ)_/¯) .

No, not Vancouver the Couv, but Vancouver, Washington which is just across the river from Portland.

This is where Hillsboro and Vancouver are, the blue dot is my home.

I moved to Vancouver and we began our new life together.

Now as you can imagine, the commute is not exactly straightforward.

To give you a sense of it, this is how the traffic is on a Saturday noon.

As you can see, I have three options to get home. They are marked as 1, 2 and 3 in the picture above. And during rush hours, the difference between each of these can be as much as 30 minutes. So I have to be very careful when I leave from work and choose the fastest one.

I soon got tired of looking at my phone every 10–15 min from 4 pm until I left to keep checking the commute time. It was a pain to stop working, pick up my phone, launch the map, wait for it to load and then sigh looking at the sad number. I needed something on my desktop which wouldn’t take much space and much effort for me to launch.

I thought this is an easy problem to solve and that means someone has already solved it. Although, this wasn’t exactly a stack overflow kind of problem. So after a lot of digging, I found this gem

https://github.com/Microsoft/Windows-appsample-trafficapp

It looked promising. It had everything I needed and a lot more. But that was the problem. It was too much. I had to download and install Visual Studio to just be able to see what it does.

I am a hardware engineer, C# is not my kind of thing. So using this was out of question.

I almost gave up (for few days).

Then it dawned on me that I don’t really need an elaborate Windows App and then use it give me notifications. I can just create a notification which appears and vanishes by itself. That thing is called a “Toast” notification in Windows world.

So I went ahead and wrote a cute little powershell script and used this code as a template.

I came up with this:

And I was quite content with it.

The next challenge was to now to figure out how to get live commute time.

Google Maps was the obvious choice for this.

I made use of these docs to get the Maps API and verify that it worked like I wanted

It wasn’t very straightforward to figure out if this was going to cost me anything. But Google lets you use their API for free if you don’t exceed certain limit. I think 10k hits per month. It was good enough for me.

So using this, I was able to come up with a new powershell script which generated toast for me with the current commute time.

This is the link to that code.

~45 lines of code, not so bad huh.

But then I hit the gold mine. I discovered BurntToast.

And my code came down to just 15 lines. Now that’s something.

This is how it looks now

I added an option to launch google maps in chrome in case I needed to check how the routes look. It was just one line of code using $mapButton above.

This was still just a poweshell script though. I had to turn into something easily usable. And PS2EXE was just the thing I needed.

I converted my .ps1 into a .exe and that was the happy ending. I pinned it to my taskbar and every time I click on it, this little thing pops up and tells me how long it will take me to see my wife tonight :)

Feel free to reuse the code from my github. I would be happy to answer any questions you have.

--

--