General Geekery

Musings of an incurable technophile

Deleting Twitter Favorites

People use the favorites feature in Twitter differently. The way I use it, is to mark tweets that I want to look up later. I usually access Twitter on the phone, and many times I find interesting tweets that link to websites or articles. I mark these tweets as favorites, and later look them up in a desktop twitter client.

Over time this has left me with a huge number of tweets marked as favorites, and I was looking for an easy way to remove the favorite status from them. The prospect of going through them one by one was not a tempting option, as we are talking about hundreds and thousands of messages. I love to code in Ruby, and John Nunemaker has coded a twitter gem that wraps the Twitter API. From there it was but a short step to write a code snippet that did what I wanted:

unfavorite.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require "twitter"
require "yaml"
class Unfavorite
def configure
twitter_credentials = YAML.load_file("twitter_credentials.yml")["twitter"]
Twitter.configure do |config|
config.consumer_key = twitter_credentials["consumer_key"]
config.consumer_secret = twitter_credentials["consumer_secret"]
config.oauth_token = twitter_credentials["oauth_token"]
config.oauth_token_secret = twitter_credentials["oauth_token_secret"]
end
end
def get_favorites
favs = []
page_num = 1
begin
page = Twitter.favorites(:page => page_num)
favs += page
page_num += 1
end while page.size > 0
favs
end
def unfavorite(favorites)
favorites.each do |tweet|
Twitter.favorite_destroy tweet.id
end
end
end
uf = Unfavorite.new
uf.configure
favs = uf.get_favorites
uf.unfavorite favs

The code above is mostly self explanatory. To use it, you need to register as a developer on the Twitter website to get the required keys and token used for authorization. I am storing the twitter authorization information in a YAML file separate from the code, but for a snippet like this, the keys and tokens could easily be hardcoded directly in the configure method.

The structure of the YAML file is as follows:

twitter_credentials.yml
1
2
3
4
5
6
twitter:
consumer_key: [replace with key assigned from dev.twitter.com]
consumer_secret: [replace with secret assigned from dev.twitter.com]
oauth_token: [replace with token assigned from dev.twitter.com]
oauth_token_secret: [replace with secret assigned from dev.twitter.com]

I have found this code to be a very convenient way to clean up my Twitter favorites, and hopefully someone else can also find it of use.

Automatic Version Control of Important Text Files

On my system I have a variety of text files in different locations. I already use version control for source code that I write, but I thought that it would be good also to keep a history of these text files. I wanted to set up a system that could pick the files from their various locations, and join them in one repository that would be automatically updated in a version control system.

Quite some time ago I remembered reading on Cory Doctorow’s blog that he had set up a system for automatic version control of his writing, and that a friend of his had written a series of python scripts called flashbake to accomplish the task.

These scripts are available on github. They are a wrapper on top of git, so they require that git already is installed on the system. For me this was not an issue, since git is the version control tool I use daily.

In order to join the different files in the same directory, I created a new directory, and for each of the files I want to control, added a hard link to the original command using the ln command in the terminal.

The syntax for ln is simple:

ln syntax
1
$ ln /path/to/original_file link_name

What the command does is to create a synonym for the original file. To the operating system the link looks and behaves like a regular file. Changes to the file made in the original location is reflected in the link, and vice-versa.

With all the links created, I created a git repository in the directory and configured flashbake to keep an eye on the files. The flashbake website suggests using cron to run the script, but since I am on OSX, I created a launchd entry instead. Instead of creating a configuration file from scratch, I used the excellent Lingon app from Peter Borg, that makes it very easy to create launchd jobs.

Every 15 minutes flashbake now checks the files for changes, and commits them to the repository without me having to lift a finger. One of the files I back up is my daily todo-list, so now I have an automatic history of the tasks I do every day. As an added bonus flashbake has a plugin system for generating commit messages. There are plugins ranging from adding the current iTunes track to RSS and twitter feeds.

The system requires a little bit of fiddling to set up, but when it is in place, it is completely automatic.

Using a Wacom Tablet With Two Monitors on OSX

I recently hooked up a second monitor to my iMac so that I could have one window for documentation open while working on other things on my main monitor. I use a Wacom tablet for drawing, and I quickly noticed a problem. The tablet was now active for the entire extended workspace, while I want it to correspond to the main monitor only.

I opened up the preferences pane but could not immediately see a setting for this, so I googled a bit. All I saw were old posts stating that this was not doable with the (at the time) current Wacom driver.

Looking closer at the preference pane, I found a setting called “Mapping”, and on opening this, I could indeed see a setting to restrict the tablet to only work with one of the monitors.

[] [Wacom preferences]

Activating this setting makes the tablet work as I want, so that the entire tablet surface is dedicated to the primary monitor. To reach the second monitor, I have to use the mouse.

What Am I Doing?

I have a short attention span, and constantly keep juggling projects. Sometimes it is hard to remember what projects I have been working on lately.

I keep all my current projects in one project directory (imaginatively named ~/projects), so a directory listing sorted by date will show me what I have been working on.

I am doing this with some frequency, so I thought of a quicker way to show me this by creating an alias for recent projects called rp, which simply lists the directory contents by date, and limits the display to the first ten entries:

Recent projects
1
alias rp='ls -t ~/projects | head -10'

Now three keystrokes in any terminal window will show me what I have been working on lately. This is definitely not rocket science, but for me at least it has been very helpful.