Integrating Big Huge Thesaurus’s API into Lean Domain Search

Big Huge Thesaurus by John Watson provides an excellent thesaurus API that can be quickly integrated into any app.

The first step is to sign up for an API key which takes less than a minute. The API is free up to 10,000 requests per day and cheap if you need more than that.

After you fill out the required information the site will generate an API key for you which you can use to access the API.

Here’s a simplified example of how I’m using it with in Lean Domain Search via jQuery:

$.ajax({
  url : "http://words.bighugelabs.com/api/2/youapikey/" + word + "/json?callback=?", 
  dataType : 'json',
  complete : function(jqXHR, textStatus) {
    if (textStatus == 'parsererror') {
      // Did not find any synonyms
    }
  },
  success : function(data) {
    // Found synonyms
    alert(data);
  }
});

(View Gist)

Here’s an example of the returned JSON data for the word “open”:

Note that the results are broken up by part of speech (noun, adjective, etc) and are further broken up into groups (“ant” for antonyms, “rel” for related terms, “sim” for similar terms, “syn” for synonyms).

All in all it took about two hours to integrate the Big Huge Thesaurus API into Lean Domain Search and only because I added some extra functionality (sorting and filtering the synonym list, tracking what % of the searches are discovered via the synonym list, etc).

Here’s what Lean Domain Search looks like now — note the synonym list in the right column:

Click here to check out the results for “open”.

How to Automatically Back Up your Heroku site to Dropbox

This post will explain how you can configure your machine to automatically back up your Heroku site each night and save the bundle to your Dropbox folder.

At a high level, here’s how it works:

1) Each night at 11pm, a cron job executes a Ruby script that tells Heroku to create a bundle of your site

2) At midnight, the same script downloads the bundle and moves it to your backup folder, which can either be a local directory or your Dropbox folder

Creating and Downloading a Heroku Bundle

The following Ruby script does one of things depending on whether a bundle exists or not.

If a bundle does not exist, the script tells Heroku to create one. If one does exist, the script will download it and move it to your backup location.

Creating a bundle can take some time depending on how large your site is, so you should wait a while before running the script again to download it, which is why we’re going to tell the cron job to wait an hour before downloading it.

The script takes two arguments:

  1. The full path to your local Heroku application
  2. The full path of your backup folder

For example, here’s how I would have the script back up jMockups:

ruby heroku_backup.rb /Users/Matt/jmockups /Users/Matt/Dropbox/Backups/

This tells the script that my app is located in /Users/Matt/jmockups and I want to save the bundle to /Users/Matt/Dropbox/Backups/.

The code:

[ruby]

APP_DIR = ARGV[0]
BACKUP_DIR = ARGV[1]

# run a command from your app’s root directory
def cmd(str)
return `cd #{APP_DIR}; #{str}`.sub(10.chr, ”)
end

puts(‘* Determining bundle status…’)
status = cmd(‘heroku bundles’)

unless status.index("has no bundles.").nil?
# No bundle currently exists, so have Heroku create one
puts(‘*** Capturing bundle because none exist…’)
capture = cmd(‘heroku bundles:capture’)
else

bundle_name = status.split.first

unless status.index(‘complete’).nil?
puts(‘*** Bundle was captured successfully’)
puts(‘* Downloading bundle…’)

download = cmd(‘heroku bundles:download’)

puts("*** Moving #{bundle_name} to backup location…")
filename = download.split.last
newname = "#{bundle_name} (#{Time.now.strftime(‘%Y-%m-%d %H%M%S’)}).tar.gz"

move = `mv #{APP_DIR}/#{filename} "#{BACKUP_DIR}/#{newname}"`

puts(‘*** Destroying remote bundle…’)
destroy = cmd("heroku bundles:destroy #{bundle_name}")

puts(‘* Done’)

end

unless status.index(‘capturing’).nil?
puts(‘*** Still capturing. Try again in a bit…’)
end

end
[/ruby]

Automating the Backup Process with Cron

Once you’re convinced this works as advertised, you can automate this process with cron:

  1. Delete any existing bundles using the heroku bundles:destroy command. If you don’t the script will download the bundle at 11pm and capture it at midnight, which will work, but is probably opposite of what you intend
  2. At the command line, type crontab -e
  3. Add the following line to the crontab file, replacing the paths with your own:

0 0,23 * * * /usr/bin/ruby /Users/Matt/Documents/Backups/heroku_backup.rb /Users/Matt/jmockups /Users/Matt/Dropbox/Backups

This basically says “When the minute value of the current time is 0 and the hour is 0 or 23 (midnight or 11pm), use Ruby to run heroku_backup.rb with these parameters.

With automatic daily backups, you can rest easier by knowing that if your site gets obliterated things will suck a little bit less. And if you have additional sites, you can simply add multiple lines to the crontab file with the information for your other apps.

Plus, it beats paying $20/month for unlimited bundles with the Heroku addon. :)

Revolution

(I’m going to start going over the major projects I’ve worked on over the years.)

This project, dubbed Revolution, was my first major programming endeavor. I worked on it heavily in late 1998 and distinctly remember sending it to my friends in middle school and watching with pride as they used it to scroll massive amounts of text in random AOL chat rooms.

This was the reason I got into programming in the first place. My friend Jake sent me an AOL prog (program) and curious, I set out to learn how to build one.

The code is absolutely terrible and the only thing uglier is the design. It was a start.

Here’s some screen shots:

And here’s the menu hierarchy which shows all the exciting features:

I almost forgot about this program until I was going through some old 3.5″ disks and came upon it. I’m glad I did… I haven’t seen the words “Lagger” or “Punter” or “Fader” in many years.

Gotta love it.