Cuttlepress

Blogging about Hacker School?

Day 33

Today started early with Tom’s workshop on deploying to Amazon EC2, where we all learned how to use a tiny subset of the dizzying array of AWServices. In the afternoon, I attended Mary’s refactoring/testing workshop; we learned about testing in general and a bit about testing on asynchronous systems. I paired with Ashton on refactoring a very small server and writing some tests for it. For the other snippets of the day, I continued to read about the Twitter API and the many possible Node modules for interacting with it. Right before it was time to leave for the Monday talk, I finally got a filter stream working with ntwitter and help from Paul. Here’s the relevent code, which is deceptively short, for opening a stream of a particular user, and attaching a handler to incoming data:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
var twit = new twitter({
  consumer_key: keys.consumer_key,
  consumer_secret: keys.consumer_secret,
  access_token_key: keys.access_token_key,
  access_token_secret: keys.access_token_secret
});

var tofollow = //whoever you want to follow, as a user id (not screenname)

twit.stream('statuses/filter', {follow:tofollow}, function(stream){
  console.log("making a stream");
  stream.on('data', function (data){
      if (data.text){
          console.log(pluck(data, ["text"]));
      }    
  });
});

The Monday lecture was an entertaining overview by Zane Lackey of some of the principles behind how he and his team handle security at Etsy.