Wishful Coding

Didn't you ever wish your
computer understood you?

Twitter OAuth for Open Source clients

After reading these two articles about how to compromise Twitter tokens from a client and about how Twitter is abusing OAuth secrets and screwing OS clients by blocking their tokens, I came up with the following plan.

key = "your key"
secret = "your secret"

try
    request = sign(twitter.com/verify_credentials, key, secret)
    request.post()
except 401
    key = "BigFish key"
    secret = "BigFish secret"

I really love Twitter and the Twitter API, but it is obvious by now that Twitter does not care about small OSS projects.

I propose small Open Source Twitter clients to use tokens from the big fish as a fallback for their own tokens. This will allow small clients to continue to work after their tokens are blocked(albeit under the big fish name), unless Twitter blocks their own clients as well or faces the fact that their approach doesn't work.

A more politically correct option would be to write an OAuth Echo service that stores your tokens in a secure place, and accepts request without a secret. Take your pick.

5 minutes Lisp in Python

I love both Python and Clojure, so after I read this gist about a Lisp in Ruby, I decided to craft my own in Python.

The idea is basically to abuse a few Python functions, namely Generators, Decorators and grouping to have a syntax that looks like Lisp with yield at the start of every statement.

It's all still Python, so you can mix and mach however you like, I sneaked a List Comprehension in the example, which fits the Lisp syntax quite well.

At the moment of writing, the Gist below is also #3 on HackerNews.

# 5 minutes Lisp in Python
# Pepijn de Vos <http://pepijndevos.nl>
#
# Inspired by 30 minutes Lisp in Ruby
# http://gist.github.com/562017
# 
# This Lisp does not read or parse anything at all.
# A generator and a Decorator are abused to run sexps.
#
# Usage:
# 
# Define a function decorated with @lisp and start every sexp with yield.
#
# The function names should be strings.
#
# Result is stored in fn name.
#
# Example below:
#

def lisp(fn):
    code = fn()
    val = code.next()
    while True:
        try:
            try:
                newval = getattr(__builtins__, val[0])(*val[1:])
            except AttributeError:
                newval = getattr(val[1], val[0])(*val[2:])

            val = code.send(newval)
        except StopIteration:
            return getattr(val[1], val[0])(*val[2:])

@lisp
def example():
  (yield 'join',
    ", #",
    (yield '__mul__',
      [(yield 'str', i) for i in
        (yield 'range', (yield '__add__', 5, 5))],
      2))

print example

Twitter in your inbox

I have been working on this for quite a while, with initial plans to make it a service. But I have changed plans, and am releasing it to the world.

What have I been working on, you ask? Not that I like sliced bread, but it's at least as good as that: It solves some problems while it introduces some others. It's a proxy between Twitter and your email client that sits on your computer or a server translating mail-language(POP, SMTP) to Twtter-language(REST API).

This way you can read your tweets in your mail client, store them in folders, search though them, and do all the other stuff mail clients are good at. It even allows you to reply and forward(retweet in Twitter lingo) tweets.

Here is how to get it. You go to my GitHub repo, which lives at the link below, and pull/download the code.

http://github.com/pepijndevos/Twemail

The next step is to get the dependencies, which include Twisted, OAuth2 and Twitter-Text-Python. You might try to use setup.py for that, but I'm not sure it works.

Now you simply run "twistd -ny twemail.tac" in the Twemail directory. If everything went well you'll see some messages rolling by about starting services.

Now all that remains is to configure your mail client with the following information"

  • email: username@twitter.com
  • password: your Twitter password
  • POP server: localhost on port 1100
  • SMTP server: localhost on port 2500

Here is how it works.

  • You can send messages by mailing post@twitter.com
  • Replying is done by hitting reply and replacing the subject line.
  • Retweets are done by forwarding to the sender of the tweet

In the future I also want to handle attachments and IMAP, but this is currently not included.