Skip to content


HTML and SQL Basics Using A Ruby Web Scraper Example

In this lesson, we will learn some basics about two languages that are fundamental to how (many) web applications work – HTML and SQL. To make this a bit real, the goal of this exercise will be to write a script in Ruby that can do the following: look at the newest stories on Reddit, and insert into a local database the following information about the top 10 of those stories – the author, how many points it has, its category, its title, and the date it was posted.

HTML, or Hypertext Markup Language, is the syntax understood by most browsers. It has been around for over thirty years and was designed initially by Tim Berners-Lee (who recently appeared on the Internets pleading for your help in keeping the Internets open – go watch this video!)

SQL, or Structured Query Language, is used in creating and querying what are called “relational” databases – where the stored data refers to various objects that have relationships to each other (a typical example would be an e-commerce database, where products are related to the companies that sell them.)

Read More →

The Unsolved Mysteries Of The World

I was inspired by this blog post by Keir Clarke 1)who incidentally has more map visualizations of Google Auto Suggest behavior on how Google Auto Suggest was completing the query Why Is X So… for various state names (in the United States), to wonder what equivalent wisdom of the crowds Google had gathered for other placenames associated with where people live.

I thought it’d be a simple matter of feeding a list of city or country names to a Google API, and realized that there isn’t one – turns out that unlike Bing, Google isn’t so happy for the common consumer to share in all its indexy goodness. Well, no matter, I figured I wasn’t trying to build a commercial-grade application, so I could do just as well by scraping the contents of a browser, via Selenium and Ruby.

Read More →

References   [ + ]

Building Your Own Gem: Adventures in Ruby Programming

I just built my second gem – I thought I’d have written about the first, but somehow it escaped my attention. The first one is already on RubyGems, and generates a seed for you from the Weather Underground API by pulling together a string from some of the weather data on the feed.

When I started writing the second one, I realized that I didn’t remember the very first command I had run to create the gem’s template files – the gemspec, the lib/ and test/ folder, and so on. So here’s a quick round-up of some good tutorials on gem-cutters. I used bundle btw, and here’s a shameless plug: I’ve uploaded a slightly modified set of template files generated from bundle gem, with this one including the requisite files to write tests using minitest.

Read More →

Ruby Metaclasses Part II: Why @@ Is Not Really a “Class Variable”

We are on our way to understanding why Ruby has metaclasses. The short answer – TL;DR – is that metaclasses are necessary because Ruby implements class inheritance in a “flat way” – all classes derive from one class called (very plainly), Class. Class can’t hold all the methods that need to be inherited by the various classes in your program, so you need each class to have a special parent class – which is what the metaclass is.

Well, let’s get back to understanding all the details of class inheritance first. In our last lesson, we got to how we create “class instance variables.” Let us now figure out what the @@ notation is all about.

Read More →

Ruby Metaclasses: What Are They Good For? Part I

I’ve been playing around with Ruby for a while now, and I know that you can create meta-classes, but why this is a feature designed into the programming language hasn’t been very clear to me. Until today, when I found a use-case that really brought it home to me.

A critical part of understanding the reasoning behind having meta-classes was actually when I took some time to understand what the @ and @@ notations really do. A lot of tutorials and descriptions will say that this is the syntax for defining, respectively, “instance variables” and “class variables.” This isn’t entirely true.

Read More →

Rails App With Goodies: Adding Devise, CanCan And More Automatically

I have been teaching myself Rails now and listening to many of Ryan Bates’ most excellent Rails Casts, about which I cannot say enough good things.

I figured there’s usually a small list of things that most web apps tend to need, and if you’re a beginner Rails programmer like myself, you have probably spent some time trying to learn how to put all this code in. In fact, if you have RailsCast religion like I do, you have been probably copy pasting it from Ryan’s tutorials, except now you need to build a new app that does some other cool thing and you can’t remember all the Devise, CanCan, DoorKeeper, OAuth magic you painstakingly put together the first time around.

And even if you know these gems inside-out like the logo of your favorite brand of yogurt, and can paste in their configurations with both hands cuffed, wouldn’t it be nice to have a simpler way to do it?

Well, now you do! Head on over to this Github repo and quickly get Devise, CanCan and OmniAuth (with two providers – Facebook and Twitter!) running in your app.*

Read More →