Get Eclipse to Recognize Your Android Device

I’m testing the waters of Android development. One of the first roadblocks was testing the app on the device (ie, without an emulator) using Eclipse’s “run” icon.

When I first plugged in my phone (via USB) and clicked “run”, among the list under “Choose a running Android device” was a single listing with a bunch of question marks (”??????????????”) where there should have been a serial number. The “OK” button was greyed-out and I was stuck.

To solve this, I first ensured the “adb” command was added to PATH. I added the following to bash.bashrc:
export PATH=$PATH:/home/my_username/android-sdk-linux_86/platform-tools/

On my phone, I went to settings > applications and checked “USB debugging”. Then in the terminal I ran adb wait-for-device, plugged in my phone, then ran adb devices. Sure enough, my HTC Droid Eris now has a serial number and will run from Eclipse. Now I need to figure out why my app keeps force closing.

If you don’t need to debug, read my previous post about using Dropbox to install an apk file.

Install apk files without USB

If you want to install an Android app (apk file) without going through the Android App Market, there’s a really simple solution:

Save the apk to your DropBox. Then, using the DropBox Android app, simply open the apk file and follow the install prompt. It worked perfectly for me, and took about 4 seconds. Another great use for DropBox.

Switching from old email software to MailChimp

As director of the Penn State Entrepreneurship Network (PSEN), I have been entrusted with managing the 300-plus person email list. The list-serve software provided by Penn State is abysmal. Its user interface is unintuitive and doesn’t provide any analytics. I decided to make the transition to MailChimp because of the powerful tools available “right out of the box”: tracking who opened emails, and of those, who clicked on the link within the email. These basic analytics allow for powerful user-segmentation. Out of 300 people, it would be nice to know who is engaged with PSEN activity, and who isn’t. MailChimp also offers dead-simple A/B testing. Essentially, MailChimp lets me know what I’m doing right and what I’m doing wrong in my campaigns.

Fortunately, MailChimp has an easy-to-use address import feature. Just upload a file of comma-separated email addresses, and you’re done. It’s that easy. Unfortunately, L-Soft has no export feature. For the benefit of others (hopefully), I’m posting the steps I took to liberate more than 300 email addresses from the clutches of L-Soft and into the warm embrace of MailChimp.

  1. Log into L-Soft and get all email addresses displayed on a single page
  2. Save the HTML of the page
  3. Extract addresses from the HTML and dump into a CSV file
  4. I used a simple Ruby script:

  5. Upload to MailChimp

A simple web service for Penn State’s Student Directory

Penn State maintains a public directory of all faculty and students at http://psu.edu/ph. Unfortunately, the directory uses POST requests, as opposed to GET requests. This makes integrating directory info into web apps difficult. For a small project I’m working on, I built a web service that lets a developer make GET requests. Simply input a PSU ID, and get the person’s full name in the response text.

The app is built using Mechanize to fill out the form, Nokogiri to parse the response, Sinatra to expose it to the web, and Heroku for hosting and deployment:

You can try it here.

Database documentation in 50 lines of Sinatra

If you want simple database documentation, check out the gist.

It’s only 50 lines of code, does one thing, but does it well.

Turning code into data with Ruby

As an application matures, storing parts of the application code as data empowers the developer. You can alter application behavior with the change of a configuration file rather than digging deep into the application code.

I’ll demonstrate this with a common pattern I’ve noticed, and hopefully you could apply the same principles to parts of your application.

Suppose we need to check to see between which two numbers a given value falls between. Here’s an obvious way to do it:

This works but is painful to alter. What if we want to add another range? Five ranges? 20 ranges? This pattern is full of boilerplate.

Here’s a much more manageable method:

Now the values for comparison are separated from the code that actually runs the comparison. Want to change any of the range values? Just alter the hash. But here’s the best part: combine this with ActiveRecord serialization:

—————————————
Quick tip about serialization: Ruby ranges do not get properly serialized. That’s why I convert them to arrays inside the hash.