
A few weeks ago I started primes, a Twitter-backed prime number generator. When I say “Twitter-backed”, I mean the bot that updates the account has very little idea of state: it only knows the last number it calculated because Twitter provides it. The program flow is this:
- Start up
- Fetch the most recently calculated prime from the Twitter feed.
- Calculate the next prime.
- Post if an hour has passed since the last posting. Wait if not, then post.
- Steps 2–4 forever.
Technically steps two and four are merged after the first posting, since Twitter returns your latest tweet as a response when you post it. You can view the code on Github. It’s written in CoffeeScript on Node.js, and uses node-fibers since I orginally built the prime number algorithm as a generator, but it’s unnecessary in this case.
The only state the application maintains is an internal “last posting” date, just as a fail-safe if the server it runs on spontaneously changed time: I didn’t want it accidentally posting too quickly.
You should give it a follow if you love primes! Or maybe fork the code and make some new Twitter bots? I’d love to see some.