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


Post has attachment
Add a comment...

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.
Add a comment...

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.
Add a comment...

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...
Add a comment...

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.
Add a comment...

Fuck you, Fandango.

I have now used exactly one online coupon deal, using livingsocial, for Fandango, where I got two movie tickets for the price of one. It sent me a code for use on the Fandango web site (which by the way sucks, but that's a different issue) and used it to buy my tickets. Of course it defaults to buying one. I did change it to two, but I might have had to backtrack and redo something in the UI. In any case, I got my confirmation number, showed up at the movie theater, and got... one ticket. Apparently it will perfectly happily let you buy just one ticket using the coupon for two. Of course I was already there and the movie was starting so I had to buy another one.

So let me just say: Fuck you, Fandango!
Add a comment...

I have a backlog of blog posts to write. Do people want to hear about how Facebook wants you to be stupid, or about how most commentary on valuations is completely chuckleheaded? Both will probably have to wait until I set up a better blog though.
Add a comment...

My question on Krugman's blog: "Do you think that if all the people in the US whose houses are underwater were to simply walk that would lower the debt burden enough to get us out of our current slump, and if so, why aren't you advocating for it?"
Add a comment...
Wait while more posts are being loaded