Profile cover photo
Profile photo
Bram Cohen
The BitTorrent guy
The BitTorrent guy

Bram's posts

Post has attachment

Post has attachment
How to get your code to work on both Python3 and Python2.

I recently got my code to run under both Python3 and Python2. Since I make a lot of use of strings and bytes, which is the hardest transition between the two, you might find my experience helpful.

First, repeat after me:

import sys
if sys.version_info[0] < 3:
import _builtin_
_builtin_.bytes = lambda x: str(bytearray(x))

That makes calls to bytes() act reasonably close to the bytes constructor in Python3, by making unencoded strings when passed an array of ints.

After that's done, the main problem is that using mybytes[i] returns an int in Python3 and a str in Python2. To make that work, replace all calls to mybytes[i] with ord(mybytes[i:i+1]). Yeah it's funny-looking, but it always works.

(I'm assuming that your code uses encode() and decode() properly. If your code started in Python2 and Python3 starts barfing at you about calling decode() on a bytes or encode() on a str, you probably have a bug.)

The above will result in calls to type() not really working on bytes. Maybe you could make bytes be a subclass of str if you need that functionality. I don't, so I haven't worried about it.

Also, if you need an OrderedDict, you should use the implementation linked to below.

Other than some minor library reorganization issues, that was all I had to do to get my code fully back-ported. It's surprisingly easy once you know how to handle the subtleties properly.

I'm trying to get my email addresses associated with Google+ properly, and would like to ask if anyone really knows what the options mean before I accidentally delete one of my accounts.

Under 'Account Overview' it lists my email address, and lets me try to add another one. Naturally, I'd like to add my work email address, because that gets most of my mail and that's important for all the implicit adding which G+ does. Unfortunately if I try to add that it complains that that account already has an associated Google account, which sort of makes sense, because my work uses Google Apps, but I'd like my G+ social networking feature to be associated with both of them.

Also under 'Account Overview' there are the options 'Delete profile and social features' and 'Delete account'. I'm guessing 'Delete account' is something I absolutely don't want to do, but have a vague hope that using the delete profile and social from my work account will allow me to add that one to the profile I'm using now, and not implicitly remove all the existing state of other peoples's profiles knowing about the account because they've exchanged email with me.

Does anybody know how this all work, in particular answers to my very concrete questions above? It seems like G+ is getting hurt by the preexisting awfulness of Google's support for multiple accounts, but that's a whole other rant.

Facebook wants you to be stupid.

Facebook clamps down on third party UIs for a very basic reason: Those UIs will inevitably enable functionality which they don't want you to have, because it makes other people less comfortable using the system, and they've crippled the web UI in ways which make people on the whole happier.

First and foremost Facebook doesn't want you to be able to see when people view your profile, for the simple reason that you don't want them to be able to know when you look at theirs. Scams frequently claim to deliver this functionality, for the simple reason that it's highly desired and completely unavailable. Granted alternate UIs wouldn't be able to offer this functionality, but it's a deep issue for projects like Diaspora.

Beyond that, Facebook doesn't want people to feel like they can stalk each other. First and foremost there, its chat system doesn't have the ability to record when your friends join and leave. It would be trivial to add such functionality, but it would make people feel like others had too detailed of a historical record of them, even though the information is already there in principle and only limited by the end user's ability to remember it. Likewise, the time of posts is fuzzed out, first to a minute granularity, then to the hour, and finally to the day, and times of likes isn't kept at all. People simply don't want others to be able to track their movements to the minute quite so easily.

Finally, there's the ability to delete posts. Obviously a client-side cache could simply keep all posts you see and remember them, and any custom client would undoubtedly do that, but people like being able to delete posts, for a variety of good reasons, and want others to be forced to use their own frail human memory to get back the content. Likewise you can hide comments that you make from your main feed, so even people who are permissioned to see them will have a harder time noticing them, and relationship status changes, which are impossible to hide, can be 'hidden' in the sense that people aren't actively notified of them.

Does Google+ want you to be stupid? That remains to be seen...

Saw a shared post about 'every random hook-up I've ever had'. Not visible when looking at the person's profile. Apparently G+ lets you easily rebroadcast non-public posts. Oops.
Wait while more posts are being loaded