Dear Toronto,

Friday, January 08, 2016

I have a few things to say to the people I met in a city I wasn't sure I would like.

Toronto at night

You, the pakistani man who makes butter chicken roti at your strangely NYC themed restaurant, who passably decorated it by throwing up old LIFE magazine covers on the walls, who has family trouble in California and a cousin doing a stint in our penal system.

You, the pupusa lady that gave me an extra tamale on the house after I had such a hard time deciding which pupusas and tamale flavors I wanted to try, who then laughed when I immediately came back to order the fried plantains, which I saw while waiting for my order (they weren't on the menu I agonized over).

You, the guy bumping to Hotline Bling outside your car that I grooved with, but politely had to decline your offer of a cigarette, because I had gone through D.A.R.E. three times as a kid.

You, the roommate who was once a kingpin of street fighter arcade sticks as well as an elite Canadian memory champion, who is unfazed by face transplant images that made me jump out of my chair, who upon learning I was leaving Toronto without seeing Niagara Falls rented a car and drove us out there at midnight.

You, the roommate who is a sound mixing engineer that did a tour of duty in Nashville but somehow managed to work on rock instead of country, who showed me the process for modern sound mixing using Britney Spears’ I'm a Slave For You (dozens of vocal tracks!), who stood in the hallway with me until 3am because we had delved too deep into our opinions about movies & games for sleep to matter anymore.

You, the roommate who is polyglot that’s lived in many different countries, who works harder to balancing work and school than most anyone I've met, who still had the energy to unabashedly start dancing the one time I casually panned you into my snapchat video.

You, the girl with an excitement that is palpable, contagious, and hard to forget, who unquestioningly shared your hopes and dreams to a complete stranger who slid into your DMs, who despite living there your whole life, seemed somehow less familiar with directions in Toronto than me.

You, the guy who has not ventured out of Montreal for over 35 years, but gave me change for the bus and humored me while I chatted you up about how your city's bagels had ruined me for life.

You all made me feel odd, like I was leaving a place that had become a home.

Sincerely,

Confused in California.

.

[travel] [toronto]

Coming up in 2016

Wednesday, January 06, 2016

It’s been a few years since I’ve done this publicly, but I’d like to bring this tradition back. Learning from past experiences, I’m keeping this list concise and specific. Life can sometimes get in the way but here’s what I’m agreeing to in 2016:

  1. Ship something in virtual reality.
  2. Write 8 posts worthy of reading.
  3. Hike at two national parks, preferably new.
  4. Live in a foreign country that's new to me.
  5. Develop a fluidity in the kitchen so most dishes I make are served on time.
  6. Be able to name all common herbs & spices by sight & smell.
  7. Accomplish at least two physical goals for surfing, snowboarding, skiing, or weightlifting.

Time's ticking.

.

[resolutions] [2016]

Refocusing

Wednesday, January 06, 2016

Before I release the 2016 ones, here are my last set of resolutions from 2013:

"100 posts about programming things I’ve encountered and want to share"

Rode the new years train a bit too hard on this one. Even without life getting in the way, this would have been a tough one to keep, but glad I managed even 14 posts even if 13 came in the first half of the year.

"Contribute a couple patches or a bug fix to an open source project."

To my credit, I did make a very small contribution to Django REST Framework as well as other smaller repositories. Work and personal projects have always gotten the best of me. I’ve since forked projects and made features I’ve needed but I’ve always been too lazy to properly submit pull requests with tests.

"Do a weekend project and get it on the front page of HN"

In retrospect, it seems silly to make a project with the explicit intention of making the HN front page. No wonder this is the resolution I remember making the least. I suspect many developers have fallen into the same trap, but I have numerous projects that are anywhere from 50% to 80% complete. Shipping products is an art.

“Read more books: I need to expand my knowledge beyond just reading the news and blogs"

By my count, I’ve read around 18 books since then. Paltry, to be sure, but not nothing.

.

[resolutions]

A little about push

Sunday, February 02, 2014

Last year I had the chance to take some time and get a better understanding of how push notifications work for iOS applications. But before I talk about that, it helps to understand why push notifications exist in the first place.

Apple developed iOS as a closed platform operating system. The source code is mostly closed except for the publicly available portions that developers use in networking programming or to interface with the camera or all the other fancy things that apps do. One of the most important design decisions made at Apple was to heavily restrict the capabilities of daemonized apps (apps running in the background). In fact, Apple's guidelines explicitly state that only apps such as music players, VoIP clients, and GPS navigation systems are allowed to run background tasks. That essentially means that once a user leaves your app, you're dead in the water until the user decides to tap your lovely retina icon again... at least that would have been the case if it weren't for push notifications.

Push notifications exist for the express purpose of letting applications pull users back into their experience. They're basically shouting "Hey, look at me, I have something to show you!"

The life of a push notification starts on an application. The application will ask iOS for a unique device token that identifies the device, sort of like an IP address. As you'd imagine, it's pretty important to know the address of the device you want to send something to. The operating system doesn't have this information regularly, it actually makes a request to the Apple Push Notification Service (APNS), which divulges a unique token for that specific iOS build on that specific device. The application should then pass the token to its backend server (this is the thing that I've been working on at EAT Club).

