How (and Why) I Wrote My First Twitterbot

This week, I wrote my first twitterbot.

For a while, I’ve been interested in Twitter robots – not spambots that auto-follow everyone who mentions Justin Bieber, but those that do something interesting with language or online data, such as Metaphor-a-minute, which uses the Wordnik API to generate random metaphors, or Library of Aleph, which tweets captions (without the photos) from the Library of Congress’s photo collection.

I’ve wanted to create a twitterbot, but didn’t think of an idea until this week while listening to one of my favorite songs, Elvis Costello’s “(What’s So Funny ’Bout) Peace, Love, and Understanding?”, and about to tweet (for the 2nd time) my favorite lines:

So where are the strong?
And who are the trusted?

It struck me that questions found in song lyrics could make a good Twitter account. Questions in song alternate between the profound:

– and the ridiculous:

A single line from a song can also be rich in memories and connotations. I now had my idea for my twitterbot.

How I Wrote It

There are a ton of “how to” options online. Because I want to learn more about Node.js, I chose this tutorial from Christian Paulsen to create the basic structure and functionality of the twitterbot.

Next, I needed questions. I put out a call on Facebook for my friends’ favorite questions from songs and ended up receiving more than 150 suggestions. I put all these into a text file and created a script that selects a random line and posts it on Twitter. If you’re interested in this sort of thing, I put the script on Github.

To automate posting the questions to Twitter, I downloaded LaunchControl, a small utility that lets you create and edit automated tasks on a Mac. Technically, LaunchControl just provides a GUI for Mac’s launchd process – see more here – but it makes launchd’s fairly confusing format much more readable. I have the script scheduled to run every three hours at the moment.

This process isn’t perfect – it runs whenever our computer is being used, but not if it’s asleep or off. So one of my next steps is to convert an old Mac into an always-on home server that can (among other things) run the Twitterbot 24–7. I’d also like to make the posting a bit less random by avoiding repeated questions too frequently or grouping some multiline questions together.

Overall, the project was very fast (started on Thursday night, finished by Saturday morning) and tremendous fun, and I’m collecting ideas for other bots. I’d like to try pulling texts from an API or a public domain source (Book of Common Prayer, perhaps?) for my next one.

Oh, and be sure to follow Lyrical Questions on Twitter.

The Inhumanity of Unmanned Drones

Let me begin with a disclaimer. I have never been in the military, and I have never been in a “kill or be killed” situation. That, however, is a trait I share with our last three presidents[1], so maybe my lack of combat experience doesn’t totally disqualify me from offering an opinion on this matter.

The use of unmanned drones to kill our enemies in war greatly concerns me, because it places such an enormous distance between combatants. There have been technological advantages in warfare for thousands of years — chariots, stirrups, the English long bow, firearms, and so on — but it wasn’t until the 20th century that one side could be removed from the battlefield and still cause enormous damage. Unmanned drones take this separation to a new level, with several dramatic consequences.

  • They reduce the human cost of waging war to zero. An unmanned drone can be piloted hundreds or thousands of miles away from the combat zone. A drone pilot can engage the enemy at no risk to his own safety. Isn’t this a good thing, though? No — the decision to go to war and kill other human beings ought to be something with enough risk to make it an option of last resort.
  • Without personal risk, the decision to wage war becomes deceptively easy. The discovery of Richard III’s body reminds us that, once upon a time, heads of state personally led their troops into battle. The cost of a foolish decision or poor preparation was often the monarch’s own life. We’ve come a long way from those day. With unmanned drones, presidents and prime ministers can send “troops” into battle without even the worry of seeing their citizens killed or wounded.
  • The human costs of war are disproportionately borne by one side of the battle. We find the accounts of war against women and infants in the Bible hard to stomach — and rightfully so. I don’t think we’re supposed to take pleasure in these measures. Today, however, we have the capability to wage the same kind of total devastation, without our soldiers even being present for the carnage.

Early in George R.R. Martin’s Game of Thrones, Ned Stark sentences a deserter to death and carries out the execution himself, beheading the man with his own sword. He even has his sons watch the execution, to drive home the brutal nature of his duty. In contrast, the king, Robert Baratheon, employs a full time executioner and usually does not even attend the executions he orders. We are meant to understand that one man understands the value of human life and the heavy cost of taking it, while the other treats his power over life and death casually and dishonorably. One of these men is a barbarian, and it’s not the one who wields the sword.

What do you think about unmanned drones in combat? If you disagree with me, let me know why.

  1. True, George W. Bush served in the Texas Air National Guard, but he never faced combat or even the risk of combat. Jimmy Carter was discharged from the Navy in 1953, which means it has now been 60 years since a future president was in active military service.  ↩

Why I Use Markdown to Write for the Web

One of my favorite single-purpose apps – Brett Terpstra’s Marked – is on-sale through Christmas. Marked allows you to preview documents written in Markdown as you write them, so that you can see what they will look like online. Each time you save the document, Marked automatically updates the HTML preview. When I’m using a dual-monitor to write for the web, I have Marked open on the second monitor as I write on the first.

When I tweeted about the Marked sale, my friend Matt Stauffer made me laugh with his reply:

He then asked me to write about why Markdown is practical. Over the last 18 months or so, I’ve become a Markdown convert. Here’s why and how I use Markdown.

What Is Markdown?

First, a brief description of Markdown, from its creator John Gruber:

Markdown is a text-to-HTML conversion tool for web writers. Markdown allows you to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML (or HTML).

If you, like me, were introduced to the Internet during the era of plain text emails and Usenet newsgroups, Markdown looks very, very similar to the rudimentary formatting used back then. Here are some simple examples. The following, written in Markdown:

##Heading  2
This text is **bold** and *italic*.  
I’m linking to [my website]( 
>; Ooh, a clever quote. 

becomes this when converted to HTML:

Heading 2

This text is bold and italic.

I’m linking to my website.


Ooh, a clever quote.

Here’s the full list of Markdown syntax. The variant of Markdown called MultiMarkdown allows you to do even more.

Why Do I Use Markdown?

Simplicity: Markdown uses plain text files, which means I can edit them using any app that writes and edits plain text. I’m not locked into a specific app, and I can be certain that my formatting will remain correct if I switch from one app to another. Further, because Markdown formatting is more compact and less intrusive than standard HTML, I can focus more easily on the text.

Continue reading