Ducktyping + Python Protobuf

08/18/2017

Given a compiled Python protobuf as follows:

message Person {
    optional string email = 1;
}

Don’t use duck typing to see if an optional field has been set!

Though the value is known to be unset, accessing the value always returns a default value! (Source. See optional field description.)

import Person_pb2

person = Person()

if person.email:
    print('Oh wow you totally have an email!')
    print('It is: '.format(person.email))
else:
    print('I got nothing')

> Oh wow you totally have an email!

> It is:

Use the compiled protobuf’s data member functions to check existance:

if person.HasField('email'):
    # do stuff

It’s not very clear you need to do it like this…

REST Example

08/17/2017

Not RESTful

REST interface: “Do something and let me know when you’re done.”

Resource: “K.”

Resource: “Hey, I’m done.”

REST interface: “K.”

RESTful

REST interface: “Do something.”

Resource: “K.”

REST interface: “Are you done?”

Resource: “No.”

REST interface: “Are you done?”

Resource: “No.”

REST interface: “Are you done?”

Resource: “No.”

REST interface: “Are you done?”

Resource: “No.”

Portrait Mode

07/10/2017

Portrait Mode

(#1) Programming is like...

06/30/2017

To be garbage collected player

Garbage collection is like if in basketball, coaches can substitute players by simply introducing the new player into play but the replaced player can remain on the court. You assume they won’t move or touch the ball or interfere with other players. And then every 5 minutes, the referees yell “FREEZE!” to check every player and sit out the ones that were substituted.

Active players

Troubleshooting Snap on Ubuntu Core

06/18/2017

I got started with Ubuntu Core on the Raspberry Pi and I had some problems (nothing major) starting with snap on Ubuntu Core. Here are some quick resolutions:

  • is the snap daemon on? Restart the service with service snapd restart
  • errors installing snaps? Did you login? Do snap login