Once you want to send a push notification to a specific user (for instance, a "Your food is ready for pickup!" notification that we send to users who have ordered a meal that day), just pluck that device token out of your database table and pass it to your push server to fire off to APNS. There are also third parties that exist as the middle man push server between your backend servers and APNS (see UrbanAirship). While it would be awesome if we could build servers that directly sent out pushes to iOS devices, Apple unfortunately maintains ultimate gatekeeper status and all your push notification requests must be routed through APNS. Such is the plight of developing on a closed source platform.

Then if all is fine and dandy, APNS will send your push to the user's device - along with a custom sound (i.e. the Gmail app), custom alert text, and even let you specify where the user lands when they open the notification (i.e. opening up the Twitter app and immediately dropping you on the tweet that just mentioned your handle).

.

[iOS] [APNS]

The Self Aware Python Function

Saturday, January 18, 2014

I've been using Python for over a year now. It's what I learned to program with. About half a year ago, a fellow coder (friend of a friend) posed the following riddle upon learning that it was my language of choice:

"How would you write a function in Python that knows how many times it's been invoked?"

Let's consider this for a moment. A function that knows how many times it has been invoked is one that would need some access to a scope outside of it's own. Functions are generally pretty transient — they do their thing and then wait until they are told to do it again. There isn't a middling dormant state where they consider how many times they've been told to execute their (probably) menial task.

As a first stab, we might consider a global counter, as in the following setup:

count = 0

def self_aware_function():
    count += 1
    if count == 1:
        print 'This is my first time doing this'
    else:
        print 'I have done this {} times now.'.format(count)

for i in range(10):
    self_aware_function()

Those familiar with Python are up in arms right now, and rightfully so. Here's what you get when invoking self_aware_function:

UnboundLocalError: local variable 'count' referenced before assignment

In Python, when you are in a function and assign a value to an immutable type variable (such as our int count), you end up shadowing the global variable with one local to the function's scope. So when count += 1 is evaluated (remember this is expanded to count = count + 1), Python cannot find the value for count in the expression to the right of the =.

Okay, local variables won't work, how about we use the global keyword or mutable variables?

# global keyword

def self_aware_function():
    global count # Now we force the use of the global count
    count += 1
    # ...
# using a list
count = [0]

def self_aware_function():
    count[0] += 1
    # ...

These both work and globals were my first idea for a solution. However, when I asked if this was acceptable, I was met with opposition.

"You are only allowed to write code within the function, not outside of it."

That's rough. How do you become self aware of an outside world/scope that you can't even interact with?

Turns out, the answer lies within a popular Python gotcha.

Self-awareness

Here's how you define a default parameter in Python:

def foo(default='bar'):
    return default

In Python, default parameters are evaluated ONLY once — when the function is defined. That means the default parameter is "the same" for all invocations of the function. I say "the same" because normally the default parameter will have the same value across multiple function invocations, but if your default parameter is mutable then you change it! And then you can do some really special things.

Case in point, self-awareness:

def self_aware_function(count=[0]):
    count[0] += 1
    if count[0] == 1:
        print 'This is my first time doing this'
    elif count[0] >= 10:
        print "Who are you to tell me what to do???"
    else:
        print 'I have done this {} times now.'.format(count[0])

for i in range(10):
    self_aware_function()

And we have our cheeky, self aware function!

$ python aware.py
This is my first time doing this
I have done this 2 times now.
I have done this 3 times now.
I have done this 4 times now.
I have done this 5 times now.
I have done this 6 times now.
I have done this 7 times now.
I have done this 8 times now.
I have done this 9 times now.
Who are you to tell me what to do???

If you're wondering, mutable default arguments was the answer I gave after a good amount of thought. I believe there are other solutions and I invite you to share them in the comments :)

.

[python]

<< Page 2 / 5 >>