Note: This guide is intended for the 9/20/2012 ONA practical programming class and is a work in progress. Feel free to add comments or visit the Github repo. Follow me at @dancow for updates.
Table of Contents
-
The problem: Programming is too hard and filled with too many technical details.The solution: First learn why programming relates to your goals and ideas. Then learn programming.
-
The problem: What do we use to write code?The solution: We’ll learn how to access our systems’ command line and install one of the free and excellent text editors ideal for writing code.
-
The problem: How do we install Ruby and run Ruby programs?The solution: With Google, StackOverflow, and a little patience.
-
The problem: How to gather and analyze U.S. Congressmembers tweetsThe solution: Use programming to avoid tedious, mind-numbing data-entry
-
The problem: How do we even put URLs into our programs?The solution: Use the String class to represent text characters.
-
The problem: The URLs all share common patterns. How do we combine these together?The solution: Strings can be added to other strings. But not all types of data can be combined together.
-
The problem: How do we actually download files off the Internet?The solution: The HTTParty gem provides methods to easily download from URLs.
-
The problem: How do we save files to our hard drive?The solution: Use the methods belonging to Ruby’s File class.
-
The problem: A lot of the text we’re using is repeated over and over.The solution: Use variables to store data for later reference in our programs.
-
The problem: Typing out the same steps to download and save files is becoming repetitive.The solution: Let’s write our own method to wrap these steps in a single call.
-
The problem: There’s a lot of boilerplate code that we’re writing over and over.The solution: Move the code into a separate text file and begin using our text-editor.
-
The problem: We’re doing the same thing, over and over, with just a minor change each time.The solution: Use a loop to repeat commands as many times as we need.
-
The problem: We need our loop to behave differently when it downloads an unwanted file.The solution: Use an if/else statement.
-
The problem: How do we put everything together into a smoothly-running routine?The solution: Review the techniques and concepts used so far.
-
The problem: We don’t want to manually enter each line of a datafile into our program.The solution: Read each line of a datafile into an Array object.
-
The problem: We need to pick out values from a given part of each data-lineThe solution: Turn each line into its own Array of values.
-
The problem: Arrays are cumbersome when trying to get the actual column of a given line.The solution: Use the FasterCSV library and Hash objects to simplify reading the datafile.
-
The problem: How do we deal with JSON data files?The solution: Use Arrays and Hashes to process JSON as easily as a spreadsheet
-
The problem: How do we find the Congressmember with the most tweets?The solution: Sort and aggregate data arrays using Ruby’s collection methods.
-
The problem: How does Twitter activity correlate with age and political prominence?The solution: Use methods and logic to filter on any attribute you’re interested in.
-
The problem: Who uses proper English when tweeting?The solution: Use simple text-pattern matching to filter tweets by content.
-
The problem: How do we publish our findings for the Web?The solution: Creating data-backed webpages is just more loops and methods.
-
The problem: How do we make interactive webpages?The solution: First, learn about HTML and Javascript. Then, break down your data-processing tasks like before.